http://codeforces.com/contest/405/problem/D

Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.

There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them back only if Chris can pick such a non-empty subset Y from the remaining blocks, that the equality holds:

"Are you kidding me?", asks Chris.

For example, consider a case where s = 8 and Chris's teacher took the blocks with numbers 1, 4 and 5. One way for Chris to choose a set is to pick the blocks with numbers 3 and 6, see figure. Then the required sums would be equal: (1 - 1) + (4 - 1) + (5 - 1) = (8 - 3) + (8 - 6) = 7.

However, now Chris has exactly s = 106 blocks. Given the set X of blocks his teacher chooses, help Chris to find the required set Y!

Input

The first line of input contains a single integer n (1 ≤ n ≤ 5·105), the number of blocks in the set X. The next line contains n distinct space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 106), the numbers of the blocks in X.

Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

Output

In the first line of output print a single integer m (1 ≤ m ≤ 106 - n), the number of blocks in the set Y. In the next line output m distinct space-separated integers y1, y2, ..., ym (1 ≤ yi ≤ 106), such that the required equality holds. The sets X and Y should not intersect, i.e. xi ≠ yj for all ij (1 ≤ i ≤ n; 1 ≤ j ≤ m). It is guaranteed that at least one solution always exists. If there are multiple solutions, output any of them.

 

题意:在1~s中给定一个子集X,求一个子集Y,满足Σ(x-1)=Σ(s-y)。

思路:观察等式,x=1,y=s;x=2,s=s-2......

我们取s=1e6,1对应1e6,2对应1e6-1,3对应1e6-2......

覆盖思路就是:i或s+1-i在X覆盖其中一个时,Y取另一个,如果i和s+1-i都在X中,那么Y取另一对等距离的。

这个覆盖方法是一定可行的。

#include<bits/stdc++.h>
using namespace std;
#define maxn 1000000+1000
#define s 1000000

int n,need;
bool cover[maxn]; 
vector<int> available;

int main()
{
	//freopen("input.in","r",stdin);
	cin>>n;
	int x;
	for(int i=1;i<=n;i++)scanf("%d",&x),cover[x]=1;
	printf("%d\n",n);
	for(int i=1;i<=s/2;i++)
	{	
		if(!cover[i] && !cover[s+1-i])available.push_back(i);
		else if(cover[i]&&cover[s+1-i])need++;
		else if(cover[i])printf("%d ",s+1-i);
		else printf("%d ",i);
	}	
	for(int i=0;i<need;i++)printf("%d %d ",available[i],s+1-available[i]);
	return 0;
}