def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

S = input()
L = len(S)
S = S[::-1]

T = [-1]*L
mod = 2019
now = 0
for i in range(L):
    s = S[i]
    now += int(s)*pow(10,i,mod)
    T[i] = now%mod
    
Nlist = [0]*2019
Nlist[0] = 1

for i in T:
    Nlist[i] += 1
    
ans = 0
for i in Nlist:
    ans += i*(i-1)//2
print(ans)