N = int(input()) S = input() yes = N >= 4 or S.find('00') != -1 or S.find('11') != -1 print('YES' if yes else 'NO')