import sys
fl = input()
sl = input()
fnumofel = len(fl)
int(fnumofel)
fnumofel - 1
l = []
slist = sl.split(" ")
n = 0
for v in slist:
	n = int(n)
	#print(slist[n])
	bina = bin(int(slist[n]))
	str(bina)
	bina.replace("0b", "")
	#print(bina)
	str(bina)
	lastdigit = bina[:-1]
	l.append(lastdigit)
	n+=1
statlist = []
n = 0
for v in slist:
	int(n)
	if n == 0 or n == fnumofel:
		if n == 0:
			nextnum = l[1]
			prevnum = l[-1]
			currnum = l[0]
			if currnum == nextnum or currnum == prevnum:
				pass
			else:
				print("No")
				sys.exit()
		elif n == fnumofel:
			nextnum = l[0]
			prevnum = l[fnumofel]
			currnum = l[n]
			if currnum == nextnum or currnum == prevnum:
				pass
			else:
				print("No")
				sys.exit()
		else:
			nntmp = n + 1
			pntmp = n - 1
			nextnum = l[nntmp]
			prevnum = l[pntmp]
			currnum = l[n]
			if currnum == nextnum or currnum == prevnum:
				pass
			else:
				print("No")
				sys.exit()
		n+=1
print("Yes")
