S = input()[::-1]

P = [0]*(len(S)+1)

for i,j in enumerate((S)):

    P[i+1] = (P[i] + int(j)*pow(10,i,2019))%2019

 

dp = [0]*2019

for i in P:

    dp[i%2019] += 1

print((sum([i*(i-1)//2 for i in dp])))
S = input()[::-1]



mods = [0]*2019

mods[0] += 1

f = 0

for i in range(len(S)):

    f = (f+pow(10,i,2019)*int(S[i]))%2019

    mods[f] += 1



print((sum([i*(i-1)//2 for i in mods])))
S = input()[::-1]
P = [0] * (len(S) + 1)
for i, j in enumerate((S)):
    P[i + 1] = (P[i] + int(j) * pow(10, i, 2019)) % 2019
dp = [0] * 2019
for i in P:
    dp[i % 2019] += 1
print((sum([i * (i - 1) // 2 for i in dp])))

S = input()[::-1]
mods = [0] * 2019
mods[0] += 1
f = 0
for i in range(len(S)):
    f = (f + pow(10, i, 2019) * int(S[i])) % 2019
    mods[f] += 1
print((sum([i * (i - 1) // 2 for i in mods])))

-P = [0] * (len(S) + 1) -for i, j in enumerate((S)): -    P[i + 1] = (P[i] + int(j) * pow(10, i, 2019)) % 2019 -dp = [0] * 2019 -for i in P: -    dp[i % 2019] += 1 -print((sum([i * (i - 1) // 2 for i in dp]))) +mods = [0] * 2019 +mods[0] += 1 +f = 0 +for i in range(len(S)): +    f = (f + pow(10, i, 2019) * int(S[i])) % 2019 +    mods[f] += 1 +print((sum([i * (i - 1) // 2 for i in mods])))