When Masha came to math classes today, she saw two integer sequences of length $n - 1$ on the blackboard. Let's denote the elements of the first sequence as $a_i$ ($0 \le a_i \le 3$), and the elements of the second sequence as $b_i$ ($0 \le b_i \le 3$).

Masha became interested if or not there is an integer sequence of length $n$, which elements we will denote as $t_i$ ($0 \le t_i \le 3$), so that for every $i$ ($1 \le i \le n - 1$) the following is true:   $a_i = t_i | t_{i + 1}$ (where $|$ denotes the bitwise OR operation) and  $b_i = t_i \& t_{i + 1}$ (where $\&$ denotes the bitwise AND operation). 

The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence $t_i$ of length $n$ exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.


-----Input-----

The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the length of the sequence $t_i$. 

The second line contains $n - 1$ integers $a_1, a_2, \ldots, a_{n-1}$ ($0 \le a_i \le 3$) — the first sequence on the blackboard.

The third line contains $n - 1$ integers $b_1, b_2, \ldots, b_{n-1}$ ($0 \le b_i \le 3$) — the second sequence on the blackboard.


-----Output-----

In the first line print "YES" (without quotes), if there is a sequence $t_i$ that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.

If there is such a sequence, on the second line print $n$ integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 3$) — the sequence that satisfies the statements conditions.

If there are multiple answers, print any of them.


-----Examples-----
Input
4
3 3 2
1 2 0

Output
YES
1 3 2 0 
Input
3
1 3
3 2

Output
NO


-----Note-----

In the first example it's easy to see that the sequence from output satisfies the given conditions:   $t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1$ and $t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1$;  $t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2$ and $t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2$;  $t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3$ and $t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3$. 

In the second example there is no such sequence.

Source: codeforces | Difficulty: MEDIUM


Solutions:
def my(a, b, c):
	for (x, y) in zip(a, b):
		for z in range(4):
			if c[-1] | z == x and c[-1] & z == y:
				c += [z]
				break
		else:
			return []
	return c
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for i in range(4):
	t = my(a, b, [i])
	if t:
		print('YES')
		print(*t)
		break
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for k in range(4):
	t = [-1] * n
	t[0] = k
	x = False
	for i in range(1, n):
		x = False
		for j in range(4):
			if a[i - 1] == j | t[i - 1] and b[i - 1] == j & t[i - 1]:
				t[i] = j
				x = True
		if not x:
			break
	if x:
		print('YES')
		print(*t)
		return
print('NO')


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
matr = [[(), (), (), ()], [(), (), (), ()], [(), (), (), ()], [(), (), (), ()]]
matr[0][0] = (0, 0)
matr[0][1] = (-1, -1)
matr[0][2] = (-1, -1)
matr[0][3] = (-1, -1)
matr[1][0] = (1, 0)
matr[1][1] = (1, 1)
matr[1][2] = (-1, -1)
matr[1][3] = (-1, -1)
matr[2][0] = (2, 0)
matr[2][1] = (-1, -1)
matr[2][2] = (2, 2)
matr[2][3] = (-1, -1)
matr[3][1] = (1, 3)
matr[3][2] = (3, 2)
matr[3][3] = (3, 3)
t = []
if (a[0] != 3 or b[0] != 0) and matr[a[0]][b[0]][0] == -1:
	print('NO')
	exit(0)
elif a[0] == 3 and b[0] == 0:
	t.append(3)
	t.append(0)
	f = False
	for i in range(1, n - 1):
		if a[i] == 3 and b[i] == 0:
			if t[i] == 0:
				t.append(3)
			elif t[i] == 1:
				t.append(2)
			elif t[i] == 2:
				t.append(1)
			else:
				t.append(0)
		elif matr[a[i]][b[i]][0] != t[i] and matr[a[i]][b[i]][1] != t[i]:
			f = True
			break
		elif matr[a[i]][b[i]][0] == t[i]:
			t.append(matr[a[i]][b[i]][1])
		else:
			t.append(matr[a[i]][b[i]][0])
	if not f:
		print('YES')
		print(*t)
	else:
		t = []
		t.append(0)
		t.append(3)
		f = False
		for i in range(1, n - 1):
			if a[i] == 3 and b[i] == 0:
				if t[i] == 0:
					t.append(3)
				elif t[i] == 1:
					t.append(2)
				elif t[i] == 2:
					t.append(1)
				else:
					t.append(0)
			elif matr[a[i]][b[i]][0] != t[i] and matr[a[i]][b[i]][1] != t[i]:
				f = True
				break
			elif matr[a[i]][b[i]][0] == t[i]:
				t.append(matr[a[i]][b[i]][1])
			else:
				t.append(matr[a[i]][b[i]][0])
		if not f:
			print('YES')
			print(*t)
		else:
			t = []
			t.append(1)
			t.append(2)
			f = False
			for i in range(1, n - 1):
				if a[i] == 3 and b[i] == 0:
					if t[i] == 0:
						t.append(3)
					elif t[i] == 1:
						t.append(2)
					elif t[i] == 2:
						t.append(1)
					else:
						t.append(0)
				elif matr[a[i]][b[i]][0] != t[i] and matr[a[i]][b[i]][1] != t[i]:
					f = True
					break
				elif matr[a[i]][b[i]][0] == t[i]:
					t.append(matr[a[i]][b[i]][1])
				else:
					t.append(matr[a[i]][b[i]][0])
			if not f:
				print('YES')
				print(*t)
			else:
				t = []
				t.append(2)
				t.append(1)
				f = False
				for i in range(1, n - 1):
					if a[i] == 3 and b[i] == 0:
						if t[i] == 0:
							t.append(3)
						elif t[i] == 1:
							t.append(2)
						elif t[i] == 2:
							t.append(1)
						else:
							t.append(0)
					elif matr[a[i]][b[i]][0] != t[i] and matr[a[i]][b[i]][1] != t[i]:
						f = True
						break
					elif matr[a[i]][b[i]][0] == t[i]:
						t.append(matr[a[i]][b[i]][1])
					else:
						t.append(matr[a[i]][b[i]][0])
				if not f:
					print('YES')
					print(*t)
				else:
					print('NO')
else:
	t.append(matr[a[0]][b[0]][0])
	t.append(matr[a[0]][b[0]][1])
	f = False
	for i in range(1, n - 1):
		if a[i] == 3 and b[i] == 0:
			if t[i] == 0:
				t.append(3)
			elif t[i] == 1:
				t.append(2)
			elif t[i] == 2:
				t.append(1)
			else:
				t.append(0)
		elif matr[a[i]][b[i]][0] != t[i] and matr[a[i]][b[i]][1] != t[i]:
			f = True
			break
		elif matr[a[i]][b[i]][0] == t[i]:
			t.append(matr[a[i]][b[i]][1])
		else:
			t.append(matr[a[i]][b[i]][0])
	if not f:
		print('YES')
		print(*t)
	else:
		t = []
		t.append(matr[a[0]][b[0]][1])
		t.append(matr[a[0]][b[0]][0])
		f = False
		for i in range(1, n - 1):
			if a[i] == 3 and b[i] == 0:
				if t[i] == 0:
					t.append(3)
				elif t[i] == 1:
					t.append(2)
				elif t[i] == 2:
					t.append(1)
				else:
					t.append(0)
			elif matr[a[i]][b[i]][0] != t[i] and matr[a[i]][b[i]][1] != t[i]:
				f = True
				break
			elif matr[a[i]][b[i]][0] == t[i]:
				t.append(matr[a[i]][b[i]][1])
			else:
				t.append(matr[a[i]][b[i]][0])
		if not f:
			print('YES')
			print(*t)
		else:
			print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def yes(t):
	nonlocal n, a, b
	if len(t) < n:
		return False
	for i in range(n - 1):
		if t[i] | t[i + 1] == a[i] and t[i] & t[i + 1] == b[i]:
			continue
		else:
			return False
	return True
ans = []
for i in range(4):
	x = [i]
	for j in range(n - 1):
		for k in range(4):
			if x[-1] | k == a[j] and x[-1] & k == b[j]:
				x.append(k)
				break
	if yes(x):
		ans = x
if ans:
	print('YES')
	print(*ans)
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for f in range(4):
	o = [-1] * n
	o[0] = f
	for i in range(n - 1):
		for j in range(4):
			if o[i] & j == b[i] and o[i] | j == a[i]:
				o[i + 1] = j
	if -1 not in o:
		print('Yes')
		print(*o)
		exit()
print('No')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def try_solve(t):
	for i in range(n - 1):
		ok = False
		for x in range(4):
			if a[i] == t[i] | x and b[i] == t[i] & x:
				t.append(x)
				ok = True
				break
		if not ok:
			return False
	return True
ok = False
for x in range(4):
	t = [x]
	if try_solve(t):
		print('YES')
		print(' '.join(map(str, t)))
		ok = True
		break
if not ok:
	print('NO')


size: int = int(input())
seq1 = []
seq2 = []
for i in input().split(' '):
	seq1.append(int(i))
for i in input().split(' '):
	seq2.append(int(i))
out = []
for i in range(0, size):
	out.append(-1)
for tFirst in range(0, 4):
	out[0] = tFirst
	for i in range(0, size - 1):
		for t2 in range(0, 4):
			if out[i] | t2 == seq1[i] and out[i] & t2 == seq2[i]:
				out[i + 1] = t2
	if -1 not in out:
		print('YES')
		for i in out:
			print(i, end=' ')
		return
if -1 in out:
	print('NO')


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
mp = [[] for i in range(64)]

def getmp(a, b, t):
	return mp[a + b * 4 + t * 16]
for i in range(4):
	for j in range(4):
		mp[(i | j) + (i & j) * 4 + i * 16].append(j)
var = [0]
while len(var) > 0 and len(var) < n:
	vv = var[-1]
	i = len(var) - 1
	p = getmp(a[i], b[i], vv)
	if len(p) == 0:
		appd = True
		while len(var) > 1 and appd:
			vv = var[-1]
			del var[-1]
			i = len(var) - 1
			p = getmp(a[i], b[i], var[-1])
			for t in p:
				if vv < t:
					p.append(t)
					appd = False
					break
		if len(var) == 1:
			if var[0] == 3:
				var = []
			else:
				var[0] += 1
	else:
		var.append(p[0])
if len(var) > 0:
	print('YES')
	print(' '.join(map(str, var)))
else:
	print('NO')


import sys
from math import *
readints = lambda : map(int, input().strip('\n').split())
n = int(input())
a = list(readints())
b = list(readints())
for t0 in range(4):
	ans = [t0]
	fail = False
	for i in range(1, n):
		last = ans[-1]
		for k in range(4):
			if last | k == a[i - 1] and last & k == b[i - 1]:
				ans.append(k)
				break
		if len(ans) != i + 1:
			fail = True
			break
	if not fail:
		print('YES')
		print(*ans, sep=' ')
		sys.exit(0)
print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ways = {(0, 0): [(0, 0)], (1, 0): [(0, 1), (1, 0)], (1, 1): [(1, 1)], (2, 0): [(2, 0), (0, 2)], (2, 2): [(2, 2)], (3, 0): [(3, 0), (0, 3), (2, 1), (1, 2)], (3, 1): [(3, 1), (1, 3)], (3, 2): [(3, 2), (2, 3)], (3, 3): [(3, 3)]}
ans = []
ddl = []
s = {0, 1, 2, 3}
for i in range(n - 2, -1, -1):
	if (a[i], b[i]) not in ways:
		print('NO')
		exit()
	d = ways[a[i], b[i]]
	ns = set()
	dd = {None: None}
	for (st, en) in d:
		if en in s:
			ns.add(st)
			dd[st] = en
	if i == 0:
		if len(ns) == 0:
			print('NO')
			exit()
		k = ns.pop()
		ans = [k, dd[k]]
	else:
		ddl.append(dd)
	s = ns
for i in range(1, n - 1):
	dd = ddl.pop()
	ans.append(dd[ans[-1]])
if ans[0] == None:
	print('NO')
else:
	print('YES')
	print(' '.join(map(str, ans)))


from itertools import product

def next(p, o, a):
	for i in range(4):
		if p | i == o and p & i == a:
			return i

def check(t):
	for j in range(n - 1):
		if not (t[j] | t[j + 1] == a[j] and t[j] & t[j + 1] == b[j]):
			return False
	return True
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
for j in range(4):
	t = [j]
	for i in range(1, n):
		nxt = next(t[-1], a[i - 1], b[i - 1])
		if nxt is None:
			break
		t.append(nxt)
	else:
		print('YES')
		print(' '.join((str(i) for i in t)))
		break
else:
	print('NO')


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
import threading
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for k in range(4):
	t = [-1] * n
	t[0] = k
	x = False
	for i in range(1, n):
		x = False
		for j in range(4):
			if a[i - 1] == j | t[i - 1] and b[i - 1] == j & t[i - 1]:
				t[i] = j
				x = True
		if not x:
			break
	if x:
		print('YES')
		print(*t)
		exit(0)
print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [[-1] * n for i in range(4)]
t[0][0] = 0
t[1][0] = 1
t[2][0] = 2
t[3][0] = 3
for i in range(1, n):
	for j in range(4):
		if t[j][i - 1] != -1:
			for k in range(4):
				if t[j][i - 1] & k == b[i - 1] and t[j][i - 1] | k == a[i - 1]:
					t[j][i] = k
					break
for j in range(4):
	if t[j][n - 1] != -1:
		print('YES')
		print(*t[j])
		break
else:
	print('NO')


a = int(input())
b = list(map(int, input().split()))
c = list(map(int, input().split()))
res = [5] * a
for i in range(4):
	res[0] = i
	for j in range(a - 1):
		for k in range(4):
			if res[j] | k == b[j] and res[j] & k == c[j]:
				res[j + 1] = k
	if 5 not in res:
		print('YES')
		print(*res)
		exit()
print('NO')


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
t = []
c = []
f = 0
for j in range(0, a[0] + b[0] + 1):
	for l in range(0, a[0] + b[0] + 1):
		if j | l == a[0] and j & l == b[0]:
			t.append(j)
			t.append(l)
s = len(t)
if len(t) != 0 and n > 2:
	for i in range(s // 2):
		if f == 1:
			break
		else:
			c = []
			c.append(t[0])
			c.append(t[1])
			del t[0]
			del t[0]
			for j in range(1, n - 1):
				f = 0
				for m in range(a[j] + b[j] + 1):
					if c[j] | m == a[j] and c[j] & m == b[j]:
						c.append(m)
						f = 1
						break
				if f != 1:
					break
else:
	f = 0
if f == 1:
	print('Yes')
	print(*c)
elif n == 2 and s > 0:
	print('Yes')
	print(*t[:n])
elif f == 0:
	print('No')


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
kk = [[[None] * 4 for i in range(4)] for j in range(4)]
for i in range(4):
	for j in range(4):
		for k in range(4):
			z = None
			for x in range(4):
				if i | x == j and i & x == k:
					z = x
			kk[i][j][k] = z
n = mint()
a = list(mints())
b = list(mints())
t = [0] * n
for i in range(4):
	t[0] = i
	ok = True
	for j in range(n - 1):
		t[j + 1] = kk[t[j]][a[j]][b[j]]
		if t[j + 1] == None:
			ok = False
			break
	if ok:
		print('YES')
		print(*t)
		return
print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lst = [[[(0, 0)], [], [], []], [[(0, 1), (1, 0)], [(1, 1)], [], []], [[(0, 2), (2, 0)], [], [(2, 2)], []], [[(0, 3), (1, 2), (2, 1), (3, 0)], [(1, 3), (3, 1)], [(2, 3), (3, 2)], [(3, 3)]]]
ans = []
prev = [0, 1, 2, 3]
res = []
for i in range(n - 1):
	if len(lst[a[i]][b[i]]) != 0:
		ans.append(lst[a[i]][b[i]])
	else:
		print('NO')
		return
	prev2 = []
	res.append([])
	for j in prev:
		for x in ans[-1]:
			if x[0] == j:
				prev2.append(x[1])
				res[-1].append((x[1], x[0]))
	prev = prev2
	if len(prev) == 0:
		print('NO')
		return
ans = [res[-1][0][0]]
prev = res[-1][0][1]
for i in range(len(res) - 2, -1, -1):
	for j in range(len(res[i])):
		if res[i][j][0] == prev:
			ans.append(res[i][j][0])
			prev = res[i][j][1]
			break
ans.append(prev)
ans.reverse()
print('YES')
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] >= b[0]:
	for x in range(4):
		for y in range(4):
			if x | y == a[0] and x & y == b[0]:
				t = [x, y]
				ans = 1
				for i in range(1, n - 1):
					if a[i] >= b[i]:
						flag = 0
						for ti in range(4):
							if t[i] | ti == a[i] and t[i] & ti == b[i]:
								t.append(ti)
								flag = 1
						if flag == 0:
							ans = 0
							break
					else:
						ans = 0
						break
				if ans == 1:
					print('YES')
					print(*t)
					return
	print('NO')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = [-1] * n
for i in range(4):
	res[0] = i
	for j in range(n - 1):
		for x in range(4):
			if res[j] | x == a[j] and res[j] & x == b[j]:
				res[j + 1] = x
	if -1 not in res:
		print('YES')
		print(*res)
		exit()
print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [-1] * n
a1 = a[0]
b1 = b[0]
k = 0
for i in range(4):
	if k == 0:
		for j in range(4):
			if a1 == i | j and b1 == i & j:
				t[0] = i
				t[1] = j
				for x in range(2, n - 1):
					for q in range(4):
						if a[x - 1] == t[x - 1] | q and b[x - 1] == t[x - 1] & q:
							t[x] = q
				for i1 in range(4):
					if a[-1] == i1 | t[-2] and b[-1] == i1 & t[-2]:
						t[-1] = i1
			if -1 not in t:
				k = 1
				print('Yes')
				print(*t)
				break
if -1 in t:
	print('No')


n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
trr = [0 for i in range(n)]
for j in range(4):
	trr[0] = j
	fl = True
	for i in range(n - 1):
		if arr[i] == brr[i]:
			if trr[i] != arr[i]:
				fl = False
				break
			trr[i + 1] = arr[i]
		else:
			if brr[i] == 3:
				fl = False
				break
			if brr[i] == 2:
				if arr[i] == 3:
					if trr[i] == 2:
						trr[i + 1] = 3
					elif trr[i] == 3:
						trr[i + 1] = 2
					else:
						fl = False
						break
				else:
					fl = False
					break
			if brr[i] == 1:
				if arr[i] == 3:
					if trr[i] == 1:
						trr[i + 1] = 3
					elif trr[i] == 3:
						trr[i + 1] = 1
					else:
						fl = False
						break
				else:
					fl = False
					break
			if brr[i] == 0:
				if arr[i] == 1:
					if trr[i] == 0:
						trr[i + 1] = 1
					elif trr[i] == 1:
						trr[i + 1] = 0
					else:
						fl = False
						break
				elif arr[i] == 2:
					if trr[i] == 2:
						trr[i + 1] = 0
					elif trr[i] == 0:
						trr[i + 1] = 2
					else:
						fl = False
						break
				elif trr[i] == 1:
					trr[i + 1] = 2
				elif trr[i] == 2:
					trr[i + 1] = 1
				elif trr[i] == 3:
					trr[i + 1] = 0
				else:
					trr[i + 1] = 3
	if fl:
		print('YES')
		print(*trr)
		break
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = []
flag = True
for i in range(4):
	if len(res) == n:
		flag = True
		break
	flag = True
	res = [i]
	for k in range(0, n - 1):
		if not flag:
			break
		for j in range(4):
			if res[k] & j == b[k] and res[k] | j == a[k]:
				res.append(j)
				break
		else:
			flag = False
if flag:
	print('YES')
	print(*res)
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(4):
	ans = [-1] * n
	ans[0] = i
	flag = False
	for j in range(1, n):
		flag = False
		for k in range(4):
			if a[j - 1] == k | ans[j - 1] and b[j - 1] == k & ans[j - 1]:
				ans[j] = k
				flag = True
		if not flag:
			break
	if flag:
		print('YES')
		print(*ans)
		exit()
print('NO')


from collections import deque
n = int(input())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
dp = [[-1 for j in range(4)] for i in range(n)]
dp[0][0] = 1
dp[0][1] = 1
dp[0][2] = 1
dp[0][3] = 1
f = 0
for i in range(1, n):
	for j in range(4):
		for k in range(4):
			if dp[i - 1][k] != -1 and j & k == l1[i - 1] and (j | k == l[i - 1]):
				dp[i][j] = k
for i in range(n):
	if sum(dp[i]) == -4:
		f = 1
		break
if f == 1:
	print('NO')
else:
	print('YES')
	lu = deque([])
	for i in range(4):
		if dp[n - 1][i] != -1:
			k = i
			break
	for i in range(n, 0, -1):
		lu.appendleft(k)
		k = dp[i - 1][k]
	print(*lu, sep=' ')


def func(a, b, prev):
	if a == 0:
		if b == 0:
			if prev == 0:
				return 0
			else:
				return -1
		else:
			return -1
	if a == 1:
		if b == 0:
			if prev == 0 or prev == 1:
				return 1 - prev
			else:
				return -1
		elif b == 1:
			if prev == 1:
				return 1
			else:
				return -1
		else:
			return -1
	if a == 2:
		if b == 0:
			if prev == 0 or prev == 2:
				return 2 - prev
			else:
				return -1
		elif b == 2:
			if prev == 2:
				return 2
			else:
				return -1
		else:
			return -1
	if a == 3:
		if b == 0:
			return 3 - prev
		elif b == 1:
			if prev == 1 or prev == 3:
				return 4 - prev
			else:
				return -1
		elif b == 2:
			if prev == 2 or prev == 3:
				return 5 - prev
			else:
				return -1
		elif prev == 3:
			return 3
		else:
			return -1
n = input()
arr = input()
brr = input()
arr = list(arr.split(' '))
brr = list(brr.split(' '))
n = int(n)
for i in range(n - 1):
	arr[i] = int(arr[i])
	brr[i] = int(brr[i])
for i in range(4):
	a = arr[0]
	b = brr[0]
	t = list()
	prev = i
	t.append(prev)
	pos = 1
	for j in range(1, n):
		prev = func(a, b, prev)
		t.append(prev)
		if prev == -1:
			pos = 0
			break
		if j == n - 1:
			break
		a = arr[j]
		b = brr[j]
	if pos == 1:
		print('YES')
		for x in t:
			print(x, end=' ')
		exit()
print('NO')


n = int(input())
lst1 = [int(x) for x in input().split()]
lst2 = [int(x) for x in input().split()]
F = False
for x in range(4):
	ans = [-1] * n
	ans[0] = x
	for y in range(1, n):
		f = False
		for z in range(4):
			if z | ans[y - 1] == lst1[y - 1] and z & ans[y - 1] == lst2[y - 1]:
				ans[y] = z
				f = True
				break
		if not f:
			break
	if f:
		F = True
		break
if F:
	print('YES')
	print(*ans)
else:
	print('NO')


n = int(input())
flag = 0
argsa = list(map(int, input().split()))
argsb = list(map(int, input().split()))
argst = [0]
for i in range(n - 1):
	for j in range(4):
		if argst[i] & j == argsb[i] and argst[i] | j == argsa[i]:
			argst.append(j)
			flag = 1
			break
	if not flag:
		flag = 2
		break
	flag = 0
if flag == 2:
	flag = 0
	argst = []
	argst.append(1)
	for i in range(n - 1):
		for j in range(4):
			if argst[i] & j == argsb[i] and argst[i] | j == argsa[i]:
				argst.append(j)
				flag = 1
				break
		if not flag:
			flag = 2
			break
		flag = 0
if flag == 2:
	flag = 0
	argst = [2]
	for i in range(n - 1):
		for j in range(4):
			if argst[i] & j == argsb[i] and argst[i] | j == argsa[i]:
				argst.append(j)
				flag = 1
				break
		if not flag:
			flag = 2
			break
		flag = 0
if flag == 2:
	flag = 0
	argst = [3]
	for i in range(n - 1):
		for j in range(4):
			if argst[i] & j == argsb[i] and argst[i] | j == argsa[i]:
				argst.append(j)
				flag = 1
				break
		if not flag:
			flag = 2
			break
		flag = 0
if not flag == 2:
	print('YES', end='\n')
	print(*argst)
else:
	print('NO')


def calc(a, b, n, f):
	t = []
	t.append(f)
	for i in range(n - 1):
		if a[i] is t[i] | 0 and b[i] is t[i] & 0:
			t.append(0)
		elif a[i] is t[i] | 1 and b[i] is t[i] & 1:
			t.append(1)
		else:
			return [False, t]
	return [True, t]

def main():
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	a0 = [x & 1 for x in a]
	a1 = [x >> 1 for x in a]
	b0 = [x & 1 for x in b]
	b1 = [x >> 1 for x in b]
	t00 = calc(a0, b0, n, 0)
	t01 = calc(a0, b0, n, 1)
	t10 = calc(a1, b1, n, 0)
	t11 = calc(a1, b1, n, 1)
	t0 = t00 if t00[0] else t01
	t1 = t10 if t10[0] else t11
	if t0[0] and t1[0]:
		print('Yes')
		for x in range(n):
			print((t1[1][x] << 1) + t0[1][x], end=' ')
	else:
		print('No')
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [0] * n
memory = list()
last = [None for _ in range(n)]
for i in range(4):
	for j in range(4):
		if i | j == a[0] and i & j == b[0]:
			(last[0], last[1]) = (i, j)
			try:
				for v in range(1, n - 1):
					for j1 in range(4):
						if last[v] | j1 == a[v] and last[v] & j1 == b[v]:
							last[v + 1] = j1
				if not last[-1] == None:
					memory.append(last[:])
			except TypeError:
				pass
			for v in range(len(last)):
				last[v] = None
if memory:
	print('YES')
	for c in memory[0]:
		print(c, end=' ')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for start in range(b[0], 4):
	answer = []
	t = start
	for i in range(len(a)):
		x = a[i]
		y = b[i]
		if len(answer) == 0:
			answer.append(t)
		for j in range(3, -1, -1):
			if t & j == y and t | j == x:
				answer.append(j)
				t = j
				break
	if len(answer) == n:
		print('YES')
		print(*answer)
		break
else:
	print('NO')


from functools import reduce
n = int(input())
(a, b) = (list(map(int, input().split())) for _ in (None, None))
oq = set(range(4))
q = oq.copy()
w = []
possible = True
for i in range(n - 1):
	p = set()
	w.append({})
	for t1 in q:
		e = set([t2 for t2 in oq if t2 | t1 == a[i] and t2 & t1 == b[i]])
		p |= e
		w[i][t1] = e
	q = p
	if len(q) == 0:
		possible = False
		break
print('YES' if possible else 'NO')
if possible:
	y = None
	for l in q:
		y = l
		break
	path = [y]
	for g in reversed(w):
		for (k, u) in list(g.items()):
			if y in u:
				y = k
				break
		path.append(y)
	print(reduce(lambda x, y: x + ' ' + str(y), reversed(path), '')[1:])


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [[[[0, 0]], [], [], []], [[[0, 1], [1, 0]], [[1, 1]], [], []], [[[0, 2], [2, 0]], [], [[2, 2]], []], [[[0, 3], [1, 2], [2, 1], [3, 0]], [[1, 3], [3, 1]], [[2, 3], [3, 2]], [[3, 3]]]]
stack = c[a[0]][b[0]][:]
i = 1
while i < n - 1 and stack:
	helper = c[a[i]][b[i]][:]
	for e in helper:
		j = 0
		while j < len(stack):
			if stack[j][-1] == e[0] and len(stack[j]) == i + 1:
				stack[j].append(e[1])
			j += 1
	j = 0
	while j < len(stack):
		if len(stack[j]) == i + 1:
			del stack[j]
		else:
			j += 1
	i += 1
if stack:
	print('YES')
	print(*stack[0])
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos_and = [{(0, 1), (0, 2), (0, 3), (0, 0), (1, 2)}, {(1, 3), (1, 1)}, {(2, 3), (2, 2)}, {(3, 3)}]
pos_or = [{(0, 0)}, {(0, 1), (1, 1)}, {(0, 2), (2, 2)}, {(0, 3), (1, 3), (2, 3), (3, 3), (1, 2)}]
res1 = []
flag1 = False
for i in range(n - 1):
	pairs = [x for x in pos_and[b[i]].intersection(pos_or[a[i]])]
	pairs.sort()
	if len(pairs) == 0:
		flag1 = True
		break
	for pair in pairs:
		rev_pair = (pair[1], pair[0])
		if len(res1) == 0:
			res1.append(pair[0])
			res1.append(pair[1])
			break
		if res1[-1] == pair[0]:
			res1.append(pair[1])
			break
		elif res1[-1] == rev_pair[0]:
			res1.append(rev_pair[1])
			break
	if len(res1) != i + 2:
		flag1 = True
		break
res2 = []
flag2 = False
for i in range(n - 1):
	pairs = [x for x in pos_and[b[i]].intersection(pos_or[a[i]])]
	pairs.sort()
	if len(pairs) == 0:
		flag2 = True
		break
	for pair in pairs:
		rev_pair = (pair[1], pair[0])
		if len(res2) == 0:
			res2.append(rev_pair[0])
			res2.append(rev_pair[1])
			break
		if res2[-1] == pair[0]:
			res2.append(pair[1])
			break
		elif res2[-1] == rev_pair[0]:
			res2.append(rev_pair[1])
			break
	if len(res2) != i + 2:
		flag2 = True
		break
if flag1 and flag2 and (a[0] == 3) and (b[0] == 0):
	res1 = []
	flag1 = False
	for i in range(n - 1):
		pairs = [x for x in pos_and[b[i]].intersection(pos_or[a[i]])]
		pairs.sort()
		if len(pairs) == 0:
			flag1 = True
			break
		for pair in pairs:
			rev_pair = (pair[1], pair[0])
			if len(res1) == 0:
				res1.append(pairs[1][0])
				res1.append(pairs[1][1])
				break
			if res1[-1] == pair[0]:
				res1.append(pair[1])
				break
			elif res1[-1] == rev_pair[0]:
				res1.append(rev_pair[1])
				break
		if len(res1) != i + 2:
			flag1 = True
			break
	res2 = []
	flag2 = False
	for i in range(n - 1):
		pairs = [x for x in pos_and[b[i]].intersection(pos_or[a[i]])]
		pairs.sort()
		if len(pairs) == 0:
			flag2 = True
			break
		for pair in pairs:
			rev_pair = (pair[1], pair[0])
			if len(res2) == 0:
				res2.append(pairs[1][1])
				res2.append(pairs[1][0])
				break
			if res2[-1] == pair[0]:
				res2.append(pair[1])
				break
			elif res2[-1] == rev_pair[0]:
				res2.append(rev_pair[1])
				break
		if len(res2) != i + 2:
			flag2 = True
			break
if not flag2:
	print('YES')
	print(*res2)
elif not flag1:
	print('YES')
	print(*res1)
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [0] * (len(a) + 1)
valids = dict()
for a1 in range(4):
	for b1 in range(4):
		valids[str(a1) + str(b1)] = list()
		for t1 in range(4):
			for t2 in range(4):
				if t1 | t2 == a1 and t1 & t2 == b1:
					valids[str(a1) + str(b1)].append(str(t1) + str(t2))
prevs = ['0', '1', '2', '3']
for i in range(0, len(a)):
	newprevs = list()
	for i in valids[str(a[i]) + str(b[i])]:
		for j in prevs:
			if j[-1] == i[0]:
				newprevs.append(str(j) + str(i[1]))
				break
	prevs = newprevs
if len(prevs) > 0:
	print('YES')
	print(' '.join(prevs[0]))
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
result = [-1] * n
for first_element in range(4):
	result[0] = first_element
	for i in range(n - 1):
		for t in range(4):
			if result[i] | t == a[i] and result[i] & t == b[i]:
				result[i + 1] = t
	if -1 not in result:
		print('YES')
		print(*result)
		exit(0)
print('NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n - 1):
	if a[i] == 3:
		a[i] = '11'
	elif a[i] == 2:
		a[i] = '10'
	elif a[i] == 1:
		a[i] = '01'
	elif a[i] == 0:
		a[i] = '00'
for i in range(n - 1):
	if b[i] == 3:
		b[i] = '11'
	elif b[i] == 2:
		b[i] = '10'
	elif b[i] == 1:
		b[i] = '01'
	elif b[i] == 0:
		b[i] = '00'

def Checker(z, x, y):
	if z == '0':
		if x == '0' and y == '0':
			return '0'
		elif x == '0' and y == '1':
			return None
		elif x == '1' and y == '0':
			return '1'
		elif x == '1' and y == '1':
			return None
	elif z == '1':
		if x == '0' and y == '0':
			return None
		elif x == '0' and y == '1':
			return None
		elif x == '1' and y == '0':
			return '0'
		elif x == '1' and y == '1':
			return '1'
s = []
flag = True
for ti in ['00', '01', '10', '11']:
	t = ti
	if len(s) == n:
		break
	elif Checker(t[0], a[0][0], b[0][0]) is not None and Checker(t[1], a[0][1], b[0][1]) is not None:
		s.append(t)
		for i in range(n - 1):
			c = Checker(t[0], a[i][0], b[i][0])
			e = Checker(t[1], a[i][1], b[i][1])
			if c is not None and e is not None:
				k = ''.join([c, e])
				s.append(k)
				t = k
			else:
				s.clear()
				break
	elif t == '11':
		flag = False
if flag and s:
	print('YES')
	for i in range(n):
		if s[i] == '11':
			print(3, end=' ')
		elif s[i] == '10':
			print(2, end=' ')
		elif s[i] == '01':
			print(1, end=' ')
		elif s[i] == '00':
			print(0, end=' ')
else:
	print('NO')