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