N = int(input()) S = input() print("YES" if N >= 4 or "00" in S or "11" in S else "NO")