s = input()
from collections import Counter
x = 1
mod = 2019
total = 0
ans = 0
cnt = Counter()
for i in range(len(s)-1,0,-1):
    cnt[total] += 1
    total = int(s[i::])%mod
    ans += cnt[total]
print(ans)