let () =
  let rec charlist_of_string str n i =
    if i = n then [] else str.[i] :: charlist_of_string str n (i+1) in
  Scanf.scanf "%s\n" @@ fun n ->
  let lst = List.tl (List.rev (charlist_of_string n (String.length n) 0)) in
  let sum = List.fold_left (fun ans c -> ans + (int_of_char c)) 0 lst in
  Printf.printf "%s\n" (if sum mod 9 = 0 then "Yes" else "No")