406B
Solution
#include <cstdio>
using namespace std;
const int MAX_S = int(1e6) + 20;
const int s = int(1e6);
bool f[MAX_S];
int ans[MAX_S];
int ans_num;
int add_num;
bool first = true;
int n;
void output(int a)
{
if (first)
{
first = false;
}else
{
putchar(' ');
}
printf("%d", a);
}
int main()
{
//input
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
int a;
scanf("%d", &a);
f[a] = true;
}
//work
ans_num = 0;
add_num = 0;
for (int i = 1; i <= (s + 1) / 2; i++)
{
int a = s - i + 1;
if (f[i] && f[a])
{
add_num++;
}else if (f[i] || f[a])
{
if (f[i])
{
ans[ans_num++] = a;
}else
{
ans[ans_num++] = i;
}
}
}
//output
printf("%d\n", ans_num + add_num * 2);
for (int i = 1; i <= (s + 1) / 2 && add_num; i++)
{
int a = s - i + 1;
if (!f[i] && !f[a])
{
output(i);
output(a);
add_num--;
}
}
for (int i = 0; i < ans_num; i++)
{
output(ans[i]);
}
return 0;
}