program main
  implicit none
  integer(16) i, add
  character(200000) N, M
  read(*, *) N
  M = trim(N)
  add = 0
  do i = 1,len(M)
    if (M(i:i) == '1') then
      add = add + 1
    elseif (M(i:i) == '2') then
      add = add + 2
    elseif (M(i:i) == '3') then
      add = add + 3
    elseif (M(i:i) == '4') then
      add = add + 4
    elseif (M(i:i) == '5') then
      add = add + 5
    elseif (M(i:i) == '6') then
      add = add + 6
    elseif (M(i:i) == '7') then
      add = add + 7
    elseif (M(i:i) == '8') then
      add = add + 8
    elseif (M(i:i) == '9') then
      add = add + 9
    end if
  end do
  if (mod(add,9) == 0) then
    write(*, *) 'Yes'
  else
    write(*, *) 'No'
  end if
  !read(*, *) (L(i), i = 1,N)

  write(*, *)
end program main
