CF336C.Vasily the Bear and Sequence

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasily the bear has got a sequence of positive integers a1,a2,...,ana_{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 b1,b2,...,bkb_{1},b_{2},...,b_{k} is such maximum non-negative integer vv , that number b1b_{1} andand b2b_{2} andand ...... andand bkb_{k} is divisible by number 2v2^{v} without a remainder. If such number vv doesn't exist (that is, for any non-negative integer vv , number b1b_{1} andand b2b_{2} andand ...... andand bkb_{k} is divisible by 2v2^{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 xx andand yy means applying the bitwise AND operation to numbers xx and yy . In programming languages C++ and Java this operation is represented by "&", in Pascal — by "and".

输入格式

The first line contains integer nn ( 1<=n<=1051<=n<=10^{5} ). The second line contains nn space-separated integers a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=a_{1}<a_{2}<...<a_{n}<=10^{9}) .

输出格式

In the first line print a single integer kk (k>0) , showing how many numbers to write out. In the second line print kk integers b1,b2,...,bkb_{1},b_{2},...,b_{k} — the numbers to write out. You are allowed to print numbers b1,b2,...,bkb_{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
    
首页