import sys sys.set_int_max_str_digits(0) from itertools import groupby def runLengthEncode(S): # list でも str でも OK grouped = groupby(S) res = [] for k, v in grouped: res.append((k, int(len(list(v))))) return res N = int(input()) S = input() if len(runLengthEncode(S)) == N: # 01010 or 101010 # 4文字以上あったら 0101 or 1010 2文字のペア同士成立する if N >= 4: print('YES') else: print('NO') else: # 縮められる時点で YES print('YES')