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
#include <iostream>
#include <algorithm>

using namespace std;

using ll = long long;

constexpr ll max_n = 1000100;

ll n;

ll fwd[2];
ll nxt[2];

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

	std::string a, b, c;

	cin >> a >> b >> c;

	std::reverse(a.begin(), a.end());
	std::reverse(b.begin(), b.end());
	std::reverse(c.begin(), c.end());

	n = a.size();
	ll res = 0;
	for(int i = 0; i < n; i++) {
		fwd[0] ++;
		for(int d = 0; d < 2; d++) {
			int add = a[i] - '0' + b[i] - '0' + d;
			if (add % 10 == c[i] - '0') {
				nxt[add / 10] = fwd[d];
			}
		}
		for(int d = 0; d < 2; d++) {
			fwd[d] = nxt[d];
			nxt[d] = 0;
		}
		res += fwd[0];
	}
	cout << res;
}