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
#include <iostream>
std::string a,b,c;
long long res=0;
int main(){
	std::cin>>a>>b>>c;
	long long pom=0;
	bool prze=false;
	for(int i=a.size();i>=0;i--){
		int roz=a[i]+b[i]-c[i]-'0';
		if(prze){
			if(roz==9)
				continue;
			if(roz==-1){
				prze=false;
				pom++;
			}else{
				res+=(pom*(pom+1))/2LL;
				if(roz==0)
					pom=1;
				else
					pom=0;
				if(roz==10)
					prze=true;
				else
					prze=false;
			}
		}else{
			if(roz==0){
				pom++;
			}else
			if(roz==10){
				prze=1;
			}else{
				res+=pom*(pom+1)/2LL;
				pom=0;
			}
		}
	}
	res+=(pom*(pom+1))/2LL;
	std::cout<<res<<std::endl;
}