

S = list(map(int, list(eval(input()))))



mod = 2019

ctr = [0] * mod

t = 0

for i, v in enumerate(reversed(S)):

    t = (t + int(v) * pow(10, i, mod)) % mod

    ctr[t] += 1



ans = ctr[0]

for v in ctr:

    ans += v * (v - 1) // 2

print(ans)



S = eval(input())



mod = 2019

ctr = [0] * mod

t = 0

for i, v in enumerate(reversed(S)):

    t = (t + int(v) * pow(10, i, mod)) % mod

    ctr[t] += 1



ans = ctr[0]

for v in ctr:

    ans += v * (v - 1) // 2

print(ans)

S = list(map(int, list(eval(input()))))
mod = 2019
ctr = [0] * mod
t = 0
for i, v in enumerate(reversed(S)):
    t = (t + int(v) * pow(10, i, mod)) % mod
    ctr[t] += 1
ans = ctr[0]
for v in ctr:
    ans += v * (v - 1) // 2
print(ans)

S = eval(input())
mod = 2019
ctr = [0] * mod
t = 0
for i, v in enumerate(reversed(S)):
    t = (t + int(v) * pow(10, i, mod)) % mod
    ctr[t] += 1
ans = ctr[0]
for v in ctr:
    ans += v * (v - 1) // 2
print(ans)

-S = list(map(int, list(eval(input())))) +S = eval(input())