# coding: utf-8

S = eval(input())

ans = 0

P = 2019

N = len(S)

S = S[::-1]

dp = [0 for _ in range(N)]

d = {}

for i in range(N):

    dp[i] = int(S[i]) * pow(10, i, P) % P

for i in range(N-1):

    dp[i+1] += dp[i]

    dp[i+1] %= P

dp[-1] %= P

for i in range(N):

    if dp[i] not in d:

        if dp[i] == 0:

            ans += 1

        d[dp[i]] = 1

    else:

        if dp[i] == 0:

            ans += 1

        ans += d[dp[i]]

        d[dp[i]] += 1

print(ans)
# coding: utf-8

S = eval(input())

ans = 0

P = 2019

N = len(S)

S = S[::-1]

cnt = [0 for _ in range(P)]

cnt[0] = 1

v = 0

bai = 1

for i in range(N):

    v = (v + int(S[i]) * bai) % P

    bai *= 10

    bai %= P

    cnt[v] += 1

for i in range(P):

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

print(ans)
# coding: utf-8
S = eval(input())
ans = 0
P = 2019
N = len(S)
S = S[::-1]
dp = [0 for _ in range(N)]
d = {}
for i in range(N):
    dp[i] = int(S[i]) * pow(10, i, P) % P
for i in range(N - 1):
    dp[i + 1] += dp[i]
    dp[i + 1] %= P
dp[-1] %= P
for i in range(N):
    if dp[i] not in d:
        if dp[i] == 0:
            ans += 1
        d[dp[i]] = 1
    else:
        if dp[i] == 0:
            ans += 1
        ans += d[dp[i]]
        d[dp[i]] += 1
print(ans)

# coding: utf-8
S = eval(input())
ans = 0
P = 2019
N = len(S)
S = S[::-1]
cnt = [0 for _ in range(P)]
cnt[0] = 1
v = 0
bai = 1
for i in range(N):
    v = (v + int(S[i]) * bai) % P
    bai *= 10
    bai %= P
    cnt[v] += 1
for i in range(P):
    ans += ((cnt[i] - 1) * cnt[i]) // 2
print(ans)

-dp = [0 for _ in range(N)] -d = {} +cnt = [0 for _ in range(P)] +cnt[0] = 1 +v = 0 +bai = 1 -    dp[i] = int(S[i]) * pow(10, i, P) % P -for i in range(N - 1): -    dp[i + 1] += dp[i] -    dp[i + 1] %= P -dp[-1] %= P -for i in range(N): -    if dp[i] not in d: -        if dp[i] == 0: -            ans += 1 -        d[dp[i]] = 1 -    else: -        if dp[i] == 0: -            ans += 1 -        ans += d[dp[i]] -        d[dp[i]] += 1 +    v = (v + int(S[i]) * bai) % P +    bai *= 10 +    bai %= P +    cnt[v] += 1 +for i in range(P): +    ans += ((cnt[i] - 1) * cnt[i]) // 2