CodeForces - 988D

D. Points and Powers of Two

time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n distinct points on a coordinate line, the coordinate of i-th point equals to xi. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.

In other words, you have to choose the maximum possible number of points xi1,xi2,,xim such that for each pair xij, xik it is true that |xijxik|=2d where d is some non-negative integer number (not necessarily the same for each pair of points).

Input

The first line contains one integer n (1n2105) — the number of points.

The second line contains n pairwise distinct integers x1,x2,,xn (109xi109) — the coordinates of points.

Output

In the first line print m — the maximum possible number of points in a subset that satisfies the conditions described above.

In the second line print m integers — the coordinates of points in the subset you have chosen.

If there are multiple answers, print any of them.

Examples

Input

6
3 5 4 7 10 12

Output

3
7 3 5

Input

5
-1 2 5 8 11

Output

1
8

Note

In the first example the answer is [7,3,5]. Note, that |73|=4=22, |75|=2=21 and |35|=2=21. You can't find a subset having more points satisfying the required property.

 

思路:列举发现选出的数字集合只能是三个而且满足:

a    a+2^n    a+2^(n+1)

  

ac代码:

// #include<bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue
#include <map>
#include <set> //multiset set<int,greater<int>>大到小
#include <vector> // vector<int>().swap(v);清空释放内存
#include <stack>
#include <cmath> // auto &Name : STLName  Name.
#include <utility>
#include <sstream>
#include <string> //__builtin_popcount(ans);//获取某个数二进制位1的个数
using namespace std;
#define rep(i,a,n) 	for(int i=a;i<=n;i++)
#define per(i,a,n) 	for(int i=n;i>=a;i--)
#define read(x) 	scanf("%d",&x)
#define Read(x,y) 	scanf("%d%d",&x,&y)
#define write(x) 	printf("%d\n",x)
#define INF 0x3f3f3f3f
#define MAX_N 200005
typedef long long ll;

ll a[MAX_N];
set<ll> s;

int main()
{	
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		s.insert(a[i]);
	}
	for(int i=0;i<n;i++){
		for(ll j=1;j<2e9;j<<=1){
			if(s.count(a[i]+j)&&s.count(a[i]+j*2))
			{
				printf("3\n");
				printf("%lld %lld %lld\n",a[i],a[i]+j,a[i]+j*2);
				return 0;
			}
		}
	}
	for(int i=0; i<n; i++)
    {
        for(ll j=1; j<=2e9; j<<=1)
            if(s.count(a[i]+j))
            {
                printf("3\n");
                printf("%lld %lld\n",a[i],a[i]+j);
				return 0;
            }
    }
    printf("1\n");
    printf("%lld\n",a[0]);

	return 0;
}

  

posted @ 2020-04-25 19:39  ジャスミン  阅读(149)  评论(0编辑  收藏  举报