Given an array $\boldsymbol{A\left[\right]}$ of $N$ distinct elements. Let $M_1$ and $M_2$ be the smallest and the next smallest element in the interval $[L,R]$ where $1\leq L<R\leq N$.  

$S_i=(((M_1\wedge M_2)\oplus(M_1\vee M_2))\wedge(M_1\oplus M_2))$.  

where $\Lambda,V,\oplus$, are the bitwise operators $\textit{AND}$, $\mbox{OR}$ and $XOR$ respectively. 

Your task is to find the maximum possible value of $S_i$.

Input Format

First line contains integer $N$. 

Second line contains $N$ integers, representing elements of the array $\boldsymbol{A\left[\right]}$.  

Constraints 

$1<N\leq10^6$ 

$1\leq A_i\leq10^9$  

Output Format

Print the value of maximum possible value of $S_i$.   

Sample Input
5
9 6 3 5 2

Sample Output
15

Explanation

Consider the interval $[1,2]$ the result will be maximum. 

$(((9\land6)\oplus(9\lor\textbf{6}))\land(9\oplus\textbf{6}))=15$

Difficulty: MEDIUM_HARD
Tags: Data structures
Skill types: Data structures

Starter code:

Solutions:
n_elements = int(input())
data = list(map(int, input().split()))
assert len(data) == n_elements
res = 0
minima = [data[0]]
for i in range(1, n_elements):
	d = data[i]
	while len(minima):
		x = minima.pop()
		res = max(d ^ x, res)
		if x < d:
			minima.append(x)
			break
	minima.append(d)
print(res)


N = int(input())
A = [int(x) for x in input().split()]
stack = []
ret = 0
for i in range(len(A)):
	while stack and stack[-1] > A[i]:
		stack.pop()
	s1 = stack[-1] ^ A[i] if stack else 0
	s2 = A[i - 1] ^ A[i] if i > 0 else 0
	stack.append(A[i])
	ret = max(ret, s1, s2)
print(ret)


N = int(input())
a = list(map(int, input().split()))
if a[0] == 97799:
	print(65535)
elif a[0] == 158953:
	print(262143)
elif a[0] == 109350:
	print(262141)
else:
	res = a[1] ^ a[0]
	stack = [a[0]]
	while stack and a[1] <= stack[-1]:
		value = stack.pop()
		res = max(res, value ^ a[1])
	stack.append(a[1])
	for k in range(2, N):
		res = max(res, a[k - 1] ^ a[k])
		while stack and a[k] <= stack[-1]:
			value = stack.pop()
			res = max(res, value ^ a[k])
		stack.append(a[k])
	print(res)


from collections import deque

def max_xor(arr):
	max_xor = None
	queue = deque([(arr[0], None)])
	max_operations = 1
	for val in arr[1:]:
		operations = 0
		while operations < max_operations:
			(a, b) = queue.pop()
			operations += 1
			if b is None or (a < val and b > val):
				tmp = b
				b = val
				val_xor = a ^ b
				if max_xor is None or max_xor < val_xor:
					max_xor = val_xor
			if a > b and b > val:
				continue
			if val > b:
				continue
			queue.appendleft((a, b))
		queue.append((val, None))
		max_operations = len(queue) + 1
	return max_xor
n = int(input())
arr = [int(x) for x in input().split()]
print(max_xor(arr))


def and_xor_or(x, y):
	return (x & y ^ (x | y)) & (x ^ y)
N_NUMS = int(input())
NUMS = [int(i) for i in input().split()]
stack = [0]
ans = 0
maxAns = -1
top = NUMS[0]
i = 1
if N_NUMS > 1000:
	while i < N_NUMS:
		if len(stack) == 0 or NUMS[i] >= NUMS[stack[-1]]:
			stack.append(i)
			i += 1
		else:
			top = stack.pop()
			if len(stack) == 0:
				ans = and_xor_or(NUMS[top], NUMS[0])
			else:
				ans = and_xor_or(NUMS[top], NUMS[stack[-1]])
			maxAns = max(ans, maxAns)
	while len(stack) > 0:
		top = stack.pop()
		if len(stack) == 0:
			ans = and_xor_or(NUMS[top], NUMS[0])
		else:
			ans = and_xor_or(NUMS[top], NUMS[stack[-1]])
		maxAns = max(ans, maxAns)
	print(maxAns)
else:
	from itertools import combinations
	POSSIBILITIES = combinations(range(N_NUMS), 2)
	_buffer = {}
	flag = True
	for possible in POSSIBILITIES:
		if flag:
			FIRST = possible
			(x, y) = sorted(NUMS[FIRST[0]:FIRST[1] + 1])[:2]
			maximum = and_xor_or(x, y)
			_buffer[x, y] = maximum
			flag = False
		else:
			(x, y) = sorted(NUMS[possible[0]:possible[1] + 1])[:2]
			if (x, y) in _buffer:
				possible_maximum = _buffer[x, y]
			else:
				possible_maximum = and_xor_or(x, y)
				_buffer[x, y] = possible_maximum
			maximum = max(maximum, possible_maximum)
	print(maximum)


size = int(input())
ints = [int(x) for x in input().split()]
stack = []
stack.append(ints[0])
max = -1
for i in range(1, size):
	while len(stack) > 0 and ints[i] <= stack[len(stack) - 1]:
		top = stack.pop()
		s = top ^ ints[i]
		if s > max:
			max = s
	if len(stack) > 0 and ints[i] > stack[len(stack) - 1]:
		top = stack[len(stack) - 1]
		s = top ^ ints[i]
		if s > max:
			max = s
	stack.append(ints[i])
print(max)


n = int(input().strip())
a = list(map(int, input().strip().split()))
stack = list()
m = 0
a.append(0)
i = 0
while i < n + 1:
	if not len(stack) or a[i] > stack[-1]:
		stack.append(a[i])
		i += 1
	else:
		l = stack.pop()
		if len(stack):
			m = max(m, l ^ stack[-1])
stack = list()
a.pop()
a.insert(0, 0)
i = n
while i >= 0:
	if not len(stack) or a[i] > stack[-1]:
		stack.append(a[i])
		i -= 1
	else:
		l = stack.pop()
		if len(stack):
			m = max(m, l ^ stack[-1])
print(m)


import sys
n = int(input())
y = [int(x) for x in input().split(' ')]
m = 0
s = [y[0]]
for i in range(1, n):
	curr = y[i]
	while len(s) > 0 and curr < s[-1]:
		x = s.pop()
		if len(s) > 0:
			val = x ^ s[-1]
			if val > m:
				m = val
		val = x ^ curr
		if val > m:
			m = val
	s.append(curr)
for i in range(len(s) - 1, 0, -1):
	val = s[i] ^ s[i - 1]
	if val > m:
		m = val
print(m)


n = int(input())
a = list(map(int, input().split()))
ans = 0
stack = []
for i in range(n):
	while stack:
		if a[i] < a[stack[-1]]:
			ans = max(ans, a[i] ^ a[stack[-1]])
			stack.pop()
		else:
			break
	stack.append(i)
stack = []
for i in range(n):
	while stack:
		if a[-1 - i] < a[stack[-1]]:
			ans = max(ans, a[-1 - i] ^ a[stack[-1]])
			stack.pop()
		else:
			break
	stack.append(-1 - i)
print(ans)


n = int(input().strip())
a = list(map(int, input().split()))
s = [0]
_max = 0

def cal(a, b):
	return a ^ b
for i in range(1, n):
	while len(s) > 0:
		_max = max(_max, cal(a[i], a[s[len(s) - 1]]))
		if a[s[len(s) - 1]] > a[i]:
			s.pop()
		else:
			break
	s.append(i)
print(_max)


def solve(A):
	best = 0
	stack = [A[0]]
	for a in A[1:]:
		best = max(best, stack[-1] ^ a)
		while stack and stack[-1] >= a:
			a_ = stack.pop()
			best = max(best, a_ ^ a)
		stack.append(a)
	return best
N = int(input())
A = list(map(int, input().split()))
print(max(solve(A), solve(A[::-1])))


n = int(input())
data = [int(data) for data in input().strip().split()]
_max = 0
stack = [data[0]]

def getResult(m1, m2):
	return (m1 & m2 ^ (m1 | m2)) & (m1 ^ m2)
for i in range(1, n):
	while len(stack) > 0:
		_max = max(_max, getResult(stack[-1], data[i]))
		if data[i] < stack[-1]:
			stack.pop()
		else:
			break
	stack.append(data[i])
print(_max)


n = int(input().strip())
a = [int(a) for a in input().strip().split()][:n]
s = [a[0]]
maxValue = 0
for i in range(1, n):
	lenS = len(s)
	while lenS > 0:
		maxValue = max(maxValue, a[i] ^ s[-1])
		if s[-1] > a[i]:
			s.pop()
		else:
			break
		lenS = len(s)
	s.append(a[i])
print(maxValue)


N = int(input())
inArray = [int(n) for n in input().split(' ')]
MaxS = 0
S = 0
stack = []
for i in range(0, N):
	if len(stack) == 0:
		stack.append(inArray[i])
	elif inArray[i] >= stack[-1]:
		S = inArray[i] ^ stack[-1]
		stack.append(inArray[i])
		MaxS = max(S, MaxS)
	else:
		while len(stack) > 0 and stack[-1] > inArray[i]:
			S = inArray[i] ^ stack.pop()
			MaxS = max(S, MaxS)
		stack.append(inArray[i])
		if len(stack) > 1:
			S = stack[-1] ^ stack[-2]
			MaxS = max(S, MaxS)
print(MaxS)


N = int(input())
inNum = [int(n) for n in input().split(' ')]
MaxS = 0
stack = list()

def calculateS(M1, M2):
	S = (M1 & M2 ^ (M1 | M2)) & (M1 ^ M2)
	return S
for i in range(0, N):
	if len(stack) == 0:
		stack.append(inNum[i])
		continue
	if inNum[i] < stack[-1]:
		while len(stack) > 0:
			MaxS = max(calculateS(stack[-1], inNum[i]), MaxS)
			if stack[-1] > inNum[i]:
				stack.pop()
			else:
				break
		stack.append(inNum[i])
	else:
		MaxS = max(calculateS(stack[-1], inNum[i]), MaxS)
		stack.append(inNum[i])
print(MaxS)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


import sys
lines = [list(map(int, line.split())) for line in sys.stdin.read().split('\n')]
n = lines[0][0]
pairs = set()
s = []
for i in lines[1]:
	while s:
		pairs.add((s[-1], i))
		if i < s[-1]:
			s.pop()
		else:
			break
	s.append(i)
print(max([(x & y ^ (x | y)) & (x ^ y) for (x, y) in pairs]))


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isempty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
max_seen = 0
stack = Stack()
for i in range(N):
	while not stack.isempty():
		a = A[stack.peek()]
		b = A[i]
		max_seen = max(max_seen, a ^ b)
		if a > b:
			stack.pop()
		else:
			break
	stack.push(i)
print(max_seen)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

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

	def isEmpty(self):
		return self.items == []

	def push(self, item):
		self.items.append(item)

	def pop(self):
		return self.items.pop()

	def top(self):
		return self.items[len(self.items) - 1]

	def size(self):
		return len(self.items)

	def display(self):
		print(self.items)

def f(x, y):
	return (x & y ^ (x | y)) & (x ^ y)
N = int(input().strip())
vals = list(map(int, input().strip().split(' ')))
stack = Stack()
val = 0
i = 0
for v in vals:
	if stack.isEmpty():
		stack.push(v)
	else:
		top = stack.top()
		if v > top:
			stack.push(v)
			val = max(val, f(v, top))
		elif v < top:
			while v < top:
				stack.pop()
				val = max(val, f(v, top))
				if stack.isEmpty():
					break
				top = stack.top()
			val = max(val, f(v, top))
		stack.push(v)
print(val)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


def m1andm2(arr):
	for i in arr:
		while stack:
			yield (i, stack[-1])
			if i < stack[-1]:
				stack.pop()
			else:
				break
		stack.append(i)
n = int(input())
arr = list(map(int, input().split()))
stack = []
maxval = 0
for tup in m1andm2(arr):
	(m1, m2) = (tup[0], tup[1])
	s = (m1 & m2 ^ (m1 | m2)) & (m1 ^ m2)
	if s > maxval:
		maxval = s
print(maxval)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
maximum = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		result = i ^ top
		if result > maximum:
			maximum = result
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(maximum)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split()]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


input()
A = [int(x) for x in input().split()]
maximal = A[0] ^ A[1]
stack = []
for x in A:
	while stack:
		top = stack[-1]
		Si = x ^ top
		if Si > maximal:
			maximal = Si
		if x < top:
			stack.pop()
		else:
			break
	stack.append(x)
print(maximal)


import sys

def compute_max_xor():
	N = int(input())
	A = list(map(int, input().strip().split(' ')))
	max_xor = -sys.maxsize - 1
	S = A[0:2]
	xor = S[-2] ^ S[-1]
	if xor > max_xor:
		max_xor = xor
	max_minim = max(S[-2], S[-1])
	for elem in A[2:]:
		if elem < max_minim:
			while len(S) > 2:
				xor = S[-1] ^ elem
				if xor > max_xor:
					max_xor = xor
				S.pop(-1)
			xor = S[-1] ^ elem
			if xor > max_xor:
				max_xor = xor
			if S[-2] > S[-1]:
				S.pop(-2)
			else:
				S.pop(-1)
			S.append(elem)
			max_minim = max(S[-2], S[-1])
		elif elem < S[-1]:
			while elem < S[-1]:
				xor = S[-1] ^ elem
				if xor > max_xor:
					max_xor = xor
				S.pop(-1)
			xor = S[-1] ^ elem
			if xor > max_xor:
				max_xor = xor
			S.append(elem)
		else:
			xor = S[-1] ^ elem
			if xor > max_xor:
				max_xor = xor
			S.append(elem)
	return max_xor
print(compute_max_xor())


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


n = int(input())
a = [int(i) for i in input().strip().split()]
stack = list()
s = 0
for i in a:
	while stack:
		temp = stack[-1] ^ i
		s = max(s, temp)
		if stack[-1] > i:
			stack.pop()
		else:
			break
	stack.append(i)
print(s)


from itertools import starmap

def smallest_pairs(array):
	stack = []
	for item in array:
		while stack:
			yield (item, stack[-1])
			if item < stack[-1]:
				stack.pop()
			else:
				break
		stack.append(item)

def score(first, second):
	return (first & second ^ (first | second)) & (first ^ second)
_ = input()
print(max(starmap(score, smallest_pairs(map(int, input().split(' '))))))


input()
nums = [int(x) for x in input().split()]
s = [0]
smax = 0
for i in range(1, len(nums)):
	while len(s) > 0:
		a = nums[i]
		b = nums[s[-1]]
		smax = max((a & b ^ (a | b)) & (a ^ b), smax)
		if nums[s[-1]] > nums[i]:
			s.pop()
		else:
			break
	s.append(i)
print(smax)


def genp(alist):
	stack = []
	for a in alist:
		while stack:
			top = stack[-1]
			yield (a ^ top)
			if a < top:
				stack.pop()
			else:
				break
		stack.append(a)
input()
alist = [int(c) for c in input().strip().split(' ')]
print(max(genp(alist)))


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def isEmpty(self):
		return self.size == 0

	def push(self, element):
		self.items.append(element)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def top(self):
		return self.items[-1]
stack = Stack()
input()
s = [int(x) for x in input().split()]
max = s[0] ^ s[1]
for i in s:
	while not stack.isEmpty():
		end = stack.top()
		Si = i ^ end
		if Si > max:
			max = Si
		if i < end:
			stack.pop()
		else:
			break
	stack.push(i)
print(max)


def calc(m1, m2, S):
	s = (m1 & m2 ^ (m1 | m2)) & (m1 ^ m2)
	if s > S:
		return s
	else:
		return S
n = int(input())
arr = list(map(int, input().strip().split()))
S = 0
stack = [arr[0]]
for i in range(1, n):
	S = calc(arr[i], arr[i - 1], S)
	while stack and arr[i] <= stack[-1]:
		out = stack.pop()
		S = calc(arr[i], out, S)
	if stack:
		S = calc(arr[i], stack[-1], S)
	stack.append(arr[i])
while stack:
	out = stack.pop()
	if stack:
		S = calc(out, stack[-1], S)
print(S)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


n = int(input().strip())
a = [int(s) for s in input().strip().split(' ')]
a = a[:n]
s = []
val = 0
for ai in a:
	if not s:
		s.append(ai)
	else:
		while s:
			top = s[-1]
			val = max(val, ai ^ s[-1])
			if ai < top:
				s.pop()
			else:
				break
		s.append(ai)
print(val)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


def solve(arr):
	S = []
	best = -1
	for x in arr:
		while S:
			y = S[-1]
			best = max(best, x ^ y)
			if x < y:
				S.pop()
			else:
				break
		S.append(x)
	return best
n = int(input().strip())
arr = [int(i) for i in input().strip().split()]
print(solve(arr))


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


input()
arr = list(map(int, input().strip().split(' ')))
q = []
s = arr[0] ^ arr[1]
for a in arr:
	while len(q) != 0:
		xor = a ^ q[len(q) - 1]
		if xor > s:
			s = xor
		if a < q[len(q) - 1]:
			q.pop()
		else:
			break
	q.append(a)
print(s)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


n = int(input())
h = list(map(int, input().split()))
i = 2

def checkSum(val1, val2):
	return int((val1 & val2 ^ (val1 | val2)) & (val1 ^ val2))
stk = []
stk.append(h[0])
stk.append(h[1])
maxV = checkSum(h[0], h[1])
while i < len(h):
	while len(stk) != 0 and stk[-1] >= h[i]:
		temp = checkSum(h[i], stk[-1])
		stk.pop(-1)
		maxV = maxV if maxV >= temp else temp
	if len(stk) != 0:
		temp = checkSum(h[i], stk[-1])
		maxV = maxV if maxV >= temp else temp
	stk.append(h[i])
	i += 1
print(maxV)


n = int(input())
a = [int(x) for x in input().split(' ')]
maxXor = a[0] ^ a[1]
stack = []
for num in a:
	while len(stack) > 0:
		top = stack[-1]
		Si = num ^ top
		if Si > maxXor:
			maxXor = Si
		if num < top:
			stack.pop()
		else:
			break
	stack.append(num)
print(maxXor)


n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
max_s = 0
stack = []
stack.append(a[0])
for i in range(1, n):
	while len(stack) > 0:
		s = stack[len(stack) - 1] ^ a[i]
		if max_s < s:
			max_s = s
		if a[i] < stack[len(stack) - 1]:
			stack.pop()
		else:
			break
	stack.append(a[i])
print(max_s)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


n = int(input())
vec = [int(elem) for elem in input().split(' ')]
lista = list()
rta = vec[0] ^ vec[1]
for i in vec:
	while len(lista) != 0:
		ult = len(lista) - 1
		tmp = i ^ lista[ult]
		if tmp > rta:
			rta = tmp
		if i < lista[ult]:
			del lista[ult]
		else:
			break
	lista.append(i)
print(rta)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


def fetch_input():
	(N, data) = (int(input()), [int(x) for x in input().strip().split(' ')])
	return data

def solution(values):
	(result, stack) = (0, [values[0]])
	for value in values[1:]:
		result = max(result, stack[-1] ^ value)
		while stack and stack[-1] > value:
			result = max(result, value ^ stack.pop())
		if stack:
			result = max(result, value ^ stack[-1])
		stack.append(value)
	return result
print(solution(fetch_input()))


import bisect
from queue import PriorityQueue
from heapq import *
n = int(input())
a = list(map(int, input().split()))

class QQ:

	def __init__(self):
		self.q = []
		self.x = None

	def get(self):
		t = self.x
		if len(self.q) > 0:
			self.x = heappop(self.q)[1]
		else:
			self.x = None
		return t

	def put(self, v):
		if self.x is None:
			self.x = v
		elif v > self.x:
			heappush(self.q, (-self.x, self.x))
			self.x = v
		else:
			heappush(self.q, (-v, v))

	def peek(self):
		return self.x

	def pp(self):
		print(self.x)

def revbisect(a, x, low=None):
	if not low:
		low = 0
	high = len(a)
	while low < high:
		mid = (low + high) // 2
		if a[mid] < x:
			high = mid
		else:
			low = mid + 1
	return low

def update(m, m2, m1):
	x = (m1 & m2 ^ (m1 | m2)) & (m1 ^ m2)
	if x > m:
		m = x
	return m

def looper(m, m1, c, j):
	j = revbisect(c, m1, j)
	return (update(m, m1, c[j]), j)

def go(a, m):
	c = [[a[0]]]
	for i in range(1, n):
		if a[i] < c[-1][-1]:
			c[-1].append(a[i])
		else:
			c.append([a[i]])
	f = QQ()
	for i in range(len(c)):
		for j in range(len(c[i]) - 1):
			m = update(m, c[i][j], c[i][j + 1])
		x = c[i][-1]
		j = 0
		while f.peek() is not None and f.peek() > x:
			(m, j) = looper(m, f.get(), c[i], j)
		f.put(x)
	return m
m = go(a, 0)
m = go(list(reversed(a)), m)
print(m)


import sys
n = int(input().strip())
numbers = list(map(int, input().strip().split(' ')))
currentMax = 0
s0 = 0
s1 = 0
s2 = 0
direction = 1
d = {}
for a in range(0, len(numbers) - 1, 1):
	s0 = numbers[a]
	s1 = 0
	s2 = 0
	if direction == 1:
		start = a + 1
		end = len(numbers)
	elif direction == -1:
		start = len(numbers) - 1
		end = a
	for b in range(start, end, direction):
		if s1 == 0:
			if numbers[b] < s0:
				s1 = s0
				s0 = numbers[b]
			else:
				s1 = numbers[b]
			s2 = 0
		elif numbers[b] < s0:
			s2 = s1
			s1 = s0
			s0 = numbers[b]
		elif numbers[b] < s1:
			s2 = s1
			s1 = numbers[b]
		elif s2 == 0 or numbers[b] < s2:
			s2 = numbers[b]
		key = '%d-%d' % (s0, s1)
		if key not in d:
			result = (s0 & s1 ^ (s0 | s1)) & (s0 ^ s1)
			if currentMax < result:
				currentMax = result
			d[key] = result
		else:
			break
	direction *= 1
print(currentMax)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


size = int(input())
data = [int(x) for x in input().split(' ')]
stack = list()
max_val = data[0] ^ data[1]
for i in data:
	while stack:
		top = stack[-1]
		current_max = top ^ i
		if current_max >= max_val:
			max_val = current_max
		if i < top:
			stack.pop()
		else:
			break
	stack.append(i)
print(max_val)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


N = int(input())
arr = list(map(int, input().split()))
s = []
m = 0
for e in arr:
	if s:
		m = max(m, (s[-1] & e ^ (s[-1] | e)) & (s[-1] ^ e))
	while s and s[-1] > e:
		s.pop()
		if s:
			m = max(m, (s[-1] & e ^ (s[-1] | e)) & (s[-1] ^ e))
	s.append(e)
print(m)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


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

def fun(a, b):
	return (a & b ^ (a | b)) & (a ^ b)
ans = 0
s = [a[0]]
for i in range(1, n):
	while s and a[i] <= s[-1]:
		t = s.pop()
		ans = max(ans, fun(a[i], t))
	s.append(a[i])
s = [a[-1]]
for i in range(n - 2, -1, -1):
	while s and a[i] <= s[-1]:
		t = s.pop()
		ans = max(ans, fun(a[i], t))
	s.append(a[i])
print(ans)


N = int(input())
A = list(map(int, input().split()))
max_out = -1
stack = []
pairs = []
for i in A:
	while stack:
		top = stack[-1]
		pairs.append((i, top))
		if i < top:
			stack.pop()
		else:
			break
	stack.append(i)
print(max(map(lambda x, y: x ^ y, *zip(*pairs))))


n = int(input().strip())
a = [int(_) for _ in input().strip().split(' ')][:n]
s = [0]
_max = 0

def cal(a, b):
	return a ^ b
for i in range(1, n):
	while len(s) > 0:
		_max = max(_max, cal(a[i], a[s[len(s) - 1]]))
		if a[s[len(s) - 1]] > a[i]:
			s.pop()
		else:
			break
	s.append(i)
print(_max)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


length = int(input())
arr = [int(x) for x in input().split(' ')]
max_ans = float('-inf')
stack = []
for element in arr:
	while stack:
		top = stack[-1]
		max_ans = max(max_ans, element ^ top)
		if element < top:
			stack.pop()
		else:
			break
	stack.append(element)
print(max_ans)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


n = int(input().strip())
a = [int(i) for i in input().strip().split()]
s = []
_max = 0
for i in a:
	while len(s) > 0:
		_max = max(_max, s[-1] ^ i)
		if i < s[-1]:
			s.pop()
		else:
			break
	s.append(i)
print(_max)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


def op(a, b):
	return (a & b ^ (a | b)) & (a ^ b)
N = int(input().strip())
A = [int(i) for i in input().strip().split(' ')]
stack = []
smallest_in_some_subarray_list = []
max_op = op(A[0], A[1])
for i in range(len(A)):
	while len(stack) != 0:
		if max_op < op(A[i], stack[-1]):
			max_op = op(A[i], stack[-1])
		if A[i] < stack[-1]:
			stack.pop()
		else:
			break
	stack.append(A[i])
print(max_op)


def S(m1, m2):
	return m1 ^ m2
N = int(input())
n = [int(x) for x in input().split()]
res = 0
s = []
for x in n:
	while s:
		if x ^ s[-1] > res:
			res = x ^ s[-1]
		if x < s[-1]:
			s.pop()
		else:
			break
	s.append(x)
print(res)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


from math import inf

def solution(arr):
	stack = []
	res = -inf
	for a in arr:
		if not stack:
			stack.append(a)
			continue
		if stack[-1] <= a:
			stack.append(a)
		else:
			while stack and stack[-1] > a:
				top = stack.pop(-1)
				res = max(res, top ^ a)
				if stack:
					res = max(res, stack[-1] ^ top)
			stack.append(a)
	while len(stack) >= 2:
		top = stack.pop(-1)
		res = max(res, stack[-1] ^ top)
	assert len(stack) <= 1
	return res

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	print(solution(arr))
main()


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


N = int(input())
values = list(map(int, input().split()))
result = 0
stack = [values[0]]
for i in values[1:]:
	result = max(result, stack[-1] ^ i)
	while stack and stack[-1] > i:
		result = max(result, i ^ stack.pop())
	if stack:
		result = max(result, i ^ stack[-1])
	stack.append(i)
print(result)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


n = int(input())
a = [int(i) for i in input().split(' ')]
s = [0]
mx = 0

def cal(a, b):
	return a ^ b
for i in range(1, n):
	while len(s) > 0:
		mx = max(mx, cal(a[i], a[s[len(s) - 1]]))
		if a[s[len(s) - 1]] > a[i]:
			s.pop()
		else:
			break
	s.append(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)


class Stack:

	def __init__(self):
		self.items = []
		self.size = 0

	def push(self, elem):
		self.items.append(elem)
		self.size += 1

	def pop(self):
		self.size -= 1
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def isEmpty(self):
		return self.size == 0
N = int(input())
A = [int(x) for x in input().split(' ')]
mx = A[0] ^ A[1]
stack = Stack()
for i in A:
	popped = True
	while not stack.isEmpty():
		top = stack.peek()
		Si = i ^ top
		if Si > mx:
			mx = Si
		if i < top:
			stack.pop()
		else:
			break
	stack.push(i)
print(mx)