Problem description

Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all.

After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting.

Input

The first line contains a single integer n (1 ≤ n ≤ 105), which represents how many numbers the array has. The next line contains n space-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive.

Output

Print n space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.

Examples

Input

5
1 2 3 4 5

Output

1 1 2 3 4

Input

5
2 3 4 5 6

Output

1 2 3 4 5

Input

3
2 2 2

Output

1 2 2
解题思路:题目的意思就是将n个数中的最大值替换成最小值(1-10^9),要求不能替换成本身并且必须用一个(相对)最小值替换此最大值。因此,如果最大值为1,则替换的最小值为2;如果最大值大于1,则替换的最小值为1,水过!
AC代码:
 #include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int n,a[maxn];
int main(){
cin>>n;
for(int i=;i<n;++i)cin>>a[i];
sort(a,a+n);
a[n-]=a[n-]>?:;
sort(a,a+n);
for(int i=;i<n;++i)
cout<<a[i]<<(i==n-?"\n":" ");
return ;
}

D - Replacement的更多相关文章

  1. BeautifulSoup Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.

    BeautifulSoup很赞的东西 最近出现一个问题:Python 3.3 soup=BeautifulSoup(urllib.request.urlopen(url_path),"htm ...

  2. LeetCode 397. Integer Replacement

    397. Integer Replacement QuestionEditorial Solution My Submissions   Total Accepted: 5878 Total Subm ...

  3. NuGet在创建pack时提示”The replacement token 'author' has no value“问题解决

    在创建pack时出现了“The replacement token 'author' has no value”的错误提示. 解决方法: 1.可能程序没生成过,在解决方案上重新生成解决方案,注意Deb ...

  4. 加州大学伯克利分校Stat2.2x Probability 概率初步学习笔记: Section 2 Random sampling with and without replacement

    Stat2.2x Probability(概率)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...

  5. Codeforces Codeforces Round #316 (Div. 2) C. Replacement set

    C. Replacement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/proble ...

  6. Is C# a clone of a Microsoft replacement for Java?

    Is C# a clone of a Microsoft replacement for Java?Let's look at what Anders Hejlsberg Said. Hejlsber ...

  7. Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树

    C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...

  8. [转]Using Replacement Strings with Regex.Replace

    本文转自:http://www.knowdotnet.com/articles/regereplacementstrings.html The String.Replace function has ...

  9. 基于年纪和成本(Age & Cost)的缓存替换(cache replacement)机制

    一.客户端的缓存与缓存替换机制 客户端的资源缓存: 在客户端游戏中,通常有大量的资源要处理,这些可能包括贴图.动作.模型.特效等等,这些资源往往存在着磁盘文件->内存(->显存)的数据通路 ...

  10. Fast Token Replacement in C#

    http://www.codeproject.com/Articles/298519/Fast-Token-Replacement-in-Csharp Fast Token Replacement i ...

随机推荐

  1. windons共享的一些问题

    有时候访问共享一直说无法打开共享,但是别人确实是开了共享. 其中可能如下: 1.首先确定网络没有问题,win+R输入cmd,ping对方IP地址,保证是网络是通的,如果不通,关闭共享电脑的防火墙. 2 ...

  2. ceph部署

    一.部署准备: 准备5台机器(linux系统为centos7.6版本),当然也可以至少3台机器并充当部署节点和客户端,可以与ceph节点共用:     1台部署节点(配一块硬盘,运行ceph-depo ...

  3. 关于static关键字的思考

    静态方法是否能调用非静态成员变量?    static关键字具有如下特点:        一.static关键字修饰的属性/方法可以通过类名直接调用,而不必先new一个对象.        二.sta ...

  4. WebService附加到IIS调试,未命中断点

    写好了一个WebService,部署到IIS上,用浏览器访问发现并不能命中断点. 经过多次的查找发现是由于附加的代码类型选择错误. 下图由于错误的选择了托管代码,导致调试时不命中断点,勾选自动解决.

  5. Python学习【第6篇】:Python之常用模块1

    常用模块一. collocations 模块 时间模块 random模块 os模块 sys模块 序列化模块 re模块 常用模块二:这些模块和面向对象有关 hashlib模块 configparse模块 ...

  6. OprenCV学习之路一:将彩色图片转换成灰度图

    //将一张彩色图片转成灰度图: //////////////////////////// #include<cv.h> #include<cvaux.h> #include&l ...

  7. uva 1587(Box UVA - 1587)

    题目大意是给定6个数对,每个数对代表一个面的长和宽,判断这6个面是否能构成一个长方体. 这种题一看很复杂,但是只要不想多了实际上这就是一个水题... 首先说明一下判断的思路: 1.长方体是有三个对面的 ...

  8. JavaScript单元测试工具-Jest

    标注: 首先这并不是一篇完整的关于Jest的教程,只是个人在接触jest学习的一点随手笔记,大部分内容都是对官方文档的一些翻译. ----------------------------------- ...

  9. [Poj3261] [Bzoj1717] [后缀数组论文例题,USACO 2006 December Gold] Milk Patterns [后缀数组可重叠的k次最长重复子串]

    和上一题(POJ1743,上一篇博客)相似,只是二分的判断条件是:是否存在一段后缀的个数不小于k #include <iostream> #include <algorithm> ...

  10. spring boot开发REST接口

    1.配置pom.xml文件的<parent>和<depencencies>,指定spring boot web依赖 <parent> <groupId> ...