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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define st first
#define nd second

void solve() {
    string A, B, C; cin >> A >> B >> C;
    int n = A.size();
    vector<int> type(n);
    for (int i = 0; i < n; i++) {
        int a = A[i]-'0', b = B[i]-'0', c = C[i]-'0';
        if (a + b == c) type[i] = 1;
        else if (a + b + 1 == c) type[i] = 2;
        else if (a + b == c + 10) type[i] = 4;
        else if (a + b + 1 == c + 10) type[i] = 3;
        else type[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        if ((type[i] >= 3) && ((i == 0 )|| (type[i-1] <= 1) || (type[i-1] == 4))) type[i] = 0;

    }
    for (int i = n-1; i >= 0; i--) {
        if (((type[i] == 3) || (type[i] == 2)) && ((i == n-1) || (type[i+1] <= 2))) type[i] = 0;   
    }
    ll ok_streak = 0;
    // int prev = 1;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int cur = type[i];
        // if (cur >= 3 && prev != 2) cur = 0;
        // else if (cur == 3 && prev == 2) cur = 2;
        // else if (cur == 4 && prev == 2) cur = 1;
        // else if (cur == 1 && prev == 2) {

        // }
        
        // cout << cur << ' ';
        if (cur == 1 || cur == 2) ok_streak++;
        if (cur == 0) {
            // cout << ok_streak << '\n';
            ans += ok_streak*(ok_streak+1)/2;
            ok_streak = 0;
        }
        // prev = cur;
    }
    ans += ok_streak*(ok_streak+1)/2;
    cout << ans << '\n';
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}