S = input()
a = []
b = [0]*2019
c = 0
d = 0
for n in range(len(S)):
    c += 10*n*int(S[-n-1])
    a.append(c%2019)
for n in range(len(S)):
    b[a[n]] += 1
for n in range(2019):
    d += int(b[n]*(b[n]-1)/2)
print(d)