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
//fast
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define all(x) x.begin(),x.end()
#define rep(n) for (int i = 0 ; i<n ; i++)
#define pb push_back

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	string a,b,c;
	cin >> a >> b >> c;
	int n = a.size();
	int pocz[2] = {0,0};
	ll w = 0;
	rep(n){
		int x = a[i]+b[i]-'0'-'0';
		if (x<9){
			if (x==c[i]-'0'){
				pocz[0]++;
				w+=pocz[0];
				pocz[1] = 0;
			}else if (x+1==c[i]-'0'){
				pocz[1] = pocz[0]+1;
				pocz[0] = 0;
			}else{
				pocz[0] = 0;
				pocz[1] = 0;
			}
		}else if (x==9){
			if (x==c[i]-'0'){
				pocz[0]++;
				w+=pocz[0];
				pocz[1] = 0;
			}else if (c[i]-'0'==0){
				pocz[0] = 0;
			}else{
				pocz[0] = 0;
				pocz[1] = 0;
			}
		}else{
			if (x%10==c[i]-'0'){
				w+=pocz[1];
				pocz[0] = pocz[1];
				pocz[1] = 0;
			}else if ((x%10)+1==c[i]-'0'){
				pocz[0] = 0;
			}else{
				pocz[0] = 0;
				pocz[1] = 0;
			}
		}
	}
	cout << w;
}