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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <deque>
#include <tuple>
#include <bitset>

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define st first
#define nd second
#define x first
#define y second

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<ll> vll;
typedef tuple<ll, ll, ll> tll;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string As, Bs, Cs;

    cin >> As >> Bs >> Cs;

    vi A(As.length());
    vi B(Bs.length());
    vi C(Cs.length());

    transform(As.begin(), As.end(), A.begin(), [](char c){
        return c - '0';
    });

    transform(Bs.begin(), Bs.end(), B.begin(), [](char c){
        return c - '0';
    });


    transform(Cs.begin(), Cs.end(), C.begin(), [](char c){
        return c - '0';
    });


    ll cur_group = 0;
    ll ans = 0;
    int carry=0;

    for(int i=A.size()-1; i>=0; i--){
        int d = (A[i]+B[i]);
        if((d+carry)%10==C[i]){
            if((d+carry)>=10){
                carry=1;
            }else{
                carry=0;
                cur_group++;
            }
        }else{
            ans+=(1l+cur_group)*cur_group/2;
            carry=0;
            cur_group = 0;

            if(d%10==C[i]){
                if(d>=10){
                    carry=1;
                }else{
                    carry=0;
                    cur_group++;
                }
            }
        }
    }
    ans+=(1l+cur_group)*cur_group/2;
    cout << ans << "\n";

    return 0;
}