A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.

You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0, 0, 0, 1, 1, 1, 0, 0, 0] can be a photo of zebra, while the photo [0, 0, 0, 1, 1, 1, 1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not?


-----Input-----

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the width of the photo.

The second line contains a sequence of integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 1) — the description of the photo. If a_{i} is zero, the i-th column is all black. If a_{i} is one, then the i-th column is all white.


-----Output-----

If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO".

You can print each letter in any case (upper or lower).


-----Examples-----
Input
9
0 0 0 1 1 1 0 0 0

Output
YES

Input
7
0 0 0 1 1 1 1

Output
NO

Input
5
1 1 1 1 1

Output
YES

Input
8
1 1 1 0 0 0 1 1

Output
NO

Input
9
1 1 0 1 1 0 1 1 0

Output
NO



-----Note-----

The first two examples are described in the statements.

In the third example all pixels are white, so the photo can be a photo of zebra.

In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Implementation


Solutions:
len = int(input())
line = input().split(' ')
cnt = 1
i = 1
while i < len:
	if line[i] != line[i - 1]:
		cnt = cnt + 1
	i = i + 1
need_len = len // cnt
if need_len * cnt != len:
	print('NO')
else:
	i = 0
	while i < len:
		size = 0
		if int(line[i]) == 1:
			while i < len and int(line[i]) == 1:
				i = i + 1
				size = size + 1
		else:
			while i < len and int(line[i]) == 0:
				i = i + 1
				size = size + 1
		if size != need_len:
			print('NO')
			i = len + 100
	if i - 10 < len:
		print('YES')


def f():
	N = int(input())
	if N == 1:
		print('YES')
		return
	strZebza = input().split(' ')
	if strZebza[-1] == ' ' or strZebza[-1] == '\n':
		del strZebza[-1]
	mass = [int(el) for el in strZebza]
	if mass[0] == 1:
		startColour = 1
		secondColour = 0
	else:
		startColour = 0
		secondColour = 1
	ind = 1
	while True:
		if mass[ind] != startColour:
			break
		ind += 1
		if ind == N:
			print('YES')
			return
	size = ind
	if N % size != 0:
		print('NO')
		return
	for i in range(int(N / size)):
		a = sum(mass[i * size:(i + 1) * size])
		if i % 2 != 0:
			if a != secondColour * size:
				print('NO')
				return
		elif a != startColour * size:
			print('NO')
			return
	print('YES')
	return
f()


arri = lambda : [int(s) for s in input().split()]
n = int(input())
a = arri()
last = a[0]
fixed = -1
l = 0
f = True
for i in a:
	if last == i:
		l += 1
	else:
		if fixed == -1:
			fixed = l
		elif l != fixed:
			f = False
			break
		l = 1
	last = i
if l != fixed and fixed != -1:
	f = False
print('Yes' if f else 'No')


n = int(input())
l = [int(x) for x in input().split()]
l.append(not l[-1])
cnt = l.index((l[0] + 1) % 2)
cnt2 = 1
for i in range(1, n + 1):
	if i == n or l[i] != l[i - 1]:
		if cnt2 != cnt:
			print('NO')
			exit(0)
		cnt2 = 1
	else:
		cnt2 += 1
print('YES')


def solve():
	n = int(input())
	p = [int(x) for x in input().split()]
	c = dict()
	cnt = 0
	for i in range(n):
		if i == 0:
			cnt += 1
			continue
		if p[i] == p[i - 1]:
			cnt += 1
		if p[i] != p[i - 1]:
			c[cnt] = 1
			cnt = 1
		if i == n - 1:
			c[cnt] = 1
	if len(c) < 2:
		print('YES')
	else:
		print('NO')
solve()


n = input()
line = [int(x) for x in input().split()]
current = line[0]
current_size = 1
line_size = -1
for i in line[1:]:
	if i == current:
		current_size = current_size + 1
		if current_size > line_size != -1:
			print('NO')
			exit(0)
	if i != current:
		if current_size != line_size and line_size != -1:
			print('NO')
			exit(0)
		line_size = current_size
		current = i
		current_size = 1
if current_size != line_size and line_size != -1:
	print('NO')
	exit(0)
print('YES')


n = int(input())
l = [int(i) for i in input().split()]
i = 0
g = []
while i < n:
	if l[i] == 0:
		c = 0
		while i < n and l[i] == 0:
			c += 1
			i += 1
		g.append(c)
	else:
		c = 0
		while i < n and l[i] == 1:
			c += 1
			i += 1
		g.append(c)
f = 0
if l.count(1) == n or l.count(0) == n:
	print('YES')
	exit()
if len(set(g)) == 1:
	print('YES')
	exit()
print('NO')


n = int(input())
s = list(map(int, input().split()))
first = 1
if len(s) != 1:
	while s[first] == s[first - 1]:
		first += 1
		if first == n:
			break
	now = s[0]
	if len(s) % first != 0:
		print('NO')
	else:
		for i in range(0, len(s), first):
			if set(s[i:i + first]) != {now}:
				print('NO')
				break
			else:
				now = 0 if now == 1 else 1
		else:
			print('YES')
else:
	print('YES')


n = int(input())
a = [int(i) for i in input().split()]
d = 0
i = 0
ok = True
while i < n:
	if not ok:
		break
	j = i
	while j < n and a[j] == a[i]:
		j += 1
	if d == 0:
		d = j - i
	elif d != j - i:
		print('No')
		ok = False
	i = j
if ok:
	print('Yes')


n = int(input())
a = list(map(int, input().split()))
len = -1
lastColor = -1
curLen = 0
a.append(-1)
for i in a:
	if i != lastColor:
		if len != -1:
			if curLen != len:
				print('NO')
				exit(0)
		elif lastColor != -1:
			len = curLen
		lastColor = i
		curLen = 1
	else:
		curLen += 1
print('YES')


n = int(input())
s = input()
p = []
for i in s:
	if i == '0' or i == '1':
		p.append(int(i))
k = int(0)
cur = p[0]
while k < n and p[k] == cur:
	k += 1
pos = int(0)
num = int(0)
fl = bool(0)
while pos < n:
	if p[pos] != cur:
		if num != k:
			fl = 1
		cur = (cur + 1) % 2
		num = 1
		pos += 1
	else:
		num += 1
		pos += 1
if num != k:
	fl = 1
if fl:
	print('NO')
else:
	print('YES')


s = 1
f = 0
n = int(input())
a = list(map(int, input().split()))
a.append(1 - a[n - 1])
n += 1
for i in range(1, n):
	if a[i] == a[i - 1]:
		s += 1
	else:
		if f == 0:
			f = s
		elif s != f:
			print('NO')
			exit()
		s = 1
print('YES')


n = int(input())
a = list(map(int, input().split()))
cnt = 0
cnt1 = 0
cnt2 = 0
p = -1
flag = True
for i in range(n):
	if a[i] == 1:
		if p != 1:
			if cnt != cnt1 and cnt != 0:
				flag = False
			cnt = cnt1
			p = 1
			cnt1 = 0
		cnt1 += 1
	if a[i] == 0:
		if p != 0:
			if cnt != cnt1 and cnt != 0:
				flag = False
			cnt = cnt1
			cnt1 = 0
			p = 0
		cnt1 += 1
if cnt != cnt1 and cnt != 0:
	flag = False
if flag:
	print('YES')
else:
	print('NO')


from sys import stdin
n = int(input())
s = str(input())
i = 0
j = 1
k = int(0)
c = 'a'
kk = int(-1)
bad = 0
while j <= n:
	if c != s[i]:
		c = s[i]
		if k != kk:
			if kk != -1:
				bad = 1
		if kk == -1:
			if i > 1:
				kk = k
		k = 0
	k = k + 1
	i = i + 2
	j = j + 1
if k != kk:
	if kk != -1:
		bad = 1
if bad == 1:
	print('NO')
if bad == 0:
	print('YES')


n = int(input())
a = [int(i) for i in input().split()]
S = set()
p = 1
for i in range(1, n):
	if a[i] != a[i - 1]:
		S.add(p)
		p = 0
	p = p + 1
S.add(p)
if len(S) != 1:
	print('NO\n')
else:
	print('YES\n')


n = int(input())
l = list(map(int, input().split()))
s = ''
for i in range(n):
	s += str(l[i])
j = 0
while j != n and l[j] == l[0]:
	j += 1
ans = ''
blocks = n // j
curr = l[0]
for i in range(blocks):
	ans += j * str(curr)
	curr ^= 1
if ans == s:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
v = list()
(last, cnt) = (a[0], 0)
for i in range(n):
	if a[i] == last:
		cnt += 1
	else:
		v.append(cnt)
		cnt = 1
		last = a[i]
v.append(cnt)
f = True
for e in v:
	if e != v[0]:
		f = False
if f:
	print('YES')
else:
	print('NO')


n = int(input())
b = input()
blen = len(b)
mask = '0'
cnt = 0
tmp = 0
f = 1
ff = 1
for i in range(0, blen, 2):
	if i == 0:
		mask = b[i]
		cnt = cnt + 1
		continue
	if b[i] != b[i - 2]:
		if f == 1:
			f = 0
			tmp = tmp + 1
		elif tmp != cnt and ff == 1:
			print('NO')
			ff = 0
		else:
			tmp = 1
	elif f == 1:
		cnt = cnt + 1
	else:
		tmp = tmp + 1
if ff == 1:
	if f == 1:
		print('YES')
	elif tmp != cnt:
		print('NO')
	else:
		print('YES')


n = int(input())
x = list(map(int, input().split()))
lastc = x[0]
last = 1
first = False
count = 0
for i in range(1, n):
	if lastc != x[i]:
		if not first:
			count = last
			first = True
		elif last != count:
			break
		last = 0
		lastc = x[i]
	last += 1
if last != count and count != 0:
	print('NO')
else:
	print('YES')


def main():
	n = int(input())
	photo = [int(x) for x in input().split()]
	color = dict()
	cnt = 0
	for i in range(n):
		if i == 0:
			cnt += 1
			continue
		if photo[i] == photo[i - 1]:
			cnt += 1
		if photo[i] != photo[i - 1]:
			color[cnt] = 1
			cnt = 1
		if i == n - 1:
			color[cnt] = 1
	if len(color) <= 1:
		print('YES')
	else:
		print('NO')
main()


n = int(input())
a = [int(i) for i in input().split()]
cnt = 0
curcnt = 0
cur = a[0]
for i in range(n):
	if a[i] == cur:
		curcnt += 1
	else:
		break
cnt = curcnt * 1
if cnt == n:
	print('YES')
else:
	curcnt = 0
	cur = a[i]
	br = 0
	for i in range(i, n):
		if a[i] == cur:
			curcnt += 1
		else:
			cur = a[i]
			if curcnt != cnt:
				br = 1
				break
			curcnt = 1
	if curcnt != cnt:
		br = 1
	if br:
		print('NO')
	else:
		print('YES')


n = input()
a = input().split()
temp = a[0]
cnt = 0
ans = -1
flag = 1
for x in a:
	if x == temp:
		cnt += 1
	else:
		if ans == -1:
			ans = cnt
		elif cnt != ans:
			flag = 0
			break
		cnt = 1
		temp = x
if ans == -1:
	ans = cnt
elif cnt != ans:
	flag = 0
if flag == 1:
	print('YES')
else:
	print('NO')


n = input()
a = list(map(int, input().split()))
len = 0
n = int(n)
len = 0
for i in range(1, n):
	sc = a[i] - a[i - 1]
	if sc > 0:
		len = i
		break
	if sc < 0:
		len = i
		break
fl = 1
if len == 0:
	len = n
r = n % len
if r == 0:
	lol = 1
else:
	print('NO')
	return
for i in range(1, n):
	sc = a[i] - a[i - 1]
	if sc > 0:
		tmp = i % len
		if tmp > 0:
			fl = 0
		if tmp < 0:
			fl = 0
	if sc < 0:
		tmp = i % len
		if tmp > 0:
			fl = 0
		if tmp < 0:
			fl = 0
	if sc == 0:
		tmp = i % len
		if tmp == 0:
			fl = 0
if fl == 0:
	print('NO')
else:
	print('YES')


q = int(input())
cnt1 = 0
cnt2 = 0
flag = 0
a = list(map(int, input().split()))
l = a[0]
for i in range(q):
	if a[i] == 0:
		if l != a[i] and cnt1 != 0 and (cnt2 != 0):
			if cnt1 != cnt2:
				flag = 1
			cnt1 = 0
		cnt1 += 1
	else:
		if l != a[i] and cnt2 != 0 and (cnt1 != 0):
			if cnt1 != cnt2:
				flag = 1
			cnt2 = 0
		cnt2 += 1
	l = a[i]
if cnt1 != cnt2 and cnt1 != 0 and (cnt2 != 0):
	flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')


n = int(input())
a = input().split()
now = -1
white = 0
black = 0
for i in range(n):
	if int(a[i]) == 0:
		if white > 0:
			if now == -1:
				now = white
			elif now != white:
				print('NO')
				return
		white = 0
		black += 1
	else:
		if black > 0:
			if now == -1:
				now = black
			elif now != black:
				print('NO')
				return
		black = 0
		white += 1
if white > 0:
	if now == -1:
		now = white
	elif now != white:
		print('NO')
		return
if black > 0:
	if now == -1:
		now = black
	elif now != black:
		print('NO')
		return
print('YES')


input()
picture = input().split()
cur_col = picture[0]
cur_len = 0
last_len = -1
for i in picture:
	if i == cur_col:
		cur_len += 1
	elif last_len != -1 and cur_len != last_len:
		print('NO')
		return
	else:
		last_len = cur_len
		cur_len = 1
		cur_col = i
if last_len != -1 and cur_len != last_len:
	print('NO')
	return
print('YES')


n = int(input())
a = list(map(int, input().split()))
if a.count(0) == n or a.count(1) == n:
	print('YES')
	return
w = a.index(not a[0])
if n % w != 0:
	print('NO')
	return
for i in range(n // w):
	if a[w * i:w * (i + 1)] != [(i % 2 + a[0]) % 2 for _ in range(w)]:
		print('NO')
		return
print('YES')


n = int(input())
ln = 0
start = 1
last = -1
check = 1
x = list(map(int, input().split()))
for i in range(n):
	num = x[i]
	if num != last:
		if ln == 0:
			ln = i + 1 - start
		elif i + 1 - start != ln:
			check = 0
		start = i + 1
	last = num
if ln != 0 and n + 1 - start != ln:
	check = 0
if check == 0:
	print('NO')
else:
	print('YES')


n = int(input())
l = []
st = set()
l = map(int, input().split())
a = list(l)
x = 0
y = 0
a.append(-1)
for i in range(n):
	x = x + 1
	if a[i] == 0:
		y = y + 1
	if a[i] + a[i + 1] == 1:
		st.add(x)
		st.add(y)
		x = 0
		y = 0
st.add(x)
st.add(y)
st.discard(0)
if len(st) == 1:
	print('YES')
else:
	print('NO')


input()
a = input().split()
curneed = -1
curl = 1
for (x, y) in zip(a, a[1:]):
	if x == y:
		curl += 1
	else:
		if curneed == -1:
			curneed = curl
		elif curl != curneed:
			break
		curl = 1
if curneed == -1 or curl == curneed:
	print('YES')
else:
	print('NO')


n = int(input())
s = input().split()
a = list(map(int, s))
i = 0
count = 0
if a[0] == 0:
	while i < len(a) and a[i] == 0:
		i += 1
		count += 1
else:
	while i < len(s) and a[i] == 1:
		i += 1
		count += 1
while i < len(a):
	t = 0
	symbol = a[i]
	while i < len(a) and a[i] == symbol:
		t += 1
		i += 1
	if t != count:
		print('NO')
		exit(0)
print('YES')


n = int(input())
num = []
num = list(map(int, input().split()))
firstZifr = 1
flag = 0
cnt = 0
nowCnt = 0
ans = 0
for i in range(n):
	if i == 0:
		firstZifr = num[0]
		cnt = cnt + 1
	elif num[i] == firstZifr and flag == 0:
		cnt = cnt + 1
	elif num[i] != firstZifr and flag == 0:
		flag = 1
		if firstZifr == 0:
			firstZifr = 1
		else:
			firstZifr = 0
		nowCnt = 1
	elif num[i] == firstZifr and flag == 1:
		nowCnt = nowCnt + 1
	elif num[i] != firstZifr and flag == 1:
		if firstZifr == 0:
			firstZifr = 1
		else:
			firstZifr = 0
		if nowCnt != cnt:
			ans = 1
		nowCnt = 1
if nowCnt != cnt and flag == 1:
	ans = 1
if ans == 0:
	print('YES')
else:
	print('NO')


n = int(input())
a = input().split()
for j in range(n):
	a[j] = int(a[j])
i = 1
last = a[0]
count = 1
while i < n and last == a[i]:
	i += 1
	count += 1
if i < n:
	last = a[i]
	buf = 1
	i += 1
	flag = 1
	while i < n:
		if last == a[i]:
			buf += 1
		elif count != buf:
			flag = 0
			break
		else:
			last = a[i]
			buf = 1
		i += 1
	if count != buf or flag == 0:
		print('NO')
	else:
		print('YES')
else:
	print('YES')


n = int(input())
s = map(int, input().split())
i = 0
k = 0
t = 0
x = 0
c = 0
ans = 1
for i in list(s):
	p = int(i)
	if c == 0:
		if k == 0:
			t = p
		if t == p:
			k += 1
		else:
			t = p
			x = 0
			c = 1
	if t == p:
		x += 1
	else:
		t = p
		if x != k:
			ans = 0
		x = 1
if x != k:
	ans = 0
if ans == 1:
	print('YES')
else:
	print('NO')


n = int(input())
line = list(map(int, input().split()))
ans = [1]
prev = line[0]
k = 1
for i in range(1, n):
	if line[i] == prev:
		ans[-1] += 1
	else:
		k += 1
		prev = line[i]
		ans.append(1)
if [ans[0]] * k != ans:
	print('NO')
else:
	print('YES')


def go():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	x = a[0]
	i = 0
	while i < n and a[i] == x:
		current = a[i]
		i += 1
	so_far = i
	if n % so_far != 0:
		return 'No'
	for start in range(so_far, n, so_far):
		s = sum(a[start:start + so_far])
		if current == 0 and s != so_far:
			return 'No'
		if current == 1 and s != 0:
			return 'No'
		current = a[start]
	return 'Yes'
print(go())


import sys
input()
data = list(map(lambda x: int(x), input().split(' ')))
length = 0
for i in data:
	if i == data[0]:
		length += 1
	else:
		break
cur_char = data[0]
counter = 0
for c in data:
	if c == cur_char:
		counter += 1
	elif counter != length:
		print('NO')
		sys.exit(0)
	else:
		counter = 1
		cur_char = c
if counter != length:
	print('NO')
else:
	print('YES')


n = int(input())
a = input()
a = a.split()
x = 1
for i in range(1, n):
	if a[i] != a[i - 1]:
		break
	else:
		x = x + 1
if n % x != 0:
	print('NO')
else:
	q = 0
	for i in range(0, n, x):
		for j in range(x - 1):
			if a[i + j] != a[i + j + 1]:
				q = 1
		if i + x < n:
			if a[i] == a[i + x]:
				q = 1
	if q == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
a = [0] * n
b = [0] * 100001
a = input().split()
for i in range(n):
	a[i] = int(a[i])
k = 0
l = 0
if a[0] == 1:
	k = 1
for i in range(n):
	if a[i] == k:
		l = l + 1
	else:
		k = a[i]
		b[l] = 1
		l = 1
b[l] = 1
k = 0
for i in range(100001):
	k += b[i]
if k == 1:
	print('YES')
else:
	print('NO')


n = int(input())
sa = input().split(' ')
a = []
flag = 1
b = []
m = 2
b.append(0)
for i in range(n):
	a.append(int(sa[i]))
for i in range(1, n):
	if a[i] != a[i - 1]:
		b.append(i)
		m = m + 1
b.append(n)
for i in range(m - 1):
	if b[i + 1] - b[i] != b[1] - b[0]:
		flag = 0
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
i = 0
while a[i] == a[0]:
	i += 1
	if i == n:
		break
b = []
b.append([a[0] for i in range(0, i)])
b.append([(a[0] + 1) % 2 for i in range(0, i)])
c = []
for i in range(n // i):
	c += b[i % 2]
if c == a:
	print('YES')
else:
	print('NO')


a = int(input())
c = input().split()
for i in range(len(c)):
	c[i] = int(c[i])
d = 1 - c[0]
if d in c:
	x = c.index(d)
else:
	print('YES')
	exit(0)
k = 0
for l in c:
	if l == (d + k // x % 2) % 2:
		print('NO')
		exit(0)
	k += 1
if k % x != 0:
	print('NO')
	exit(0)
print('YES')


n = int(input())
a = list(map(int, input().split()))
last = -1
cnt = 0
fx = -1
kek = 0
for i in range(0, n):
	cur = a[i]
	if last == -1:
		cnt = cnt + 1
	elif last == cur:
		cnt = cnt + 1
	else:
		if fx == -1:
			fx = cnt
		elif fx != cnt:
			kek = -1
		cnt = 1
	last = cur
if fx == -1:
	fx = cnt
elif fx != cnt:
	kek = -1
if kek == -1:
	print('NO')
else:
	print('YES')


from itertools import groupby
input()
print(['YES', 'NO'][len(set((len(list(g)) for (k, g) in groupby(input().split())))) > 1])


n = int(input())
str = input()
array = str.split(' ')
i = 0
first_bit = int(array[i])
i += 1
first_len = 1
current_bit = 0
while i < n:
	current_bit = int(array[i])
	if current_bit == first_bit:
		first_len += 1
		i += 1
	else:
		break
first_bit = current_bit
if i == n:
	print('YES')
	exit(0)
current_len = 0
while i < n:
	current_bit = int(array[i])
	i += 1
	if current_bit == first_bit:
		current_len += 1
	else:
		if current_len != first_len:
			print('NO')
			exit(0)
		current_len = 1
		first_bit = current_bit
if current_len != first_len:
	print('NO')
	exit(0)
print('YES')


x = int(input())
arr = [int(x) for x in input().split()]
d = {}
cnt = 0
for i in range(x):
	if arr[i] == 0:
		cnt += 1
	else:
		if cnt > 0:
			d[cnt] = 1
		cnt = 0
if cnt > 0:
	d[cnt] = 1
cnt = 0
for i in range(x):
	if arr[i] == 1:
		cnt += 1
	else:
		if cnt > 0:
			d[cnt] = 1
		cnt = 0
if cnt > 0:
	d[cnt] = 1
if len(d.keys()) == 1:
	print('YES')
else:
	print('NO')


from itertools import groupby
n = int(input())
mas = ''.join([i for i in input().split()])
zebra = []
zebra = [len(list(j)) for (i, j) in groupby(mas)]
a = [len(list(j)) for (i, j) in groupby(zebra)]
if len(a) == 1:
	print('YES')
else:
	print('NO')


n = int(input())
l = input()
l = [int(i) for i in l.split()] + [-1]
s = set()
t = 0
for i in range(len(l) - 1):
	if l[i] == l[i + 1]:
		t += 1
	else:
		t += 1
		s.add(t)
		if i == len(l) - 2:
			t = 1
		else:
			t = 0
if len(s) == 1:
	print('YES')
else:
	print('NO')


n = int(input())
stripes = [int(x) for x in input().split()] + [-1]
ln = 1
while ln < n and stripes[ln] == stripes[ln - 1]:
	ln += 1
cur = ln
flag = True
for i in range(ln, n + 1):
	if stripes[i] != stripes[i - 1]:
		if cur != ln:
			flag = False
			break
		cur = 0
	cur += 1
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
arr = list(map(int, input().split()))
i = 0
last = 0
now = 0
ln = -1
flag = 0
for i in range(len(arr)):
	if arr[i] == arr[last]:
		now += 1
	elif not (ln == -1 or ln == now):
		flag = 1
		break
	elif ln == -1:
		ln = now
		last = i
		now = 1
	else:
		last = i
		now = 1
if not flag and (ln == -1 or ln == now):
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
lst = []
sz = 1
for i in range(1, n):
	if a[i] == a[i - 1]:
		sz += 1
	else:
		lst.append(sz)
		sz = 1
lst.append(sz)
lst.sort()
if lst[0] == lst[len(lst) - 1]:
	print('YES')
else:
	print('NO')


n = int(input())
a = [int(item) for item in input().split()]
s = set()
am = 1
for i in range(1, n):
	if a[i] == a[i - 1]:
		am = am + 1
	else:
		s.add(am)
		am = 1
s.add(am)
if len(s) == 1:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
m = a[0]
wid = 0
len = 0
for i in a:
	if i == m:
		wid += 1
	else:
		break
for i in a:
	if i == m:
		len += 1
	elif len != wid:
		print('NO')
		exit(0)
	else:
		len = 1
		if m == 1:
			m = 0
		else:
			m = 1
if len != wid:
	print('NO')
else:
	print('YES')


N = int(input())
arr = list(map(int, input().split(' ')[:N]))
i = 0
comp = 0
while i < N and arr[i] == arr[0]:
	comp += 1
	i += 1
flag = True
while i < N:
	c2 = 0
	check = arr[i]
	while i < N and arr[i] == check:
		i += 1
		c2 += 1
	if comp != c2:
		flag = False
if flag == True:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
stripe = -1
cur_stripe = 1
for i in range(1, len(a)):
	if a[i] == a[i - 1]:
		cur_stripe += 1
	elif stripe == -1:
		stripe = cur_stripe
		cur_stripe = 1
	elif cur_stripe != stripe:
		print('NO')
		break
	else:
		cur_stripe = 1
else:
	if stripe == -1:
		print('YES')
	elif cur_stripe != stripe:
		print('NO')
	else:
		print('YES')


input()
(l, ll) = (list(map(int, input().split())), [])
(x, y) = (l[0], 1)
for i in range(1, len(l)):
	if l[i] == x:
		y += 1
	else:
		ll.append(y)
		x = l[i]
		y = 1
print('YES' if len(set(ll + [y])) == 1 else 'NO')


n = int(input())
a = list(map(int, input().split()))
q = 0
p = 0
l = 0
for i in range(0, n):
	if i > 0 and a[i] == a[i - 1]:
		p += 1
	if i == 0 or a[i] != a[i - 1]:
		if q == 0:
			q = p
		if q != p:
			l = 1
		p = 1
if q == 0:
	q = p
if q != p:
	l = 1
if l == 0:
	print('YES')
else:
	print('NO')


z = input()
c = list(map(int, input().split()))
if len(set(c)) != 1:
	if c[0] == 0:
		t = 1
	else:
		t = 0
	d = c.index(t)
	s = list()
	t = not t
	for i in range(0, len(c), d):
		s += [int(t)] * d
		t = not t
	if s == c:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


n = int(input())
x = list(map(int, input().split()))
d = None
s = 1
c = x[0]
for i in range(1, n):
	if x[i] == c:
		s += 1
	else:
		if d is None:
			d = s
		elif s != d:
			print('NO')
			break
		s = 1
		c = x[i]
else:
	if d is None or s == d:
		print('YES')
	else:
		print('NO')


n = int(input())
arr = list(map(int, input().split()))
color = [0]
for i in range(1, len(arr)):
	if arr[i] == arr[i - 1]:
		color.append(color[i - 1] + 1)
	else:
		color.append(0)
maxx = max(color)
count = color.count(max(color))
if count * (maxx + 1) == n:
	print('YES')
else:
	print('NO')


n = int(input())
a = input().split()
s = ''.join(a)
w = set(s.split('0')) - {''}
b = set(s.split('1')) - {''}
if len(w) > 1 or len(b) > 1:
	print('NO')
elif len(w) == 0 or len(b) == 0:
	print('YES')
elif len(list(w)[0]) == len(list(b)[0]):
	print('YES')
else:
	print('NO')