program main
  implicit none
  integer(8) :: n, i, dig, cnt(0:2018), res
  integer(8), allocatable :: d(:)
  integer(8), parameter :: m = 2019
  character(200000) :: s
  read *, s
  n = len(trim(s))
  allocate (d(n))

  read (s(n:n), *) dig
  cnt = 0
  cnt(0) = 1
  d(n) = dig
  cnt(d(n)) = cnt(d(n)) + 1
  do i = n - 1, 1, -1
    read (s(i:i), *) dig
    d(i) = d(i + 1) + pow(10_8, n - i) * dig
    d(i) = modulo(d(i), m)
    cnt(d(i)) = cnt(d(i)) + 1
  end do

  res = 0
  do i = 0, 2018
    res = res + cnt(i) * (cnt(i) - 1) / 2
  end do
  print "(i0)", res
  contains

  recursive function pow(n, p) result(res)
    integer(8), intent(in) :: n, p
    integer(8) :: res
    if (p == 0) then
      res = 1
    else if (modulo(p, 2_8) == 0) then
      res = modulo(pow(n, p / 2) ** 2, m)
    else
      res = modulo(pow(n, p - 1) * n, m)
    end if
  end function pow
end program main
