N=int(input()) A=[*map(int,input().split())] R='Yes' for i in range(N-2): if A[i]==A[i+2] or A[i]==A[i+1]: break else: R='No' print(R)