s = eval(input())

#s = '9' * 200000



mod = [1] + [0]*2018

t = 0

a = 1

n = len(s)

s = s[::-1]

for i in range(n):

    t = (t + int(s[i])*a) % 2019

    a = a * 10 % 2019

    mod[t] += 1

ans = 0

for i in range(2019):

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

print(ans)
s = eval(input())

#s = '9' * 200000



mod = [1] + [0]*2018

t, a, n = 0 , 1, len(s)

s = s[::-1]

for i in range(n):

    t = (t + int(s[i])*a) % 2019

    a = a * 10 % 2019

    mod[t] += 1

ans = 0

for i in range(2019):

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

print(ans)
s = eval(input())
# s = '9' * 200000
mod = [1] + [0] * 2018
t = 0
a = 1
n = len(s)
s = s[::-1]
for i in range(n):
    t = (t + int(s[i]) * a) % 2019
    a = a * 10 % 2019
    mod[t] += 1
ans = 0
for i in range(2019):
    ans += mod[i] * (mod[i] - 1) // 2
print(ans)

s = eval(input())
# s = '9' * 200000
mod = [1] + [0] * 2018
t, a, n = 0, 1, len(s)
s = s[::-1]
for i in range(n):
    t = (t + int(s[i]) * a) % 2019
    a = a * 10 % 2019
    mod[t] += 1
ans = 0
for i in range(2019):
    ans += mod[i] * (mod[i] - 1) // 2
print(ans)

-t = 0 -a = 1 -n = len(s) +t, a, n = 0, 1, len(s)