Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.

We define function f(x, l, r) as a bitwise OR of integers x_{l}, x_{l} + 1, ..., x_{r}, where x_{i} is the i-th element of the array x. You are given two arrays a and b of length n. You need to determine the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n. [Image] 


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays.

The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^9).

The third line contains n integers b_{i} (0 ≤ b_{i} ≤ 10^9).


-----Output-----

Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.


-----Examples-----
Input
5
1 2 4 3 2
2 3 3 12 1

Output
22
Input
10
13 2 7 11 8 4 9 8 5 1
5 7 18 9 2 3 0 11 8 6

Output
46


-----Note-----

Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation.

In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, 4) = (2 OR 4 OR 3) + (3 OR 3 OR 12) = 7 + 15 = 22. Other ways to get maximum value is to choose l = 1 and r = 4, l = 1 and r = 5, l = 2 and r = 4, l = 2 and r = 5, l = 3 and r = 4, or l = 3 and r = 5.

In the second sample, the maximum value is obtained for l = 1 and r = 9.

Difficulty: EASY

Solutions:
from functools import reduce
__author__ = 'artyom'

def main():
	read(0)
	l = lambda x, y: x | y
	return reduce(l, read(3)) + reduce(l, read(3))

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='\n')
write(main())


n = int(input())
R = lambda : list(map(int, input().split()))
a = R()
b = R()
x = a[0]
y = b[0]
for i in range(1, n):
	x = x | a[i]
	y = y | b[i]
print(x + y)


import bisect
import math
import collections
import sys
import copy
from functools import reduce
import decimal
from io import BytesIO, IOBase
import os
sys.setrecursionlimit(10 ** 9)
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
graphDict = collections.defaultdict
queue = collections.deque

class Graphs:

	def __init__(self):
		self.graph = graphDict(list)

	def add_edge(self, u, v):
		self.graph[u].append(v)

	def dfs_utility(self, nodes, visited_nodes):
		visited_nodes.add(nodes)
		for neighbour in self.graph[nodes]:
			if neighbour not in visited_nodes:
				self.dfs_utility(neighbour, visited_nodes)
			else:
				return neighbour

	def dfs(self, node):
		Visited = set()
		self.dfs_utility(node, Visited)

	def bfs(self, node):
		visited = set()
		if node not in visited:
			queue.append(node)
			visited.add(node)
		while queue:
			parent = queue.popleft()
			print(parent)
			for item in self.graph[parent]:
				if item not in visited:
					queue.append(item)
					visited.add(item)

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
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))

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

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
n = int(inp())
a = list_inp(int)
b = list_inp(int)
print(reduce(lambda x, y: x | y, a) + reduce(lambda x, y: x | y, b))


a = int(input())
x = 0
y = 0
l1 = list(map(int, input().split(' ')))
l2 = list(map(int, input().split(' ')))
for e1 in l1:
	x |= e1
for e2 in l2:
	y |= e2
print(x + y)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
	tmp_a = 0
	tmp_b = 0
	for j in range(i, n):
		tmp_a = tmp_a | a[j]
		tmp_b = tmp_b | b[j]
	ans = max(ans, tmp_b + tmp_a)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.append(0)
b = list(map(int, input().split()))
b.append(0)
max_ab = a[0] + b[0]
for l in range(n):
	f_a = a[l]
	f_b = b[l]
	for r in range(l, n):
		if f_a + f_b > max_ab:
			max_ab = f_a + f_b
		f_a |= a[r + 1]
		f_b |= b[r + 1]
print(max_ab)


n = int(input())
l_i1 = list(map(int, input().split()))
l_i2 = list(map(int, input().split()))
o1 = 0
o2 = 0
for i in range(n):
	o1 |= l_i1[i]
	o2 |= l_i2[i]
print(o1 + o2)


input()
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
a1 = a[0]
for i in a[1:]:
	a1 = a1 | i
b1 = b[0]
for i in b[1:]:
	b1 = b1 | i
print(a1 + b1)


n = int(input())
maxf = -9999
p = input().rstrip().split(' ')
q = input().rstrip().split(' ')
S = 0
D = 0
F = 0
for k in range(0, len(p)):
	S = S | int(p[k])
	D = D | int(q[k])
F = S + D
print(F)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for l in range(n):
	for r in range(l, n):
		(fa, fb) = (0, 0)
		for k in range(l, r + 1):
			fa |= a[k]
			fb |= b[k]
		ans = max(ans, fa + fb)
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(1, n):
	a[i] = a[i] | a[i - 1]
	b[i] = b[i] | b[i - 1]
print(a[n - 1] + b[n - 1])


import sys
from functools import reduce

def main(arrs):
	first = reduce(lambda x, y: x | y, arrs[0], 0)
	second = reduce(lambda x, y: x | y, arrs[1], 0)
	print(first + second)
arrs = []
for (e, line) in enumerate(sys.stdin.readlines()):
	if e == 0:
		continue
	arrs.append(list(map(int, line.strip().split())))
main(arrs)


n = int(input())
ps = list(map(int, input().split()))
qs = list(map(int, input().split()))
maxi = 0
(s_a, s_b) = (0, 0)
for l in range(n):
	s_a = ps[l]
	s_b = qs[l]
	for r in range(l, n):
		s_a = s_a | ps[r]
		s_b = s_b | qs[r]
		maxi = max(maxi, s_a + s_b)
print(maxi)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = a[0]
for x in a:
	c = c | x
d = b[0]
for x in b:
	d = d | x
print(c + d)


from functools import reduce
input()
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
print(reduce(lambda x, y: x | y, a) + reduce(lambda x, y: x | y, b))


read = lambda : list(map(int, input().split()))
n = int(input())
a = list(read())
b = list(read())
f1 = 0
for i in a:
	f1 |= i
f2 = 0
for i in b:
	f2 |= i
print(f1 + f2)


n = int(input())

def work():
	val = 0
	raw = input()
	raw = raw.split()
	raw = [int(num) for num in raw]
	for num in raw:
		val = val | num
	return val
print(work() + work())


(n, t1, t2) = (int(input()), 0, 0)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	(t1, t2) = (t1 | a[i], t2 | b[i])
print(t1 + t2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maxi1 = 0
maxi2 = 0
maxi = 0
for beg in range(n):
	tmp1 = a[beg]
	tmp2 = b[beg]
	for end in range(beg + 1, n):
		tmp1 = tmp1 | a[end]
		tmp2 = tmp2 | b[end]
		if tmp1 + tmp2 > maxi:
			maxi = tmp1 + tmp2
	if tmp1 + tmp2 > maxi:
		maxi = tmp1 + tmp2
print(maxi)


x = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
OR1 = a[0]
OR2 = b[0]
for i in range(1, x):
	OR1 = OR1 | a[i]
	OR2 = OR2 | b[i]
print(OR1 + OR2)


import sys
Input = sys.stdin.readline
t = int(Input())
x = list(map(int, Input().split()))
y = list(map(int, Input().split()))
(a, b) = (0, 0)
for i in range(t):
	a |= x[i]
	b |= y[i]
print(a + b)


input()
print(eval(input().replace(' ', '|')) + eval(input().replace(' ', '|')))


n = int(input())
l = list(map(int, input().split()))
d = list(map(int, input().split()))
(x, y) = (0, 0)
for i in range(n):
	x = x | l[i]
	y = y | d[i]
print(x + y)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s1 = 0
s2 = 0
for i in range(n):
	s1 |= a[i]
	s2 |= b[i]
print(s1 + s2)


def f(array, left, right):
	left -= 1
	result = 0
	for each in array[left:right]:
		result = result | each
	return result
n = int(input())
a = [int(each) for each in input().split()]
b = [int(each) for each in input().split()]
print(f(a, 1, n) + f(b, 1, n))


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
n = ii()
a = li()
b = li()
ma = 0
mb = 0
for i in range(n):
	ma = ma | a[i]
	mb = mb | b[i]
print(ma + mb)


t = int(input())
l1 = [int(x) for x in input().split()]
ans = l1[0]
for x in l1:
	ans |= x
l2 = [int(x) for x in input().split()]
ans1 = l2[0]
for x in l2:
	ans1 |= x
print(ans + ans1)


input()
a = input().replace(' ', '|')
b = input().replace(' ', '|')
print(eval(a) + eval(b))


def s(a):
	res = 0
	for i in range(len(a)):
		curr = a[i]
		res = max(res, curr)
		for j in range(i + 1, len(a)):
			curr |= a[j]
			res = max(res, curr)
	return res
input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(s(a) + s(b))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = 0
y = 0
for l in a:
	x = x | l
for l in b:
	y = y | l
print(x + y)


n = int(input())
ip1 = list(map(int, input().split()))
ip2 = list(map(int, input().split()))
ans = 0
ans2 = 0
for i in range(n):
	ans = ans | ip1[i]
for j in range(n):
	ans2 = ans2 | ip2[j]
print(ans + ans2)


def read():
	return [int(c) for c in input().split()]
(n,) = read()
a = read()
b = read()
x = y = 0
for (aa, bb) in zip(a, b):
	x |= aa
	y |= bb
print(x + y)


from functools import reduce
from operator import or_

def table(a):
	t = []
	for l in range(len(a)):
		al = [0] * l + [a[l]]
		for r in range(l + 1, len(a)):
			al.append(al[-1] | a[r])
		t.append(al)
	return t

def max_sum(a, b):
	ta = table(a)
	tb = table(b)
	n = len(a)
	return max((ta[l][r] + tb[l][r] for l in range(n) for r in range(l, n)))

def get_input():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	assert n == len(a) == len(b)
	return (a, b)
(a, b) = get_input()
print(max_sum(a, b))


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
mxa = 0
for i in range(n):
	cur = a[i]
	for j in range(i, n):
		cur |= a[j]
	mxa = max(mxa, cur)
mxb = 0
for i in range(n):
	cur = b[i]
	for j in range(i, n):
		cur |= b[j]
	mxb = max(mxb, cur)
print(mxa + mxb)


from functools import reduce
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
(a, b) = (reduce(lambda x, y: x | y, A), reduce(lambda x, y: x | y, B))
print(a + b)


n = int(input())
f1 = f2 = 0
for x in input().split():
	f1 |= int(x)
for x in input().split():
	f2 |= int(x)
print(f1 + f2)


from functools import reduce

def solve(n, a, b):
	return reduce(lambda x, y: x | y, a) + reduce(lambda x, y: x | y, b)

def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	print(solve(n, a, b))
main()


num = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
ans1 = 0
ans2 = 0
for n in arr1:
	ans1 |= n
for n in arr2:
	ans2 |= n
print(ans1 + ans2)


from functools import reduce
R = lambda : map(int, input().split())
(n,) = R()
arr = list(R())
arr_two = list(R())
print(reduce(lambda a, b: a | b, arr) + reduce(lambda a, b: a | b, arr_two))


def f(j, k):
	(q, e) = (0, 0)
	for i in range(j, k + 1):
		q |= a[i]
		e |= b[i]
	return q + e
n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
maximum = 0
for j in range(0, len(a)):
	for k in range(j, len(a)):
		maximum = max(maximum, f(j, k))
print(maximum)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
abit = 0
bbit = 0
for i in range(n):
	abit |= a[i]
	bbit |= b[i]
print(abit + bbit)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
f1 = 0
f2 = 0
for i in range(n):
	f1 = f1 | a[i]
	f2 = f2 | b[i]
print(f1 + f2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l_a = []
l_b = []
l_sum = []
for i in range(n):
	x = a[i]
	for j in range(n - i):
		x = x | a[j]
		l_a.append(x)
for i in range(n):
	x = b[i]
	for j in range(n - i):
		x = x | b[j]
		l_b.append(x)
for i in range(len(l_a)):
	l_sum.append(l_a[i] + l_b[i])
l_sum.sort(reverse=True)
print(l_sum[0])


n = int(input())
(ans1, ans2) = (0, 0)
data1 = list(map(int, input().split()))
data2 = list(map(int, input().split()))
for i in range(n):
	ans1 = ans1 | data1[i]
	ans2 = ans2 | data2[i]
print(ans1 + ans2)


n = int(input())
s = input()
a = [int(x) for x in s.split()]
s = input()
b = [int(x) for x in s.split()]
res = 0
for i in range(n):
	(A, B) = (0, 0)
	for j in range(i, n):
		A |= a[j]
		B |= b[j]
		res = max(res, A + B)
print(res)


def f(m):
	v = 0
	for x in m:
		v |= x
	return v
input()
print(f(map(int, input().split())) + f(map(int, input().split())))


a = 0
b = 0
n = int(input())
x = [int(q) for q in input().split()]
y = [int(q) for q in input().split()]
for i in range(n):
	a = a | x[i]
	b = b | y[i]
print(a + b)


n = int(input())
a = map(int, input().split())
b = map(int, input().split())
va = vb = 0
for i in a:
	va |= i
for i in b:
	vb |= i
print(va + vb)


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
ans = 0
for beg in range(len(a)):
	max1 = 0
	max2 = 0
	cur1 = 0
	cur2 = 0
	for e in range(beg, len(a)):
		cur1 |= a[e]
		cur2 |= b[e]
		if cur1 + cur2 > max1 + max2:
			max1 = cur1
			max2 = cur2
	ans = max([ans, max1 + max2])
print(ans)


li = []
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	x = a[i]
	y = b[i]
	li += [x + y]
	for j in range(i + 1, n):
		x |= a[j]
		y |= b[j]
		li += [x + y]
print(max(li))


n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
v1 = v2 = 0
for idx in range(n):
	v1 = v1 | arr1[idx]
	v2 = v2 | arr2[idx]
print(v1 + v2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
r = 0
for i in range(n):
	fa = a[i]
	fb = b[i]
	for j in range(i, n):
		fa |= a[j]
		fb |= b[j]
	r = max(r, fa + fb)
print(r)


import sys
n = int(sys.stdin.readline())
a = [int(x) for x in sys.stdin.readline().strip().split()]
b = [int(x) for x in sys.stdin.readline().strip().split()]
A = a[0]
for x in a:
	A |= x
B = b[0]
for x in b:
	B |= x
print(A + B)


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

def f(x, l, r):
	res = 0
	for i in range(l, r + 1):
		res |= x[i]
	return res
t = [None] * n
sum_a = 0
sum_b = 0
max_sum = 0
for i in range(n):
	sum_a |= a[i]
	sum_b |= b[i]
	t[i] = sum_a + sum_b
	max_sum = max(max_sum, t[i])
print(max_sum)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
tot = bot = 0
for i in range(0, n):
	tot |= a[i]
	bot |= b[i]
print(tot + bot)
exit()


n = int(input())

def f(x):
	res = 0
	for el in x:
		res |= el
	return res
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(f(a[0:n + 1]) + f(b[0:n + 1]))


def doit(n, a, b):
	rv = 0
	aor = 0
	bor = 0
	for i in a:
		aor = aor | i
	for i in b:
		bor = bor | i
	rv = aor + bor
	return rv
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(doit(n, a, b))


def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	print(solver(a, b))

def solver(a, b):
	n = len(a)
	best = 0
	for l in range(n):
		bitwiseA = a[l]
		bitwiseB = b[l]
		total = bitwiseA + bitwiseB
		if total >= best:
			best = total
		for r in range(l + 1, n):
			bitwiseA |= a[r]
			bitwiseB |= b[r]
			total = bitwiseA + bitwiseB
			if total >= best:
				best = total
	return best
main()


import itertools
import math
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
max1 = -1
for i in range(n):
	last_or_a = 0
	last_or_b = 0
	for j in range(i, n):
		last_or_a |= a[j]
		last_or_b |= b[j]
		max1 = max(max1, last_or_b + last_or_a)
print(max1)


def read():
	return [int(c) for c in input().split()]
(n,) = read()
a = read()
b = read()
acc_a = [0]
acc_b = [0]
for i in range(n):
	acc_a.append(acc_a[-1] | a[i])
	acc_b.append(acc_b[-1] | b[i])
acc = [x + y for (x, y) in zip(acc_a, acc_b)]
ans = 0
for i in range(n):
	for j in range(i, n):
		ans = max(ans, acc[j + 1] - acc[i])
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(resA, resB) = (0, 0)
for i in range(n):
	resA |= a[i]
	resB |= b[i]
print(resA + resB)


from sys import *
from collections import defaultdict as dd
from math import *
from bisect import *

def sinp():
	return input()

def inp():
	return int(sinp())

def minp():
	return map(int, sinp().split())

def linp():
	return list(minp())

def strl():
	return list(sinp())

def pr(x):
	print(x)
mod = int(1000000000.0 + 7)
n = inp()
a = linp()
b = linp()
res = -maxsize
(oa, ob) = (0, 0)
for i in range(n):
	for j in range(n):
		oa |= a[j]
		ob |= b[j]
		res = max(res, oa + ob)
pr(res)


from functools import reduce
input()
a = 0
for _ in [0, 0]:
	a += reduce(lambda x, y: x | y, map(int, input().split()))
print(a)


n = int(input())
tot = bot = 0
for i in input().split():
	tot |= int(i)
for i in input().split():
	bot |= int(i)
print(tot + bot)
exit()


x = int(input())
s = [int(n) for n in input().split()]
z = [int(n) for n in input().split()]
m = k = 0
for n in s:
	m = m | n
for n in z:
	k = k | n
print(m + k)


n = int(input())
a = [int(s) for s in input().split(' ')]
b = [int(s) for s in input().split(' ')]
x = 0
for u in a:
	x = x | u
y = 0
for v in b:
	y = y | v
print(x + y)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
	ans1 = a[i]
	ans2 = b[i]
	for j in range(i + 1, n):
		ans1 = ans1 | a[j]
		ans2 = ans2 | b[j]
	ans = max(ans, ans1 + ans2)
print(ans)


n = int(input())
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
answer1 = 0
answer2 = 0
for i in range(n):
	answer1 |= s1[i]
	answer2 |= s2[i]
print(answer1 + answer2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aOR = 0
bOR = 0
for i in range(n):
	aOR |= a[i]
	bOR |= b[i]
print(aOR + bOR)


n = int(input())
s = input()
a = s.split(' ')
s = input()
b = s.split(' ')
for i in range(n):
	(a[i], b[i]) = (int(a[i]), int(b[i]))
res = a[0] + b[0]
for l in range(n):
	sumA = 0
	sumB = 0
	for r in range(l, n):
		sumA |= a[r]
		sumB |= b[r]
		sum = sumA + sumB
		res = max(res, sum)
print(res)


from collections import defaultdict, deque, Counter, OrderedDict
import threading, sys

def main():
	n = int(input())
	ans = 0
	for i in map(int, input().split()):
		ans |= i
	b = 0
	for j in map(int, input().split()):
		b |= j
	print(ans + b)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = 0
sb = 0
for i in range(n):
	sa |= a[i]
	sb |= b[i]
print(sa + sb)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c1 = c2 = 0
for i in a:
	c1 = c1 | i
for i in b:
	c2 = c2 | i
print(c1 + c2)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
n = get_int()
lst1 = get_int_list()
lst2 = get_int_list()
a = b = 0
for i in range(n):
	a = a | lst1[i]
	b = b | lst2[i]
print(a + b)


from functools import reduce
n = int(input())
mass_a = list(map(int, input().split()))
mass_b = list(map(int, input().split()))
max_sum = 0
for i in range(n):
	x = mass_a[i]
	y = mass_b[i]
	for j in range(i + 1, n):
		x = x | mass_a[j]
		y = y | mass_b[j]
		if max_sum < x + y:
			max_sum = x + y
if n == 1:
	print(mass_a[0] + mass_b[0])
else:
	print(max_sum)


n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
or1 = 0
or2 = 0
for i in arr1:
	or1 = or1 | i
for i in arr2:
	or2 = or2 | i
print(or1 + or2)


n = int(input())
data1 = [int(x) for x in input().split()]
data2 = [int(x) for x in input().split()]
k = 0
for i in range(len(data2)):
	k = k | data2[i]
k1 = 0
for i in range(len(data1)):
	k1 = k1 | data1[i]
print(k1 + k)


n = int(input())
arr1 = list(map(int, input().split()))[:n]
arr2 = list(map(int, input().split()))[:n]
sum1 = 0
sum2 = 0
for i in range(0, n):
	sum1 |= arr1[i]
	sum2 |= arr2[i]
print(sum1 + sum2)


n = int(input())
a = 0
for i in input().split():
	a |= int(i)
b = 0
for i in input().split():
	b |= int(i)
print(a + b)


import math, re, sys, string, operator, functools, fractions, collections
sys.setrecursionlimit(10 ** 7)
RI = lambda x=' ': list(map(int, input().split(x)))
RS = lambda x=' ': input().rstrip().split(x)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
mod = int(1000000000.0 + 7)
eps = 1e-06
pi = math.acos(-1.0)
MAX = 1010
n = RI()
a = RI()
b = RI()
a1 = functools.reduce(lambda x, y: x | y, a)
b1 = functools.reduce(lambda x, y: x | y, b)
print(a1 + b1)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a_sum = 0
b_sum = 0
for i in range(n):
	a_sum |= A[i]
	b_sum |= B[i]
print(a_sum + b_sum)


from functools import reduce

def solve():
	n = int(input())
	a = reduce(lambda a0, a1: a0 | a1, [int(s) for s in input().split()])
	b = reduce(lambda a0, a1: a0 | a1, [int(s) for s in input().split()])
	print(a + b)
solve()


n = int(input())
n1 = input().split(' ')
n2 = input().split(' ')
sum1 = 0
loops = 0
for i in n1:
	sum1 = sum1 | int(n1[loops])
	loops += 1
sum2 = 0
loops = 0
for i in n2:
	sum2 = sum2 | int(n2[loops])
	loops += 1
print(sum1 + sum2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maximum = 0
for i in range(len(a)):
	temp1 = 0
	temp2 = 0
	for j in range(i, len(a)):
		temp1 |= a[j]
		temp2 |= b[j]
	if temp1 + temp2 > maximum:
		maximum = temp1 + temp2
print(maximum)


from functools import reduce

def calc():
	return reduce(lambda x, y: x | y, map(int, input().split()))
n = int(input())
print(calc() + calc())


from functools import *
n = int(input())
s = ss = 0
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(0, len(a), 1):
	s |= a[i]
for i in range(0, len(b), 1):
	ss |= b[i]
print(s + ss)


from functools import reduce
from operator import ior
n = int(input())
l = list(map(int, input().split()))
m = list(map(int, input().split()))
res = reduce(ior, l)
res1 = reduce(ior, m)
print(res + res1)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in a:
	ans = ans | i
ansb = 0
for i in b:
	ansb = ansb | i
print(ans + ansb)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tot = bot = 0
for i in range(0, n):
	tot |= a[i]
	bot |= b[i]
print(tot + bot)
exit()


n = int(input())
(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
(s1, s2) = (a[0], b[0])
for x in range(1, n):
	s1 = s1 | a[x]
for y in range(1, n):
	s2 = s2 | b[y]
print(s1 + s2)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
orA = 0
orB = 0
for i in a:
	orA |= i
for i in b:
	orB |= i
print(orA + orB)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = a[0]
c1 = b[0]
for i in range(1, n):
	c |= a[i]
	c1 |= b[i]
print(c + c1)


__author__ = 'aste'

def main():
	n = int(input())
	a = map(int, input().split())
	b = map(int, input().split())
	a_or = 0
	for x in a:
		a_or |= x
	b_or = 0
	for x in b:
		b_or |= x
	print(a_or + b_or)
main()


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
ans = 0
n = inp()
a = li()
b = li()
for i in range(n):
	(x, y) = (0, 0)
	for j in range(i, n):
		x |= a[j]
		y |= b[j]
		ans = max(ans, x + y)
pr(ans)


a = int(input())
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
B = 0
for i in b:
	B = B | i
C = 0
for i in c:
	C = C | i
print(B + C)


def f(c):
	x = 0
	for _ in range(n):
		x = x | c[_]
	return x
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(f(a) + f(b))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ma = 0
for i in range(n):
	aor = 0
	bor = 0
	for j in range(i, n):
		aor |= a[j]
		bor |= b[j]
		ma = max(ma, aor + bor)
print(ma)


n = int(input())
print(eval('|'.join(input().split())) + eval('|'.join(input().split())))


n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
sum1 = 0
sum2 = 0
for i in x:
	sum1 = sum1 | i
for i in y:
	sum2 = sum2 | i
print(sum1 + sum2)


n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
fa = a[0]
fb = b[0]
for i in a[1:]:
	fa = fa | i
for i in b[1:]:
	fb = fb | i
print(fa + fb)


from functools import reduce
f = lambda : reduce(int.__or__, map(int, input().split()))
input()
print(f() + f())


n = int(input())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
res = [0, 0]
for e in a:
	res[0] |= e
for e in b:
	res[1] |= e
print(sum(res))


n = int(input())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
for j in range(n - 1):
	la[j + 1] = la[j + 1] | la[j]
	lb[j + 1] = lb[j + 1] | lb[j]
print(la[-1] + lb[-1])


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if n == 1:
	print(a[0] + b[0])
	exit()
max_val = 0
for i in range(n):
	for j in range(i, n):
		l1 = a[i:j + 1]
		l2 = b[i:j + 1]
		c = 0
		d = 0
		for ii in l1:
			c |= ii
		for ii in l2:
			d |= ii
		if c + d > max_val:
			max_val = c + d
print(max_val)


n = int(input())
a = eval(input().replace(' ', '|'))
b = eval(input().replace(' ', '|'))
print(a + b)


from operator import or_
from functools import reduce
n = int(input())
xs = [int(r) for r in input().split()]
ys = [int(r) for r in input().split()]
print(reduce(or_, xs) + reduce(or_, ys))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(x, y) = (0, 0)
for i in range(n):
	x |= a[i]
	y |= b[i]
print(x + y)


n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
totala = 0
totalb = 0
for i in range(n):
	totala |= a[i]
	totalb |= b[i]
print(totala + totalb)


maxi = 0
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for i in range(n):
	opa = opb = 0
	for j in range(i, n):
		opa = opa | a[j]
		opb = opb | b[j]
		if maxi < opa + opb:
			maxi = opa + opb
print(maxi)


def f(x, l, r):
	result = x[l]
	for i in x[l + 1:r + 1]:
		result |= i
	return result

def foo(a, b, n):
	max_a = max(a)
	max_b = max(b)
	(a, max_a, b, max_b) = (a, max_a, b, max_b) if max_a > max_b else (b, max_b, a, max_a)
	l = r = a.index(max_a)
	while r < n and f(a, l, r) + f(b, l, r) <= f(a, l, r + 1) + f(b, l, r + 1):
		r += 1
	while l > 0 and f(a, l, r) + f(b, l, r) <= f(a, l - 1, r) + f(b, l - 1, r):
		l -= 1
	return f(a, l, r) + f(b, l, r)
n = int(input())
a = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
max_a = max(a)
max_b = max(b)
(a, max_a, b, max_b) = (a, max_a, b, max_b) if max_a > max_b else (b, max_b, a, max_a)
l = r = a.index(max_a)
while r < n and f(a, l, r) + f(b, l, r) <= f(a, l, r + 1) + f(b, l, r + 1):
	r += 1
while l > 0 and f(a, l, r) + f(b, l, r) <= f(a, l - 1, r) + f(b, l - 1, r):
	l -= 1
print(f(a, l, r) + f(b, l, r))


def sobesedovanie(lst1, lst2):
	(sum1, sum2) = (0, 0)
	for i in range(len(lst1)):
		sum1 |= lst1[i]
		sum2 |= lst2[i]
	return sum1 + sum2
n = int(input())
a = [int(j) for j in input().split()]
b = [int(x) for x in input().split()]
print(sobesedovanie(a, b))


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
asum = 0
bsum = 0
for i in range(n):
	asum = asum | a[i]
	bsum = bsum | b[i]
print(asum + bsum)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

def somme(a, b):
	p = 1
	r = 0
	while a or b:
		p *= 2
		if a % 2 or b % 2:
			r += p // 2
		a = a // 2
		b = b // 2
	return r
r = 0
r2 = 0
for i in range(n):
	r = somme(r, A[i])
	r2 = somme(r2, B[i])
print(r + r2)


leng = int(input())
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]

def f(arr, leng):
	hsl = 0
	for i in range(leng):
		hsl |= arr[i]
	return hsl
tot = f(a, leng) + f(b, leng)
print(tot)


n = int(input())
l = list(map(int, input().split()))
y = list(map(int, input().split()))
(a, b) = (l[0], y[0])
for i in range(1, n):
	a |= l[i]
	b |= y[i]
print(a + b)


n = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))
m = 0

def f(a, l, r):
	seq = a[l:r]
	ret = 0
	for i in seq:
		ret |= i
	return ret
print(f(a, 0, len(a)) + f(b, 0, len(b)))


n = int(input())
a = input().strip('\n').split(' ')
b = input().strip('\n').split(' ')
ares = bres = 0
for i in range(n):
	ares = ares | int(a[i])
	bres = bres | int(b[i])
res = ares + bres
print(res)


a = int(input())
F = input().split()
sumF = 0
for x in F:
	sumF = sumF | int(x)
G = input().split()
sumG = 0
for y in G:
	sumG = sumG | int(y)
print(sumF + sumG)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m1 = 0
s1 = 0
s2 = 0
m2 = 0
for i in range(n):
	s1 = m1 | a[i]
	s2 = m2 | b[i]
	if s1 + s2 > a[i] + b[i]:
		m1 = s1
		m2 = s2
	else:
		m1 = a[i]
		m2 = b[i]
print(m1 + m2)


Input = lambda : map(int, input().split())
n = int(input())
ans = 0
ans1 = 0
for i in input().split():
	ans |= int(i)
for i in input().split():
	ans1 |= int(i)
print(ans + ans1)


import functools
import operator
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(functools.reduce(operator.or_, a) + functools.reduce(operator.or_, b))


(t, a1, a2) = (int(input()), 0, 0)
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(t):
	(a1, a2) = (a1 | x[i], a2 | y[i])
print(a1 + a2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
bitwise_or = 0
operator_or = 0
for m in range(n):
	bitwise_or = bitwise_or | a[m]
	operator_or = operator_or | b[m]
print(bitwise_or + operator_or)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans1 = A[0]
ans2 = B[0]
for i in range(1, n):
	ans1 = ans1 | A[i]
	ans2 = ans2 | B[i]
print(ans1 + ans2)


input()
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
(SUM1, SUM2) = (list(reversed(bin(max(X))[2:])), list(reversed(bin(max(Y))[2:])))
for i in X:
	if SUM1.count('1') == len(SUM1):
		break
	Temp = list(reversed(bin(i)[2:]))
	for j in range(len(Temp)):
		if Temp[j] == '1':
			SUM1[j] = '1'
for i in Y:
	if SUM2.count('1') == len(SUM2):
		break
	Temp = list(reversed(bin(i)[2:]))
	for j in range(len(Temp)):
		if Temp[j] == '1':
			SUM2[j] = '1'
print(int(''.join(reversed(SUM1)), 2) + int(''.join(reversed(SUM2)), 2))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(fa, fb) = (0, 0)
for i in range(n):
	fa |= a[i]
	fb |= b[i]
print(fa + fb)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tmp1 = tmp2 = 0
for i in range(n):
	tmp1 |= a[i]
	tmp2 |= b[i]
print(tmp1 + tmp2)


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

def f(x, l, r):
	t = 0
	for i in x[l:r]:
		t |= i
	return t
ms = 0
for s in range(n, 0, -1):
	for l in range(0, s):
		r = l + s
		if r > n:
			break
		elif f(a, l, r) + f(b, l, r) > ms:
			ms = f(a, l, r) + f(b, l, r)
print(ms)


n = int(input().split()[0])
a = input().split()
b = input().split()
a_bit = 0
b_bit = 0
for i in range(n):
	a_bit |= int(a[i])
	b_bit |= int(b[i])
print(a_bit + b_bit)


from functools import reduce
from operator import or_
I = lambda : map(int, input().split())
I()
print(reduce(or_, I()) + reduce(or_, I()))


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
a_or = 0
b_or = 0
for i in l1:
	a_or |= i
for i in l2:
	b_or |= i
print(a_or + b_or)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tmp = 0
(ans1, ans2) = (0, 0)
for i in range(len(a)):
	tmp = a[i]
	ans1 |= tmp
for i in range(len(b)):
	tmp = b[i]
	ans2 |= tmp
print(ans1 + ans2)


n = int(input())
daf1 = list(map(int, input().split()))
daf2 = list(map(int, input().split()))
sum_1 = 0
sum_2 = 0
for i in range(n):
	sum_1 = sum_1 | daf1[i]
	sum_2 = sum_2 | daf2[i]
print(sum_1 + sum_2)


z = int(input())
x1 = list(map(int, input().split()))
x2 = list(map(int, input().split()))
a1 = x1[0]
a2 = x2[0]
for i in range(1, z):
	a1 |= x1[i]
for i in range(1, z):
	a2 |= x2[i]
print(a1 + a2)


def arr_inp():
	return [int(x) for x in input().split()]
(n, a, b) = (int(input()), arr_inp(), arr_inp())
(a1, b1) = (0, 0)
for i in range(n):
	a1 |= a[i]
	b1 |= b[i]
print(a1 + b1)


def f(a, l, r):
	if l == r:
		return a[l]
	x = a[l] | a[l + 1]
	for i in range(l + 2, r + 1):
		x = x | a[i]
	return x
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = f(a, 0, n - 1)
y = f(b, 0, n - 1)
print(x + y)


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

def ORSUM(l):
	m = 0
	for i in l:
		m = m | i
	return m
print(ORSUM(a) + ORSUM(b))


import sys
import math
import bisect
import itertools
import random
import re

def solve(A):
	ans = 0
	for a in A:
		ans |= a
	return ans

def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = solve(A) + solve(B)
	print(ans)
main()


n = int(input())
ans = 0
a = [int(i) for i in input().split()]
for i in a:
	ans |= i
(n, ans) = (ans, 0)
a = [int(i) for i in input().split()]
for i in a:
	ans |= i
print(n + ans)


n = int(input())
a = input().split()
b = input().split()
or_a = 0
or_b = 0
for i in range(n):
	or_a |= int(a[i])
	or_b |= int(b[i])
print(or_a + or_b)


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
from math import ceil, floor, log, sqrt, factorial, pow, pi

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

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

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph():
	d = {}
	(v, e) = mi()
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(l, n):
	d = {}
	for i in range(1, n + 1):
		if i not in d.keys():
			d[i] = l[i]
		else:
			d[i].append(l[i])
	return d
n = ii()
a = li()
b = li()
ao = a[0]
bo = b[0]
for i in range(1, n):
	ao |= a[i]
for i in range(1, n):
	bo |= b[i]
print(ao + bo)


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

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 get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = a[0]
bb = b[0]
for i in range(1, n):
	aa |= a[i]
	bb |= b[i]
print(aa + bb)


n = input()
a = input().split(' ')
b = input().split(' ')
ans1 = 0
ans2 = 0
for i in range(len(a)):
	ans1 |= int(a[i])
	ans2 |= int(b[i])
print(ans2 + ans1)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ansA = 0
ansB = 0
for a in A:
	ansA |= a
for b in B:
	ansB |= b
print(ansA + ansB)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = 0
for l in range(n):
	x = a[l]
	y = b[l]
	for r in range(l, n):
		x = x | a[r]
		y = y | b[r]
		m = max(m, x + y)
print(m)


array_len = int(input())
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
max_sum = -1
for l in range(array_len):
	cur_a = a[l]
	cur_b = b[l]
	max_sum = max(max_sum, cur_a + cur_b)
	for r in range(l + 1, array_len):
		cur_a = cur_a | a[r]
		cur_b = cur_b | b[r]
		max_sum = max(max_sum, cur_a + cur_b)
print(max_sum)


def solution(a, b):
	m = 0
	ans = function(a, 1, len(a)) + function(b, 1, len(b))
	print(ans)

def function(a, l, r):
	sum = 0
	i = l - 1
	while i <= r - 1:
		sum = sum | a[i]
		i += 1
	return sum
n = int(input(''))
a = list(map(int, input('').split()))
b = list(map(int, input('').split()))
solution(a, b)


n = int(input())
mas1 = input().split(' ')
mas2 = input().split(' ')
mx = 0
ai = int(mas1[0])
bi = int(mas2[0])
for a in range(n):
	for b in range(a, n):
		ai |= int(mas1[a])
		bi |= int(mas2[b])
		c = ai + bi
		if c > mx:
			mx = c
print(mx)


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
a = inara()
b = inara()
asum = 0
for i in range(n):
	ans = 0
	for j in range(i, n):
		ans |= a[j]
		asum = max(asum, ans)
bsum = 0
for i in range(n):
	ans = 0
	for j in range(i, n):
		ans |= b[j]
		bsum = max(bsum, ans)
print(asum + bsum)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
s = [a[i] + b[i] for i in range(n)]
max = None
for l in range(0, n):
	aa = a[l]
	bb = b[l]
	for r in range(l, n):
		aa |= a[r]
		bb |= b[r]
		if not max or max < aa + bb:
			max = aa + bb
print(max)


from functools import reduce
I = lambda : reduce(lambda x, y: x | y, map(int, input().split()))
input()
print(I() + I())


import sys
import math
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
from functools import reduce
sys.setrecursionlimit(10 ** 6)

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

def printt(n):
	sys.stdout.write(str(n) + '\n')

def listt():
	return [int(i) for i in inputt().split()]

def gcd(a, b):
	return math.gcd(a, b)

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

def factors(n):
	step = 2 if n % 2 else 1
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(math.sqrt(n)) + 1, step) if n % i == 0)))

def comb(n, k):
	factn = math.factorial(n)
	factk = math.factorial(k)
	fact = math.factorial(n - k)
	ans = factn // (factk * fact)
	return ans

def is_prime(n):
	if n <= 1:
		return False
	if n == 2:
		return True
	if n > 2 and n % 2 == 0:
		return False
	max_div = math.floor(math.sqrt(n))
	for i in range(3, 1 + max_div, 2):
		if n % i == 0:
			return False
	return True
t = 1
for _ in range(t):
	n = int(inputt())
	l = listt()
	l1 = listt()
	k = l[0]
	q = l1[0]
	for (i, j) in zip(l[1:], l1[1:]):
		k = k | i
		q = q | j
	print(k + q)


n = int(input())
tmp1 = list(map(int, input().split()))
tmp2 = list(map(int, input().split()))
x1 = 0
x2 = 0
for i in tmp1:
	x1 |= i
for i in tmp2:
	x2 |= i
ans = x1 + x2
print(ans)


n = int(input())
li = list(map(int, input().split()))
li1 = list(map(int, input().split()))
a = 0
b = 0
for i in range(n):
	a = a | li[i]
	b = b | li1[i]
print(a + b)


size = int(input())
num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
(op1, op2) = (0, 0)
for x in range(size):
	op1 |= num1[x]
	op2 |= num2[x]
print(op1 + op2)


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
a = 0
b = 0
for i in range(len(l1)):
	a = a | l1[i]
	b = b | l2[i]
print(a + b)


from operator import ior
import functools
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(functools.reduce(ior, a) + functools.reduce(ior, b))


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = 0
d = 0
for i in range(0, n):
	c = c | a[i]
	d = d | b[i]
print(c + d)


n = int(input())
l = list(map(int, input().split()))
k = list(map(int, input().split()))
ans = 0
for t in range(n):
	z = 0
	w = 0
	for j in range(t, n):
		z = z | l[j]
		w = w | k[j]
		ans = max(ans, z + w)
print(ans)


def main():
	from functools import reduce
	from operator import __or__
	input()
	print(sum((reduce(__or__, map(int, input().split())) for _ in (0, 1))))
main()


def bitwise_or(array):
	result = array[0]
	for number in array[1:]:
		result |= number
	return result

def main():
	input()
	a = [int(_) for _ in input().split()]
	b = [int(_) for _ in input().split()]
	print(bitwise_or(a) + bitwise_or(b))
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_or = 0
b_or = 0
for i in range(n):
	a_or |= a[i]
	b_or |= b[i]
print(a_or + b_or)