program answer
  implicit none
  integer(16) :: N, i, a, b
  integer(16), allocatable :: s(:)
  read(*,*) N
  if(N==0) then
     write(*,*) 'Yes'
     stop
  end if
  
  do i = 1, 200000
     if(10**(i-1)<=N.and.N<10**i) then
        a=i
        allocate(s(a))
        exit
     end if
  end do

  do i = 1, a
     s(a-i+1)=int(N/10**(a-i))
     N=N-10**(a-i)*int(N/10**(a-i))
  end do

  if(mod(sum(s),9)==0) then
     write(*,*) 'Yes'
  else
     write(*,*) 'No'
  end if
  deallocate(s)
  stop
 end program answer