1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	string a, b, c;
	long long length, plus_counter = 0, res = 0, i, j;
	bool new_ten = false;
	cin >> a >> b >> c;
	length = a.size();

	for(i = length - 1; i >= 0; --i) {
		if(!new_ten) {
			if(a[i] + b[i] - '0' == c[i]) plus_counter++;
			else if(a[i] + b[i] - '0' - 10 == c[i]) new_ten = true, res -= plus_counter;
			else plus_counter = 0;
		}
		else {
			new_ten = false;
			if(a[i] + b[i] - '0' == c[i]) plus_counter = 1;
			else if(a[i] + b[i] - '0' - 10 == c[i]) plus_counter = 0, new_ten = true;
			else if(a[i] + b[i] - '0' + 1 == c[i]) plus_counter++;
			else if(a[i] + b[i] - '0' - 9 == c[i]) new_ten = true, res -= plus_counter;
			else plus_counter = 0;
		}
		res += plus_counter;
	}
	
	cout << res;
	return 0;
}