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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ans, dpj, dpz;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    string a, b, c;
    cin >> a >> b >> c;

    for (int i = a.size()- 1; i >= 0; i--) {
        ll p = a[i] - '0', d = b[i] - '0', ce = c[i] - '0', nz = 0, nj = 0;

        if (p + d == ce) {
            nz += dpz + 1;
            ans += dpz + 1;
        }

        if (p + d == ce + 10) nj += dpz + 1;

        if (p + d + 1 == ce) {
            nz += dpj;
            ans += dpj;
        }

        if (p + d + 1 == ce + 10) nj += dpj;

        dpz = nz;
        dpj = nj;
    }

    cout << ans;
    return 0;
}