Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: 

 Arrange all the rangers in a straight line in the order of increasing strengths.

 Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength.

 Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: 

 The strength of first ranger is updated to $5 \oplus 2$, i.e. 7.

 The strength of second ranger remains the same, i.e. 7.

 The strength of third ranger is updated to $9 \oplus 2$, i.e. 11.

 The strength of fourth ranger remains the same, i.e. 11.

 The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13.

 The new strengths of the 5 rangers are [7, 7, 11, 11, 13]

Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him?


-----Input-----

First line consists of three integers n, k, x (1 ≤ n ≤ 10^5, 0 ≤ k ≤ 10^5, 0 ≤ x ≤ 10^3) — number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively.

Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^3).


-----Output-----

Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times.


-----Examples-----
Input
5 1 2
9 7 11 15 5

Output
13 7
Input
2 100000 569
605 986

Output
986 605

Difficulty: MEDIUM_HARD

Solutions:
(n, k, x) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
(p1, i) = ([], 0)
while i < k:
	a.sort()
	p1 = a.copy()
	for j in range(0, n, 2):
		a[j] = a[j] ^ x
	if n * k > 500000 and min(a) == p1[0] and (max(a) == p1[-1]):
		break
	i += 1
print(max(a), min(a))


from sys import stdin, stdout
MOD = 10 ** 9 + 7
p = 137

def hashh(a):
	cnt = [0]
	for i in range(1, len(a) + 1):
		cnt.append((cnt[-1] * p + a[i - 1]) % MOD)
	return cnt[len(a)]
(n, k, x) = map(int, stdin.readline().split())
values = sorted(list(map(int, stdin.readline().split())))
newvalues = values[:]
d = {hashh(values): 0}
m = k
if k <= 100:
	for i in range(k):
		for j in range(0, n, 2):
			values[j] ^= x
		values.sort()
	stdout.write(str(values[-1]) + ' ' + str(values[0]))
else:
	for i in range(1, 1000):
		for j in range(0, n, 2):
			newvalues[j] ^= x
		newvalues.sort()
		value = hashh(newvalues)
		if value in d:
			T = i - d[value]
			k -= i
			values = newvalues[:]
			break
		else:
			d[value] = i
	k %= T
	for i in range(k):
		for j in range(0, n, 2):
			values[j] ^= x
		values.sort()
	stdout.write(str(values[-1]) + ' ' + str(values[0]))


(n, k, x) = map(int, input().split())
r = list(map(int, input().split()))
k %= 64
while k:
	k -= 1
	r.sort()
	for i in range(0, n, 2):
		r[i] ^= x
print(max(r), min(r))


import sys
from random import *
from bisect import *
pl = 1
from math import gcd, sqrt
from copy import *
sys.setrecursionlimit(10 ** 5)
if pl:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('outpt.txt', 'w')

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

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())
t = 1
ans = []
time = flag = 1
d = {}
while t > 0:
	t -= 1
	(n, k, x) = mi()
	k %= 1024
	a = li()
	d = [0] * 1024
	for i in range(n):
		d[a[i]] += 1
	for i in range(k):
		r = [0] * 1024
		c = 0
		for j in range(1024):
			if d[j] == 0:
				continue
			if (d[j] + 1 - c) // 2:
				r[j ^ x] += (d[j] + 1 - c) // 2
			if d[j] - (d[j] + 1 - c) // 2:
				r[j] += d[j] - (d[j] + 1 - c) // 2
			c = c ^ d[j] % 2
		d = deepcopy(r)
	p = []
	for i in range(1024):
		if d[i]:
			p.append(i)
	p = sorted(p)
	print(max(p), min(p))


(n, k, x) = map(int, input().split())
rangers = list(map(int, input().split()))
for i in range(min(k, 8 + k % 4)):
	rangers.sort()
	rangers = [rangers[i] if i % 2 else rangers[i] ^ x for i in range(n)]
rangers.sort()
print(rangers[-1], rangers[0])


def main():
	first_line = input()
	second_line = input()
	(n, k, x) = map(int, first_line.split())
	rangers = list(map(int, second_line.split()))
	xor_results = get_xor_results(x)
	rangers = snow(k, xor_results, rangers)
	print_max_min(rangers)

def get_xor_results(x):
	return [val ^ x for val in range(1024)]

def snow(k, xor_results, rangers):
	stack = []
	i = 0
	rangers.sort()
	while i < k:
		cycle_length = has_cycle(stack, rangers)
		if cycle_length:
			missing_steps = (k - i) % cycle_length
			return snow(k=missing_steps, xor_results=xor_results, rangers=rangers)
		stack.append(rangers)
		rangers = change_rangers(rangers, xor_results)
		i += 1
	return rangers

def has_cycle(stack, rangers):
	try:
		index = stack.index(rangers)
		current_step = len(stack)
		cycle = current_step - index
		return cycle
	except ValueError:
		return False

def change_rangers(rangers, xor_results):
	rangers = rangers[1::2] + [xor_results[val] for val in rangers[0::2]]
	rangers.sort()
	return rangers

def print_max_min(rangers):
	print(f'{max(rangers)} {min(rangers)}')
main()


from sys import stdin, stdout

def ri():
	return map(int, input().split())
(n, k, x) = ri()
a = []
a.append(list(ri()))
t = 0
j = 0
goout = 0
for j in range(0, k):
	a[j].sort()
	if j != 0:
		for t in range(j):
			if a[t] == a[j]:
				goout = 1
				break
	if goout:
		break
	a.append([a[j][i] ^ x if not i % 2 else a[j][i] for i in range(n)])
else:
	a[k].sort()
	print(a[k][-1], a[k][0])
	exit()
m = t + (k - t) % (j - t)
print(a[m][-1], a[m][0])


(n, k, x) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = []
i = 0
while i < k:
	a.sort()
	c = list()
	for each in a:
		c.append(each)
	b.append(c)
	if i - 4 >= 0 and b[i] == b[i - 4]:
		break
	for j in range(0, n, 2):
		a[j] = a[j] ^ x
	i = i + 1
a.sort()
if i == k:
	print(a[-1], a[0])
else:
	print(b[(k - i + 4) % 4 + i - 4][-1], b[(k - i + 4) % 4 + i - 4][0])


s = input().split()
n = int(s[0])
k = int(s[1])
x = int(s[2])
a = [[]]
s = input().split()
for i in range(n):
	a[0].append(int(s[i]))
a[0].sort()
for i in range(1, k + 1):
	a.append([a[i - 1][t] ^ x * ((t + 1) % 2) for t in range(len(a[i - 1]))])
	a[i].sort()
	for t in range(i):
		if a[i] == a[t]:
			flag = True
			break
	if t != i - 1:
		break
if k == 0:
	tag = 0
elif i == k:
	tag = k
else:
	tag = (k - i + 1) % (t - i) + i - 1
print(max(a[tag]), min(a[tag]))


(n, k, x) = map(int, input().split())
s = list(map(int, input().split()))
if k == 0:
	k = 0
else:
	k %= 64
while k:
	s = sorted(s)
	for i in range(0, n, 2):
		s[i] ^= x
	k -= 1
print(max(s), min(s))


inp = [(10, 10, 98), (1, 58, 62, 71, 55, 4, 20, 17, 25, 29)]
read = lambda : tuple(map(int, input().split()))
(n, k, x) = read()
l = sorted(read())
if k > 10:
	k = k % 4 + 4
for i in range(k):
	l = sorted([l[j] ^ x if j % 2 == 0 else l[j] for j in range(0, len(l), 1)])
print(max(l), min(l))


(n, k, x) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
n1 = []
n2 = []
p = True
from sys import exit
if n == 74 and k == 361:
	print(987, 39)
	exit()
if k == 0:
	print(max(a), min(a))
	exit()
elif k < 100 and n < 200:
	for i in range(k):
		a.sort()
		for j in range(0, n, 2):
			a[j] = a[j] ^ x
	print(max(a), min(a))
	exit()
for i in range(21):
	a.sort()
	for j in range(0, n, 2):
		a[j] = a[j] ^ x
	a.sort()
	if i == 10 and k % 2 != 0 or (min(a) == 168 and k == 22196):
		p = False
		break
	elif i == 9 and k % 2 == 0 or (min(a) == 168 and k == 22196):
		p = False
		break
	if p == False:
		break
print(max(a), min(a))


(n, k, x) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
if k != 0:
	k = k % 64
else:
	k = 0
while k:
	arr.sort()
	for i in range(0, n, 2):
		arr[i] ^= x
	k -= 1
print(max(arr), min(arr))


[n, k, x] = list(map(int, input().split()))
arr = list(map(int, input().split()))
if k % 2:
	y = 1
else:
	y = 2
if n * k < 1000000:
	y = k
if k == 0:
	print(max(arr), min(arr))
else:
	for j in range(y):
		arr.sort()
		for i in range(0, n, 2):
			arr[i] = arr[i] ^ x
	print(max(arr), min(arr))


f = lambda : [int(x) for x in input().split()]
(n, k, x) = f()
L = f()
mi = min(L)
ma = max(L)
for i in range(k % 128):
	L.sort()
	mi = 10 ** 3 ^ 2 * 10 ** 3
	ma = 0
	for j in range(len(L)):
		if j % 2 == 0:
			L[j] = L[j] ^ x
		if L[j] < mi:
			mi = L[j]
		if L[j] > ma:
			ma = L[j]
print(str(ma) + ' ' + str(mi))


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class SegmentTree1:

	def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
		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):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

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

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a * a + b * b):
		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):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

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

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, k, x) = map(int, input().split())
l = list(map(int, input().split()))
ind = []
ind.append(l + [])
c = 0
while True:
	if c == k:
		print(max(ind[-1]), min(ind[-1]))
		sys.exit()
	l.sort()
	for i in range(0, n, 2):
		l[i] = l[i] ^ x
	if l in ind:
		inde = ind.index(l)
		break
	ind.append(l + [])
	c += 1
k -= inde
cur = len(ind) - inde
r = ind[k % cur + inde]
print(max(r), min(r))