Ridhiman challenged Ashish to find the maximum valued subsequence of an array $a$ of size $n$ consisting of positive integers. 

The value of a non-empty subsequence of $k$ elements of $a$ is defined as $\sum 2^i$ over all integers $i \ge 0$ such that at least $\max(1, k - 2)$ elements of the subsequence have the $i$-th bit set in their binary representation (value $x$ has the $i$-th bit set in its binary representation if $\lfloor \frac{x}{2^i} \rfloor \mod 2$ is equal to $1$). 

Recall that $b$ is a subsequence of $a$, if $b$ can be obtained by deleting some(possibly zero) elements from $a$.

Help Ashish find the maximum value he can get by choosing some subsequence of $a$.


-----Input-----

The first line of the input consists of a single integer $n$ $(1 \le n \le 500)$ — the size of $a$.

The next line consists of $n$ space-separated integers — the elements of the array $(1 \le a_i \le 10^{18})$.


-----Output-----

Print a single integer — the maximum value Ashish can get by choosing some subsequence of $a$.


-----Examples-----
Input
3
2 1 3

Output
3
Input
3
3 1 4

Output
7
Input
1
1

Output
1
Input
4
7 7 1 1

Output
7


-----Note-----

For the first test case, Ashish can pick the subsequence $\{{2, 3}\}$ of size $2$. The binary representation of $2$ is 10 and that of $3$ is 11. Since $\max(k - 2, 1)$ is equal to $1$, the value of the subsequence is $2^0 + 2^1$ (both $2$ and $3$ have $1$-st bit set in their binary representation and $3$ has $0$-th bit set in its binary representation). Note that he could also pick the subsequence $\{{3\}}$ or $\{{2, 1, 3\}}$.

For the second test case, Ashish can pick the subsequence $\{{3, 4\}}$ with value $7$.

For the third test case, Ashish can pick the subsequence $\{{1\}}$ with value $1$.

For the fourth test case, Ashish can pick the subsequence $\{{7, 7\}}$ with value $7$.

Source: codeforces | Difficulty: MEDIUM


Solutions:
def main():
	n = input().split()[0]
	arr = list(map(int, input().split()))
	answer = 0
	n = int(n)
	for i in range(n):
		answer = max(answer, arr[i])
	for i in range(n):
		for j in range(i + 1, n):
			answer = max(answer, arr[i] | arr[j])
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				answer = max(answer, arr[i] | arr[j] | arr[k])
	print(answer)
	return
main()


from sys import stdin
import sys
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
if n < 3:
	ans = 0
	for i in a:
		ans |= i
	print(ans)
	sys.exit()
ans = 0
for i in range(n):
	for j in range(i):
		for k in range(j):
			ans = max(ans, a[i] | a[j] | a[k])
print(ans)


import sys
import collections as cc
import bisect as bi
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
if n < 3:
	ans = 0
	for i in l:
		ans |= i
	print(ans)
else:
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				ans = max(ans, l[i] | l[j] | l[k])
	print(ans)


import os
import sys
from io import BytesIO, IOBase
profile = 0
pypy = 1

def iin():
	return int(input())

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

def main():
	n = iin()
	a = lin()
	ans = 0
	for i in range(n):
		for j in range(i, n):
			for k in range(j, n):
				ans = max(ans, a[i] | a[j] | a[k])
	print(ans)
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')
if pypy:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
if profile:
	import cProfile
	cProfile.run('main()')
else:
	main()


from sys import stdin, stdout
R = lambda : stdin.readline().strip()
RL = lambda : list(map(int, R().split(' ')))
output = lambda x: stdout.write(str(x))
n = int(R())
a = RL()
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, a[i] | a[j] | a[k])
output(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
answer = arr[0]
if len(arr) == 2:
	answer = arr[0] | arr[1]
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		for k in range(j + 1, n):
			answer = max(answer, arr[i] | arr[j] | arr[k])
out(answer)


n = int(input())
arr = list(map(int, input().split()))
ans = 0
arr.sort(reverse=True)
if n == 1:
	ans = arr[0]
elif n == 2:
	ans = arr[0] | arr[1]
else:
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				y = arr[i] | arr[j] | arr[k]
				ans = max(ans, y)
print(ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n = int(input())
arr = [int(x) for x in input().split()]
ans = 0
if n == 1:
	ans = arr[0]
if n == 2:
	ans = arr[0] | arr[1]
else:
	for x in range(n):
		for y in range(x + 1, n):
			for z in range(y + 1, n):
				ans = max(ans, arr[x] | arr[y] | arr[z])
print(ans)


def prog():
	n = int(input())
	nums = list(map(int, input().split()))
	if n == 1:
		print(nums[0])
	elif n == 2:
		print(nums[0] | nums[1])
	else:
		largest = 0
		for i in range(n - 2):
			for j in range(i + 1, n - 1):
				for k in range(j + 1, n):
					largest = max(largest, nums[i] | nums[j] | nums[k])
		print(largest)
prog()


from bisect import bisect_left, bisect_right

class Result:

	def __init__(self, index, value):
		self.index = index
		self.value = value

class BinarySearch:

	def __init__(self):
		pass

	@staticmethod
	def greater_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_right(func, num)
			if index == len(func):
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(omega) <= num:
				return Result(None, None)
			while alpha < omega:
				if func(alpha) > num:
					return Result(alpha, func(alpha))
				if omega == alpha + 1:
					return Result(omega, func(omega))
				mid = (alpha + omega) // 2
				if func(mid) > num:
					omega = mid
				else:
					alpha = mid

	@staticmethod
	def less_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_left(func, num) - 1
			if index == -1:
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(alpha) >= num:
				return Result(None, None)
			while alpha < omega:
				if func(omega) < num:
					return Result(omega, func(omega))
				if omega == alpha + 1:
					return Result(alpha, func(alpha))
				mid = (alpha + omega) // 2
				if func(mid) < num:
					alpha = mid
				else:
					omega = mid
import os
import sys
from io import BytesIO, IOBase
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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
		continue
	if n == 2:
		print(a[0] | a[1])
		continue
	ans = 0
	for i in range(n):
		for j in range(i, n):
			for k in range(j, n):
				ans = max(ans, a[i] | a[j] | a[k])
	print(ans)


from math import ceil, floor, sqrt, log

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def dec_pow(a, n):
	res = 1
	while n > 0:
		if n % 2 == 1:
			res *= a
		a *= a
		n //= 2
	return res

def find_k_powers(l, r, k):
	m = 1
	res = []
	while m <= pow(10, 18):
		if m >= l and m <= r:
			res.append(m)
		m *= k
	if len(res) == 0:
		print(-1)
	print(*res, sep=' ')

def find_mx_set_bits(n, arr):
	mx = 0
	if n == 1:
		return arr[0]
	if n == 2:
		return arr[0] | arr[1]
	if n == 3:
		return arr[0] | arr[1] | arr[2]
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				mx = max(mx, arr[i] | arr[j] | arr[k])
	return mx
t = 1
while t:
	t = t - 1
	n = int(input())
	l = list(map(int, input().strip().split()))[:n]
	print(find_mx_set_bits(n, l))


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


from sys import stdin, stdout
n = int(stdin.readline())
a = sorted([int(x) for x in stdin.readline().split()], reverse=True)
if n <= 3:
	base = 0
	for x in a:
		base = base | x
	print(base)
else:
	high = 0
	for x in range(n):
		for y in range(x, n):
			for z in range(y, n):
				high = max(high, a[x] | a[y] | a[z])
	print(high)


def main():
	n = int(input())
	a = readIntArr()
	ans = 0
	if n <= 3:
		for x in a:
			ans = ans | x
	else:
		for i in range(n):
			for j in range(i + 1, n):
				for k in range(j + 1, n):
					ans = max(ans, a[i] | a[j] | a[k])
	print(ans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
main()


import sys
import math
import operator as op
from functools import reduce
from bisect import *
from collections import deque

def read_line():
	return sys.stdin.readline()[:-1]

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

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
N = int(1000000.0) + 10
fenwick = [0] * N

def add(i, x, n):
	while i < n:
		fenwick[i] += x
		i = i | i + 1

def fsum(i, n):
	res = 0
	while i >= 0:
		res += fenwick[i]
		i = (i & i + 1) - 1
	return res

def fsum_range(i, j, n):
	return fsum(j, n) - fsum(i - 1, n)
mod = int(1000000000.0) + 7
mod2 = 998244353
t = 1
for i in range(t):
	n = read_int()
	a = read_int_line()
	if n == 1:
		print(a[0])
		continue
	ans = -1
	for i in range(n):
		for j in range(i, n):
			for k in range(j, n):
				ans = max(ans, a[i] | a[j] | a[k])
	print(ans)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
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')

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

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

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return flag

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None
t = 1
for i in range(t):
	n = N()
	a = RLL()
	if n <= 3:
		ans = list(accumulate(a, lambda x, y: x | y))[-1]
	else:
		ans = 0
		for i in range(n - 2):
			for j in range(i + 1, n - 1):
				for k in range(j + 1, n):
					ans = max(ans, a[i] | a[j] | a[k])
	print(ans)


import math
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def main():
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	if n < 3:
		for i in range(0, n):
			ans |= l[i]
		print(ans)
	else:
		for i in range(0, n):
			for j in range(i + 1, n):
				for k in range(j + 1, n):
					ans = max(ans, l[i] | l[j] | l[k])
		print(ans)
t = 1
for i in range(0, t):
	main()


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


from sys import stdin, stdout

def maximum_sebsequence_value(n, a):
	res = 0
	for i in range(n):
		for j in range(i, n):
			for k in range(j, n):
				res = max(res, a[i] | a[j] | a[k])
	return res
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
stdout.write(str(maximum_sebsequence_value(n, a)) + '\n')


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	n = II()
	aa = LI()
	ans = 0
	if n == 1:
		ans = aa[0]
	elif n == 2:
		for i in range(n):
			for j in range(i):
				ans = max(ans, aa[i] | aa[j])
	else:
		for i in range(n):
			for j in range(i):
				for k in range(j):
					ans = max(ans, aa[i] | aa[j] | aa[k])
	print(ans)
main()


(n, a) = (int(input()), [int(x) for x in input().split()])
x = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			x = max(x, a[i] | a[j] | a[k])
print(x)


def main():
	N = int(input())
	A = list(map(int, input().split()))
	maxVal = 0
	for i in range(N):
		for j in range(i, N):
			for k in range(j, N):
				maxVal = max(maxVal, A[i] | A[j] | A[k])
	print(maxVal)
main()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	ma = 0
	for i in range(n):
		for j in range(i, n):
			for k in range(j, n):
				ma = max(ma, a[i] | a[j] | a[k])
	print(ma)
main()


class Solution:

	def __init__(self):
		n = int(input())
		a = list(map(int, input().split()))
		self.solve(n, a)

	def solve(self, n, a):
		if len(a) == 1:
			return print(a[0])
		if len(a) == 2:
			return print(a[0] | a[1])
		res = 0
		for i in range(0, n):
			for j in range(i + 1, n):
				for k in range(j + 1, n):
					res = max(res, a[i] | a[j] | a[k])
		print(res)
Solution()


def solve(nums):
	res = 0
	if len(nums) == 1:
		return nums[0]
	elif len(nums) == 2:
		return nums[0] | nums[1]
	for i in range(len(nums)):
		for j in range(i + 1, len(nums)):
			for k in range(j + 1, len(nums)):
				val = nums[i] | nums[j] | nums[k]
				res = max(res, val)
	return res
t = int(input())
nums = list(map(int, input().split()))
print(solve(nums))


import sys
from collections import deque
readline = sys.stdin.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))

def solve():
	n = ni()
	a = nl()
	if n <= 3:
		ans = 0
		for y in a:
			ans |= y
	else:
		ans = 0
		for i in range(n - 2):
			for j in range(i + 1, n - 1):
				for k in range(j + 1, n):
					ans = max(ans, a[i] | a[j] | a[k])
	print(ans)
	return
solve()


n = int(input())
a = list(map(int, input().split()))
maxi = 0
if n >= 3:
	for i in range(n):
		for j in range(i + 1, n):
			for z in range(j + 1, n):
				maxi = max(maxi, a[i] | a[j] | a[z])
else:
	for i in range(n):
		maxi |= a[i]
print(maxi)


import sys

def input():
	return sys.stdin.readline().rstrip()
n = int(input())
arr = [int(i) for i in input().split()]
best = 0
for i in range(n):
	x = arr[i]
	best = max(best, x)
	for j in range(i + 1, n):
		x = arr[i] | arr[j]
		best = max(best, x)
		for k in range(j + 1, n):
			x = arr[i] | arr[j] | arr[k]
			best = max(best, x)
print(best)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
elif n == 2:
	print(a[0] | a[1])
else:
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				ans = max(ans, a[i] | a[j] | a[k])
	print(ans)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
best = 0
if n <= 3:
	for i in A:
		best = best | i
else:
	for i in range(n - 2):
		for j in range(i + 1, n - 1):
			temp = A[i] | A[j]
			for k in range(j + 1, n):
				best = max(best, temp | A[k])
print(best)


n = int(input())
a = [int(x) for x in input().split()]
high = 0
for x in range(n):
	for y in range(x, n):
		for z in range(y, n):
			high = max(high, a[x] | a[y] | a[z])
print(high)


import sys
from math import *

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

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

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

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

def main():

	def pro(q, s, n):
		if n == 0:
			print('YES')
			exit()
		print(n // 2, q, s, n)
		f = q[n // 2]
		a = s.index(f)
		if a < n // 2:
			s = s[:a] + s[a:n - a - 1] + s[n - a - 1:]
		a = s.index(f)
		s = s[a:] + s[n - a - 1:a] + s[:n - a - 1]
		s = [s[n - 1]] + s[1:n - 2] + [s[0]]
		s = s[n // 2:] + s[:n // 2]
		if s[n // 2 - 1] == q[n // 2 - 1]:
			del s[n // 2]
			del s[n // 2 + 1]
			del q[n // 2]
			del q[n // 2 + 1]
			pro(q, s, n - 2)
		print('NO')
		exit()
	n = iinput()
	q = rlinput()
	s = rlinput()
	if sorted(s) != sorted(q):
		print('NO')
	elif n == 1:
		print('YES')
	elif n % 2 and q[(n + 1) // 2] != s[(n + 1) // 2]:
		print('NO')
	else:
		if n % 2:
			del q[(n + 1) // 2]
			del s[(n + 1) // 2]
		pro(q, s, n - n % 2)

def main1():
	n = iinput()
	q = rlinput()
	res = 0
	for i in range(n):
		f = q[i]
		res = max(res, f)
		for o in range(i + 1, n):
			f1 = f | q[o]
			res = max(res, f1)
			for p in range(o + 1, n):
				res = max(res, f1 | q[p])
	print(res)
for inytd in range(1):
	main1()


import sys
input = sys.stdin.readline
from collections import *
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
elif n == 2:
	print(a[0] | a[1])
else:
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				ans = max(ans, a[i] | a[j] | a[k])
	print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, a[i] | a[j] | a[k])
print(ans)


n = int(input())
in1 = list(map(int, input().split()))
ans1 = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans1 = max(ans1, in1[i] | in1[j] | in1[k])
print(ans1)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def solve(n, A):
	if n == 1:
		return A[0]
	if n == 2:
		return A[0] | A[1]
	ans = 0
	for i in range(n - 2):
		for j in range(i + 1, n - 1):
			for k in range(j + 1, n):
				ans = max(ans, A[i] | A[j] | A[k])
	return ans

def main():
	n = int(input())
	A = list(map(int, input().split()))
	ans = solve(n, A)
	sys.stdout.write(str(ans) + '\n')
main()


def process(n, a):
	if n == 1:
		print(a[0])
	elif n == 2:
		print(a[1] | a[0])
	else:
		mx = 0
		for i in range(n):
			for j in range(i + 1, n):
				for k in range(j + 1, n):
					mx = max(mx, a[i] | a[j] | a[k])
		print(mx)
n = int(input())
a = list(map(int, input().split()))
process(n, a)


from sys import stdin
from collections import Counter
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
ans = 1
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, a[i] | a[j] | a[k])
print(ans)


import sys
import math
from collections import defaultdict, deque
import heapq
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, arr[i] | arr[j] | arr[k])
print(ans)


n = int(input())
l = list(map(int, input().split()))
if n <= 3:
	m = l[0]
	for i in range(1, n):
		m = m | l[i]
else:
	m = 0
	for i in range(n - 2):
		for j in range(i + 1, n - 1):
			for k in range(j + 1, n):
				m = max(m, l[i] | l[j] | l[k])
print(m)


n = int(input())
a = list(map(int, input().split()))
wynik = 0
if n < 3:
	wyn = a[0]
	for i in range(1, n):
		wyn = wyn | a[i]
	print(wyn)
else:
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				wynik = max(wynik, a[i] | a[j] | a[k])
	print(wynik)


n = int(input())
l = list(map(int, input().split()))
ans = l[0]
if n > 1:
	ans = l[0] | l[1]
for i in range(n):
	for j in range(i + 1, n):
		for z in range(j + 1, n):
			ans = max(ans, l[i] | l[j] | l[z])
print(ans)


import sys

def line():
	return sys.stdin.readline()

def main():
	n = int(line())
	arr = list(map(int, line().split(' ')))
	if len(arr) == 1:
		print(arr[0])
	elif len(arr) == 2:
		print(arr[0] | arr[1])
	else:
		ans = 0
		for i in range(n):
			for j in range(i + 1, n):
				for k in range(j + 1, n):
					ans = max(ans, arr[i] | arr[j] | arr[k])
		print(ans)
main()


from collections import defaultdict
import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

class UnionFind:

	def __init__(self):
		self.__table = {}
		self.__size = defaultdict(lambda : 1)
		self.__rank = defaultdict(lambda : 1)

	def __root(self, x):
		if x not in self.__table:
			self.__table[x] = x
		elif x != self.__table[x]:
			self.__table[x] = self.__root(self.__table[x])
		return self.__table[x]

	def same(self, x, y):
		return self.__root(x) == self.__root(y)

	def union(self, x, y):
		x = self.__root(x)
		y = self.__root(y)
		if x == y:
			return False
		if self.__rank[x] < self.__rank[y]:
			self.__table[x] = y
			self.__size[y] += self.__size[x]
		else:
			self.__table[y] = x
			self.__size[x] += self.__size[y]
			if self.__rank[x] == self.__rank[y]:
				self.__rank[x] += 1
		return True

	def size(self, x):
		return self.__size[self.__root(x)]

	def num_of_group(self):
		g = 0
		for (k, v) in self.__table.items():
			if k == v:
				g += 1
		return g

def slv(N, A):
	A.sort(reverse=True)
	ans = 0
	for i in range(N):
		t = (1 << A[i].bit_length()) - 1
		ans = max(ans, A[i])
		for j in range(i + 1, N):
			b = A[i] | A[j]
			ans = max(ans, b)
			for k in range(j + 1, N):
				ans = max(ans, b | A[k])
	return ans

def main():
	N = read_int()
	A = read_int_n()
	print(slv(N, A))
main()


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	found['G'] = set()
	found['B'] = set()
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char].add((i + 1) * (w + 2) + s.index(char) + 1)
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in range(base ** n):
		s = [tb // base ** bt % base for bt in range(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.size = len(ls) + 1
				(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in edge]) for edge in self.edges]):
			print([[nd for (nd, d) in edge] for edge in self.edges])
		else:
			print(self)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0
n = I()
a = LI()
ans = max(a)
for i in range(n):
	for j in range(i + 1, n):
		tmp = a[i] | a[j]
		ans = max(ans, tmp)
		for k in range(j + 1, n):
			ans = max(ans, tmp | a[k])
print(ans)


import sys
import math
input = sys.stdin.readline
n = int(input())
a = [int(_) for _ in input().split()]
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, a[i] | a[j] | a[k])
print(ans)


n = int(input())
l = list(map(int, input().split()))
best = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			best = max(best, l[i] | l[j] | l[k])
print(best)


n = int(input())
a = list(map(int, input().split()))
best = 0
if n <= 3:
	for e in a:
		best |= e
else:
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				best = max(best, a[i] | a[j] | a[k])
print(best)


import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
if n <= 3:
	m = 0
	for v in A:
		m |= v
	print(m)
	sys.exit(0)
cnt = [[] for _ in range(64)]
best = 0
for i in range(n):
	for j in range(64):
		if i & 1 << j:
			cnt[j].append(i)
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			best = max(best, A[i] | A[j] | A[k])
print(best)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
cu = lambda x: max(0, x - 1)
cd = lambda x: min(r - 1, x + 1)
cl = lambda x: max(0, x - 1)
cr = lambda x: min(c - 1, x + 1)
n = I()
a = list(R())
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, a[i] | a[j] | a[k])
print(ans)


import sys
from array import array
from typing import List, Tuple, TypeVar, Generic, Sequence, Union

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	from functools import reduce
	from operator import or_
	n = int(input())
	if n < 3:
		print(reduce(or_, map(int, input().split())))
		exit()
	mask = (1 << 30) - 1
	(upper, lower) = (array('i', [0]) * n, array('i', [0]) * n)
	for (i, x) in enumerate(map(int, input().split())):
		upper[i] = x >> 30
		lower[i] = x & mask
	(ans_upper, ans_lower) = (0, 0)
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				if ans_upper < upper[i] | upper[j] | upper[k] or (ans_upper == upper[i] | upper[j] | upper[k] and ans_lower < lower[i] | lower[j] | lower[k]):
					(ans_upper, ans_lower) = (upper[i] | upper[j] | upper[k], lower[i] | lower[j] | lower[k])
	print((ans_upper << 30) + ans_lower)
main()


import math
m = int(math.log(pow(10, 18), 2))
n = int(input())
arr = list(map(int, input().split(' ')))
res = arr[0]
if n <= 3:
	for i in arr:
		res = res | i
	print(res)
else:
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				res = max(res, arr[i] | arr[j] | arr[k])
	print(res)


import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
mx = 0
if n > 3:
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				mx = max(mx, l[i] | l[j] | l[k])
else:
	for i in l:
		mx = mx | i
print(mx)


from collections import defaultdict
it = lambda : list(map(int, input().strip().split()))
INF = float('inf')

def solve():
	n = int(input())
	A = it()
	if n < 3:
		ans = 0
		for a in A:
			ans = ans | a
		return ans
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				ans = max(ans, A[i] | A[j] | A[k])
	return ans
print(solve())


import sys
from collections import deque, Counter
from itertools import product
n = int(input())
ls = list(map(int, input().split()))
mx = 0
for i in range(n):
	mx = max(mx, ls[i])
	for j in range(i + 1, n):
		mx = max(mx, ls[i] | ls[j])
		for k in range(j + 1, n):
			mx = max(mx, ls[i] | ls[j] | ls[k])
print(mx)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
if n <= 3:
	X = 0
	for a in A:
		X |= a
	print(X)
else:
	ANS = 0
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				ANS = max(ANS, A[i] | A[j] | A[k])
	print(ANS)


n = int(input())
a = list(map(int, input().split()))
ans = 0
if n < 3:
	for i in range(n):
		ans = ans | a[i]
else:
	for first in range(n):
		for second in range(first + 1, n):
			for third in range(second + 1, n):
				ans_local = a[first] | a[second] | a[third]
				if ans_local > ans:
					ans = ans_local
print(ans)


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

def print_list(l):
	print(' '.join(map(str, l)))
n = int(input())
nums = read_list()
res = 0
for i in range(n):
	a = nums[i]
	for j in range(i, n):
		b = nums[j]
		for k in range(j, n):
			res = max(a | b | nums[k], res)
print(res)


import math, sys, bisect
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
N = int(input())
A = alele()
if N <= 3:
	Ans = A[0]
	for i in range(1, N):
		Ans |= A[i]
	print(Ans)
else:
	maxi = -1
	for i in range(N):
		for j in range(i + 1, N):
			for k in range(j + 1, N):
				maxi = max(maxi, A[i] | A[j] | A[k])
	print(maxi)


n = int(input())
a = tuple(map(int, input().split()))
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, a[i] | a[j] | a[k])
print(ans)


n = int(input())
a = [*map(int, input().split())]
res = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			res = max(res, a[i] | a[j] | a[k])
print(res)


import sys
input = sys.stdin.readline
t = int(input())
n = list(map(int, input().split()))
maxx = 0
for i in range(t):
	for j in range(i, t):
		for k in range(j, t):
			maxx = max(maxx, n[i] | n[j] | n[k])
print(maxx)


import sys
ip = lambda : sys.stdin.readline().rstrip()
n = int(ip())
a = list(map(int, ip().split()))
ans = 0
if n <= 3:
	for i in range(n):
		ans |= a[i]
else:
	for i in range(n - 2):
		for j in range(i + 1, n - 1):
			for k in range(j + 1, n):
				ans = max(ans, a[i] | a[j] | a[k])
print(ans)


(N,) = map(int, input().split())
X = list(map(int, input().split()))
R = 0
for i in range(N):
	x = X[i]
	R = max(R, x)
	for j in range(i + 1, N):
		y = X[j]
		R = max(R, x | y)
		for k in range(j + 1, N):
			z = X[k]
			R = max(R, x | y | z)
print(R)


n = int(input())
lis = list(map(int, input().split()))
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, lis[i] | lis[j] | lis[k])
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
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()))
m = 0
for i in range(0, len(a)):
	for j in range(i, len(a)):
		for k in range(j, len(a)):
			m = max(m, a[i] | a[j] | a[k])
print(m)


def parseint():
	ln = input().split()
	for i in range(len(ln)):
		ln[i] = int(ln[i])
	return ln

def solve(n, a):
	if n == 1:
		print(a[0])
	elif n == 2:
		print(a[0] | a[1])
	else:
		max_val = 0
		for i in range(n - 2):
			for j in range(i + 1, n - 1):
				for k in range(j + 1, n):
					val = a[i] | a[j] | a[k]
					if val > max_val:
						max_val = val
		print(max_val)
n = int(input())
a = parseint()
solve(n, a)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, a):
	if n < 3:
		result = 0
		for item in a:
			result |= item
		return result
	best = 0
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				best = max(best, a[i] | a[j] | a[k])
	return best
n = int_in()
a = arr_in()
out(solve(n, a))


from collections import *
import math

def main():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	res = 0
	if n < 3:
		for v in arr:
			res = res | v
	else:
		for i in range(n):
			for j in range(i + 1, n):
				for k in range(j + 1, n):
					res = max(res, arr[i] | arr[j] | arr[k])
	print(res)
main()


import sys
input = sys.stdin.readline
n = int(input())
lista = list(map(int, input().split()))
resposta = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			resposta = max(resposta, lista[i] | lista[j] | lista[k])
print(resposta)


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
ans = -float('inf')
if len(a) == 1:
	print(a[0])
elif len(a) == 2:
	print(a[0] | a[1])
else:
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				ans = max(ans, a[i] | a[j] | a[k])
	print(ans)


n = int(input())
arr = list(map(int, input().split()))
fin = 0
for i in range(n):
	fin = max(fin, arr[i])
	for j in range(i + 1, n):
		fin = max(fin, arr[i] | arr[j])
		for k in range(j + 1, n):
			fin = max(fin, arr[i] | arr[j] | arr[k])
print(fin)


n = int(input())
values = list(map(int, input().strip().split()))
_max = values[0]
if len(values) > 1:
	_max |= values[1]
if len(values) > 2:
	_max |= values[2]
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		for k in range(j + 1, n):
			_max = max(values[i] | values[j] | values[k], _max)
print(_max)


from collections import *
n = int(input())
a = list(map(int, input().split()))
ans = max(a)
for i in range(n):
	for j in range(i + 1, n):
		ans = max(ans, a[i] | a[j])
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			val = a[i] | a[j]
			val |= a[k]
			ans = max(ans, val)
print(ans)


from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
res = max(a)
for i in range(n):
	for j in range(i + 1, n):
		res = max(res, a[i] | a[j])
		for k in range(j + 1, n):
			res = max(res, a[i] | a[j] | a[k])
print(res)


n = int(input())
a = list(map(int, input().split()))
m = 0
for i in range(0, len(a)):
	for j in range(i, len(a)):
		for k in range(j, len(a)):
			m = max(m, a[i] | a[j] | a[k])
print(m)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	best = 0
	for i in range(N):
		best = max(best, A[i])
		for j in range(i + 1, N):
			temp = A[i] | A[j]
			best = max(best, temp)
			bothZeroes = ~A[i] & ~A[j]
			for k in range(j + 1, N):
				best = max(best, temp | A[k])
	return best
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)


import sys
input = sys.stdin.readline

def calc(arr):
	v = max(1, len(arr) - 2)
	ans = 0
	for i in range(m):
		count = 0
		for j in range(len(arr)):
			if arr[j][i] == '1':
				count += 1
		if count >= v:
			ans += 2 ** (m - i - 1)
	return ans
n = int(input())
a = sorted(list(map(int, input().split())))
a = a[::-1]
if n == 1:
	print(a[0])
	exit()
if n == 2:
	print(a[0] | a[1])
	exit()
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			ans = max(ans, a[i] | a[j] | a[k])
print(ans)


import os
from io import BytesIO, IOBase
import sys
from collections import Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor

def main():
	n = int(input())
	a = list(map(int, input().split()))
	ma = 0
	for i in range(n):
		for j in range(i, n):
			for k in range(j, n):
				ma = max(ma, a[i] | a[j] | a[k])
	print(ma)
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')
main()


import os
import sys
from io import BytesIO, IOBase
import threading

def main(n, arr):
	a = max(arr)
	res = 0
	for i in range(min(3, n)):
		res |= arr[i]
	for k in range(n):
		for i in range(k + 1, n):
			for j in range(i + 1, n):
				res = max(res, arr[k] | arr[i] | arr[j])
	p_2 = 1
	ans = 0
	for i in range(64):
		if 1 << i & res:
			ans += p_2
		p_2 *= 2
	return ans
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())
arr = tuple(map(int, input().split()))
print(main(n, arr))


from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
m = max(a)
for x in range(n):
	for y in range(x + 1, n):
		t = a[x] | a[y]
		if t > m:
			m = t
		for z in range(y + 1, n):
			t = a[x] | a[y] | a[z]
			if t > m:
				m = t
print(m)


n = int(input())
a = list(map(int, input().strip().split()))
if n == 1:
	print(a[0])
elif n == 2:
	print(a[0] | a[1])
else:
	maks = 0
	for i in range(len(a)):
		for j in range(i + 1, len(a)):
			for k in range(j + 1, len(a)):
				maks = max(maks, a[i] | a[j] | a[k])
	print(maks)


from sys import stdin, stdout
import sys
from math import *
from collections import deque
input = stdin.readline
n = int(input())
ar = list(map(int, input().split()))
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, ar[i] | ar[j] | ar[k])
print(ans)


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 ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

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

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
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 fsep():
	return map(float, inp().split())

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

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

def pow(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
from functools import reduce

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

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		self.num_sets -= 1
		self.parent[a] = b
		self.size[b] += self.size[a]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

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

def solve():
	m = 1
	n = N()
	ar = lis()
	if n < 100:
		for i in range(n):
			for j in range(n):
				for k in range(n):
					t = ar[i] | ar[j] | ar[k]
					m = max(m, t)
		print(m)
	else:
		for i in range(n):
			for j in range(i, n):
				for k in range(j, n):
					t = ar[i] | ar[j] | ar[k]
					m = max(m, t)
		print(m)
solve()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.append(0)
n = len(a)
b = a[0]
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			b = max(b, a[i] | a[j] | a[k])
print(b)


import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
n = inp()
x = ip()
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, x[i] | x[j] | x[k])
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
mx = 0
for i1 in range(n):
	for i2 in range(i1, n):
		for i3 in range(i2, n):
			mx = max(mx, a[i1] | a[i2] | a[i3])
print(mx)


import os
import sys
from io import BytesIO, IOBase
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')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

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

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

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	n = N()
	arr = RLL()
	res = 0
	for i in range(n):
		for j in range(i, n):
			for k in range(j, n):
				res = max(res, arr[i] | arr[j] | arr[k])
	print(res)
main()


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
	ans = 0
	for i in a:
		ans = ans | i
	print(ans)
else:
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				ans = max(ans, a[i] | a[j] | a[k])
	print(ans)


n = int(input())
a = list(map(int, input().split()))
max = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			if max < a[i] | a[j] | a[k]:
				max = a[i] | a[j] | a[k]
print(max)


n = int(input())
u = list(map(int, input().split()))
if n == 1:
	print(u[0])
	exit()
if n == 2:
	print(u[0] | u[1])
	exit()
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			ans = max(u[i] | u[j] | u[k], ans)
print(ans)


import math as mt
import sys, string
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heapify, heappop
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
l = L()
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, l[i] | l[j] | l[k])
print(ans)


PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007
N = 64

def bin32(num):
	return '{0:064b}'.format(num)

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

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

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
n = ii()
a = li()
if n == 1:
	print(a[0])
elif n == 2:
	print(a[0] | a[1])
else:
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				ans = max(ans, a[i] | a[j] | a[k])
	print(ans)


n = int(input())
s = list(map(int, input().split()))
MAX = s[0]
if n == 2:
	MAX = MAX | s[1]
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			MAX = max(MAX, s[i] | s[j] | s[k])
print(MAX)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
n = int(input())
a = list(mapi())
res = max(a)
if n <= 3:
	for i in range(n):
		res |= a[i]
else:
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				res = max(res, a[i] | a[j] | a[k])
print(res)


import sys
input = sys.stdin.readline
import heapq
import copy
import math

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

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

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

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

class Node:

	def _init_(self, val):
		self.data = val
		self.left = None
		self.right = None

def pre_sum(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def pre_back(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def search_leftmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[l] == val:
			return l
		if r - l <= 1:
			if arr[r] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] >= val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def search_rightmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[r] == val:
			return r
		if r - l <= 1:
			if arr[l] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] > val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = 1
	mod = 1000000007
	limit = 10 ** 18
	for test in range(tests):
		n = inp()
		a = inlt()
		ans = 0
		for k in range(0, n):
			for i in range(k, n):
				for j in range(i, n):
					ans = max(ans, a[i] | a[j] | a[k])
		print(ans)
main()


import collections

def read():
	return input().strip()

def readInt():
	return int(input().strip())

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

def solve(n, arr):
	ans = 0
	for i in range(n):
		for j in range(i, n):
			for k in range(j, n):
				(valI, valJ, valK) = (arr[i], arr[j], arr[k])
				ans = max(ans, valI | valJ | valK)
	return ans
n = readInt()
arr = readList()
print(solve(n, arr))


def f():
	n = int(input())
	A = [int(s) for s in input().split()]
	A.sort(reverse=True)
	ans = 0
	for i in range(n):
		for j in range(i, n):
			for k in range(j, n):
				x = A[i] | A[j] | A[k]
				ans = max(ans, x)
	print(ans)
f()


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def solve(N, A):
	if N == 1:
		return A[0]
	elif N == 2:
		return A[0] | A[1]
	ans = 0
	for i in range(N):
		for j in range(i + 1, N):
			for k in range(j + 1, N):
				ans = max(ans, A[i] | A[j] | A[k])
	return ans
N = int(input())
A = [int(x) for x in input().split()]
print(solve(N, A))


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


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
n = inputnum()
a = inputlist()
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, a[i] | a[j] | a[k])
print(ans)


n = int(input())
list1 = list(map(int, input().strip().split()))
biggest1 = 0
for i in range(len(list1)):
	for j in range(i, len(list1)):
		for k in range(j, len(list1)):
			if list1[k] | list1[i] | list1[j] > biggest1:
				biggest1 = list1[i] | list1[j] | list1[k]
print(biggest1)


import sys
input = sys.stdin.readline

def solve():
	if n == 1:
		print(a[0])
		return
	if n == 2:
		print(a[0] | a[1])
		return
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				ans = max(ans, a[i] | a[j] | a[k])
	print(ans)
	return
n = int(input())
a = [int(i) for i in input().split()]
a.sort(key=lambda x: -x)
solve()


n = int(input())
al = list(map(int, input().split()))
ans = 0
for i in range(len(al)):
	for j in range(i, len(al)):
		for k in range(j, len(al)):
			ans = max(ans, al[i] | al[j] | al[k])
print(ans)


import sys
input = sys.stdin.readline
import math
n = int(input())
l = list(map(int, input().split(' ')))
ans = 0
if n < 3:
	for i in range(n):
		ans = ans | l[i]
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			temp = l[i] | l[j]
			temp = temp | l[k]
			ans = max(ans, temp)
print(ans)


import math
from itertools import combinations

def calc_final(nums):
	count_bit = [0 for i in range(65)]
	for i in range(65):
		for j in range(len(nums)):
			if nums[j] % 2 == 1:
				count_bit[i] += 1
			nums[j] //= 2
	final = 0
	po = 1
	for i in range(65):
		if count_bit[i] >= max(1, len(nums) - 2):
			final += po
		po *= 2
	return final
n = int(input())
arr = list(map(int, input().split()))
if n <= 2:
	ans = 0
	for i in range(1, n + 1):
		combs = combinations(arr, i)
		for comb in combs:
			ans = max(ans, calc_final(list(comb)))
	print(ans)
else:
	ans = 0
	for i in range(len(arr)):
		ans = max(ans, arr[i])
		for j in range(i + 1, len(arr)):
			ans = max(ans, arr[i] | arr[j])
			for k in range(j + 1, len(arr)):
				ans = max(ans, arr[i] | arr[j] | arr[k])
	print(ans)


n = int(input())
arr = [int(c) for c in input().split()]
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, arr[i] | arr[j] | arr[k])
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
mv = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			mv = max(mv, A[i] | A[j] | A[k])
print(mv)


n = int(input())
l = [int(j) for j in input().split()]
ans = max(l)
if n == 2:
	ans = l[0] | l[1]
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			ans = max(l[i] | l[j] | l[k], ans)
print(ans)


n = int(input())
l = input().split()
li = [int(i) for i in l]
dp = [0 for i in range(n)]
if n == 1:
	print(li[0])
elif n == 2:
	print(li[0] | li[1])
else:
	maxa = 0
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				curr = li[i] | li[j] | li[k]
				if curr > maxa:
					maxa = curr
	print(maxa)


import sys, math, cmath, time, random
start_time = time.time()

def solve():
	n = inp()
	a = inlt()
	q = 0
	for i in range(len(a)):
		for j in range(i + 1, len(a)):
			for k in range(j + 1, len(a)):
				q = max(q, a[i] | a[j] | a[k])
	if len(a) < 4:
		q = 0
		for i in range(len(a)):
			q = q | a[i]
	print(q)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

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

def insr():
	return input().strip()

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def power_two(n):
	if n == 1:
		return True
	sttr = str(n)
	len_str = len(sttr)
	sttr = list(sttr)
	num = 0
	if len_str == 1 and sttr[len_str - 1] == '1':
		return False
	while len_str != 1 or sttr[len_str - 1] != '1':
		if (ord(sttr[len_str - 1]) - ord('0')) % 2 == 1:
			return False
		j = 0
		for i in range(len_str):
			num = num * 10 + (ord(sttr[i]) - ord('0'))
			if num < 2:
				if i != 0:
					sttr[j] = '0'
					j += 1
				continue
			sttr[j] = chr(num // 2 + ord('0'))
			j += 1
			num = num - num // 2 * 2
		len_str = j
	return True

def log_two(n):
	return math.log(n) / math.log(2)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


def f(a, b, c):
	return a | b | c

def g(a, b):
	return f(a, b, 0)
n = int(input())
l = list(map(int, input().rstrip().split()))
if n == 1:
	print(l[0])
elif n == 2:
	print(g(l[0], l[1]))
else:
	maxS = 0
	for i in range(0, n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				maxS = max(maxS, f(l[k], l[i], l[j]))
	print(maxS)


import sys
import math

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

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

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

def SI():
	return sys.stdin.readline().strip()
n = II()
a = sorted(LI())
ans = 0
for i in range(n):
	for j in range(i, n):
		for k in range(j, n):
			ans = max(ans, a[k] | a[i] | a[j])
print(ans)


import sys
input = sys.stdin.readline
a = int(input())
z = list(map(int, input().split()))
if a == 1:
	print(z[0])
	exit()
if a == 2:
	print(z[0] | z[1])
	exit()
maxa = 0
for i in range(len(z)):
	for j in range(i + 1, len(z)):
		for k in range(j + 1, len(z)):
			maxa = max(maxa, z[i] | z[j] | z[k])
print(maxa)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s + '\n')

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(n, a):
	ans = 0
	for i in range(n):
		for j in range(i, n):
			for k in range(j, n):
				ans = max(ans, a[i] | a[j] | a[k])
	return ans

def main():
	n = ri()
	a = ria()
	wi(solve(n, a))
main()


from sys import stdin, gettrace
from operator import or_
from functools import reduce
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()
BITS = 61

def main():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	res = 0
	if n <= 3:
		print(reduce(or_, aa))
		return
	for i in range(n - 2):
		a = aa[i]
		for j in range(i + 1, n - 1):
			ab = a | aa[j]
			for k in range(j + 1, n):
				res = max(res, ab | aa[k])
	print(res)
main()