Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.

Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.

Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., ynin her work, that the following conditions are met:

  • the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
  • all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
  • the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.

Help Anya to write such a set of measurements that the conditions above are met.

Input

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.

The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.

Output

In the first line print the minimum possible number of equal measurements.

In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.

If there are multiple answers, print any of them.

Examples
input
6
-1 1 1 0 0 -1
output
2
0 0 0 0 0 0
input
3
100 100 101
output
3
101 100 100
input
7
-10 -9 -10 -8 -10 -9 -9
output
5
-10 -10 -9 -9 -9 -9 -9 题意:给出a串,保证每个数字是整数且所有数间差值最大不超过2,输出b串使其:1.两串总和相等 2.b串数取值范围和a串数相同 3.两串相同数尽量少
找规律题,分类讨论
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
#define eps 0.00000001
#define pn printf("\n")
using namespace std;
typedef long long ll; const int maxn = 1e5+;
int n, a[maxn];
int MIN = INF, MAX = -INF, tot = ;
int k = , fl = ;
vector <int> vi;
map <int,int> mp; int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",a+i);
mp[a[i]] ++;
tot += a[i];
MIN = min(MIN, a[i]);
MAX = max(MAX, a[i]);
} if(MAX - MIN <= )
{
printf("%d\n", n);
for(int i=;i<n;i++)
{
if(i) printf(" ");
printf("%d", a[i]);
}pn;
}
else
{
if(!mp.count(MAX-))
{
int mt, res;
if(mp[MIN] < mp[MAX])
{
mt = mp[MIN];
res = MAX;
}
else
{
mt = mp[MAX];
res = MIN;
}
int mid = * mt, fl = ;
printf("%d\n" ,n - mid);
for(int i=;i<mid;i++)
{
if(!fl) fl = ;
else printf(" ");
printf("%d", MIN +);
}
for(int i=mid;i<n;i++)
{
if(!fl) fl = ;
else printf(" ");
printf("%d", res);
}
}
else // 1 2 2 2 2 3
{
if(min(mp[MIN],mp[MAX])* > mp[MIN+]/*)
{
int mt, res;
if(mp[MIN] < mp[MAX])
{
mt = mp[MIN];
res = MAX;
}
else
{
mt = mp[MAX];
res = MIN;
}
int mid = * mt + mp[MIN+], fl = ;
printf("%d\n" ,n - * mt);
for(int i=;i<mid;i++)
{
if(!fl) fl = ;
else printf(" ");
printf("%d", MIN +);
}
for(int i=mid;i<n;i++)
{
if(!fl) fl = ;
else printf(" ");
printf("%d", res);
} }
else
{
int mt = mp[MIN+]/;
int ans = (mp[MIN+]&) + mp[MIN] + mp[MAX];
printf("%d\n",ans);
int fl = , cn = mp[MIN] + mt, cx = mp[MAX] + mt;
if(mp[MIN+]&)
{
printf("%d",MIN + ); fl = ;
}
for(int i=;i<cn;i++)
{
if(!fl) fl = ;
else printf(" ");
printf("%d", MIN);
}
for(int i=;i<cx;i++)
{
if(!fl) fl = ;
else printf(" ");
printf("%d", MAX);
}
}
}
pn;
} }

最新文章

  1. Delphi容器类之---Tlist,TStringlist,THashedStringlist的效率比较
  2. java selenium后报错Element not found in the cache元素定位要重新赋值之前的定义
  3. java Decompiler的bug
  4. Struts2中的 配置文件
  5. 安装VVDocumenter-Xcode-master (Xcode 7.1)的过程
  6. Spring源码入门——AnnotationBeanNameGenerator解析
  7. 常用mysql命令(经常更新)
  8. ip,子网掩码,网关,DNS
  9. Scala数组操作实战详解
  10. HDU 3726 Graph and Queries 平衡树+前向星+并查集+离线操作+逆向思维 数据结构大综合题
  11. ELK-初识Elasticsearch
  12. CentOS 6.2下搭建Web服务器
  13. 关于iOS常用的26中公共方法,可copy的代码
  14. Spring事务操作介绍
  15. nodejs-- vuex中mapActions
  16. Java之基础学习(数据类型、运算符、分支语句和循环语句)
  17. 【Redis】安装 Redis接口时异常 ,系统ruby版本过低
  18. 隐藏和显示服务器端控件以及Html控件
  19. go fmt格式化----“占位符”
  20. centos上yum安装异常处理

热门文章

  1. POJ 1021 人品题
  2. CSDN日报20170423 ——《私活,永远挽救不了自己屌丝的人生!》
  3. ABCDE
  4. Node.js具体解析
  5. GCD&amp;amp;&amp;amp;LCM的一些经典问题
  6. org.openqa.selenium.NoSuchElementException:
  7. objective-c 中数据类型之四 字典(NSDictionary)
  8. 36岁IT老人再次随笔——程序员的门槛其实并不高,但却是一个易学难精的行当——IT的快车很快,我常看到不少人摔落下去,但又有不少身手敏捷的人跳了上来 good
  9. oc23--变量修饰符
  10. EOJ 1114 素数环