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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
#define e using u=ostream;template<class a,class b>u&operator<<(u&o,pair<a,b>&x)
using namespace std;e;u&operator<<(u&o,string&s){return o<<s.c_str();}template<
class t>auto operator<<(u&o,t&x)->decltype(x.end(),o){o<<'{';int i=2;for(auto y:
x)o<<", "+i<<y,i=0;return o<<'}';}e{return o<<'('<<x.first<<", "<<x.second<<')';}
#ifdef DEBUG
#define LOG(x...)cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<'\n';}(x)
#else
#define LOG(...)
#endif
#define ff first
#define ss second
#define ll long long

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

	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	int n = (int)s1.size();
	vector <int> l1(n), l2(n), l3(n);
	for (int i = 0; i < n; i++) {
		l1[i] = s1[n-i-1] - '0';
		l2[i] = s2[n-i-1] - '0';
		l3[i] = s3[n-i-1] - '0';
	}
	vector <int> sum12(n);
	for (int i = 0; i < n; i++) {
		sum12[i] = l1[i] + l2[i];
	}
	vector <int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		if (sum12[i] < 9)
			a[i] = 0;
		else if (sum12[i] == 9)
			a[i] = -1;
		else
			a[i] = 1;
	}
	for (int i = 0; i < n; i++) {
		if (l3[i] == sum12[i] % 10)
			b[i] = 0;
		else if (l3[i] == (sum12[i] + 1) % 10)
			b[i] = 1;
		else
			b[i] = -1;
	}

	vector <ll> dp0(n+1), dp1(n+1);
	for (int i = 0; i < n; i++) {
		if (b[i] == 0) {
			if (a[i] == 1) {
				dp0[i+1] = 0;
				dp1[i+1] = dp0[i] + 1;
			}
			else {
				dp0[i+1] = dp0[i] + 1;
				dp1[i+1] = 0;
			}
		}
		else if (b[i] == 1) {
			if (a[i] == 1 || a[i] == -1) {
				dp0[i+1] = 0;
				dp1[i+1] = dp1[i];
			}
			else {
				dp0[i+1] = dp1[i];
				dp1[i+1] = 0;
			}
		}
	}
	LOG(dp0);
	LOG(dp1);
	ll res = 0;
	for (auto i : dp0) {
		res += i;
	}
	cout << res << "\n";
}