N = int(input()) S = input() print('NO' if S in {'1', '0', '10', '01', '101', '010'} else 'YES')