import collections

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
def ConN(i):
    n_num = int(i*(i-1)/2)
    return n_num

S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [0]*len(S) 
modcount=[]
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[i] = A_num 
    keta*=10
    
c = collections.Counter(mod)
x += ConZ(mod.count(0))
modcount=list(c.values())
#print(mod)
#print(modcount)
k = 0

for j in range(len(modcount)):
    if modcount[j] >=2:
        x+=ConN(modcount[j])
print(x)