main :-
	read_num(N),
	read_n_num_list(N, L),
	more_than_three_same(L, 0),
	write('Yes'),
	nl,
	halt.
main :- write('No'),
	nl,
	halt.

more_than_three_same(_, N) :-
        N >= 3,
        !.
more_than_three_same([], _) :-
        false.
more_than_three_same([[HA, HB]|T], _) :-
        HA =\= HB,
        !,
        more_than_three_same(T, 0).
more_than_three_same([[HA, HB]|T], N) :-
        HA =:= HB,
        NewN is N + 1,
        !,
        more_than_three_same(T, NewN).


read_n_num_list(Num, List) :-
	read_n_num_list_aux(Num, [], List),
	!.
read_n_num_list_aux(0, List, List).
read_n_num_list_aux(Num, Old, Accum) :-
	read_num(NewItem1),
        read_num(NewItem2),
	NewNum is Num - 1,
	append(Old, [[NewItem1, NewItem2]], NewList),
	read_n_num_list_aux(NewNum, NewList, Accum).
	

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

read_num(N) :-
	read_str(S),
	number_string(N, S).

