S = eval(input())

S = S[::-1]

d = 1

mods = [0]

counter = [0]*2019

counter[0] += 1

result = 0

for s in S:

  s = int(s)

  mods.append((mods[-1]+s*d)%2019)

  counter[mods[-1]] += 1

  result += counter[mods[-1]] - 1

  d *= 10

  d %= 2019



print(result)
S = eval(input())

S = S[::-1]

d = 1

mods = [0]

counter = [0]*2019

counter[0] += 1

for s in S:

  s = int(s)

  mods.append((mods[-1]+s*d)%2019)

  counter[mods[-1]] += 1

  d *= 10

  d %= 2019



print((sum([i*(i-1)//2 for i in counter])))

S = eval(input())
S = S[::-1]
d = 1
mods = [0]
counter = [0] * 2019
counter[0] += 1
result = 0
for s in S:
    s = int(s)
    mods.append((mods[-1] + s * d) % 2019)
    counter[mods[-1]] += 1
    result += counter[mods[-1]] - 1
    d *= 10
    d %= 2019
print(result)

S = eval(input())
S = S[::-1]
d = 1
mods = [0]
counter = [0] * 2019
counter[0] += 1
for s in S:
    s = int(s)
    mods.append((mods[-1] + s * d) % 2019)
    counter[mods[-1]] += 1
    d *= 10
    d %= 2019
print((sum([i * (i - 1) // 2 for i in counter])))

-result = 0 -    result += counter[mods[-1]] - 1 -print(result) +print((sum([i * (i - 1) // 2 for i in counter])))