from collections import Counter

S = input()
S = S[::-1]
base = 2019
count = 0
mod_list = [0]
ten = 1
for i in range(len(S)):
    mod = (ten*int(S[i]))%base
    mod_list.append((mod+mod_list[i])%base)
    ten*= 10
    ten%= base

c = Counter(mod_list)

for i in range(2019):
    num = c[i]
    count += num*(num-1)//2
print(count)
