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: interview

Starter code:

Solutions:
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())))

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()))
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)


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)


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)

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())
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)


#!/usr/bin/env python3

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)


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)


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()))
a_sum = 0
b_sum = 0
for i in range(n):
    a_sum |= A[i]
    b_sum |= B[i]
print(a_sum + b_sum)

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)


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)

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)

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())
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)

3

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

# n = 5
# a = [1,2,4,3,2]
# b = [2,3,3,12,1]

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)


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())
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])
    


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 = 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

# for leng in range(1, n+1):
#     for start in range(0, n-leng+1):
#         tmp = f(a, start, leng) + f(b, start, leng)
#         if tmp > m:
#             m = tmp
# print(tmp)
print(f(a, 0, len(a)) + f(b, 0, len(b)))


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)


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))

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)


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)