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
81
82
83
#include <bits/stdc++.h>
using namespace std;
#define fwd(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n)    fwd(i, 0, n)
#define all(X)       X.begin(), X.end()
#define sz(X)        int(size(X))
#define pb           push_back
#define eb           emplace_back
#define st           first
#define nd           second
using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;
using ld = long double;
#ifdef LOC
auto SS = signal(6, [](int) {
	*(int *)0 = 0;
});
#	define DTP(x, y)                                      \
		auto operator<<(auto &o, auto a)->decltype(y, o) { \
			o << "(";                                      \
			x;                                             \
			return o << ")";                               \
		}
DTP(o << a.st << ", " << a.nd, a.nd);
DTP(for (auto i : a) o << i << ", ", all(a));
void dump(auto... x) {
	((cerr << x << ", "), ...) << '\n';
}
#	define deb(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", dump(x)
#else
#	define deb(...) 0
#endif

int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	string a, b, c;
	cin >> a >> b >> c;
	long long res = 0;
	long long without_carry = 0, with_carry = 0;
	auto dp_step = [&](int a_val, int b_val, int c_val) {
		long long res_contribution = 0;
		long long new_without_carry = 0, new_with_carry = 0;
		// without carry
		if ((a_val + b_val) % 10 == c_val) {
			bool carry = (a_val + b_val) >= 10;
			if (carry) {
				res_contribution += with_carry;
				new_without_carry += with_carry;
			} else {
				res_contribution += without_carry + 1;
				new_without_carry += without_carry + 1;
			}
		}
		// with carry
		if ((a_val + b_val + 1) % 10 == c_val) {
			bool carry = (a_val + b_val + 1) >= 10;
			if (carry) {
				new_with_carry += with_carry;
			} else {
				new_with_carry += without_carry + 1;
			}
		}
		res += res_contribution;
		without_carry = new_without_carry;
		with_carry = new_with_carry;
	};
	rep(i, sz(a)) {
		int a_val = a[i] - '0';
		int b_val = b[i] - '0';
		int c_val = c[i] - '0';
		dp_step(a_val, b_val, c_val);
	}
	cout << res << "\n";
#ifdef LOCF
	cout.flush();
	cerr << "- - - - - - - - -\n";
	(void)!system(
		"grep VmPeak /proc/$PPID/status | sed s/....kB/\' MB\'/1 >&2"); // 4x.kB
																		// ....kB
#endif
	return 0;
}