s = input()[::-1]

l = len(s)

c = [0] * 2019

c[0] = 1

ten = 1

mod = 0

ans = 0



for i in range(l):

    mod = (mod + int(s[i]) * ten) % 2019

    ten = ten * 10 % 2019

    c[mod] += 1



for i in c:

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



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

c = [0] * 2019

c[0] = 1

mod = 0

ten = 1

ans = 0



for i in s:

    mod = (mod + int(i) * ten) % 2019

    ten = ten * 10 % 2019

    c[mod] += 1



for i in c:

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



print(ans)
s = input()[::-1]
l = len(s)
c = [0] * 2019
c[0] = 1
ten = 1
mod = 0
ans = 0
for i in range(l):
    mod = (mod + int(s[i]) * ten) % 2019
    ten = ten * 10 % 2019
    c[mod] += 1
for i in c:
    ans += i * (i - 1) // 2
print(ans)

s = input()[::-1]
c = [0] * 2019
c[0] = 1
mod = 0
ten = 1
ans = 0
for i in s:
    mod = (mod + int(i) * ten) % 2019
    ten = ten * 10 % 2019
    c[mod] += 1
for i in c:
    ans += i * (i - 1) // 2
print(ans)

-l = len(s) +mod = 0 -mod = 0 -for i in range(l): -    mod = (mod + int(s[i]) * ten) % 2019 +for i in s: +    mod = (mod + int(i) * ten) % 2019