program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,nl(0:2018),tmp,ans
    character(200000):: s

    read*, s
    n = len_trim(s)
    tmp=0
    nl(:) = 0
    nl(0) = 1
    do i=0,n-1
        tmp=mod(tmp+(ichar(s(n-i:n-i))-ichar('0'))*10**i,2019)
        nl(tmp)=nl(tmp)+1 
    end do

    ans=0
    do i=0,2018
        ans=ans+((nl(i)*(nl(i)-1))/2)
    end do

    print'(i0)', ans
end program 