program multiple_of_2019
  implicit none
  character(200000) :: s
  integer :: n, d, k, i, j, l = 0
  integer(8) :: dp(0:1,0:2018) = 0, c(0:2018) = 0
  read(*,*) s
  n = len_trim(s)
  do i = 1, n
    l = 1-l
    dp(l,:) = 0
    d = ichar(s(i:i))-48
    do j = 0, 2018
      k = mod(10*j+d,2019)
      dp(l,k) = dp(l,k)+dp(1-l,j)
      c(j) = c(j)+dp(1-l,j)
    end do
    dp(l,d) = dp(l,d)+1
  end do
  write(*,'(i0)') c(0)+dp(l,0)
end program multiple_of_2019