let () =
  let nlst = [0;1;2;3;4;5;6;7;8;9] in
  let rec charlist_of_string str n i =
    if i = n then [] else str.[i] :: charlist_of_string str n (i+1) in
  let rec search lst n i = match lst with
    | [] -> raise Not_found
    | h :: t -> if h = (int_of_char n)-48 then i else search t n (i+1) in
  let rec solve lst ans = match lst with
    | [] -> ans
    | h :: t -> solve t ((search nlst h 0) + ans) in
  Scanf.scanf "%s\n" @@ fun n ->
  let lst = charlist_of_string n (String.length n) 0 in
  Printf.printf "%s\n" (if (solve lst 0) mod 9 = 0 then "Yes" else "No") 