import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) S = read().rstrip().decode() if N > 4: print('YES') exit() answer = 'NO' for T in ['00', '11', '0101', '1010']: if S.count(T): answer = 'YES' print(answer)