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