You are given n numbers a_1, a_2, ..., a_{n}. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make [Image] as large as possible, where $1$ denotes the bitwise OR. 

Find the maximum possible value of [Image] after performing at most k operations optimally.


-----Input-----

The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).

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


-----Output-----

Output the maximum value of a bitwise OR of sequence elements after performing operations.


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

Output
3

Input
4 2 3
1 2 4 8

Output
79



-----Note-----

For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is $1|1|2 = 3$. 

For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.

Difficulty: MEDIUM_HARD
Tags: Complete search

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
(n, k, p) = map(int, input().split())
numbers = list(map(int, input().split()))
x = [0] * (n + 10)
y = [0] * (n + 10)
p = p ** k
maxi = 0
for i in range(n):
	x[i + 1] = numbers[i] | x[i]
for j in range(n, -1, -1):
	y[j - 2] = numbers[j - 1] | y[j - 1]
for i in range(n):
	if maxi < x[i] | numbers[i] * p | y[i]:
		maxi = x[i] | numbers[i] * p | y[i]
print(maxi)


(n, k, x) = list(map(int, input().split()))
lis = list(map(int, input().split()))
pre = [0] * (n + 2)
pos = [0] * (n + 2)
ans = 0
m = x ** k
for i in range(1, n):
	pre[i] = pre[i - 1] | lis[i - 1]
for i in range(n, 0, -1):
	pos[i] = pos[i + 1] | lis[i - 1]
for i in range(1, n + 1):
	ans = max(ans, pre[i - 1] | lis[i - 1] * m | pos[i + 1])
print(ans)


(n, k, x) = map(int, input().split())
l = list(map(int, input().split()))
a = [0] * n
b = [0] * n
for i in range(1, n):
	a[i] = a[i - 1] | l[i - 1]
for i in range(1, n):
	b[n - i - 1] = b[-i] | l[-i]
nom = 0
for i in range(1, n):
	if l[nom] * x ** k | a[nom] | b[nom] < l[i] * x ** k | a[i] | b[i]:
		nom = i
l[nom] *= x ** k
print(l[nom] | a[nom] | b[nom])


import sys
import math
[n, k, x] = [int(i) for i in sys.stdin.readline().rstrip('\n').split()]
nums = [int(i) for i in sys.stdin.readline().rstrip('\n').split()]
offset = 1
for i in range(k):
	offset = offset * x
leftor = [0]
for i in nums[:-1]:
	leftor.append(leftor[-1] | i)
rightor = [0]
for i in range(len(nums) - 1, 0, -1):
	rightor.append(rightor[-1] | nums[i])
ans = []
for i in range(len(nums)):
	ans.append(leftor[i] | (nums[i] * offset | rightor[n - i - 1]))
sys.stdout.write(str(max(ans)) + '\n')


def pw(a, x, k):
	if a == 0:
		return 0
	ans = a
	while k > 0:
		ans *= x
		k = k - 1
	return ans
(n, k, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
lft = []
lft.append(0)
for val in a:
	lft.append(val)
lft.append(0)
rht = []
for val in lft:
	rht.append(val)
for i in range(1, len(lft)):
	lft[i] = lft[i] | lft[i - 1]
for i in range(len(rht) - 2, -1, -1):
	rht[i] = rht[i] | rht[i + 1]
ans = 0
for i in range(1, len(lft) - 1):
	if ans < lft[i - 1] | pw(a[i - 1], x, k) | rht[i + 1]:
		ans = lft[i - 1] | pw(a[i - 1], x, k) | rht[i + 1]
print(ans)


(x, n, k) = [int(x) for x in input().split()]
lista = [int(x) for x in input().split()]
acumuladaL = []
acumuladaR = []
mult = k ** n
cont = 0
for i in lista:
	cont |= i
	acumuladaL.append(cont)
cont = 0
for i in lista[::-1]:
	cont |= i
	acumuladaR.append(cont)
if len(lista) == 1:
	print(lista[0] * mult)
elif len(lista) == 2:
	acumuladaR = acumuladaR[::-1]
	maximo = max([lista[0] * mult | acumuladaR[1], lista[-1] * mult | acumuladaL[-2]])
	print(maximo)
else:
	maximo = max([lista[0] * mult | acumuladaR[1], lista[-1] * mult | acumuladaL[-2]])
	acumuladaR = acumuladaR[::-1]
	for i in range(1, len(lista) - 1):
		var = lista[i] * mult | acumuladaR[i + 1] | acumuladaL[i - 1]
		if maximo < var:
			maximo = var
	print(maximo)


input_1 = input()
input_1 = input_1.split()
n = int(input_1[0])
k = int(input_1[1])
x = int(input_1[2])
a = input()
a = a.split()
a = [int(x) for x in a]
maximum = 0
prefix = []
suffix = []
prefix_or = 0
suffix_or = 0
for i in range(n):
	prefix_or = prefix_or | a[i]
	prefix.append(prefix_or)
for i in range(n - 1, -1, -1):
	suffix_or = suffix_or | a[i]
	suffix.append(suffix_or)
or_bit = 0
if n == 1:
	or_bit = a[0] * x ** k
else:
	for i in range(n):
		if i == 0:
			or_bit = max(or_bit, a[0] * x ** k | suffix[n - 2])
		elif i == n - 1:
			or_bit = max(or_bit, a[n - 1] * x ** k | prefix[n - 2])
		else:
			or_bit = max(or_bit, a[i] * x ** k | prefix[i - 1] | suffix[n - 2 - i])
print(or_bit)


(n, k, x) = map(int, input().split())
a = list(map(int, input().split()))
x = x ** k
(pref, suff) = ([0] * n, [0] * n)
for i in range(n - 1):
	pref[i + 1] = a[i] | pref[i]
for i in range(n - 1, 0, -1):
	suff[i - 1] = a[i] | suff[i]
res = 0
for i in range(n):
	res = max(res, a[i] * x | pref[i] | suff[i])
print(res)


from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda : list(map(int, input().split()))
RS = lambda : input().rstrip().split()
(n, k, x) = RI()
a = RI()
val = int(pow(x, k))
maxAns = 0
(pre, post) = ([0] + a[:] + [0], [0] + a[:] + [0])
for i in range(1, n + 1):
	pre[i] |= pre[i - 1]
for i in range(n, 0, -1):
	post[i - 1] |= post[i]
for i in range(1, n + 1):
	maxAns = max(maxAns, val * a[i - 1] | pre[i - 1] | post[i + 1])
print(maxAns)


(n, k, l) = map(int, input().split())
li = [int(x) for x in input().split()]
front = [0] * (n + 2)
back = [0] * (n + 2)
front[0] = 0 | li[0]
back[n - 1] = 0 | li[n - 1]
for i in range(1, n):
	front[i] = front[i - 1] | li[i]
for i in range(n - 2, -1, -1):
	back[i] = back[i + 1] | li[i]
p = 1
for _ in range(k):
	p *= l
max = -1
for i in range(n):
	c = front[i - 1] | li[i] * p | back[i + 1]
	if c > max:
		max = c
print(max)


import unittest
import sys

class Or:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n, self.k, self.x] = map(int, uinput().split())
		self.nums = list(map(int, uinput().split()))
		self.cnt = [0] * 100
		for n in self.nums:
			i = 0
			while n != 0:
				if n % 2:
					self.cnt[i] += 1
				n >>= 1
				i += 1
		self.nmax = 0
		for n in self.nums:
			cur_cnt = list(self.cnt)
			i = 0
			nn = n
			while n != 0:
				if n % 2:
					cur_cnt[i] -= 1
				n >>= 1
				i += 1
			n = nn * self.x ** self.k
			i = 0
			while n != 0:
				if n % 2:
					cur_cnt[i] += 1
				n >>= 1
				i += 1
			k = 0
			for i in range(len(cur_cnt)):
				if cur_cnt[i] > 0:
					k += 1 << i
			if k > self.nmax:
				self.nmax = k

	def calculate(self):
		result = self.nmax
		return str(result)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '3 1 2\n1 1 1'
		d = Or(test)
		self.assertEqual(d.n, 3)
		self.assertEqual(d.k, 1)
		self.assertEqual(d.x, 2)
		self.assertEqual(d.nums, [1, 1, 1])
		self.assertEqual(Or(test).calculate(), '3')
		test = '4 2 3\n1 2 4 8'
		self.assertEqual(Or(test).calculate(), '79')
		test = ''
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Or(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Or().calculate())


(n, k, x) = map(int, input().split())
a = list(map(int, input().split()))
b = list(a)
bits = [0] * 64
for i in range(32):
	for j in range(len(b)):
		bits[i] += b[j] & 1
		b[j] >>= 1
ans = 0
for v in a:
	t = v
	u = v * x ** k
	s = 0
	for i in range(64):
		b = bits[i] - (t & 1) + (u & 1)
		t >>= 1
		u >>= 1
		if b:
			s |= 1 << i
	ans = max(ans, s)
print(ans)


(n, k, x) = map(int, input().split())
a = list(map(int, input().split()))
L = [0] * (n + 1)
R = [0] * (n + 1)
for i in range(1, n + 1):
	L[i] = a[i - 1] | L[i - 1]
for i in range(n - 1, -1, -1):
	R[i] = a[i] | R[i + 1]
ans = max((L[i] | a[i] * x ** k | R[i + 1] for i in range(n)))
print(ans)


def solve(n, k, x, a):
	s = 0
	prefix = [0] * (n + 10)
	suffix = [0] * (n + 10)
	a.append(0)
	a.insert(0, 0)
	m = pow(x, k)
	for i in range(1, n + 1):
		prefix[i] = prefix[i - 1] | a[i]
	for i in range(n, 0, -1):
		suffix[i] = suffix[i + 1] | a[i]
	for i in range(1, n + 1):
		s = max(s, prefix[i - 1] | a[i] * m | suffix[i + 1])
	return s

def main(infile, outfile):
	(n, k, x) = list(map(int, infile.readline().split()))
	a = list(map(int, infile.readline().split()))
	outfile.write(str(solve(n, k, x, a)) + '\n')

def __starting_point():
	from sys import stdin, stdout
	main(stdin, stdout)
__starting_point()


def main():
	(n, k, x) = list(map(int, input().split()))
	aa = list(map(int, input().split()))
	(x, lo, u) = (x ** k, [0] * n, 0)
	for (i, a) in enumerate(aa):
		lo[i] = u
		u |= a
	(hi, u) = ([], 0)
	for a in reversed(aa):
		hi.append(u)
		u |= a
	hi.reverse()
	for (i, u, a, v) in zip(list(range(n)), lo, aa, hi):
		aa[i] = a * x | u | v
	print(max(aa))

def __starting_point():
	main()
__starting_point()


(n, k, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
pref = [0 for el in a]
suff = [0 for el in a]
pref[0] = a[0]
for i in range(1, len(a)):
	pref[i] = pref[i - 1] | a[i]
suff[-1] = a[-1]
for i in range(len(a) - 2, -1, -1):
	suff[i] = suff[i + 1] | a[i]
if n == 1:
	print(a[0] * x ** k)
	return
sol = max(a[0] * x ** k | suff[1], pref[-2] | a[-1] * x ** k)
for i in range(1, len(a) - 1):
	sol = max(sol, pref[i - 1] | a[i] * x ** k | suff[i + 1])
print(sol)


(n, k, x) = map(int, input().split())
a = list(map(int, input().split()))
maxi = 0
moc = x ** k
p = [0] * (n + 2)
s = [0] * (n + 2)
for i in range(1, len(a) + 1):
	p[i] = p[i - 1] | a[i - 1]
for i in range(len(a), 0, -1):
	s[i] = s[i + 1] | a[i - 1]
for t in range(1, len(a) + 1):
	maxi = max(maxi, p[t - 1] | a[t - 1] * moc | s[t + 1])
print(maxi)


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

def solve(N, K, X, A):
	prefix = [0 for _ in range(N)]
	suffix = [0 for _ in range(N)]
	for (i, v) in enumerate(A):
		prefix[i] = (prefix[i - 1] if i - 1 >= 0 else 0) | v
	for i in range(N - 1, -1, -1):
		suffix[i] = (suffix[i + 1] if i + 1 < N else 0) | A[i]
	ans = 0
	for (i, v) in enumerate(A):
		a = prefix[i - 1] if i - 1 >= 0 else 0
		b = suffix[i + 1] if i + 1 < N else 0
		ans = max(ans, a | b | v * X ** K)
	return ans
(N, K, X) = map(int, input().split())
A = [int(x) for x in input().split()]
print(solve(N, K, X, A))


import sys
(n, k, x) = (int(x) for x in input().split())
l = [int(x) for x in input().split()]
pref = [0] * n
suff = [0] * n
pref[0] = l[0]
for i in range(1, n):
	pref[i] = pref[i - 1] | l[i]
suff[n - 1] = l[n - 1]
for i in range(n - 2, -1, -1):
	suff[i] = suff[i + 1] | l[i]

def get_pref(index):
	if index < 0:
		return 0
	else:
		return pref[index]

def get_suff(index):
	if index >= n:
		return 0
	else:
		return suff[index]
power = x ** k
ans = 0
for i in range(n):
	contender = get_pref(i - 1) | l[i] * power | get_suff(i + 1)
	if contender > ans:
		ans = contender
print(ans)


__author__ = 'kitkat'
import sys
try:
	while True:
		(n, k, x) = map(int, input().split(' '))
		val = [0] + list(map(int, input().split(' ')))
		res = 0
		L = [0 for i in range(200003)]
		R = [0 for i in range(200003)]
		for i in range(1, n + 1, 1):
			L[i] = L[i - 1] | val[i]
			R[n - i + 1] = R[n - i + 2] | val[n - i + 1]
		for i in range(1, n + 1, 1):
			for j in range(k):
				val[i] *= x
		for i in range(1, n + 1, 1):
			res = max(res, L[i - 1] | R[i + 1] | val[i])
		print(res)
except EOFError:
	pass


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

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

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 testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

def modInverse(b):
	g = gcd(b, mod)
	if g != 1:
		return -1
	else:
		return pow(b, mod - 2, mod)

def power(x, y, p):
	y %= p - 1
	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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	(n, k, x) = sep()
	a = lis()
	pre = [0] * (n + 1)
	suff = [0] * (n + 1)
	temp = 1
	for i in range(k):
		temp *= x
	for i in range(n):
		pre[i] = pre[i - 1] | a[i]
	for i in range(n - 1, -1, -1):
		suff[i] = suff[i + 1] | a[i]
	ans = -inf
	for i in range(n):
		lol = pre[i - 1] | suff[i + 1]
		ans = max(ans, lol | a[i] * temp)
	print(ans)
testcase(1)


(n, k, x) = map(int, input().split())
(*Arr,) = map(int, input().split())
Prfx = [0] * (n + 2)
Sffx = [0] * (n + 2)
for i in range(0, n):
	Prfx[i + 1] = Prfx[i] | Arr[i]
	Sffx[n - i - 1] = Sffx[n - i] | Arr[n - i - 1]
now = x ** k
Res = 0
for i in range(0, n):
	Res = max(Prfx[i] | Arr[i] * now | Sffx[i + 1], Res)
print(Res)


import math
a = list(map(int, input().split()))
n = a[0]
k = a[1]
x = a[2]
a = list(map(int, input().split()))
b = [None] * n
c = [None] * n
b[0] = a[0]
mul = 1
c[n - 1] = a[n - 1]
for i in range(k):
	mul *= x
if n == 1:
	print(mul * a[0])
else:
	for i in range(1, n):
		b[i] = b[i - 1] | a[i]
	for i in range(n - 2, -1, -1):
		c[i] = c[i + 1] | a[i]
	ans = max(a[0] * mul | c[1], a[n - 1] * mul | b[n - 2])
	for i in range(1, n - 1):
		ans = max(ans, a[i] * mul | b[i - 1] | c[i + 1])
	print(ans)


import sys

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

def solve(N, K, X, A):
	(prefix, suffix) = ([0] * (N + 2), [0] * (N + 2))
	for i in range(N):
		prefix[i + 1] = prefix[i] | A[i]
	for i in range(N - 1, -1, -1):
		suffix[i] = suffix[i + 1] | A[i]
	ans = 0
	val = X ** K
	for i in range(N):
		ans = max(ans, prefix[i] | A[i] * val | suffix[i + 1])
	return ans
(N, K, X) = map(int, input().split())
A = get_ints()
print(solve(N, K, X, A))


from sys import stdin
input = stdin.readline

def get_or(a, b):
	return a | b

class SegmentTree:

	def __init__(self, data, default=0, func=max):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		start += self._size
		stop += self._size
		res_left = res_right = self._default
		while start < stop:
			if start & 1:
				res_left = self._func(res_left, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res_right = self._func(self.data[stop], res_right)
			start >>= 1
			stop >>= 1
		return self._func(res_left, res_right)

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

def f(a, k, x):
	st = SegmentTree(data=a, func=get_or, default=0)
	n = len(a)
	x = pow(x, k)
	cmax = st.query(0, n)
	for i in range(len(a)):
		st.__setitem__(i, a[i] * x)
		cmax = max(cmax, st.query(0, n))
		st.__setitem__(i, a[i])
	return cmax
(n, k, x) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
print(f(a, k, x))


import sys

class IoTool:
	DEBUG = 0

	def _reader_dbg():
		with open('./input.txt', 'r') as f:
			lines = f.readlines()
		for l in lines:
			yield l.strip()

	def _reader_oj():
		return iter(sys.stdin.read().split('\n'))
	reader = _reader_dbg() if DEBUG else _reader_oj()

	def read():
		return next(IoTool.reader)
input = IoTool.read

def main():
	(n, k, x) = map(int, input().split())
	a = list(map(int, input().split()))
	mul = 1
	for i in range(k):
		mul *= x
	if n == 1:
		print(a[0] * mul)
		return
	(pre, tail) = ([0] * n, [0] * n)
	pre[0] = a[0]
	tail[n - 1] = a[n - 1]
	for i in range(1, n):
		pre[i] = pre[i - 1] | a[i]
	for i in range(n - 2, -1, -1):
		tail[i] = tail[i + 1] | a[i]
	answer = max(pre[0] * mul | tail[1], pre[n - 2] | tail[n - 1] * mul)
	for i in range(1, n - 1):
		answer = max(answer, a[i] * mul | pre[i - 1] | tail[i + 1])
	print(answer)
main()


(n, k, x) = map(int, input().split())
a = [None] + list(map(int, input().split()))
prefix = [0] * (n + 2)
suffix = [0] * (n + 2)
for i in range(1, n + 1):
	prefix[i] = a[i] | prefix[i - 1]
for i in range(n, 0, -1):
	suffix[i] = a[i] | suffix[i + 1]
mul = x ** k
ans = 0
for i in range(1, n + 1):
	ans = max(ans, prefix[i - 1] | a[i] * mul | suffix[i + 1])
print(ans)


(n, k, x) = map(int, input().split())
(*a,) = map(int, input().split())
l = [0] * (n + 1)
r = [0] * (n + 1)
for i in range(0, n):
	l[i + 1] = l[i] | a[i]
	r[n - i - 1] = r[n - i] | a[n - i - 1]
num = x ** k
res = -1
for i in range(0, n):
	res = max(l[i] | a[i] * num | r[i + 1], res)
print(res)


import sys
import os
from io import BytesIO, IOBase

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

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

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(defaultdict(int))
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 collections import defaultdict
for _ in range(1):
	(n, k, x) = mi()
	a = li()
	mx = 0
	prefix = [0 for i in range(n)]
	suffix = [0 for i in range(n)]
	for i in range(n):
		prefix[i] = (prefix[i - 1] if i - 1 >= 0 else 0) | a[i]
	for i in range(n - 1, -1, -1):
		suffix[i] = (suffix[i + 1] if i + 1 < n else 0) | a[i]
	for i in range(n):
		tmp1 = prefix[i - 1] if i - 1 >= 0 else 0
		tmp2 = suffix[i + 1] if i + 1 < n else 0
		mx = max(mx, tmp1 | tmp2 | a[i] * x ** k)
	print(mx)


import sys
import math
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
(n, k, x) = invr()
ara = inara()
ara.append(0)
ara.reverse()
ara.append(0)
ara.reverse()
mul = int(math.pow(x, k))
pref = [0] * (n + 2)
for i in range(1, n + 1):
	pref[i] = pref[i - 1] | ara[i]
suff = [0] * (n + 2)
for i in range(n, 0, -1):
	suff[i] = suff[i + 1] | ara[i]
ans = 0
for i in range(1, n + 1):
	ans = max(ans, pref[i - 1] | ara[i] * mul | suff[i + 1])
print(ans)


(n, k, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
c = x ** k
pr = [0]
su = [0]
b = 0
for i in range(n - 1):
	b = a[i] | b
	pr.append(b)
b = 0
for i in range(n - 1, 0, -1):
	b = a[i] | b
	su.append(b)
su = su[::-1]
d = []
for i in range(n):
	d.append(pr[i] | a[i] * c | su[i])
print(max(d))


import sys
(n, k, x) = [int(x) for x in sys.stdin.readline().split()]
a = [int(x) for x in sys.stdin.readline().split()]
tl = 0
l = [0] * (n + 1)
for i in range(n - 1, -1, -1):
	tl |= a[i]
	l[i] = tl
ans = 0
tr = 0
for i in range(0, n):
	ta = tr | a[i] * x ** k | l[i + 1]
	ans = ans if ans > ta else ta
	tr |= a[i]
print(ans)


class Ortree:

	def __init__(self, n, As):
		size = 1
		while n > size:
			size *= 2
		self.size = size
		data = [0] * size + As[:] + [0] * (size - n)
		for idx in range(self.size - 1, 0, -1):
			idx2 = idx << 1
			data[idx] = data[idx2] | data[idx2 + 1]
		self.data = data

	def update(self, idx, val):
		pos = idx + self.size
		self.data[pos] = val
		pos >>= 1
		while pos:
			pos2 = pos << 1
			self.data[pos] = self.data[pos2] | self.data[pos2 + 1]
			pos >>= 1
		return self.data[1]

def solve(n, k, x, As):
	As.sort(reverse=True)
	xk = x ** k
	if n == 1:
		As[0] *= xk
		return As[0]
	if is_simplecase(xk, As):
		As[0] *= xk
		return cumor(As)
	return complexcase(n, xk, As)

def cumor(As):
	result = 0
	for a in As:
		result |= a
	return result

def is_simplecase(xk, As):
	len0 = len(bin(As[0] * xk))
	len1 = len(bin(As[1] * xk))
	return len0 > len1

def complexcase(n, xk, As):
	len0 = len(bin(As[0] * xk))
	for (i, a) in enumerate(As[1:], 1):
		if len(bin(a * xk)) < len0:
			end = i
			rest = cumor(As[end:])
			break
	else:
		end = n
		rest = 0
	ortree = Ortree(end, As[:end])
	record = rest
	for i in range(end):
		score = ortree.update(i, As[i] * xk) | rest
		if record < score:
			record = score
		ortree.update(i, As[i])
	return record
(n, k, x) = map(int, input().split())
As = list(map(int, input().split()))
print(solve(n, k, x, As))


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

def blen(val):
	s = 0
	while val > 0:
		s += 1
		val >>= 1
	return s

def solve(N, K, X, A):
	left = [0 for _ in range(N)]
	right = [0 for _ in range(N)]
	for (i, v) in enumerate(A):
		left[i] = (left[i - 1] if i - 1 >= 0 else 0) | v
	for i in range(N - 1, -1, -1):
		right[i] = (right[i + 1] if i + 1 < N else 0) | A[i]
	ans = 0
	for (i, v) in enumerate(A):
		a = left[i - 1] if i - 1 >= 0 else 0
		b = right[i + 1] if i + 1 < N else 0
		ans = max(ans, a | b | v * X ** K)
	return ans
(N, K, X) = map(int, input().split())
A = [int(x) for x in input().split()]
print(solve(N, K, X, A))


(n, k, x) = map(int, input().strip().split())
numbers = list(map(int, input().strip().split()))
from_b = [0 for i in range(n)]
from_e = [0 for i in range(n)]
or_no = [0 for i in range(n)]
for j in range(1, n):
	from_b[j] = from_b[j - 1] | numbers[j - 1]
	from_e[n - j - 1] = from_e[n - j] | numbers[n - j]
for j in range(n):
	or_no[j] = from_b[j] | from_e[j]
number = pow(x, k)
maxa = 0
for j in range(n):
	maxa = max(maxa, numbers[j] * number | or_no[j])
print(maxa)