You are given an array $a$ consisting of $n$ non-negative integers. You have to choose a non-negative integer $x$ and form a new array $b$ of size $n$ according to the following rule: for all $i$ from $1$ to $n$, $b_i = a_i \oplus x$ ($\oplus$ denotes the operation bitwise XOR).

An inversion in the $b$ array is a pair of integers $i$ and $j$ such that $1 \le i < j \le n$ and $b_i > b_j$.

You should choose $x$ in such a way that the number of inversions in $b$ is minimized. If there are several options for $x$ — output the smallest one.


-----Input-----

First line contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the number of elements in $a$.

Second line contains $n$ space-separated integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.


-----Output-----

Output two integers: the minimum possible number of inversions in $b$, and the minimum possible value of $x$, which achieves those number of inversions.


-----Examples-----
Input
4
0 1 3 2

Output
1 0

Input
9
10 7 9 10 7 5 5 3 5

Output
4 14

Input
3
8 10 3

Output
0 8



-----Note-----

In the first sample it is optimal to leave the array as it is by choosing $x = 0$.

In the second sample the selection of $x = 14$ results in $b$: $[4, 9, 7, 4, 9, 11, 11, 13, 11]$. It has $4$ inversions:

  $i = 2$, $j = 3$;  $i = 2$, $j = 4$;  $i = 3$, $j = 4$;  $i = 8$, $j = 9$. 

In the third sample the selection of $x = 8$ results in $b$: $[0, 2, 11]$. It has no inversions.

Source: codeforces | Difficulty: HARD


Solutions:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
groups = [a]
tot = 0
ans = 0
for pos in range(32)[::-1]:
	bit = 1 << pos
	invs = 0
	flipped_invs = 0
	nxt_groups = []
	for group in groups:
		bin = []
		big = []
		small = []
		for x in group:
			if x & bit:
				bin.append(1)
				big.append(x)
			else:
				bin.append(0)
				small.append(x)
		if big:
			nxt_groups.append(big)
		if small:
			nxt_groups.append(small)
		zeros = 0
		ones = 0
		for x in bin[::-1]:
			if x == 0:
				zeros += 1
				flipped_invs += ones
			else:
				ones += 1
				invs += zeros
	groups = nxt_groups
	if flipped_invs < invs:
		ans |= bit
	tot += min(flipped_invs, invs)
print(tot, ans)


dp = [[0, 0] for _ in range(34)]

def solve(arr, bit):
	if bit < 0 or len(arr) == 0:
		return
	(inv1, inv0, o, z, x) = (0, 0, 0, 0, 1 << bit)
	(O, Z) = ([], [])
	for el in arr:
		if el & x:
			o += 1
			O.append(el)
			inv1 += z
		else:
			z += 1
			Z.append(el)
			inv0 += o
	dp[bit][0] += inv0
	dp[bit][1] += inv1
	solve(Z, bit - 1)
	solve(O, bit - 1)
n = int(input())
arr = [int(x) for x in input().split()]
solve(arr, 30)
(invCnt, ans) = (0, 0)
for b in range(30, -1, -1):
	if dp[b][1] < dp[b][0]:
		ans += 1 << b
	invCnt += min(dp[b][1], dp[b][0])
print(invCnt, ans, sep=' ')


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

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

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

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

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

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

def solve(aa):
	x = 0
	inv = 0
	q = [aa]
	for k in range(32, -1, -1):
		inv0 = inv1 = 0
		nq = []
		for aa in q:
			(aa0, aa1) = ([], [])
			c0 = c1 = 0
			for a in aa:
				if a >> k & 1:
					inv1 += c0
					c1 += 1
					aa1.append(a)
				else:
					inv0 += c1
					c0 += 1
					aa0.append(a)
			if aa0:
				nq.append(aa0)
			if aa1:
				nq.append(aa1)
		if inv1 < inv0:
			x |= 1 << k
			inv += inv1
		else:
			inv += inv0
		q = nq
	print(inv, x)
n = II()
aa = LI()
solve(aa)


n = int(input())
a = [int(x) for x in input().split()]

def solve(w, bit_level):
	l = []
	h = []
	openers = 0
	inversions = 0
	alt_openers = 0
	alt_inversions = 0
	for x in w:
		if x & bit_level:
			h.append(x)
			openers += 1
			alt_inversions += alt_openers
		else:
			l.append(x)
			inversions += openers
			alt_openers += 1
	return (inversions, alt_inversions, l, h)
out = 0
tot_inversions = 0
active_groups = [a]
for bit_level in reversed(range(31)):
	(sum_i, sum_ai) = (0, 0)
	next_batch = []
	for group in active_groups:
		(i, ai, l, h) = solve(group, 1 << bit_level)
		sum_i += i
		sum_ai += ai
		if l:
			next_batch.append(l)
		if h:
			next_batch.append(h)
	if sum_ai < sum_i:
		out |= 1 << bit_level
		tot_inversions += sum_ai
	else:
		tot_inversions += sum_i
	active_groups = next_batch
print(tot_inversions, out)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
current = 0
fail = 0
for i in range(31, -1, -1):
	yescount = 0
	nocount = 0
	tmp = 2 ** i
	dic = {}
	for j in range(n):
		r = a[j] // tmp
		if r % 2 == 0 and r + 1 in dic:
			yescount += dic[r + 1]
		elif r % 2 == 1 and r - 1 in dic:
			nocount += dic[r - 1]
		if r in dic:
			dic[r] += 1
		else:
			dic[r] = 1
	if yescount > nocount:
		fail += nocount
		current += tmp
	else:
		fail += yescount
print(fail, current)


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

def solve(N, A):
	total = 0
	ans = 0
	groups = [A]
	for pos in reversed(range(32)):
		bit = 1 << pos
		invs = 0
		flippedInvs = 0
		nextGroups = []
		for group in groups:
			binary = []
			big = []
			small = []
			for x in group:
				if x & bit:
					binary.append(1)
					big.append(x)
				else:
					binary.append(0)
					small.append(x)
			if big:
				nextGroups.append(big)
			if small:
				nextGroups.append(small)
			numZeroes = 0
			numOnes = 0
			for x in binary[::-1]:
				if x == 0:
					numZeroes += 1
					flippedInvs += numOnes
				else:
					numOnes += 1
					invs += numZeroes
		groups = nextGroups
		if flippedInvs < invs:
			ans |= 1 << pos
		total += min(flippedInvs, invs)
	return str(total) + ' ' + str(ans)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)


import sys
z = sys.stdin.readline
z()
a = [*map(int, z().split())]
v = 30
t = x = 0
while v:
	u = d = 0
	r = {}
	w = 1 << v - 1
	for i in a:
		p = i >> v
		b = i & w
		r[2 * p] = 1 + r.get(2 * p, 0)
		if b:
			r[2 * p + 1] = 1 + r.get(2 * p + 1, 0)
		else:
			d += r.get(2 * p + 1, 0)
	for p in r:
		if p % 2:
			(rp, cp) = (r.get(p, 0), r.get(p - 1, 0))
			u += cp * (cp - 1) // 2 - rp * (rp - 1) // 2 - (cp - rp) * (cp - rp - 1) // 2
	if d > u - d:
		x += w
		d = u - d
	t += d
	v -= 1
print(t, x)


import sys
import collections
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
maxs = max(arr)
cnt = 0
x = 0
prefix = [0] * n
for k in range(maxs.bit_length() - 1, -1, -1):
	tx = 2 ** k
	one = collections.Counter()
	zero = collections.Counter()
	rev = 0
	rev2 = 0
	for i in range(n):
		if arr[i] & tx:
			one[prefix[i]] += 1
			rev += zero[prefix[i]]
			prefix[i] += tx
		else:
			zero[prefix[i]] += 1
			rev2 += one[prefix[i]]
	if rev < rev2:
		cnt += rev
		x += tx
	else:
		cnt += rev2
print(cnt, x)


import sys
input = sys.stdin.buffer.readline
(n, ls) = (int(input()), list(map(int, input().split())))
(cur, res, cc) = ([ls], 0, 0)
for i in range(30, -1, -1):
	(t_rc0, t_rc1, nx) = (0, 0, [])
	for ar in cur:
		(ar0, ar1) = ([], [])
		(rc0, cc0, rc1, cc1) = (0, 0, 0, 0)
		for u in ar:
			b = u & 1 << i
			if b:
				(rc1, cc1) = (rc1 + cc0, cc1 + 1)
				ar1.append(u)
			else:
				(rc0, cc0) = (rc0 + cc1, cc0 + 1)
				ar0.append(u)
		(t_rc0, t_rc1) = (t_rc0 + rc0, t_rc1 + rc1)
		if ar0:
			nx.append(ar0)
		if ar1:
			nx.append(ar1)
	if t_rc0 > t_rc1:
		res |= 1 << i
	cc += min(t_rc0, t_rc1)
	cur = nx
print(cc, res)


import copy

def inv(L):
	s = sum(L)
	ss = s
	c = 0
	n = len(L)
	for i in range(n):
		if L[i] == 1:
			s -= 1
			c += n - i - 1 - s
	c00 = (n - ss) * (n - ss - 1) // 2
	c11 = ss * (ss - 1) // 2
	c01 = n * (n - 1) // 2 - c00 - c11 - c
	return (c, c01)

def check(n, c):
	return n ^ c < n
n = int(input())
L = list(map(int, input().split()))
mx = max(L)
c = 1
while c <= mx:
	c *= 2
c //= 2
ans = 0
invcount = 0
splitL = [L]
while c:
	newL = []
	a = 0
	b = 0
	for lists in splitL:
		L0 = []
		L1 = []
		checkL = []
		for i in lists:
			k = check(i, c)
			checkL.append([0, 1][k])
			if k:
				L1.append(i)
			else:
				L0.append(i)
		(aa, bb) = inv(checkL)
		a += aa
		b += bb
		if len(L0):
			newL.append(L0)
		if len(L1):
			newL.append(L1)
	if a > b:
		ans += c
	invcount += min(a, b)
	c //= 2
	splitL = newL
print(invcount, ans)


import sys
input = sys.stdin.buffer.readline

class BinaryIndexedTree:

	def __init__(self, n):
		self.size = n
		self.bit = [0] * (n + 1)

	def build(self, array):
		for (i, val) in enumerate(array):
			self.bit[i + 1] = val
		for i in range(1, self.size):
			if i + (i & -i) > self.size:
				continue
			self.bit[i + (i & -i)] += self.bit[i]

	def _sum(self, i):
		s = 0
		while i > 0:
			s += self.bit[i]
			i -= i & -i
		return s

	def add(self, i, val):
		i += 1
		while i <= self.size:
			self.bit[i] += val
			i += i & -i

	def sum(self, l, r):
		return self._sum(r) - self._sum(l)
n = int(input())
a_ = list(map(int, input().split()))
a_all = [a_[:]]
ans = 0
for bit in range(32)[::-1]:
	inv_cnt0 = 0
	inv_cnt1 = 0
	for a in a_all:
		cnt1 = 0
		cnt0 = 0
		for val in a:
			if val >> bit & 1:
				cnt1 += 1
				inv_cnt0 += cnt0
			else:
				cnt0 += 1
				inv_cnt1 += cnt1
	if inv_cnt0 < inv_cnt1:
		ans += 1 << bit
	new_a_all = []
	for a in a_all:
		tmp0 = []
		tmp1 = []
		for val in a:
			if val >> bit & 1:
				tmp1.append(val)
			else:
				tmp0.append(val)
		if tmp1:
			new_a_all.append(tmp1)
		if tmp0:
			new_a_all.append(tmp0)
	a_all = new_a_all[:]
a_ = [ans ^ val for val in a_]

def compress(array):
	array2 = sorted(set(array))
	memo = {value: index for (index, value) in enumerate(array2)}
	for i in range(len(array)):
		array[i] = memo[array[i]]
	return array
a_ = compress(a_)
bit = BinaryIndexedTree(n)
res = 0
for i in range(n):
	bit.add(a_[i], 1)
	res += bit.sum(a_[i] + 1, n)
print(res, ans)


from sys import stdin
tt = 1
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	nows = [a]
	ansr = 0
	ansd = 0
	for d in range(32, -1, -1):
		nd = 2 ** d
		rev = 0
		nev = 0
		nex = []
		for lis in nows:
			one = []
			zero = []
			for i in lis:
				if i & nd > 0:
					nev += len(zero)
					one.append(i)
				else:
					rev += len(one)
					zero.append(i)
			if len(one) > 0:
				nex.append(one)
			if len(zero) > 0:
				nex.append(zero)
		if rev > nev:
			ansd ^= nd
			ansr += nev
		else:
			ansr += rev
		nows = nex
	print(ansr, ansd)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = list(map(int, input().split()))
	v = 30
	t = x = 0
	while v:
		u = d = 0
		r = {}
		w = 1 << v - 1
		for i in a:
			p = i >> v
			b = i & w
			if b:
				r[2 * p + 1] = 1 + r.get(2 * p + 1, 0)
			else:
				d += r.get(2 * p + 1, 0)
			r[2 * p] = 1 + r.get(2 * p, 0)
		for p in r:
			if p % 2:
				(rp, cp) = (r.get(p, 0), r.get(p - 1, 0))
				u += cp * (cp - 1) // 2 - rp * (rp - 1) // 2 - (cp - rp) * (cp - rp - 1) // 2
		if d > u - d:
			x += w
			d = u - d
		t += d
		v -= 1
	print(t, x)
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()
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, io, os
from collections import defaultdict
inp = [int(x) for x in sys.stdin.buffer.read().split()]
n = inp.pop(0)
A = inp
t = 0.0
x = 0
for v in range(1, 31)[::-1]:
	u = d = 0.0
	r1 = defaultdict(int)
	r2 = defaultdict(int)
	w = 1 << v - 1
	for a in A:
		p = a >> v
		b = a & w
		if b:
			r1[p] += 1
		elif p in r1:
			d += 2 * r1[p]
		r2[p] += 1
	for p in r1:
		if p in r2:
			rp = r1[p] + 0.0
			cp = r2[p] + 0.0
			u += cp * (cp - 1) - rp * (rp - 1) - (cp - rp) * (cp - rp - 1)
	if d > u - d:
		x += w
		d = u - d
	t += d
print(int(t) // 2, x)


def parse(n):
	ans = [0 for _ in range(30)]
	for i in range(30):
		if n & 1 == 1:
			ans[i] = 1
		n >>= 1
	return ans

def proc(bits, pos, f):
	zero = []
	one = []
	cnt0 = 0
	cnt1 = 0
	val0 = 0
	val1 = 0
	for (i, x) in enumerate(bits):
		if x[pos] == 1:
			cnt1 += 1
			val1 += cnt0
			one.append(x)
		else:
			cnt0 += 1
			val0 += cnt1
			zero.append(x)
	f[pos][0] += val0
	f[pos][1] += val1
	if pos > 0:
		if len(zero) > 0:
			proc(zero, pos - 1, f)
		if len(one) > 0:
			proc(one, pos - 1, f)
n = int(input())
a = [int(x) for x in input().split()]
bits = [parse(x) for x in a]
f = [[0, 0] for _ in range(30)]
proc(bits, 29, f)
ans = [0 for _ in range(30)]
cnt = 0
for i in range(30):
	if f[i][0] <= f[i][1]:
		ans[i] = 0
		cnt += f[i][0]
	else:
		ans[i] = 1
		cnt += f[i][1]
y = 1
ans2 = 0
for x in ans:
	ans2 += y * x
	y <<= 1
print(cnt, ans2)


import sys, math
import io, os
data = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = float('inf')
mod = 10 ** 9 + 7
n = int(data())
a = mdata()
t = 1 << 30
ans = 0
X = 0
cur = [a]
while t and cur:
	next = []
	(inv, finv) = (0, 0)
	for arr in cur:
		(arr0, arr1) = ([], [])
		for a in arr:
			if a & t:
				finv += len(arr0)
				arr1.append(a)
			else:
				inv += len(arr1)
				arr0.append(a)
		next.append(arr0) if arr0 else None
		next.append(arr1) if arr1 else None
	if inv <= finv:
		ans += inv
	else:
		ans += finv
		X += t
	cur = next[:]
	t >>= 1
print(ans, X)


n = int(input())
l = input().split()
li = [int(i) for i in l]
xori = 0
ans = 0
mul = 1
for i in range(32):
	hashi1 = dict()
	hashi0 = dict()
	inv1 = 0
	inv2 = 0
	for j in li:
		if j // 2 in hashi1 and j % 2 == 0:
			inv1 += hashi1[j // 2]
		if j // 2 in hashi0 and j % 2 == 1:
			inv2 += hashi0[j // 2]
		if j % 2:
			if j // 2 not in hashi1:
				hashi1[j // 2] = 1
			else:
				hashi1[j // 2] += 1
		elif j // 2 not in hashi0:
			hashi0[j // 2] = 1
		else:
			hashi0[j // 2] += 1
	if inv1 <= inv2:
		ans += inv1
	else:
		ans += inv2
		xori = xori + mul
	mul *= 2
	for j in range(n):
		li[j] = li[j] // 2
print(ans, xori)


from collections import deque
n = int(input())
a = list(map(int, input().split()))
que = deque([tuple([i for i in range(n)])])
(rev_cnt, x) = (0, 0)
for i in range(30, -1, -1):
	(inv_cnt, notinv_cnt) = (0, 0)
	L = len(que)
	for _ in range(L):
		seq = que.popleft()
		(onecnt, seqrev, seqlen) = (0, 0, len(seq))
		(group0, group1) = ([], [])
		for v in seq:
			if a[v] >> i & 1 == 0:
				seqrev += onecnt
				group0.append(v)
			else:
				onecnt += 1
				group1.append(v)
		inv_cnt += seqrev
		notinv_cnt += seqlen * (seqlen - 1) // 2 - onecnt * (onecnt - 1) // 2 - (seqlen - onecnt) * (seqlen - onecnt - 1) // 2 - seqrev
		if len(group0) > 1:
			que.append(tuple(group0))
		if len(group1) > 1:
			que.append(tuple(group1))
	if inv_cnt <= notinv_cnt:
		rev_cnt += inv_cnt
		continue
	else:
		rev_cnt += notinv_cnt
		x += 1 << i
		continue
print(rev_cnt, x)


def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	minInv = 0
	minX = 0
	batch = [list(range(n))]
	for i in range(29, -1, -1):
		bit = 1 << i
		dontToggleInv = 0
		toggleInv = 0
		nextBatch = []
		for group in batch:
			zeros = []
			ones = []
			for idx in group:
				if a[idx] & bit > 0:
					ones.append(idx)
					toggleInv += len(zeros)
				else:
					zeros.append(idx)
					dontToggleInv += len(ones)
			if len(zeros) > 1:
				nextBatch.append(zeros)
			if len(ones) > 1:
				nextBatch.append(ones)
		batch = nextBatch
		if dontToggleInv <= toggleInv:
			minInv += dontToggleInv
		else:
			minInv += toggleInv
			minX = minX | bit
	print('{} {}'.format(minInv, minX))
	return
import sys
input = sys.stdin.buffer.readline

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

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

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


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A_list = [list(map(int, input().split()))]
	cnt = 0
	x = 0
	for lv in range(30, -1, -1):
		A_list_new = []
		inv_sum = 0
		inv_max = 0
		for A in A_list:
			AA = [a >> lv & 1 for a in A]
			zero = 0
			one = 0
			inv = 0
			A_new_0 = []
			A_new_1 = []
			for (i, a) in enumerate(AA):
				if a == 0:
					zero += 1
					inv += one
					A_new_0.append(A[i])
				else:
					one += 1
					A_new_1.append(A[i])
			if A_new_0:
				A_list_new.append(A_new_0)
			if A_new_1:
				A_list_new.append(A_new_1)
			inv_max += zero * one
			inv_sum += inv
		inv_flipped = inv_max - inv_sum
		if inv_sum <= inv_flipped:
			cnt += inv_sum
		else:
			cnt += inv_flipped
			x += 1 << lv
		A_list = A_list_new
	print(cnt, x)
main()


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')
import math
n = int(input())
vals = [list(map(int, input().split()))]
if max(vals[0]) == 0:
	print(0, 0)
else:
	orig = vals[0].copy()
	nums = math.floor(math.log2(max(vals[0])))

	def inv_count(a, m=1 << 29):
		if not m or not a:
			return 0
		count = 0
		(ones, zeros) = ([], [])
		for n in a:
			if n & m:
				ones.append(n & ~m)
			else:
				count += len(ones)
				zeros.append(n & ~m)
		m = m // 2
		return count + inv_count(ones, m) + inv_count(zeros, m)
	xmin = 0
	for s in range(nums, -1, -1):
		x = 1 << s
		add = []
		neg = 0
		inv = 0
		while len(vals) > 0:
			arr = vals.pop()
			barr = [i ^ x for i in arr]
			one = []
			zero = []
			onec = 0
			zeroc = 0
			for i in barr:
				if i & x == 0:
					zero.append(i)
					zeroc += 1
					inv += onec
				else:
					one.append(i)
					onec += 1
					neg += zeroc
			if len(one) > 0:
				add.append(one)
			if len(zero) > 0:
				add.append(zero)
		if neg - inv > 0:
			xmin += x
		vals = add
	print(inv_count([i ^ xmin for i in orig]), xmin)


from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *
import sys
n = int(input())
ans = x = 0
arr = [list(map(int, input().split()))]
for k in range(29, -1, -1):
	(a, b) = (0, 0)
	mask = 1 << k
	tmp = []
	for ar in arr:
		one = zero = 0
		tmp1 = []
		tmp2 = []
		for ai in ar:
			cur = ai & mask
			if cur == 0:
				b += one
				zero += 1
				tmp1.append(ai)
			else:
				a += zero
				one += 1
				tmp2.append(ai)
		if len(tmp1) > 1:
			tmp.append(tmp1)
		if len(tmp2) > 1:
			tmp.append(tmp2)
	if b > a:
		x |= mask
		ans += a
	else:
		ans += b
	arr = tmp
print(ans, x)


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

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

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

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

def print_list(l):
	print(' '.join(map(str, l)))
from collections import defaultdict as dc
n = N()
a = RLL()
res = 0
ans = 0
dic = dc(list)
for i in range(n):
	dic[a[i]].append(i)
t = list(sorted(dic.keys()))
dic = [[i] + dic[i] for i in t]

def merge(a, b):
	(inverse, i, j, na, nb) = (0, 1, 1, len(a), len(b))
	r = []
	while i < na and j < nb:
		if a[i] < b[j]:
			r.append(a[i])
			i += 1
		else:
			r.append(b[j])
			j += 1
			inverse += i - 1
	inverse += (i - 1) * (nb - j)
	r += b[j:]
	r += a[i:]
	return (inverse, (na - 1) * (nb - 1) - inverse, r)
k = 0
while len(dic) > 1:
	(x, y, i, nd) = (0, 0, 0, len(dic))
	nex = []
	while i < nd - 1:
		if dic[i][0] & 1 == 0 and dic[i + 1][0] == dic[i][0] + 1:
			(dx, dy, r) = merge(dic[i + 1], dic[i])
			x += dx
			y += dy
			nex.append([dic[i][0] >> 1] + r)
			i += 2
		else:
			dic[i][0] >>= 1
			nex.append(dic[i])
			i += 1
	if i == nd - 1:
		dic[i][0] >>= 1
		nex.append(dic[i])
	res += min(x, y)
	if x > y:
		ans |= 1 << k
	k += 1
	dic = nex
print(res, ans)


import sys, collections as cc
input = sys.stdin.buffer.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
an = ban = 0
ar = cc.defaultdict(list)
ar[0] = l
xo = 1 << 30
for i in range(30, -1, -1):
	a = b = 0
	pr = cc.defaultdict(list)
	for j in ar:
		ff = j
		j = ar[j]
		aa = bb = 0
		oo = zz = 0
		for x in range(len(j)):
			if j[x] & xo:
				aa += zz
				oo += 1
				pr[2 * ff + 0].append(j[x])
			else:
				bb += oo
				zz += 1
				pr[2 * ff + 1].append(j[x])
		a += aa
		b += bb
	ar = pr
	if a < b:
		an += xo
		ban += a
	else:
		ban += b
	xo //= 2
print(ban, an)


import sys

def readnumbers(zero=0):
	_ord = ord if round(0.5) else lambda x: x
	nums = []
	(num, neg) = (zero, False)
	(i, s) = (0, sys.stdin.buffer.read())
	try:
		while True:
			if s[i] >= b'0'[0]:
				num = 10 * num + _ord(s[i]) - 48
			elif s[i] == b'-'[0]:
				neg = True
			elif s[i] != b'\r'[0]:
				nums.append(-num if neg else num)
				(num, neg) = (zero, False)
			i += 1
	except IndexError:
		pass
	if s and s[-1] >= b'0'[0]:
		nums.append(-num if neg else num)
	return nums
a = readnumbers()[1:]
v = 30
t = x = 0
while v:
	u = d = 0
	r = {}
	w = 1 << v - 1
	for i in a:
		p = i >> v
		b = i & w
		if b:
			r[2 * p + 1] = 1 + r.get(2 * p + 1, 0)
		else:
			d += r.get(2 * p + 1, 0)
		r[2 * p] = 1 + r.get(2 * p, 0)
	for p in r:
		if p % 2:
			(rp, cp) = (r.get(p, 0), r.get(p - 1, 0))
			u += cp * (cp - 1) // 2 - rp * (rp - 1) // 2 - (cp - rp) * (cp - rp - 1) // 2
	if d > u - d:
		x += w
		d = u - d
	t += d
	v -= 1
print(t, x)


import os
from sys import stdin, stdout

class Input:

	def __init__(self):
		self.lines = stdin.readlines()
		self.idx = 0

	def line(self):
		try:
			return self.lines[self.idx].strip()
		finally:
			self.idx += 1

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def known_tests(self):
		(num_of_cases,) = self.array()
		for case in range(num_of_cases):
			yield self

	def unknown_tests(self):
		while self.idx < len(self.lines):
			yield self

def problem_solver():
	oo = float('Inf')
	mem = None

	def backtrack(a, L, R, B=31):
		if B < 0 or L == R:
			return
		mask = 1 << B
		l = L
		r = L
		inv0 = 0
		inv1 = 0
		zero = 0
		one = 0
		la = []
		ra = []
		while l < R:
			while r < R and a[l] & mask == a[r] & mask:
				if a[r] & mask:
					la.append(a[r])
					one += 1
					inv1 += zero
				else:
					ra.append(a[r])
					zero += 1
					inv0 += one
				r += 1
			l = r
		backtrack(la, 0, len(la), B - 1)
		backtrack(ra, 0, len(ra), B - 1)
		mem[B][0] += inv0
		mem[B][1] += inv1

	def solver(inpt):
		nonlocal mem
		(n,) = inpt.array()
		a = inpt.array()
		mem = [[0, 0] for i in range(32)]
		backtrack(a, 0, n)
		inv = 0
		x = 0
		for b in range(32):
			if mem[b][0] <= mem[b][1]:
				inv += mem[b][0]
			else:
				inv += mem[b][1]
				x |= 1 << b
		print(inv, x)
	return solver
try:
	solver = problem_solver()
	for tc in Input().unknown_tests():
		solver(tc)
except Exception as e:
	import traceback
	traceback.print_exc(file=stdout)


n = int(input())
l = list(map(int, input().split()))
inv = 0
out = 0
mult = 1
for i in range(32):
	curr = dict()
	opp = 0
	same = 0
	for v in l:
		if v ^ 1 in curr:
			if v & 1:
				opp += curr[v ^ 1]
			else:
				same += curr[v ^ 1]
		if v not in curr:
			curr[v] = 0
		curr[v] += 1
	for i in range(n):
		l[i] >>= 1
	if same <= opp:
		inv += same
	else:
		inv += opp
		out += mult
	mult *= 2
print(inv, out)


import sys
input = sys.stdin.readline
(N,) = map(int, input().split())
A = list(map(int, input().split()))

def check(l, i):
	(al, bl) = ([], [])
	a = b = 0
	ta = tb = 0
	for j in l:
		if A[j] >> i & 1:
			al.append(j)
			ta += 1
			b += tb
		else:
			bl.append(j)
			tb += 1
			a += ta
	return (a, b, al, bl)
ll = [list(range(N))]
R = 0
X = 0
for i in range(29, -1, -1):
	nll = []
	ac = bc = 0
	for l in ll:
		(a, b, al, bl) = check(l, i)
		ac += a
		bc += b
		if al:
			nll.append(al)
		if bl:
			nll.append(bl)
	if ac > bc:
		X += 1 << i
		R += bc
	else:
		R += ac
	ll = nll
print(R, X)


n = int(input())
a = list(map(int, input().split()))
cur = [a]
s = sum(a)
ans = 0
cnt = 0
i = 1 << 31
while i:
	i >>= 1
	fcnt = 0
	bcnt = 0
	nex = []
	for arr in cur:
		(aa, bb) = ([], [])
		zcnt = 0
		ocnt = 0
		for ai in arr:
			if ai & i:
				ocnt += 1
				fcnt += zcnt
				aa.append(ai)
			else:
				zcnt += 1
				bcnt += ocnt
				bb.append(ai)
		if aa:
			nex.append(aa)
		if bb:
			nex.append(bb)
	if bcnt > fcnt:
		ans |= i
		cnt += fcnt
	else:
		cnt += bcnt
	cur = nex
print(cnt, ans)


import os, sys
from io import BytesIO, IOBase

def countInversions(arr):
	arr = list(map(lambda xx: [xx], arr))
	ans = 0
	while len(arr) != 1:
		arr1 = []
		for i in range(0, len(arr), 2):
			if i == len(arr) - 1:
				arr1.append(arr[-1])
				continue
			arr1.append([])
			(a, b) = (0, 0)
			for _ in range(len(arr[i]) + len(arr[i + 1])):
				if a == len(arr[i]):
					arr1[-1].append(arr[i + 1][b])
					b += 1
				elif b == len(arr[i + 1]):
					arr1[-1].append(arr[i][a])
					a += 1
				elif arr[i][a] <= arr[i + 1][b]:
					arr1[-1].append(arr[i][a])
					a += 1
				else:
					arr1[-1].append(arr[i + 1][b])
					b += 1
					ans += len(arr[i]) - a
		arr = arr1
	return ans
num = [[] for _ in range(100)]

def rec(a, val, ind):
	global num
	(old, new) = ([0, 0], [0, 0])
	(a1, a2) = ([], [])
	for i in a:
		if i & val:
			old[1] += 1
			new[0] += new[1]
			a1.append(i)
		else:
			new[1] += 1
			old[0] += old[1]
			a2.append(i)
	if val != 1:
		if len(a1):
			rec(a1, val >> 1, ind + 1)
		if len(a2):
			rec(a2, val >> 1, ind + 1)
	num[ind].append((old[0], new[0]))

def main():
	global num
	n = int(input())
	a = list(map(int, input().split()))
	r = max(a).bit_length() - 1
	if r < 0:
		print(0, 0)
		exit()
	val = 1 << r
	rec(a, val, 0)
	ans = 0
	for i in num:
		if not len(i):
			continue
		(a1, b1) = (0, 0)
		for x in i:
			a1 += x[0]
			b1 += x[1]
		if a1 > b1:
			ans |= val
		val >>= 1
	a = list(map(lambda xx: xx ^ ans, a))
	print(countInversions(a), ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin
input = stdin.readline
n = int(input())
ll = list(map(int, input().split()))
wynik = 0
pot = 1
inwersje = 0
m = max(ll)
while pot * 2 <= m:
	pot *= 2
listy = [ll]
while pot >= 1:
	inww = 0
	chujnww = 0
	nowe = []
	for l in listy:
		jedna = []
		druga = []
		inw = 0
		jedynki = 0
		zera = 0
		chujnw = 0
		for i in range(len(l)):
			if l[i] ^ pot < l[i]:
				jedna.append(l[i])
				chujnw += zera
				jedynki += 1
			else:
				inw += jedynki
				zera += 1
				druga.append(l[i])
		if jedna:
			nowe.append(jedna)
		if druga:
			nowe.append(druga)
		inww += inw
		chujnww += chujnw
	if inww > chujnww:
		wynik += pot
	inwersje += min(inww, chujnww)
	listy = nowe
	pot //= 2
print(inwersje, wynik)


import sys
input = sys.stdin.readline
n = int(input())
A = [list(map(int, input().split()))]

def calc(B):
	ZERO = 0
	ONE = 0
	ZEROINV = 0
	ONEINV = 0
	for b in B:
		if b == 0:
			ZEROINV += ONE
			ZERO += 1
		else:
			ONEINV += ZERO
			ONE += 1
	return (ZEROINV, ONEINV)
ANS = []
SCORE = 0
for i in range(31, -1, -1):
	zs = 0
	os = 0
	NA = []
	for X in A:
		Y = []
		Z = []
		B = []
		for x in X:
			if x & 1 << i == 0:
				B.append(0)
				Y.append(x)
			else:
				B.append(1)
				Z.append(x)
		if Y != []:
			NA.append(Y)
		if Z != []:
			NA.append(Z)
		(z, o) = calc(B)
		zs += z
		os += o
	if zs <= os:
		ANS.append(0)
		SCORE += zs
	else:
		ANS.append(1)
		SCORE += os
	A = NA
print(SCORE, int(''.join(map(str, ANS)), 2))


n = int(input())
a = list(map(int, input().split()))
m = max(a)
b = 0
while 1 << b < m:
	b += 1
now = [a]
x = 0
inv = 0
for i in reversed(range(b)):
	nxt = []
	zrs = ons = 0
	for arr in now:
		zeroes = []
		ones = []
		zr = 0
		on = 0
		for j in arr:
			if 1 << i & j != 0:
				on += len(zeroes)
				ones.append(j)
			else:
				zr += len(ones)
				zeroes.append(j)
		if len(zeroes) > 0:
			nxt.append(zeroes)
		if len(ones) > 0:
			nxt.append(ones)
		zrs += zr
		ons += on
	inv += min(zrs, ons)
	if ons < zrs:
		x += 1 << i
	now = nxt.copy()
print(inv, x)


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.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(io.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()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
N = int(input())
A = list(map(int, input().split()))
ans_count = 0
ans_x = 0
C = [A[:]]
for b in range(31, 0, -1):
	C_new = []
	if b >= 15:
		D = [[] for _ in range(1 << 32 - b)]
		for a in A:
			D[a >> b].append(a >> b - 1 & 1)
	else:
		D = {}
		for a in A:
			if a >> b not in D:
				D[a >> b] = [a >> b - 1 & 1]
			else:
				D[a >> b].append(a >> b - 1 & 1)
	count_inv_0 = count_inv_1 = 0
	for v in D.values() if b < 15 else D:
		if len(v) <= 1:
			continue
		cnt_1 = 0
		cnt_0 = 0
		cnt_inv_0 = 0
		cnt_inv_1 = 0
		for zero_one in v:
			if zero_one:
				cnt_1 += 1
				cnt_inv_1 += cnt_0
			else:
				cnt_0 += 1
				cnt_inv_0 += cnt_1
		count_inv_0 += cnt_inv_0
		count_inv_1 += cnt_inv_1
	if count_inv_0 <= count_inv_1:
		ans_count += count_inv_0
	else:
		ans_count += count_inv_1
		ans_x |= 1 << b - 1
print(ans_count, ans_x)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = list(map(int, input().split()))
	workingList = [a]
	ans = 0
	totalInvCount = 0
	for i in range(29, -1, -1):
		newWorkingList = []
		invCountStay = 0
		invCountMove = 0
		for curList in workingList:
			listZero = []
			listOne = []
			for elem in curList:
				if elem & 1 << i:
					listOne.append(elem)
					invCountMove += len(listZero)
				else:
					listZero.append(elem)
					invCountStay += len(listOne)
			if listZero:
				newWorkingList.append(listZero)
			if listOne:
				newWorkingList.append(listOne)
		if invCountMove < invCountStay:
			ans |= 1 << i
			totalInvCount += invCountMove
		else:
			totalInvCount += invCountStay
		workingList = newWorkingList
	print(str(totalInvCount) + ' ' + str(ans))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
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 TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 30, 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 + 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 binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if a.get_at(m)[0] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)

def minSwaps(arr):
	n = len(arr)
	arrpos = [*enumerate(arr)]
	arrpos.sort(key=lambda it: it[1])
	vis = {k: False for k in range(n)}
	ans = 0
	for i in range(n):
		if vis[i] or arrpos[i][0] == i:
			continue
		cycle_size = 0
		j = i
		while not vis[j]:
			vis[j] = True
			j = arrpos[j][0]
			cycle_size += 1
		if cycle_size > 0:
			ans += cycle_size - 1
	return ans

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
n = int(input())
l = list(map(int, input().split()))
lis = [l]
x = 0
tot = 0
for i in range(29, -1, -1):
	w = 2 ** i
	cur = []
	inv0 = 0
	inv1 = 0
	for j in lis:
		zero = []
		ones = []
		for k in j:
			if k & w == 0:
				inv0 += len(ones)
				zero.append(k)
			else:
				inv1 += len(zero)
				ones.append(k)
		if zero != []:
			cur.append(zero)
		if ones != []:
			cur.append(ones)
	if inv1 >= inv0:
		x += 0
		tot += inv0
	else:
		x += w
		tot += inv1
	lis = cur
print(tot, x)


n = input()
a = [list(map(int, input().split()))]
ans = 0
x = 0
for w in range(31, -1, -1):
	w = 1 << w
	b = []
	sum_inv_one = 0
	sum_inv_zero = 0
	for aa in a:
		one = 0
		zero = 0
		inv_one = 0
		inv_zero = 0
		a1 = []
		a0 = []
		for (i, ai) in enumerate(aa):
			if ai & w:
				one += 1
				inv_one += zero
				a1.append(ai)
			else:
				zero += 1
				inv_zero += one
				a0.append(ai)
		sum_inv_one += inv_one
		sum_inv_zero += inv_zero
		if a1:
			b.append(a1)
		if a0:
			b.append(a0)
	if sum_inv_zero > sum_inv_one:
		ans += sum_inv_one
		x |= w
	else:
		ans += sum_inv_zero
	a = b
print(ans, x)


import sys
readline = sys.stdin.readline
from collections import Counter
N = int(readline())
A = list(map(int, readline().split()))
B = 31
table = [0] * N
ans = 0
rev = 0
for b in range(B - 1, -1, -1):
	one = Counter()
	zero = Counter()
	cnt = 0
	cntr = 0
	for i in range(N):
		a = A[i] >> b & 1
		if a:
			one[table[i]] += 1
			cntr += zero[table[i]]
			table[i] += 1 << b
		else:
			zero[table[i]] += 1
			cnt += one[table[i]]
	if cntr < cnt:
		rev += cntr
		ans |= 1 << b
	else:
		rev += cnt
print(rev, ans)


MB = 29

def ibit(n, k):
	return n >> k & 1

def count(m, k):
	res0 = 0
	on = 0
	res1 = 0
	zer = 0
	prr = None
	for ell in m:
		el = ibit(ell, k)
		ot = ell >> k + 1
		if ot != prr:
			prr = ot
			on = 0
			zer = 0
		if el == 1:
			res1 += zer
			on += 1
		else:
			res0 += on
			zer += 1
	return [res0, res1]

def diff(m, k):
	res0 = []
	res1 = []
	res = []
	prr = None
	for el in m:
		ot = el >> k + 1
		if ot != prr:
			prr = ot
			res += res0 + res1
			res0 = []
			res1 = []
		if ibit(el, k):
			res1.append(el)
		else:
			res0.append(el)
	res += res0 + res1
	return res
n = int(input())
a = list(map(int, input().split()))
ll = a
bt = MB
rs = 0
inv = 0
while bt >= 0:
	ll = diff(ll, bt + 1)
	(r0, r1) = count(ll, bt)
	if r0 > r1:
		rs += 1 << bt
		inv += r1
	else:
		inv += r0
	bt -= 1
print(inv, rs)


import sys, io, os
z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(z())
a = [*map(int, z().split())]
v = 30
t = x = 0
while v:
	u = d = 0
	r = {}
	w = 1 << v - 1
	for i in a:
		p = i >> v
		b = i & w
		if b:
			r[2 * p + 1] = 1 + r.get(2 * p + 1, 0)
		else:
			d += r.get(2 * p + 1, 0)
		r[2 * p] = 1 + r.get(2 * p, 0)
	for p in r:
		if p % 2:
			(rp, cp) = (r.get(p, 0), r.get(p - 1, 0))
			u += cp * (cp - 1) // 2 - rp * (rp - 1) // 2 - (cp - rp) * (cp - rp - 1) // 2
	if d > u - d:
		x += w
		d = u - d
	t += d
	v -= 1
print(t, x)


n = int(input())
A = list(map(int, input().split()))
que = [A, 1]
ans = 0
ans1 = 0
p = 29
for p in range(29, -1, -1):
	X1 = 0
	Y1 = 0
	r = 2 ** p
	q1 = que.pop()
	q2 = 0
	que1 = []
	for i in range(q1):
		x = 0
		y = 0
		X = 0
		Y = 0
		A1 = []
		A2 = []
		a = que.pop()
		for j in a:
			if j < r:
				X += x
				y += 1
				A1 += [j]
			else:
				x += 1
				Y += y
				A2 += [j - r]
		if A1:
			q2 += 1
			que1 += [A1]
		if A2:
			q2 += 1
			que1 += [A2]
		X1 += X
		Y1 += Y
	if X1 > Y1:
		ans += r
	ans1 += min(X1, Y1)
	que += que1
	que += [q2]
print(ans1, ans)


import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
data_0 = [0 for i in range(30)]
data_1 = [0 for i in range(30)]

def solve(b, A):
	if not A:
		return 0
	N = len(A)
	res_0 = []
	res_1 = []
	A_bit = [0 for i in range(N)]
	for i in range(N):
		if A[i] >> b:
			A_bit[i] = 1
			res_1.append(A[i] ^ 1 << b)
		else:
			A_bit[i] = 0
			res_0.append(A[i])
	cnt_0 = 0
	cnt_1 = 0
	for i in range(N):
		if A_bit[i] == 1:
			data_1[b] += cnt_0
			cnt_1 += 1
		else:
			data_0[b] += cnt_1
			cnt_0 += 1
	if b != 0:
		solve(b - 1, res_0)
		solve(b - 1, res_1)
solve(29, a)
x = 0
inv = 0
for i in range(30):
	if data_0[i] <= data_1[i]:
		inv += data_0[i]
	else:
		inv += data_1[i]
		x += 1 << i
print(inv, x)