S = input()[::-1]



m = 2019

cnt = [0] * m

cnt[0] = 1

total = 0

x = 1

ans = 0



for i in range(len(S)):

    total += int(S[i])*x

    total %= m

    cnt[total] += 1

    x = 10*x

    x %= m



for i in range(2019):

    ans += cnt[i]*(cnt[i]-1)//2



print(ans)
S = input()[::-1]

 

cnt = [0] * 2019

cnt[0] = 1

total = 0

x = 1

ans = 0

 

for a in S:

    total += int(a) * x

    total %= 2019

    cnt[total] += 1

    x = x*10

    x %= 2019

 

for i in range(2019):

    ans += cnt[i]*(cnt[i]-1)//2

 

print(ans)
S = input()[::-1]
m = 2019
cnt = [0] * m
cnt[0] = 1
total = 0
x = 1
ans = 0
for i in range(len(S)):
    total += int(S[i]) * x
    total %= m
    cnt[total] += 1
    x = 10 * x
    x %= m
for i in range(2019):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

S = input()[::-1]
cnt = [0] * 2019
cnt[0] = 1
total = 0
x = 1
ans = 0
for a in S:
    total += int(a) * x
    total %= 2019
    cnt[total] += 1
    x = x * 10
    x %= 2019
for i in range(2019):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

-m = 2019 -cnt = [0] * m +cnt = [0] * 2019 -for i in range(len(S)): -    total += int(S[i]) * x -    total %= m +for a in S: +    total += int(a) * x +    total %= 2019 -    x = 10 * x -    x %= m +    x = x * 10 +    x %= 2019