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
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
#define pii pair<ll,ll>
#define vii vector<pair<ll,ll>>
#define vi vector<ll>
#define pll pair<ll, ll>
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define count_bits(x) __builtin_popcountll((x))
const ll M1 = 1e9+7;
const ll M2 = 999999937;
const ll INF = 1e9;
//mt19937 mt;void random_start(){mt.seed(chrono::time_poll_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

struct chash{
    int operator()(int x) const {return x ^ 104804094;}
};

map<pii, int> cnt;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string a, b, c;
    cin >> a >> b >> c;
    reverse(all(a));
    reverse(all(b));
    reverse(all(c));
    ll n = siz(a);
    ll x1 = 0;
    ll y1 = 0;
    ll x2 = 0;
    ll y2 = 0;
    ll p1 = 1;
    ll p2 = 1;
    ll ans = 0;
    cnt[{0,0}]++;
    for(ll i = 0; i < n; ++i){
        x1 += ((a[i] - '0') + (b[i] - '0') + 1) * p1;
        y1 += (c[i] - '0' + 1) * p1;
        p1 *= 10;
        p1 %= M1;
        x1 %= M1;
        y1 %= M1;

        x2 += ((a[i] - '0') + (b[i] - '0') + 1) * p2;
        y2 += (c[i] - '0' + 1) * p2;
        p2 *= 10;
        p2 %= M2;
        x2 %= M2;
        y2 %= M2;
        ll t1 = (x1-y1+M1)%M1;
        ll t2 = (x2-y2+M2)%M2;
        ans += cnt[{t1, t2}];
        cnt[{t1, t2}]++;
    }
    cout << ans << "\n";
    return 0;
}