from collections import defaultdict

def main():
  s = input()
  n = len(s)

  mod = 2019

  t_vals = [0] * n
  t_vals[-1] = int(s[-1])
  for i in range(2, n + 1):
    t_vals[-i] = t_vals[-i + 1] + int(s[-i]) * 10 ** (i - 1)

  counts = defaultdict(int)
  counts[0] = 1
  for t in t_vals:
    counts[t % mod] += 1

  ans = 0
  for count in counts.values():
    ans += count * (count - 1) // 2

  print(ans)

main()
