N = int(input()) if N >= 4: print("YES") elif N == 3: S = input() if S == "101" or S == "010": print("NO") else: print("YES") elif N == 2: S = input() if S == "01" or S == "10": print("NO") else: print("YES") else: print("NO")