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. Python实现八大排序(基数排序、归并排序、堆排序、简单选择排序、直接插入排序、希尔排序、快速排序、冒泡排序)

    目录 八大排序 基数排序 归并排序 堆排序 简单选择排序 直接插入排序 希尔排序 快速排序 冒泡排序 时间测试 八大排序 大概了解了一下八大排序,发现排序方法的难易程度相差很多,相应的,他们计算同一列 ...

  2. 用函数来编写实现strlen()函数功能

    strlen( )函数: 测试字符串实际长度的函数,它的返回值是字符串中字符的个数(不包含’\0’) //strlen( )函数:测试字符串实际长度的函数,它的返回值是字符串中字符的个数(不包含’\0 ...

  3. django API返回中文乱码

    renturn HttpResponse(json.dumps(data,ensure_ascii=False))

  4. outlook邮箱备份

  5. luogu1313计算系数题解--二项式定理

    题目链接 https://www.luogu.org/problemnew/show/P1313 分析 二项式定理 \((a+b)^n=\sum_{k=0}^{n}{C^k_n a^k b^{n-k} ...

  6. Android opengl 笔记

    1. varying vec2 vTextureCoord; 不能用in vec2 ,varying 表示在vs 和 fs中都可见. 2. android 里面 0 和1 都要打小数点 比如0.0 1 ...

  7. 安装laravel-ide-helper

    前言 使用laravel作为PHP开发框架的朋友都知道,laravel提供的门面操作都对于PHPStorm的代码提示和方法跳转都不是很友好.然而没有关系,今天介绍一个组件帮助到我们.就是!就是!就是! ...

  8. JS笛卡尔积算法与多重数组笛卡尔积实现方法示例

    js 笛卡尔积算法的实现代码,据对象或者数组生成笛卡尔积,并介绍了一个javascript多重数组笛卡尔积的例子,以及java实现笛卡尔积的算法与实例代码. 一.javascript笛卡尔积算法代码 ...

  9. shell script 编程入门

    参考 <linux shell scripting cookbook> 控制台输出 结构化输出 #!/bin/bash #Filename: printf.sh printf " ...

  10. 如何准备Java的高级技术面试

    一. 换位思考下,如果你面试官,你会怎么做 只能通过简历和面试来衡量,别无他法.如果某位大牛确认能力很行,但面试时无法充分地自证能力,那对不起了,过不了,现实就这样. 如果面试官由于能力不行,招进来一 ...