program dm
    implicit none
    character(2*10**5)::S
    integer(16)::A(0:2018,2)
    integer(16)::ANS=0
    integer::i,j
    read*,S
    A=0
    do i=1,len_trim(S)
        do j=0,2018
            A(mod(j*10+ichar(S(i:i))-ichar("0"),2019),2)=A(j,1)
        end do
        A(ichar(S(i:i))-ichar("0"),2) = A(ichar(S(i:i))-ichar("0"),2)+1
        ANS=ANS+A(0,2)
        A(:,1)=A(:,2)
        A(:,2)=0
    end do
    print"(i0)",ANS
contains
end program dm