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, bi=ai⊕x (⊕ denotes the operation bitwise XOR).
An inversion in the b array is a pair of integers i and j such that 1≤i<j≤n and bi>bj.
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≤n≤3⋅105) — the number of elements in a.
Second line contains n space-separated integers a1,a2,⋯,an (0≤ai≤109), where ai 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
1 2
4 0 1 3 2
output
1
1 0
input
1 2
9 10 7 9 10 7 5 5 3 5
output
1
4 14
input
1 2
3 8 10 3
output
1
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.
Translation
给出序列 a1,a2,⋯,an,找出 x,使得序列所有元素都与 x 进行异或运算后,得到的逆序对个数最少。当有多个满足条件的 x 存在时,输出最小的。
Idea
将每个数的二进制形式从高位到低位存在字典树中。我们考虑字典树的其中一棵子树 TSub,由于两个数的大小取决于它们二进制位上第一个不同的高位;因此,TSub 的左子树里的所有数字都小于右子树中的数。只要枚举左子树里有多少数字下标比右子树的下标大,就能得到 TSub 中的逆序对个数。
接下来考虑贪心构造 x 的过程。我们从低位到高位构造 x,每次考虑 x 第 i 位取 0 或 1 时产生的效果。假设当且考察到 x 的第 i 位,若 x 的第 i 位取 0,就表明保持所有数字的第 i 位不变;若 x 取 1,表面要取反所有数字的第 i 位,即对换第 i 层节点的左右儿子。
因此,我们需要开两个数组分别记录数字第 i 位保持原样和取反产生的逆序对个数。自底向上遍历字典树节点并枚举其左右儿子包含数字的下标即可。