S = input()
N = len(S)

ans = 0
cnt = [0] * 2019
s=""

for i in range(N)[::-1]:
    s = "".join([S[i],s])
    cnt[int(s) % 2019] += 1

ans += cnt[0]
for i in range(1, 2019):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)
