s_l = list(eval(input()))

n = len(s_l)



# 公式解説参照

dp_dict = {0:1}

t = 0

for i in range(n):

    a = int(s_l[-(i+1)])

    t = (t + a*(pow(10,i,2019)))%2019

    dp_dict[t] = dp_dict.get(t,0) + 1



ans = 0

for val in list(dp_dict.values()):

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



print(ans)

s_l = list(eval(input()))

n = len(s_l)



# 公式解説参照

dp_dict = {0:1}

t = 0

x = 1

for i in range(n):

    a = int(s_l[-(i+1)])

    t = (t + a*x)%2019

    x = x*10 %2019

    dp_dict[t] = dp_dict.get(t,0) + 1



ans = 0

for val in list(dp_dict.values()):

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



print(ans)

s_l = list(eval(input()))
n = len(s_l)
# 公式解説参照
dp_dict = {0: 1}
t = 0
for i in range(n):
    a = int(s_l[-(i + 1)])
    t = (t + a * (pow(10, i, 2019))) % 2019
    dp_dict[t] = dp_dict.get(t, 0) + 1
ans = 0
for val in list(dp_dict.values()):
    ans += val * (val - 1) // 2
print(ans)

s_l = list(eval(input()))
n = len(s_l)
# 公式解説参照
dp_dict = {0: 1}
t = 0
x = 1
for i in range(n):
    a = int(s_l[-(i + 1)])
    t = (t + a * x) % 2019
    x = x * 10 % 2019
    dp_dict[t] = dp_dict.get(t, 0) + 1
ans = 0
for val in list(dp_dict.values()):
    ans += val * (val - 1) // 2
print(ans)

+x = 1 -    t = (t + a * (pow(10, i, 2019))) % 2019 +    t = (t + a * x) % 2019 +    x = x * 10 % 2019