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;
} }

Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)C. Laboratory Work的更多相关文章

  1. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)B. World Cup

    The last stage of Football World Cup is played using the play-off system. There are n teams left in ...

  2. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)

    A.B都是暴力搞一搞. A: #include<bits/stdc++.h> #define fi first #define se second #define mk make_pair ...

  3. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)D. Peculiar apple-tree

    In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity ...

  4. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)A. Friends Meeting

    Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the ...

  5. Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】

    C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  6. Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861B Which floor?【枚举,暴力】

    B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  7. Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861A k-rounding【暴力】

    A. k-rounding time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  8. Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)

    A. Technogoblet of Fire 题意:n个人分别属于m个不同的学校 每个学校的最强者能够选中 黑客要使 k个他选中的可以稳被选 所以就为这k个人伪造学校 问最小需要伪造多少个 思路:记 ...

  9. Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)

    A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...

随机推荐

  1. 推荐一个同步Mysql数据到Elasticsearch的工具

    把Mysql的数据同步到Elasticsearch是个很常见的需求,但在Github里找到的同步工具用起来或多或少都有些别扭. 例如:某记录内容为"aaa|bbb|ccc",将其按 ...

  2. 我要带徒弟学JAVA架构 ( 写架构,非用架构 )

    80元,当然我不觉得我带的徒弟比花了1万多在培训班学习的学生差,你努力了.会比他们出色的多.等你学有所成.相同能够成为jeecg核心成员之中的一个.一起构建Java学习平台.你也能够成为非常好的师傅. ...

  3. 公司须要内部的地图服务,准备自己去开发可是成本太高,如今有没有专门为企业提供GIS地图开发的产品呀?大概价格多少?

    公司须要内部的地图服务,准备自己去开发可是成本太高,如今有没有专门为企业提供GIS地图开发的产品呀?大概价格多少?

  4. 【BZOJ1029】【JSOI2007】【建筑抢修】【贪心+堆】

    Description 小刚在玩JSOI提供的一个称之为"建筑抢修"的电脑游戏:经过了一场激烈的战斗,T部落消灭了全部z部落的入侵者.可是T部落的基地里已经有N个建筑设施受到了严重 ...

  5. Qt5.8 提供 Apple tvOS,watchOS的技术预览版

    New Platforms Apple tvOS (technology preview) Apple watchOS (technology preview) https://wiki.qt.io/ ...

  6. QMap的性能,只要超过10个元素,就被QHash彻底拉开差距

    QMap vs. QHash: A small benchmark While working on my Qt developer days 2012 presentation (QtCore in ...

  7. JS垃圾回收——和其他语言一样,JavaScript 的 GC 策略也无法避免一个问题:GC 时,停止响应其他操作,这是为了安全考虑

    JavaScript 内存管理 & 垃圾回收机制 标记清除 js 中最常用的垃圾回收方式就是标记清除.当变量进入环境时,例如,在函数中声明一个变量,就将这个而变量标记为“进入环境”.从逻辑上讲 ...

  8. 南海区行政审批管理系统接口规范v0.3(规划) 5.投资项目联合审批系统API 5.1.【uploadFile】证件文书附件上传

  9. 关于java1.8中LocalDateTime实现日期,字符串互转小坑。

    今天无聊,来看了下1.8的时间类型LocalDateTime,当想把字符串转成LocalDateTime的时候报错!! java.time.format.DateTimeParseException: ...

  10. Django之缓存机制

    1.1 缓存介绍 1.缓存的简介 在动态网站中,用户所有的请求,服务器都会去数据库中进行相应的增,删,查,改,渲染模板,执行业务逻辑,最后生成用户看到的页面. 当一个网站的用户访问量很大的时候,每一次 ...