s=eval(input())

n=len(s)

mod=2019

d=0

p=1

ml=[0]*mod

for i in range(1,n+1):

  k=int(s[-i])

  d+=p*k

  d%=mod

  ml[d]+=1

  p*=10

  p%=mod

ans=0

for i in ml:

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

print((ans+ml[0]))
S = input()[::-1]



m = 2019

cnt = [0] * m

cnt[0] = 1

total = 0

x = 1

ans = 0



for i in range(len(S)):

    total += int(S[i])*x

    total %= m

    cnt[total] += 1

    x = 10*x

    x %= m



for i in range(2019):

    ans += cnt[i]*(cnt[i]-1)//2



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

S = input()[::-1]
m = 2019
cnt = [0] * m
cnt[0] = 1
total = 0
x = 1
ans = 0
for i in range(len(S)):
    total += int(S[i]) * x
    total %= m
    cnt[total] += 1
    x = 10 * x
    x %= m
for i in range(2019):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

-s = eval(input()) -n = len(s) -mod = 2019 -d = 0 -p = 1 -ml = [0] * mod -for i in range(1, n + 1): -    k = int(s[-i]) -    d += p * k -    d %= mod -    ml[d] += 1 -    p *= 10 -    p %= mod +S = input()[::-1] +m = 2019 +cnt = [0] * m +cnt[0] = 1 +total = 0 +x = 1 -for i in ml: -    ans += i * (i - 1) // 2 -print((ans + ml[0])) +for i in range(len(S)): +    total += int(S[i]) * x +    total %= m +    cnt[total] += 1 +    x = 10 * x +    x %= m +for i in range(2019): +    ans += cnt[i] * (cnt[i] - 1) // 2 +print(ans)