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
#include <cassert>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
#define all(a) begin(a), end(a)

vector<int> read() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = s[i] - '0';
    }
    return a;
}

void solve() {
    auto a = read(), b = read(), c = read();
    int n = a.size();
    vector<ll> dp(2);
    dp[0] = 1;

    ll res = 0;
    for (int i = 0; i < n; i++) {
        vector<ll> nxt(2);

        for (int d = 0; d <= 1; d++) {
            int x = a[i] + b[i] + d;
            if (x % 10 != c[i]) {
                continue;
            }

            bool over = x >= 10;
            nxt[d] += dp[over];
        }

        res += nxt[0];
        nxt[0] += 1;
        dp = nxt;
    }
    cout << res << "\n";
}

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

    int q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
}