# coding: utf-8



s=eval(input())

ans=0

p = 2019

n = len(s)

s=s[::-1]

accum=[0]*n

d=dict()

for i in range(n):

    accum[i]=int(s[i])*pow(10,i,p)%p

for i in range(n-1):

    accum[i+1]+=accum[i]

    accum[i+1]%=p

accum[-1]%=p

    #print(accum)

for i in range(n):

    if accum[i] not in d:

        if accum[i]==0:

            ans+=1

        d[accum[i]]=1

    else:

        if accum[i]==0:

            ans+=1

        ans+=d[accum[i]]

        d[accum[i]]+=1

    #print(d)

print(ans)

# coding: utf-8



S = eval(input())

P = 2019

N = len(S)

num = [0] * P

num[0] = 1

c = 0

ans = 0

dgt = 1

for i in range(N-1, -1, -1):

    c = (c + int(S[i]) * dgt) % P

    dgt *= 10

    dgt %= P

    ans += num[c]

    num[c] += 1

 

print(ans)
# coding: utf-8
s = eval(input())
ans = 0
p = 2019
n = len(s)
s = s[::-1]
accum = [0] * n
d = dict()
for i in range(n):
    accum[i] = int(s[i]) * pow(10, i, p) % p
for i in range(n - 1):
    accum[i + 1] += accum[i]
    accum[i + 1] %= p
accum[-1] %= p
# print(accum)
for i in range(n):
    if accum[i] not in d:
        if accum[i] == 0:
            ans += 1
        d[accum[i]] = 1
    else:
        if accum[i] == 0:
            ans += 1
        ans += d[accum[i]]
        d[accum[i]] += 1
    # print(d)
print(ans)

# coding: utf-8
S = eval(input())
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N - 1, -1, -1):
    c = (c + int(S[i]) * dgt) % P
    dgt *= 10
    dgt %= P
    ans += num[c]
    num[c] += 1
print(ans)

-s = eval(input()) +S = eval(input()) +P = 2019 +N = len(S) +num = [0] * P +num[0] = 1 +c = 0 -p = 2019 -n = len(s) -s = s[::-1] -accum = [0] * n -d = dict() -for i in range(n): -    accum[i] = int(s[i]) * pow(10, i, p) % p -for i in range(n - 1): -    accum[i + 1] += accum[i] -    accum[i + 1] %= p -accum[-1] %= p -# print(accum) -for i in range(n): -    if accum[i] not in d: -        if accum[i] == 0: -            ans += 1 -        d[accum[i]] = 1 -    else: -        if accum[i] == 0: -            ans += 1 -        ans += d[accum[i]] -        d[accum[i]] += 1 -    # print(d) +dgt = 1 +for i in range(N - 1, -1, -1): +    c = (c + int(S[i]) * dgt) % P +    dgt *= 10 +    dgt %= P +    ans += num[c] +    num[c] += 1