n=int(input()) s=input() if n>3: print("YES") else: if "00" in s or "11" in s: print("YES") else: print("NO")