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
def solve5(a, b, c):
    n = len(a)

    dp0 = 0
    dp1 = 0
    output = 0

    for i in range(n - 1, -1, -1):
        a1 = ord(a[i]) - 48
        b1 = ord(b[i]) - 48
        c1 = ord(c[i]) - 48

        ndp0 = 0
        ndp1 = 0

        s = a1 + b1
        if s % 10 == c1:
            if s // 10 == 0:
                ndp0 += dp0 + 1

            else:
                ndp1 += dp0 + 1

        s = a1 + b1 + 1
        if s % 10 == c1:
            if s // 10 == 0:
                ndp0 += dp1

            else:
                ndp1 += dp1

        dp0 = ndp0
        dp1 = ndp1

        output += dp0

    return output

a = input()
b = input()
c = input()
print(solve5(a, b, c))