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