import sys
data = sys.stdin.buffer.read().split()
a = data[0].strip()
b = data[1].strip()
c = data[2].strip()
n = len(a)
dp0 = 0
dp1 = 0
ans = 0
for k in range(n - 1, -1, -1):
da = a[k] - 48
db = b[k] - 48
dc = c[k] - 48
ndp0 = 0
ndp1 = 0
if dp0:
s = da + db
if s % 10 == dc:
if s >= 10:
ndp1 += dp0
else:
ndp0 += dp0
if dp1:
s = da + db + 1
if s % 10 == dc:
if s >= 10:
ndp1 += dp1
else:
ndp0 += dp1
s = da + db
if s % 10 == dc:
if s >= 10:
ndp1 += 1
else:
ndp0 += 1
dp0, dp1 = ndp0, ndp1
ans += dp0
print(ans)
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 | import sys data = sys.stdin.buffer.read().split() a = data[0].strip() b = data[1].strip() c = data[2].strip() n = len(a) dp0 = 0 dp1 = 0 ans = 0 for k in range(n - 1, -1, -1): da = a[k] - 48 db = b[k] - 48 dc = c[k] - 48 ndp0 = 0 ndp1 = 0 if dp0: s = da + db if s % 10 == dc: if s >= 10: ndp1 += dp0 else: ndp0 += dp0 if dp1: s = da + db + 1 if s % 10 == dc: if s >= 10: ndp1 += dp1 else: ndp0 += dp1 s = da + db if s % 10 == dc: if s >= 10: ndp1 += 1 else: ndp0 += 1 dp0, dp1 = ndp0, ndp1 ans += dp0 print(ans) |
English