n = input() s = input() a = "00" in s or "11" in s or "1010" in s or "0101" in s if a: print("YES") else: print("NO")