Toy Sum

CodeForces - 405D

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 x1x2, ..., 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 y1y2, ..., ym (1 ≤ yi ≤ 106), such that the required equality holds. The sets X and Yshould 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.

Examples

Input
3
1 4 5
Output
2
999993 1000000
Input
1
1
Output
1
1000000 sol:显然可以从两边往中间做,如果一边有就弄另一边,两边都有就弄一对新的即可
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=; bool f=; char ch=' ';
while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
while(isdigit(ch)) {s=(s<<)+(s<<)+(ch^); ch=getchar();}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<) {putchar('-'); x=-x;}
if(x<) {putchar(x+''); return;}
write(x/); putchar((x%)+'');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int S=,n,m=,a[N],b[N];
bool Bo[N];
int main()
{
int i;
R(n);
for(i=;i<=n;i++) Bo[a[i]=read()]=;
int up=S>>,cnt=;
for(i=;i<=up;i++)
{
int o1=i,o2=S-i+;
if((Bo[o1])&&(!Bo[o2]))
{
b[++m]=o2; Bo[o2]=;
}
else if((!Bo[o1])&&(Bo[o2]))
{
b[++m]=o1; Bo[o1]=;
}
else if(Bo[o1]&&Bo[o2]) cnt++;
}
for(i=;i<=up&&cnt;i++)
{
if(!Bo[i])
{
b[++m]=i; b[++m]=S-i+; cnt--;
}
}
sort(b+,b+m+);
Wl(m);
for(i=;i<=m;i++) W(b[i]);
return ;
}
 

codeforces405D的更多相关文章

随机推荐

  1. shell习题第11题:输入数字执行命令

    [题目要求] 写一个脚本实现如下功能:输入一个数字,然后运行对应的一个命令 显示命令如下: *cmd menu* 1--data  2--ls 3--who 4--pwd 输入1时,会运行data [ ...

  2. 基于白名单的Payload

    利用 Msiexec 命令DLL反弹 Msiexec是Windows Installer的一部分.用于安装Windows Installer安装包(MSI),一般在运行Microsoft Update ...

  3. linux——环境变量

    环境变量 基本概念: 一般是指在操作系统中用来指定操纵系统运行环境的一些参数 当我们用动态库链接成功的时候,其实就是相关的环境变量帮助编译器进行查找. 环境变量通常具有某种特殊用途,还有在系统当中通常 ...

  4. 检测对象类型的两种方式,constructor属性和instanceof

    //本例是为了记录检测对象类型的两种方式,即constructor属性和instanceof操作符.详见<高三>P145        function Person(name, age, ...

  5. Js setTimeout 用法

    setTimeout( ) 是属于 window 的 method, 但我们都是略去 window 这顶层物件名称, 这是用来设定一个时间, 时间到了, 就会执行一个指定的 method. setTi ...

  6. loj 2292「THUSC 2016」成绩单

    loj 看着就很区间dp,所以考虑求\(f_{i,j}\)表示区间\([i,j]\)的答案.注意到贡献答案的方式是每次选一个连续段,拿走后剩下的段拼起来继续段,所以转移就考虑从最后一次选的方法转移过来 ...

  7. DICOM文件修改方法

    /// <summary> /// 读取dicom文件 /// </summary> /// <param name="srcdirectory"&g ...

  8. 【Struts2】文件上传与下载

    一.上传 1.1 Struts2实现步骤 浏览器端 服务器端 1.2 关于Struts2中文件上传细节: 1.3 示例 jsp文件 Action类 struts.xml文件配置 二.下载 2.1 文件 ...

  9. shell脚本编写之Hello World

    Linux下编写第一个Shell脚本 //创建一个.sh文件 vi demo1.sh //按i进入编辑模式 echo "Hello World !" //按esc→shift+:→ ...

  10. QTP10破解步骤(亲试有效)

    QTP10破解步骤: 1.安装qtp,一路默认下来(一定要默认安装目录),一直到要求输入License的界面 2.拷贝mgn-mqt82.exe到C:\Program Files\Mercury In ...