#P1416C. XOR Inverse

    ID: 2938 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>bitmasksdata structuresdivide and conquerdpgreedymathsortingsstringstrees*2000

XOR Inverse

Description

You are given an array aa consisting of nn non-negative integers. You have to choose a non-negative integer xx and form a new array bb of size nn according to the following rule: for all ii from 11 to nn, bi=aixb_i = a_i \oplus x (\oplus denotes the operation bitwise XOR).

An inversion in the bb array is a pair of integers ii and jj such that 1i<jn1 \le i < j \le n and bi>bjb_i > b_j.

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

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

Second line contains nn space-separated integers a1a_1, a2a_2, ..., ana_n (0ai1090 \le a_i \le 10^9), where aia_i is the ii-th element of aa.

Output two integers: the minimum possible number of inversions in bb, and the minimum possible value of xx, which achieves those number of inversions.

Input

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

Second line contains nn space-separated integers a1a_1, a2a_2, ..., ana_n (0ai1090 \le a_i \le 10^9), where aia_i is the ii-th element of aa.

Output

Output two integers: the minimum possible number of inversions in bb, and the minimum possible value of xx, which achieves those number of inversions.

Sample Input 1

4
0 1 3 2

Sample Output 1

1 0

Sample Input 2

9
10 7 9 10 7 5 5 3 5

Sample Output 2

4 14

Sample Input 3

3
8 10 3

Sample Output 3

0 8

Note

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

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

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

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