printРабочее место участника


2037. Casino

Ограничения: время – 1000ms/2000ms, память – 256MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

In a lazy afternoon Gibibyte came to realize that, to make his future plans successful he needs a lot of money. To make some quick cash he decided to go to the casino to play a game. The rule of the game is the following:
1. The player is given `N` cards. Each card has a non-negative integer printed in it.
2. The player will choose `K` cards from the given cards.
3. The bitwise AND value of the chosen cards will be calculated and the player will be given the same amount of money (i.e. equal to the bitwise AND value of the chosen cards).
After getting `N` cards Gibibyte was in a fix as usual. He could not decide which of the cards to choose. So he called you to help him. Please tell him the maximum amount he can win from these set of cards. If you are confused about bitwise AND operation see the notes section below.
The first line of input will contain two integers `N` and `K` (`0\ <\ K\ <\ N\ ≤\ 10^5`). Then the following line will contain `N` non-negative integers `C_i` (`0\ ≤\ C_i\ <\ 2^31`) separated by space, denoting the numbers printed on each of the cards.
Print the maximum amount, that Gibibyte can win, on the first line of output and chosen cards on the second line (in any order).
A bitwise AND takes two binary representations of equal length and performs the logical AND operation on each pair of corresponding bits. The resulting bit of a position is 1 if the bit at that position of both numbers is 1; otherwise, that bit is 0.
For example:
        0101 (decimal 5)
    AND 0011 (decimal 3)
      = 0001 (decimal 1)

Sample Input

4 2
8 5 0 3

Sample Output

3 5