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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	string a, b, c;
	if (!(cin >> a >> b >> c)) return 0;

	const int n = static_cast<int>(a.size());

	long long end0 = 0; 
	long long end1 = 0; 
	long long answer = 0;

	for (int i = 0; i < n; ++i) {
		const int da = a[i] - '0';
		const int db = b[i] - '0';
		const int dc = c[i] - '0';
		const int d = dc - da - db;

		const long long before0 = end0 + 1;
		const long long before1 = end1;

		long long next0 = 0;
		long long next1 = 0;

		if (d == 0) {
			next0 += before0; 
		} else if (d == 1) {
			next1 += before0; 
		} else if (d == -10) {
			next0 += before1; 
		} else if (d == -9) {
			next1 += before1; 
		}

		end0 = next0;
		end1 = next1;
		answer += end0;
	}

	cout << answer << '\n';
	return 0;
}