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
63
64
65
#include <iostream>
#include <string>

using namespace std;

class BajtekZdolnyMatematyk {
    string a;
    string b;
    string c;
    int n;

public:
    BajtekZdolnyMatematyk(const string& a_input, const string& b_input, const string& c_input) {
        a = a_input;
        b = b_input;
        c = c_input;
        n = a.size();
    }

    long long ile_razy_bajtek_mial_racje() {
        long long total_pairs = 0;

        long long ways0 = 0;
        long long ways1 = 0;

        for (int i = n - 1; i >= 0; --i) {
            int d = (c[i] - '0') - (a[i] - '0') - (b[i] - '0');

            long long next_ways0 = 0;
            long long next_ways1 = 0;

            if (d == 0) {
                next_ways0 = 1 + ways0;
            } else if (d == 1) {
                next_ways0 = ways1;
            } else if (d == -10) {
                next_ways1 = 1 + ways0;
            } else if (d == -9) {
                next_ways1 = ways1;
            }

            ways0 = next_ways0;
            ways1 = next_ways1;

            total_pairs += ways0;
        }

        return total_pairs;
    }
};

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

    string a_input, b_input, c_input;
    if (cin >> a_input >> b_input >> c_input) {

        BajtekZdolnyMatematyk sprawdzian(a_input, b_input, c_input);

        cout << sprawdzian.ile_razy_bajtek_mial_racje() << endl;
    }

    return 0;
}