Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.

The current state of the wall can be respresented by a sequence $a$ of $n$ integers, with $a_i$ being the height of the $i$-th part of the wall.

Vova can only use $2 \times 1$ bricks to put in the wall (he has infinite supply of them, however).

Vova can put bricks horizontally on the neighboring parts of the wall of equal height. It means that if for some $i$ the current height of part $i$ is the same as for part $i + 1$, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part $1$ of the wall or to the right of part $n$ of it).

The next paragraph is specific to the version 1 of the problem.

Vova can also put bricks vertically. That means increasing height of any part of the wall by 2.

Vova is a perfectionist, so he considers the wall completed when:

  all parts of the wall has the same height;  the wall has no empty spaces inside it. 

Can Vova complete the wall using any amount of bricks (possibly zero)?


-----Input-----

The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of parts in the wall.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the initial heights of the parts of the wall.


-----Output-----

Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).

Print "NO" otherwise.


-----Examples-----
Input
5
2 1 1 2 5

Output
YES

Input
3
4 5 3

Output
YES

Input
2
10 10

Output
YES

Input
3
1 2 3

Output
NO



-----Note-----

In the first example Vova can put a brick on parts 2 and 3 to make the wall $[2, 2, 2, 2, 5]$ and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it $[5, 5, 5, 5, 5]$.

In the second example Vova can put a brick vertically on part 3 to make the wall $[4, 5, 5]$, then horizontally on parts 2 and 3 to make it $[4, 6, 6]$ and then vertically on part 1 to make it $[6, 6, 6]$.

In the third example the wall is already complete.

Difficulty: HARD

Solutions:
import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
A = list(map(int, input().split()))
A2 = [A[i] % 2 for i in range(n)]
if n == 1:
	print('YES')
	sys.exit()
if n == 2:
	if A2[0] != A2[1]:
		print('NO')
		sys.exit()
	else:
		print('YES')
		sys.exit()
QUE = deque()
for i in range(n):
	QUE.append(A2[i])
	while len(QUE) >= 2 and QUE[-1] == QUE[-2]:
		QUE.pop()
		QUE.pop()
if len(QUE) >= 2:
	print('NO')
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
(n0, n1) = (0, 0)
for (i, x) in enumerate(a):
	add = (x + 1) // 2
	if i % 2 == 0:
		n0 += add
		n1 += x - add
	else:
		n1 += add
		n0 += x - add
if n0 - n1 == 0 or (n0 - n1 == 1 and len(a) % 2 == 1):
	print('YES')
else:
	print('NO')


(i, p) = (input, print)
(n, b, q) = (int(i()), [int(x) & 1 for x in i().split()], [])
f = q.append
f(b[0])
for a in b[1:]:
	q.pop() if q and q[-1] == a else f(a)
p('NO' if len(q) > 1 else 'YES')


n = int(input())
a = [int(i) for i in input().split()]
st = []
for i in a:
	if len(st) > 0 and st[-1] == i & 1:
		st.pop()
	else:
		st.append(i & 1)
if len(st) <= 1:
	print('YES')
else:
	print('NO')


while True:
	try:
		n = int(input())
		nu = [int(x) for x in input().split()]
		re = list(map(lambda x: (x + 1) % 2, nu))
		posi = False
		su = 0
		ba = 0
		for i in range(0, n - 1, 2):
			if re[i] == re[i + 1]:
				pass
			elif re[i] == 0:
				su += 1
			else:
				ba += 1
		posi = su == ba
		if n % 2 == 1:
			if su + 1 == ba and re[n - 1] == 0:
				posi = True
			if ba + 1 == su and re[n - 1] == 1:
				posi = True
		if not posi:
			print('NO')
		else:
			print('YES')
	except Exception as e:
		break


n = int(input())
a = list(map(int, input().split()))
q = 10 ** 6 * [-1]
pnt = -1
ans = 'YES'
for i in range(n):
	if pnt == -1:
		pnt += 1
		q[pnt] = a[i]
	elif q[pnt] == a[i] or abs(q[pnt] - a[i]) % 2 == 0:
		q[pnt] = -1
		pnt -= 1
	else:
		pnt += 1
		q[pnt] = a[i]
if pnt > 0:
	ans = 'NO'
print(ans)


n = int(input())
l1 = list(map(int, input().split()))
segments = 0
for i in range(0, n):
	if l1[i] % 2 == 1:
		if i % 2 == 1:
			segments -= 1
		else:
			segments += 1
if n % 2 == 1 and (segments == 0 or segments == 1):
	print('YES')
elif n % 2 == 0 and segments == 0:
	print('YES')
else:
	print('NO')


n = int(input())
aa = []
l = [*map(int, input().split())]
for i in l:
	res = i % 2
	if not len(aa) or aa[-1] != res:
		aa.append(res)
	else:
		aa.pop(-1)
print('YES' if len(aa) <= 1 else 'NO')


n = int(input())
arr = list(map(int, input().split()))
arr = list(map(lambda x: x % 2, arr))
stack = []
for i in range(n):
	if len(stack):
		if stack[-1] == arr[i]:
			stack.pop()
		else:
			stack.append(arr[i])
	else:
		stack.append(arr[i])
if len(stack) == 0 or len(stack) == 1:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
s = []
for i in range(n):
	a[i] = a[i] & 1
for i in range(n):
	if len(s) == 0 or s[-1] != a[i]:
		s.append(a[i])
	else:
		s.pop()
if len(s) <= 1:
	print('YES')
else:
	print('NO')


def D1():
	n = int(input())
	bricks = input().split()
	bricks = [int(x) % 2 for x in bricks]
	stack = []
	for i in range(n):
		if not len(stack):
			stack.append(bricks[i])
			continue
		if stack[-1] == bricks[i]:
			stack.pop()
			continue
		stack.append(bricks[i])
	if len(stack) < 2:
		print('YES')
		return
	print('NO')
D1()


(a, n) = ([], input())
for i in [int(x) & 1 for x in input().split()]:
	if a and a[-1] == i:
		a.pop()
	else:
		a.append(i)
print(len(a) > 1 and 'NO' or 'YES')


n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(n):
	if a[i] % 2 == 1:
		if i % 2 == 1:
			c = c - 1
		else:
			c = c + 1
if n % 2 == 1 and (c == 0 or c == 1) or (n % 2 == 0 and c == 0):
	print('YES')
else:
	print('NO')


x = int(input())
l = list(map(int, input().split()))
l1 = []
for i in range(x):
	if l1 != [] and l[i] % 2 == l1[-1]:
		del l1[-1]
	else:
		l1 += [l[i] % 2]
if len(l1) <= 1:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
st = [a[0]]
for i in range(1, n):
	if len(st) > 0 and st[-1] % 2 == a[i] % 2:
		st.pop()
	else:
		st.append(a[i])
if len(st) <= 1:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = [0] * 1000000
sp = -1
for i in range(n):
	sp = sp + 1
	b[sp] = a[i]
	if sp > 0:
		if (b[sp] + b[sp - 1]) % 2 == 0:
			sp = sp - 2
if sp <= 0:
	print('YES')
else:
	print('NO')


def wall(n, a):
	a = [0 if x % 2 == 0 else 1 for x in a]
	stack = [a[0]]
	append = stack.append
	pop = stack.pop
	for i in range(1, n):
		if len(stack) > 0:
			ele = stack[-1]
			if ele == a[i]:
				pop()
			else:
				append(a[i])
		else:
			append(a[i])
	return len(stack) <= 1
n = int(input())
a = map(int, input().split())
res = wall(n, a)
print('YES' if res else 'NO')


n = int(input())
l = list(map(int, input().split()))
stack = []
for i in range(n):
	if len(stack) == 0:
		stack.append(l[i] % 2)
	elif l[i] % 2 == stack[-1]:
		stack.pop()
	else:
		stack.append(l[i] % 2)
if len(stack) <= 1:
	print('YES')
else:
	print('NO')


n = int(input())
l = [int(x) for x in input().split()]
st = []
for i in l:
	d = i % 2
	if len(st) and st[-1] == d:
		st.pop()
	else:
		st.append(d)
if len(st) < 2:
	print('YES')
else:
	print('NO')


n = int(input())
inp = input()
alt = list(map(int, inp.rstrip().split()))
nuovo = []
for i in range(n):
	alt[i] %= 2
	if len(nuovo) != 0:
		if nuovo[-1] == alt[i]:
			nuovo.pop()
		else:
			nuovo.append(alt[i])
	else:
		nuovo.append(alt[i])
if len(nuovo) > 1:
	print('NO')
else:
	print('YES')


n = int(input())
l = []
for i in list(map(int, input().split())):
	tmp = 1 & i
	if l == [] or l[-1] != tmp:
		l.append(tmp)
	else:
		l.pop()
print('YES' if len(l) <= 1 else 'NO')


n = int(input())
a = [i for i in map(int, input().split(' '))]
mx = max(a)
stack = [a[0]]
for i in range(1, n):
	if len(stack) != 0:
		if a[i] % 2 == stack[-1] % 2:
			stack.pop()
		else:
			stack.append(a[i])
	else:
		stack.append(a[i])
if len(stack) > 1:
	print('NO')
else:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
track = []
track.append(l[0] % 2)
r = ''
for i in range(1, n):
	if track == [] or track[-1] != l[i] % 2:
		track.append(l[i] % 2)
	else:
		track.pop()
if len(track) <= 1:
	r = 'YES'
else:
	r = 'NO'
print(r)


def merge(b1, b2):
	if abs(b1[0] - b2[0]) % 2 == 0 or (b1[1] % 2 == 0 and b2[1] % 2 == 0):
		return (True, (max(b1[0], b2[0]), b1[1] + b2[1]))
	elif b1[1] % 2 == 0 or b2[1] % 2 == 0:
		if b1[1] % 2 == 1:
			return (True, (b1[0] if b1[0] > b2[0] else b2[0] + 1, b1[1] + b2[1]))
		if b2[1] % 2 == 1:
			return (True, (b2[0] if b2[0] > b1[0] else b1[0] + 1, b1[1] + b2[1]))
	return (False, None)
n = int(input())
x = [int(i) for i in input().split()]
wl = [[x[0], 1]]
for i in x[1:]:
	if i == wl[-1][0]:
		wl[-1][1] += 1
	else:
		wl.append([i, 1])
i = 1
last_brick = wl[0]
res = []

def fix_res():
	global res, last_brick
	if len(res) == 0:
		return
	x = merge(res[-1], last_brick)
	while x[0]:
		res.pop()
		last_brick = x[1]
		x = merge(res[-1], last_brick) if len(res) != 0 else (False,)
for i in wl[1:]:
	fix_res()
	x = merge(last_brick, i)
	if x[0] == False:
		res.append(last_brick)
		last_brick = i
	else:
		last_brick = x[1]
fix_res()
res.append(last_brick)
res = len(res) == 1
print('YES' if res else 'NO')


class node:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def is_solvable(this):
	while this.pre is not None or this.next is not None:
		if this.pre is not None:
			if this.val[0] % 2 == 0:
				merged = node((this.pre.val[0] % 2, this.pre.val[1]))
				merged.next = this.next
				merged.pre = this.pre.pre
				if this.next is not None:
					this.next.pre = merged
				if this.pre.pre is not None:
					this.pre.pre.next = merged
				this = merged
				continue
			elif this.pre.val[0] % 2 == 0:
				merged = node((this.val[0] % 2, this.val[1]))
				merged.next = this.next
				merged.pre = this.pre.pre
				if this.next is not None:
					this.next.pre = merged
				if this.pre.pre is not None:
					this.pre.pre.next = merged
				this = merged
				continue
			elif not this.val[1] ^ this.pre.val[1]:
				merged = node((this.val[0] % 2 + this.pre.val[0] % 2, this.val[1]))
				merged.next = this.next
				merged.pre = this.pre.pre
				if this.next is not None:
					this.next.pre = merged
				if this.pre.pre is not None:
					this.pre.pre.next = merged
				this = merged
				continue
		if this.next is not None:
			if this.val[0] % 2 == 0:
				merged = node((this.next.val[0] % 2, this.next.val[1]))
				merged.next = this.next.next
				merged.pre = this.pre
				if this.next.next is not None:
					this.next.next.pre = merged
				if this.pre is not None:
					this.pre.next = merged
				this = merged
				continue
			elif this.next.val[0] % 2 == 0:
				merged = node((this.val[0] % 2, this.val[1]))
				merged.next = this.next.next
				merged.pre = this.pre
				if this.next.next is not None:
					this.next.next.pre = merged
				if this.pre is not None:
					this.pre.next = merged
				this = merged
				continue
			elif not this.val[1] ^ this.next.val[1]:
				merged = node((this.val[0] % 2 + this.next.val[0] % 2, this.val[1]))
				merged.next = this.next.next
				merged.pre = this.pre
				if this.next.next is not None:
					this.next.next.pre = merged
				if this.pre is not None:
					this.pre.next = merged
				this = merged
				continue
			this = this.next
		else:
			return False
	return True

def great_vova_wall(size, wall):
	count = 1
	state = wall[0] % 2 == 0
	head = None
	this = head
	for i in range(1, size):
		if state ^ wall[i] % 2 == 0:
			new = node((count, state))
			if this is not None:
				new.pre = this
				this.next = new
			if head is None:
				head = new
			count = 1
			state = wall[i] % 2 == 0
			this = new
		else:
			count += 1
	new = node((count, state))
	if this is not None:
		new.pre = this
		this.next = new
	if head is None:
		head = new
	return is_solvable(head)
n = int(input())
a = list(map(int, input().split()))
if great_vova_wall(n, a):
	print('YES')
else:
	print('NO')


def f():
	b = [a[0]]
	for e in a[1:]:
		if b != []:
			if e == b[-1] or abs(e - b[-1]) % 2 == 0:
				b.pop()
			else:
				b.append(e)
		else:
			b.append(e)
	for i in range(1, len(b)):
		if abs(b[i] - b[i - 1]) % 2:
			print('NO')
			return
	print('YES')
n = int(input())
a = [int(i) for i in input().split()]
f()


n = int(input())
a = [int(_) & 1 for _ in input().split()]
v = [a[0]]
for i in range(1, n):
	if v and v[-1] == a[i]:
		v.pop()
	else:
		v.append(a[i])
print('NO' if len(v) > 1 else 'YES')


n = int(input())
arr = list(map(int, input().split()))
stack = []
for i in range(n):
	if len(stack) <= 1:
		stack.append(arr[i] % 2)
		continue
	else:
		while len(stack) >= 2 and stack[-1] == stack[-2]:
			stack.pop()
			stack.pop()
		stack.append(arr[i] % 2)
while len(stack) >= 2 and stack[-1] == stack[-2]:
	stack.pop()
	stack.pop()
if len(stack) <= 1:
	print('YES')
else:
	print('NO')


n_input = int(input())
l_input = list(map(int, str(input()).split()))
l_binary = []
for _ in range(n_input):
	pop = l_input.pop() % 2
	if l_binary == []:
		l_binary.append(pop)
	elif pop == l_binary[-1]:
		l_binary.pop()
	else:
		l_binary.append(pop)
n = len(l_binary)
if n <= 1:
	print('YES')
else:
	print('NO')


i = int(input())
s = input().split()
l = []
for j in s:
	if not l or int(j) % 2 != l[-1]:
		l.append(int(j) % 2)
	else:
		l.pop()
if len(l) < 2:
	print('YES')
else:
	print('NO')


n = int(input())
L = [int(x) % 2 for x in input().split()]
S = []
temp = 1
LW = []
RW = []
Close = []
for i in range(1, n):
	if L[i] == L[i - 1]:
		temp += 1
	else:
		S.append(temp)
		temp = 1
S.append(temp)
z = 0
for i in range(0, len(S)):
	S[i] = S[i] % 2
	if S[i] == 0:
		z += 1
		LW.append(i)
		RW.append(len(S) - i - 1)
		if len(LW) > 1:
			Close.append(LW[-1] - LW[-2])
index = 0
removed = 0
while index < z - 1:
	if Close[index] <= LW[index] - removed:
		removed += 2 * Close[index]
		index += 2
	else:
		removed += 2 * (LW[index] - removed) + 1
		index += 1
if index == z - 1:
	if abs(LW[z - 1] - removed - RW[z - 1]) <= 1:
		print('YES')
	else:
		print('NO')
elif removed >= len(S) - 1:
	print('YES')
else:
	print('NO')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	n = int(inp())
	a = lis()
	mx = max(a)
	for i in range(n):
		if (mx - a[i]) % 2 == 0:
			a[i] = mx
		else:
			a[i] = mx + 1
	for i in range(n - 1):
		if a[i] == mx:
			if a[i + 1] == mx:
				a[i] = mx + 1
				a[i + 1] = mx + 1
	if a.count(mx) == 0:
		print('YES')
		return
	cnt = 0
	have = []
	for i in range(0, n):
		if len(have) == 0:
			have.append(a[i])
			continue
		if have[len(have) - 1] == a[i]:
			have.pop()
		else:
			have.append(a[i])
	if len(have) < 2:
		print('YES')
	else:
		print('NO')
testcase(1)


n = int(input())
re = [int(x) % 2 for x in input().split()]
su = 0
ba = 0
for i in range(0, n - 1, 2):
	if re[i] == re[i + 1]:
		pass
	elif re[i] == 0:
		su += 1
	else:
		ba += 1
posi = su == ba
if n % 2 == 1:
	if su + 1 == ba and re[n - 1] == 0:
		posi = True
	if ba + 1 == su and re[n - 1] == 1:
		posi = True
if not posi:
	print('NO')
else:
	print('YES')


import math
n = int(input())
columns = list(map(int, input().rstrip().split()))
modcolumns = [i % 2 for i in columns]
test = 0
previouslist = []
for i in range(0, n):
	if len(previouslist) == 0:
		previouslist.append(modcolumns[i])
	elif modcolumns[i] == previouslist[-1]:
		previouslist.pop()
	else:
		previouslist.append(modcolumns[i])
if len(previouslist) <= 1:
	print('YES')
else:
	print('NO')


import sys
import collections as cc
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
for i in range(n):
	l[i] &= 1
st = [l[0]]
i = 1
for i in range(1, n):
	if st and st[-1] == l[i]:
		st.pop()
	else:
		st.append(l[i])
if len(st) <= 1:
	f = 0
else:
	f = 1
print('YNEOS'[f::2])


from sys import stdin

def myfunction(n, arr):
	mystack = []
	mystack.append(arr[0])
	for i in range(1, n):
		if len(mystack) > 0 and abs(mystack[-1] - arr[i]) % 2 == 0:
			mystack.pop()
		else:
			mystack.append(arr[i])
	if len(mystack) <= 1:
		return 'YES'
	else:
		return 'NO'
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
print(myfunction(n, arr))


import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
n = int(input())
A = list(map(int, input().split()))
A2 = [A[i] % 2 for i in range(n)]
if n == 1:
	print('YES')
	sys.exit()
if n == 2:
	if A2[0] != A2[1]:
		print('NO')
		sys.exit()
	else:
		print('YES')
		sys.exit()
i = 0
j = 1
SKIPLIST = [0] * n
BLIST = [None] * (n + 1)

def back(i):
	if i == -1:
		return -1
	if SKIPLIST[i] == 0:
		return i
	if BLIST[i] != None:
		BLIST[i] = back(BLIST[i])
		return BLIST[i]
	else:
		BLIST[i] = back(i - 1)
		return BLIST[i]
while j < n:
	if A2[i] != A2[j]:
		(i, j) = (j, j + 1)
	else:
		SKIPLIST[i] = SKIPLIST[j] = 1
		i = back(i)
		if i == -1:
			(i, j) = (j + 1, j + 2)
		else:
			j = j + 1
if SKIPLIST.count(0) <= 1:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
an = [l[0] % 2]
for i in range(1, n):
	if an and l[i] % 2 == an[-1] % 2:
		an.pop()
	else:
		an.append(l[i] % 2)
if not an:
	an = [1]
print('YNEOS'[bool(len(an) - 1)::2])


import math
n = int(input())
a = list(map(int, input().split()))
b = [2]
for i in a:
	y = b.pop()
	if i % 2 == y:
		continue
	else:
		b.append(y)
		b.append(i % 2)
if len(b) > 2:
	print('NO')
else:
	print('YES')


import sys
input = sys.stdin.readline
from collections import *
n = int(input())
a = list(map(int, input().split()))
q = deque([])
for i in range(n):
	if len(q) > 0 and q[-1] % 2 == a[i] % 2:
		q.pop()
	else:
		q.append(a[i])
if len(q) <= 1:
	print('YES')
else:
	print('NO')


n = int(input())
wall = list(map(int, input().split()))
if n == 1:
	print('YES')
else:
	in1 = []
	for i in range(n):
		wall[i] = wall[i] % 2
		if wall[i] == 1:
			in1.append(i)
	if len(in1) == 0 or len(in1) == n:
		print('YES')
	elif len(in1) == 1:
		if (n - 1) % 2 == 0 and in1[0] % 2 == 0 and ((n - in1[0] - 1) % 2 == 0):
			print('YES')
		else:
			print('NO')
	else:
		i = 0
		while i + 1 < len(in1):
			if i >= 0 and i + 1 < len(in1) and ((in1[i + 1] - in1[i] - 1) % 2 == 0):
				del in1[i + 1]
				del in1[i]
				i -= 1
			else:
				i += 1
		if len(in1) == 0:
			print('YES')
		elif len(in1) == 1:
			if (n - 1) % 2 == 0 and in1[0] % 2 == 0 and ((n - in1[0] - 1) % 2 == 0):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


n = int(input())
w = list(map(int, input().split()))
count = 0
for i in range(n):
	if w[i] % 2 == 1:
		if i % 2 == 1:
			count -= 1
		else:
			count += 1
if n % 2 == 1 and (count == 1 or count == 0):
	print('YES')
elif n % 2 == 0 and count == 0:
	print('YES')
else:
	print('NO')


s = []
n = int(input())
a = list(map(lambda x: int(x) % 2, input().split()))
for i in a:
	if len(s) != 0 and s[-1] == i:
		s.pop()
	else:
		s.append(i)
if len(s) > 1:
	print('NO')
else:
	print('YES')


n = int(input())
a = [int(x) % 2 for x in input().split()]
s = []
for x in a:
	if len(s) == 0:
		s.append(x)
	elif s[len(s) - 1] != x:
		s.append(x)
	else:
		s.pop()
if len(s) <= 1:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	y = 0
	a = list(map(int, input().split()))
	for v in a:
		if (v - y) % 2 == 1:
			y -= 1
		elif y < 0:
			y += 1
	if y == 0:
		print('YES')
		return
	y = 1
	for v in a:
		if (v - y) % 2 == 1:
			y -= 1
		elif y < 1:
			y += 1
	if y == 1:
		print('YES')
		return
	print('NO')
solve()


n = int(input())
a = list(map(int, input().split()))
stack = []
for i in a:
	if stack and i & 1 == stack[-1]:
		stack.pop()
	else:
		stack.append(i & 1)
if len(stack) > 1:
	print('NO')
else:
	print('YES')


n = int(input())
a = map(lambda s: int(s) & 1, input().split())
st = []
for x in a:
	if len(st) > 0 and st[-1] == x:
		st.pop()
	else:
		st.append(x)
if len(st) <= 1:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = 0
for i in range(n):
	if a[i] % 2 == 1:
		if i % 2 == 0:
			b += 1
		else:
			b -= 1
if n % 2 == 0:
	if b == 0:
		print('YES')
	else:
		print('NO')
elif b == 0 or b == 1:
	print('YES')
else:
	print('NO')


n = int(input())
A = list(map(int, input().split()))
s = []
for a in A:
	if s:
		if s[-1] % 2 == a % 2:
			s.pop()
		else:
			s.append(a)
	else:
		s.append(a)
if len(s) > 1:
	print('NO')
else:
	print('YES')


def main():
	n = int(input())
	a = list(map(int, input().split()))
	stack = []
	for val in a:
		if stack:
			last = stack.pop()
			if val % 2 != last % 2:
				stack.append(last)
				stack.append(val)
			else:
				pass
		else:
			stack.append(val)
	print('YES' if len(stack) <= 1 else 'NO')
main()


n = int(input())
bricks = list(map(int, input().split()))

def solve(n, bs):
	if n <= 1:
		return 'YES'
	x = list()
	for b in bs:
		if not x:
			x.append(b % 2)
			continue
		cur = x.pop()
		if cur == b % 2:
			continue
		else:
			x.append(cur)
			x.append(b % 2)
	return 'NO' if len(x) > 1 else 'YES'
print(solve(n, bricks))


n = int(input())
A = [int(x) % 2 == 0 for x in input().split(' ')]
segments = []
segmentLength = 1
for i in range(n):
	if i == n - 1:
		segments.append(segmentLength)
	elif A[i] == A[i + 1]:
		segmentLength += 1
	else:
		segments.append(segmentLength)
		segmentLength = 1
lastIndexStack = []
for i in range(len(segments)):
	if segments[i] != 0:
		if segments[i] % 2 == 0:
			if i == len(segments) - 1:
				for _ in range(len(lastIndexStack)):
					lastIndex = lastIndexStack.pop()
					segments[i] += segments[lastIndex]
					segments[lastIndex] = 0
					if segments[i] % 2 != 0:
						break
			else:
				j = 0
				while True:
					for _ in range(len(lastIndexStack)):
						lastIndex = lastIndexStack.pop()
						segments[i] += segments[lastIndex] + segments[i + 1 + j]
						segments[lastIndex] = 0
						segments[i + 1 + j] = 0
						j += 1
						if segments[i] % 2 != 0 or i + 1 + j > len(segments) - 1:
							break
					if segments[i] % 2 != 0 or i + 1 + j > len(segments) - 1:
						break
					segments[i] += segments[i + 1 + j]
					segments[i + 1 + j] = 0
					j += 1
					if segments[i] % 2 != 0 or i + 1 + j > len(segments) - 1:
						break
		if segments[i] != 0:
			lastIndexStack.append(i)
segments = [x for x in segments if x != 0]
if len(segments) == 1:
	print('YES')
else:
	print('NO')


n_input = int(input())
l_input = list(map(int, str(input()).split()))
l_binary = []
for _ in range(n_input):
	pop = l_input.pop() % 2
	if l_binary == []:
		l_binary.append(pop)
	elif pop == l_binary[-1]:
		l_binary.pop()
	else:
		l_binary.append(pop)

def solve(n, l_binary):
	if n <= 1:
		return 1
	elif n == 2:
		sum_l = sum(l_binary) % 2
		return sum_l - 1
	else:
		for k in range(n - 2):
			l_sequence = [l_binary[k], l_binary[k + 1], l_binary[k + 2]]
			if l_sequence == [0, 1, 0] or l_sequence == [1, 0, 1]:
				return 0
		return 1
if solve(len(l_binary), l_binary):
	print('YES')
else:
	print('NO')


import sys

def rint():
	return map(int, sys.stdin.readline().split())
h = 0
l = 1
n = int(input())
a = rint()
a = [i % 2 for i in a]
cnt = 0
cur = -1
ae = []
for i in range(n):
	if a[i] == 0:
		if cur == 0 or cur == -1:
			cur = 0
			cnt += 1
		else:
			ae.append([cur, cnt % 2])
			cnt = 1
			cur = 0
	elif cur == 1 or cur == -1:
		cur = 1
		cnt += 1
	else:
		ae.append([cur, cnt % 2])
		cnt = 1
		cur = 1
ae.append([cur, cnt % 2])
stack = []
for e in ae:
	if e[l] == 1:
		if len(stack) == 0:
			stack.append(e[h])
		elif e[h] == stack[-1]:
			stack.pop()
		else:
			stack.append(e[h])
if len(stack) > 1:
	print('NO')
else:
	print('YES')


s = int(input())
arr = list(map(int, input().split()))
stack = []
for data in arr:
	if stack and stack[-1] == data % 2:
		stack.pop(-1)
	else:
		stack.append(data % 2)
if len(stack) <= 1:
	print('YES')
else:
	print('NO')