def solve(n, A): if A.count(A[2]) != 1: return False if n <= 1: return False if A[0] == A[5]: return False return True n = int(input()) A = list(map(int, input().split())) if solve(n, A): print("YES") else: print("NO")