local s=io.read()
local n=#s
local p=2019

local t={}
for i=1,p do
    t[i]=(i==1 and 1 or 0)
end

local combination=0
local digit=1
local smod=0
for i=n,1,-1 do
    local x=tonumber(s:sub(i,i))
    smod=(smod+x*digit)%p
    combination=combination+t[smod+1]
    t[smod+1]=t[smod+1]+1
    digit=(digit*10)%p
end
print(combination)