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

 
#define ll long long
#define ve vector
#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9+7, mod2 = 1e9+9;
 
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    string a, b, c;
    cin >> a >> b >> c;
    int n = a.size();
    ll res = 0;
    ll suma = 0, sumb = 0, sumc = 0;
    map<ve<ll>, ll> cnt;
    cnt[{0, 0}]++;
    ll pow10 = 1, pow102 = 1;
    ll suma2 = 0, sumb2 = 0, sumc2 = 0;
    for(int i = n-1; i >= 0; i--){
        suma = (suma + pow10*(a[i]-'0'))%mod;
        sumb = (sumb + pow10*(b[i]-'0'))%mod;
        sumc = (sumc + pow10*(c[i]-'0'))%mod;
        suma2 = (suma2 + pow102*(a[i]-'0'))%mod2;
        sumb2 = (sumb2 + pow102*(b[i]-'0'))%mod2;
        sumc2 = (sumc2 + pow102*(c[i]-'0'))%mod2;
        res += cnt[{(suma+sumb-sumc+mod)%mod, (suma2+sumb2-sumc2+mod2)%mod2}]++;
        pow10 = (pow10*10)%mod;
        pow102 = (pow102*10)%mod2;
    }
    cout << res << "\n";

}