N = int(input()) S = input() if N >= 4: print('YES') elif '00' in S: print('YES') elif '11' in S: print('YES') else: print('NO')