s = input()
n = len(s)
right = n-1
ans = 0

def count(s,i):
    counta = 0
    for left in range(n-i-3):
        k = int(s[left:n-i+1])
        if k%2019==0:
            counta += 1
    return counta


for i in range(2,n-2):
    ans += count(s,i-1)
print(ans)
