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
#include <cstdio>
#include <cstring>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REPD(i,n) FORD(i,0,n)

typedef long long LL;

char a[1000100], b[1000100], c[1000100];
bool out[1000100], p[1000100], q[1000100];

int main() {
	fgets(a, 1000100, stdin);
	fgets(b, 1000100, stdin);
	fgets(c, 1000100, stdin);
	int n = strlen(a);
	while (a[n - 1] < '0' || a[n - 1] > '9') --n;
	REP(i,n) {
		int aa = a[i] - '0', bb = b[i] - '0', cc = c[i] - '0';
		int s = (aa + bb) % 10;
		p[i] = cc == (s + 1) % 10;
		q[i] = aa + bb >= 10 || (aa + bb == 9 && p[i]);
		if (cc != s && !p[i]) out[i] = 1;
	}
	REP(i,n) if (!out[i] && q[i] && (!i || out[i - 1] || !p[i - 1])) out[i] = 1;
	REPD(i,n) if (!out[i] && p[i] && (i == n - 1 || out[i + 1] || !q[i + 1])) out[i] = 1;
	int x = 0;
	LL r = 0;
	out[n] = 1;
	REP(i,n+1) {
		if (out[i]) {
			r += (LL(x) * (x + 1)) >> 1;
			x = 0;
		} else if (!p[i]) ++x;
	}
	printf("%lld\n", r);
}