XOR Sequence

Choose B in [0, N-1] to XOR every element of A, then find the maximum possible count of index pairs i < j with C_i < C_j.

Hard8Divide and conquerBit manipulationSortingRecursionNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given an integer NN and a sequence AA of length MM. NN is a power of two, and every element of AA is an integer between 00 and N1N-1.

You may pick one integer BB between 00 and N1N-1 and build a new sequence CC. For every ii, set Ci=AiBC_i = A_i \oplus B, where \oplus is bitwise exclusive or (XOR).

Then count the pairs (i,j)(i, j) with i<ji < j and Ci<CjC_i < C_j in CC.

Write a program that finds the largest possible number of such pairs over every choice of BB.

Input

The first line contains NN. (2N2302 \le N \le 2^{30}, NN is a power of two)

The second line contains the size MM of the sequence AA. (2M1310722 \le M \le 131072)

The third line contains A1,A2,,AMA_1, A_2, \dots, A_M separated by spaces. (0AiN10 \le A_i \le N-1)

Output

Print the largest possible number of pairs (i,j)(i, j) with i<ji < j and Ci<CjC_i < C_j.

Hint

For N=4N = 4 and A=[3,2,1,0,3,2]A = [3, 2, 1, 0, 3, 2], choosing B=3B = 3 gives C=[0,1,2,3,0,1]C = [0, 1, 2, 3, 0, 1]. That sequence has 8 pairs with i<ji < j and Ci<CjC_i < C_j.