program sample
    implicit none
    character(200000)::s,t
    integer(8) :: i,j,k,m,n
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)
  
    read(*,*) s
    m=0
    n=len_trim(s)
    do i=1,n
        read(s(i:i),*)a
        m=m+a
    end do
    if(mod(m,9)==0)then
        write(*,*)'Yes'
    else
        write(*,*)'No'
    end if

    stop
end program sample
  

