N = int(input()) S = '10' * (N // 2) T = '01' * (N // 2) if N % 2: S += '1' T += '0' if input() in (S, T): print('NO') else: print('YES')