Vasily the Bear and Sequence

题意翻译

Vasily the bear有一些数$a_1,a_2,...,a_n$,它想要写下几个数字,使写下的数字的“美感”最大。 对于数字$b_1,b_2,...,b_k$,他们的“美感”是一个尽可能大的非负整数$v$,使得$b_1$&$b_2$&...&$b_k$的结果能够被$2^v$整除(&指“按位与”运算),如果不存在这样一个数,则这组数的“美感”为-1。 请告诉它写下哪些数字能使“美感”最大,如果有多组方案,你需要选择数字尽可能多的。 ## 输入 第一行为一个整数$n$,表示数字个数。 第二行为$a_1,a_2,...,a_n$。 ## 输出 第一行输出一个整数$k$,表示Vasily the bear需要写下多少数字。 第二行为以空格分离的$k$个整数$b_1,b_2,...,b_k$,输出顺序不受限制,但不能有重复的数字,如果存在多组方案使“美感”最大,需要选择数字尽可能多的,如果仍有多组方案,可输出任意一组。

题目描述

Vasily the bear has got a sequence of positive integers $ a_{1},a_{2},...,a_{n} $ . Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers $ b_{1},b_{2},...,b_{k} $ is such maximum non-negative integer $ v $ , that number $ b_{1} $ $ and $ $ b_{2} $ $ and $ $ ... $ $ and $ $ b_{k} $ is divisible by number $ 2^{v} $ without a remainder. If such number $ v $ doesn't exist (that is, for any non-negative integer $ v $ , number $ b_{1} $ $ and $ $ b_{2} $ $ and $ $ ... $ $ and $ $ b_{k} $ is divisible by $ 2^{v} $ without a remainder), the beauty of the written out numbers equals -1. Tell the bear which numbers he should write out so that the beauty of the written out numbers is maximum. If there are multiple ways to write out the numbers, you need to choose the one where the bear writes out as many numbers as possible. Here expression $ x $ $ and $ $ y $ means applying the bitwise AND operation to numbers $ x $ and $ y $ . In programming languages C++ and Java this operation is represented by "&", in Pascal — by "and".

输入输出格式

输入格式


The first line contains integer $ n $ ( $ 1<=n<=10^{5} $ ). The second line contains $ n $ space-separated integers $ a_{1},a_{2},...,a_{n} $ $ (1<=a_{1}&lt;a_{2}&lt;...&lt;a_{n}<=10^{9}) $ .

输出格式


In the first line print a single integer $ k $ $ (k&gt;0) $ , showing how many numbers to write out. In the second line print $ k $ integers $ b_{1},b_{2},...,b_{k} $ — the numbers to write out. You are allowed to print numbers $ b_{1},b_{2},...,b_{k} $ in any order, but all of them must be distinct. If there are multiple ways to write out the numbers, choose the one with the maximum number of numbers to write out. If there still are multiple ways, you are allowed to print any of them.

输入输出样例

输入样例 #1

5
1 2 3 4 5

输出样例 #1

2
4 5

输入样例 #2

3
1 2 4

输出样例 #2

1
4