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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3

import sys

DEBUG = 0


def main():
    x = [int(x) for x in input()]
    y = [int(x) for x in input()]
    z = [int(x) for x in input()]

    result = 0
    cont_c0_count = 0
    cont_c1_count = 0
    for i in range(len(x) - 1, -1, -1):
        s = x[i] + y[i]

        new_cont_c0_count = 0
        new_cont_c1_count = 0

        if cont_c0_count:
            d_cont = s
            c_cont = 0
            if d_cont >= 10:
                d_cont -= 10
                c_cont = 1
            if d_cont == z[i]:
                if c_cont == 0:
                    result += cont_c0_count
                    new_cont_c0_count += cont_c0_count
                else:
                    new_cont_c1_count += cont_c0_count

        if cont_c1_count:
            d_cont = s + 1
            c_cont = 0
            if d_cont >= 10:
                d_cont -= 10
                c_cont = 1
            if d_cont == z[i]:
                if c_cont == 0:
                    result += cont_c1_count
                    new_cont_c0_count += cont_c1_count
                else:
                    new_cont_c1_count += cont_c1_count

        cont_c0_count = new_cont_c0_count
        cont_c1_count = new_cont_c1_count

        d_here = s
        c_here = 0
        if d_here >= 10:
            d_here -= 10
            c_here = 1
        if d_here == z[i]:
            if c_here == 0:
                result += 1
                cont_c0_count += 1
            else:
                cont_c1_count += 1

        debugprint(f"{s=}")

    debugprint(f"{x=}")
    debugprint(f"{y=}")
    debugprint(f"{z=}")
    print(result)


if DEBUG:

    def debugprint(*args, **kwargs):
        print(*args, **kwargs)

else:

    def debugprint(*args, **kwargs):
        pass


if __name__ == "__main__":
    if len(sys.argv) == 2:
        sys.stdin = open(sys.argv[1])
    main()