from collections import Counter

S = list(reversed(eval(input())))

l = len(S)

N = 0

counts = Counter([(N := N + (pow(10, i, 2019) * int(S[i])) % 2019) % 2019 for i in range(l)] + [0])

print((sum(n * (n - 1) // 2 for n in list(counts.values()))))

from collections import Counter

l = len(S := eval(input()))

counts = Counter((n := (n + (d := d * 10 % 2019) * int(S[-i])) % 2019 if i else (n := 0 * (d := 202)) for i in range(l + 1)))

print((sum(n * (n - 1) // 2 for n in list(counts.values()))))

from collections import Counter

S = list(reversed(eval(input())))
l = len(S)
N = 0
counts = Counter(
    [(N := N + (pow(10, i, 2019) * int(S[i])) % 2019) % 2019 for i in range(l)] + [0]
)
print((sum(n * (n - 1) // 2 for n in list(counts.values()))))

from collections import Counter

l = len(S := eval(input()))
counts = Counter(
    (
        n := (n + (d := d * 10 % 2019) * int(S[-i])) % 2019
        if i
        else (n := 0 * (d := 202))
        for i in range(l + 1)
    )
)
print((sum(n * (n - 1) // 2 for n in list(counts.values()))))

-S = list(reversed(eval(input()))) -l = len(S) -N = 0 +l = len(S := eval(input())) -    [(N := N + (pow(10, i, 2019) * int(S[i])) % 2019) % 2019 for i in range(l)] + [0] +    ( +        n := (n + (d := d * 10 % 2019) * int(S[-i])) % 2019 +        if i +        else (n := 0 * (d := 202)) +        for i in range(l + 1) +    )