from collections import Counter



MOD = 2019

S = eval(input())

S = tuple(map(int, reversed(S)))

counter = Counter()

digit = 1

cumsum = 0

ans = 0



for i in range(len(S)):

    counter[cumsum] += 1

    cumsum += (S[i] * digit) % MOD

    cumsum %= MOD

    ans += counter[cumsum]

    digit *= 10

    digit %= MOD



print(ans)

from collections import Counter



MOD = 2019

S = eval(input())

S = tuple(map(int, reversed(S)))

counter = Counter([0])

digit = 1

cumsum = 0



for i in range(len(S)):

    cumsum += S[i] * digit % MOD

    cumsum %= MOD

    counter[cumsum] += 1

    digit = digit * 10 % MOD



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

from collections import Counter

MOD = 2019
S = eval(input())
S = tuple(map(int, reversed(S)))
counter = Counter()
digit = 1
cumsum = 0
ans = 0
for i in range(len(S)):
    counter[cumsum] += 1
    cumsum += (S[i] * digit) % MOD
    cumsum %= MOD
    ans += counter[cumsum]
    digit *= 10
    digit %= MOD
print(ans)

from collections import Counter

MOD = 2019
S = eval(input())
S = tuple(map(int, reversed(S)))
counter = Counter([0])
digit = 1
cumsum = 0
for i in range(len(S)):
    cumsum += S[i] * digit % MOD
    cumsum %= MOD
    counter[cumsum] += 1
    digit = digit * 10 % MOD
print((sum([v * (v - 1) // 2 for v in list(counter.values())])))

-counter = Counter() +counter = Counter([0]) -ans = 0 +    cumsum += S[i] * digit % MOD +    cumsum %= MOD -    cumsum += (S[i] * digit) % MOD -    cumsum %= MOD -    ans += counter[cumsum] -    digit *= 10 -    digit %= MOD -print(ans) +    digit = digit * 10 % MOD +print((sum([v * (v - 1) // 2 for v in list(counter.values())])))