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
#include<bits/stdc++.h>
using namespace std;
string a,b,c;
int d[1000009], e[1000009], f[1000009];
int main()
{
    ios_base::sync_with_stdio(0);
    cin>>a>>b>>c;
    int n = a.length();
    //cerr<<"n="<<n<<endl;
    for(int i=n;i>0;i--)
    {
        int sum = a[i-1]-48+b[i-1]-48;
        d[i]=sum % 10;
        e[i]+=sum % 10;
        e[i-1]+=sum/10;
        f[i]=c[i-1]-48;
    }
    long long otwarte=0;
    long long result=0;
    long long tmpresult=0;
    for(int i=n;i>0;i--)
    {
        if (e[i]!=f[i])
        {
            otwarte=0;
            //cerr<<"i="<<i<<" otwarte=0"<<endl;;
        }
        tmpresult+=otwarte;
        //cerr<<"i="<<i<<" result+="<<otwarte<<endl;
        if (d[i]==f[i] )
        {
            otwarte++;
            //cerr<<"i="<<i<<" otwarte++"<<endl;;
            if(a[i-1]+b[i-1]-48-48<10)
            {
                tmpresult++;
                result+=tmpresult;
                tmpresult=0;
                //cerr<<"special case result++. result="<<result<<endl;
            }
        }
    }
    cout<<result<<endl;
    return 0;
}