S = eval(input())

ans = 0

mods = [0] * 2019

mods[0] = 1

curr = 0

x = 1

for d in S:

    curr = curr * 10 + int(d)

    ans += mods[curr * x % 2019]

    mods[curr * x % 2019] += 1

    x = x * 202 % 2019

    curr %= 2019

print(ans)

S = eval(input())

ans = 0

mods = [0] * 2019

mods[0] = 1

curr = 0

x = 1

for d in reversed(S):

    curr = (curr + int(d) * x) % 2019

    ans += mods[curr % 2019]

    mods[curr % 2019] += 1

    x = x * 10 % 2019

print(ans)

S = eval(input())
ans = 0
mods = [0] * 2019
mods[0] = 1
curr = 0
x = 1
for d in S:
    curr = curr * 10 + int(d)
    ans += mods[curr * x % 2019]
    mods[curr * x % 2019] += 1
    x = x * 202 % 2019
    curr %= 2019
print(ans)

S = eval(input())
ans = 0
mods = [0] * 2019
mods[0] = 1
curr = 0
x = 1
for d in reversed(S):
    curr = (curr + int(d) * x) % 2019
    ans += mods[curr % 2019]
    mods[curr % 2019] += 1
    x = x * 10 % 2019
print(ans)

-for d in S: -    curr = curr * 10 + int(d) -    ans += mods[curr * x % 2019] -    mods[curr * x % 2019] += 1 -    x = x * 202 % 2019 -    curr %= 2019 +for d in reversed(S): +    curr = (curr + int(d) * x) % 2019 +    ans += mods[curr % 2019] +    mods[curr % 2019] += 1 +    x = x * 10 % 2019