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$.

Difficulty: MEDIUM

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


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)


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


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


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)


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)


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)