main :-
	read_num(N),
	sum_of_digit(N, S),
        R is S mod 9,
        R =:= 0,
        !,
	write('Yes'),
	nl.
main :-
        write('No'),
        nl.

sum_of_digit(Num, Sum) :-
	sum_of_digit_aux(Num, 0, Sum), !.
sum_of_digit_aux(Num, Accum, Sum) :-
	Num > 0,
	M is Num mod 10,
	NewAccum is Accum + M,
	NewNum is Num // 10,
	sum_of_digit_aux(NewNum, NewAccum, Sum).
sum_of_digit_aux(_, Sum, Sum).



read_str(S) :-
        read_string(current_input, ' \n', '', _, S).
 
read_num(N) :-
	read_str(S),
	number_string(N, S).

:- main.
