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
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    int n = a.size();
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        d[i] = (c[i]-'0') - (a[i]-'0') - (b[i]-'0');
    }

    i64 res = 0;
    for (int i = 0; i < n;) {
        int j = i, m = 0;
        while (j < n) {
            if (d[j] == 0) {
                j++, m++;
            } else if (d[j] == 1) {
                int k = j+1;
                while (k < n && d[k] == -9) k++;
                if (k < n && d[k] == -10) {
                    j = k+1, m++;
                } else {
                    j = k-1; break;
                }
            } else {
                break;
            }
        }
        res += i64(m)*(m+1) / 2;
        i = j+1;
    }
    cout << res << '\n';
}