n = int(input()) s = input() ans = "YES" if s in ["0","1","01","10","010","101"]: ans = "NO" print(ans)