n=int(input()) s=input() print('YES' if '00' in s or '11' in s or '0101' in s or '1010' in s else 'NO')