from collections import Counter

S = eval(input())

C = Counter()

MOD = 2019



n = 0

for i, s in enumerate(S[::-1]):

    s = int(s)

    n += pow(10, i, MOD) * s % MOD

    C[n % MOD] += 1



C[0] += 1

ans = 0

for v in list(C.values()):

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

print(ans)

from collections import Counter

S = list(map(int, list(eval(input()))))

A = [0]

for i, s in enumerate(S[::-1]):

    A.append((A[-1] + s * pow(10, i, 2019)) % 2019)

print((sum([v * (v - 1) // 2 for v in list(Counter(A).values())])))

from collections import Counter

S = eval(input())
C = Counter()
MOD = 2019
n = 0
for i, s in enumerate(S[::-1]):
    s = int(s)
    n += pow(10, i, MOD) * s % MOD
    C[n % MOD] += 1
C[0] += 1
ans = 0
for v in list(C.values()):
    ans += v * (v - 1) // 2
print(ans)

from collections import Counter

S = list(map(int, list(eval(input()))))
A = [0]
for i, s in enumerate(S[::-1]):
    A.append((A[-1] + s * pow(10, i, 2019)) % 2019)
print((sum([v * (v - 1) // 2 for v in list(Counter(A).values())])))

-S = eval(input()) -C = Counter() -MOD = 2019 -n = 0 +S = list(map(int, list(eval(input())))) +A = [0] -    s = int(s) -    n += pow(10, i, MOD) * s % MOD -    C[n % MOD] += 1 -C[0] += 1 -ans = 0 -for v in list(C.values()): -    ans += v * (v - 1) // 2 -print(ans) +    A.append((A[-1] + s * pow(10, i, 2019)) % 2019) +print((sum([v * (v - 1) // 2 for v in list(Counter(A).values())])))