local s=io.read()
local map={[0]=1}
for i=#s,1,-1 do
    local n=tonumber(s:sub(i))
    n=n%2019
    map[n]=(map[n] or 0)+1
end
local counter=0
for k,v in pairs(map) do
    counter=counter+v*(v-1)//2
end
print(counter)