S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i])*10**(N-i-1))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1
ans = cnt[0]
for i in range(1,p):
  if cnt[i] > 0:
    ans += cnt[i]-1

print(ans)