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
import sys

a = sys.stdin.buffer.readline().strip()
b = sys.stdin.buffer.readline().strip()
c = sys.stdin.buffer.readline().strip()

n = len(a)

ans = 0
cnt_out0 = 0
prev_req = -2  

for i in range(n):
    da = a[i] - 48
    db = b[i] - 48
    dc = c[i] - 48

    s = da + db


    if s % 10 == dc:
        req = 0
        out = s // 10
    elif (s + 1) % 10 == dc:
        req = 1
        out = (s + 1) // 10
    else:
        req = -1
        out = 2   

    if i == 0 or prev_req != out:
        cnt_out0 = 0

    if out == 0:
        cnt_out0 += 1

    if req == 0:
        ans += cnt_out0

    prev_req = req

print(ans)