local s = io.read()
local t = {}
for i = 1, 2019 do
  t[i] = 0
end
t[2019] = 1
local mul = 1
local v = 0
local ret = 0
for i = #s, 1, -1 do
  v = v + mul * (s:sub(i, i):byte() - 48)
  v = v % 2019
  if v == 0 then
    ret = ret + t[2019]
    t[2019] = t[2019] + 1
  else
    ret = ret + t[v]
    t[v] = t[v] + 1
  end
  mul = (mul * 10) % 2019
end
print(ret)
