N = input() S = raw_input() print 'YES' if '00' in S or '11' in S or '1010' in S or '0101' in S else 'NO'