_ = input() S = raw_input() print('NO' if S in set(['0', '1', '01', '10', '010', '101']) else 'YES')