from collections import Counter

S = input()[::-1]



memo = [0]

d = 0

mod = 2019



for s in S:

    tmp = int(s) * pow(10, d, mod) % mod

    tmp = memo[-1] + tmp

    memo.append(tmp % mod)

    d += 1



c = Counter(memo)

ans = sum(v * (v - 1) // 2 for v in list(c.values()))

print(ans)
from collections import defaultdict

S = eval(input())

N = len(S)



memo = defaultdict(int)

memo[0] += 1



mod = 2019

d = 1

val = 0



for s in S[::-1]:

    s = int(s)

    val += s * d

    val %= mod

    memo[val] += 1

    d *= 10

    d %= mod



print((sum(v * (v - 1) // 2 for v in list(memo.values()))))
from collections import Counter

S = input()[::-1]
memo = [0]
d = 0
mod = 2019
for s in S:
    tmp = int(s) * pow(10, d, mod) % mod
    tmp = memo[-1] + tmp
    memo.append(tmp % mod)
    d += 1
c = Counter(memo)
ans = sum(v * (v - 1) // 2 for v in list(c.values()))
print(ans)

from collections import defaultdict

S = eval(input())
N = len(S)
memo = defaultdict(int)
memo[0] += 1
mod = 2019
d = 1
val = 0
for s in S[::-1]:
    s = int(s)
    val += s * d
    val %= mod
    memo[val] += 1
    d *= 10
    d %= mod
print((sum(v * (v - 1) // 2 for v in list(memo.values()))))

-from collections import Counter +from collections import defaultdict -S = input()[::-1] -memo = [0] -d = 0 +S = eval(input()) +N = len(S) +memo = defaultdict(int) +memo[0] += 1 -for s in S: -    tmp = int(s) * pow(10, d, mod) % mod -    tmp = memo[-1] + tmp -    memo.append(tmp % mod) -    d += 1 -c = Counter(memo) -ans = sum(v * (v - 1) // 2 for v in list(c.values())) -print(ans) +d = 1 +val = 0 +for s in S[::-1]: +    s = int(s) +    val += s * d +    val %= mod +    memo[val] += 1 +    d *= 10 +    d %= mod +print((sum(v * (v - 1) // 2 for v in list(memo.values()))))