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>
using namespace std;
using ind = long long;
using cind = const ind;
#define FOR(i,l,r) for(int i = (l); i <= (r); i++)
#define FORD(i,l,r) for(int i = (l); i >= (r); i--)

ind v[1'000'002];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
string s1;
string s2;
string s3;
cin >> s1 >> s2 >> s3;
ind N;
N = s1.size();
FOR(i,0,N-1) v[i] = s1[i] + s2[i] - s3[i] - '0';
ind s=0;
ind prev=0;
ind wyn=0;
FORD(i,N-1,0){

ind now = v[i];

if(prev==0){
if(now==0){ s++; continue;}
if(now==10){prev=9; continue;}
wyn += s*(s+1)/2; s=0;
prev=0; continue;
}

if(prev==9){
if(now==9) continue;
if(now==-1){
s++;
prev=0;
continue;
}
if(now==10){
wyn += s*(s+1)/2;
prev=9;
s=0;
continue;
}
if(now==0){
wyn += s*(s+1)/2;
s=1;
prev=0;
continue;
}
wyn += s*(s+1)/2;
prev=0;
s=0;
continue;
}

}

wyn += s*(s+1)/2; s=0;
cout << wyn << endl;
}

//3 10 0 9 10 -9


//0 10 9 -1