N = int(input()) S = input() if S in ("0","1","01","10","101","010"): print ("NO") else: print ("YES")