program main
      implicit none
      character(200000) :: s
      integer(4) :: n, i, j, k, sum, ans, m
      integer(4) :: cnt(0:2018)
      integer, parameter :: asciicode = 48

      read *, s
      n = len(trim(s))
      cnt(:) = 0
      sum = 0
      do i = n, 1, -1
        m = ichar(s(i:i)) - asciicode
        if ( m == 0 ) cycle
        do j = 0, n-i
          if ( j == 0 ) then
            m = mod(m,2019)
          else
            m = mod(10*m,2019)
          end if
        end do
        sum = sum + m
        k = mod(sum,2019)
        sum = k
        cnt(k) = cnt(k) + 1
      end do

      ans = cnt(0)
      do i = 1, 2018
       ans = ans + cnt(i) * ( cnt(i)-1 ) / 2
      end do
      print *, ans
end program main
