s=input()
N=len(s)
kyonen=2019
modlist=[int(s[-1])%kyonen]
t=0
for i in range(2,N+1):
    modlist.append((modlist[-1]+int(s[(-1)*i])*10**(i-1))%kyonen)
modlist.sort()
now=modlist[0]
nowc=1
ans=0
if modlist[0]==0:
    ans+=1
for i in range(1,N):
    if modlist[i]==0:
        ans+=1
    if modlist[i]==now:
        nowc+=1
    else:
        if nowc>=2:
            ans+=int(nowc*(nowc-1)/2)
        nowc=1
        now=modlist[i]

if nowc>=2:
    ans+=int(nowc*(nowc-1)/2)

print(ans)