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
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    string pierwsza, druga, trzecia;
    cin >> pierwsza >> druga >> trzecia;

    int n = pierwsza.size();   
    
    ll wynik = 0;
    vector<ll> ile(2, 0), ile2(2, 0); 
    
    for (int i = n-1; i >= 0; i--) {
        ile[0] += 1;

        int p = pierwsza[i] - '0';
        int d = druga[i] - '0';
        int t = trzecia[i] - '0';

        ile2[0] = 0;
        ile2[1] = 0;
        
        int s = p + d;
        if (s % 10 == t) {
            ile2[s/10] += ile[0];
        }

        int s2 = p + d + 1;
        if (s2 % 10 == t) {
            ile2[s2/10] += ile[1];
        }

        wynik += ile2[0];
        ile = ile2;
    }

    cout << wynik;

    return 0;
}