100 atcoder#ABC117D. [ABC117D] XXOR

[ABC117D] XXOR

Score : 400400 points

Problem Statement

You are given NN non-negative integers A1,A2,...,ANA_1, A_2, ..., A_N and another non-negative integer KK.

For a integer XX between 00 and KK (inclusive), let f(X)=(Xf(X) = (X XOR A1)A_1) ++ (X(X XOR A2)A_2) ++ ...... ++ (X(X XOR AN)A_N).

Here, for non-negative integers aa and bb, aa XOR bb denotes the bitwise exclusive OR of aa and bb.

Find the maximum value of ff.

What is XOR?

The bitwise exclusive OR of aa and bb, XX, is defined as follows:

  • When XX is written in base two, the digit in the 2k2^k's place (k0k \geq 0) is 11 if, when written in base two, exactly one of AA and BB has 11 in the 2k2^k's place, and 00 otherwise.

For example, 33 XOR 5=65 = 6. (When written in base two: 011011 XOR 101=110101 = 110.)

Constraints

  • All values in input are integers.
  • 1N1051 \leq N \leq 10^5
  • 0K10120 \leq K \leq 10^{12}
  • 0Ai10120 \leq A_i \leq 10^{12}

Input

Input is given from Standard Input in the following format:

NN KK

A1A_1 A2A_2 ...... ANA_N

Output

Print the maximum value of ff.

3 7
1 6 3
14

The maximum value is: f(4)=(4f(4) = (4 XOR 1)+(41) + (4 XOR 6)+(46) + (4 XOR 3)=5+2+7=143) = 5 + 2 + 7 = 14.

4 9
7 4 0 3
46
1 0
1000000000000
1000000000000