s=eval(input())

s=s[::-1]

n=len(s)



count=[0]*2019

count[0]=1

num,d=0,1



for i in s:

  num+=int(i)*d

  num%=2019

  d*=10

  d%=2019

  count[num]+=1



ans=0

for i in count:

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

  

print(ans)

s = eval(input())

s = s[::-1]

n = len(s)



num = [0]*2019

num[0] = 1

number = 0

d = 1



for i in s:

    number += int(i)*d

    num[number%2019] += 1

    d *= 10

    d %= 2019



ans = 0



for i in num:

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



print(ans)
s = eval(input())
s = s[::-1]
n = len(s)
count = [0] * 2019
count[0] = 1
num, d = 0, 1
for i in s:
    num += int(i) * d
    num %= 2019
    d *= 10
    d %= 2019
    count[num] += 1
ans = 0
for i in count:
    ans += i * (i - 1) // 2
print(ans)

s = eval(input())
s = s[::-1]
n = len(s)
num = [0] * 2019
num[0] = 1
number = 0
d = 1
for i in s:
    number += int(i) * d
    num[number % 2019] += 1
    d *= 10
    d %= 2019
ans = 0
for i in num:
    ans += i * (i - 1) // 2
print(ans)

-count = [0] * 2019 -count[0] = 1 -num, d = 0, 1 +num = [0] * 2019 +num[0] = 1 +number = 0 +d = 1 -    num += int(i) * d -    num %= 2019 +    number += int(i) * d +    num[number % 2019] += 1 -    count[num] += 1 -for i in count: +for i in num: