题库练习 Sereja and Stairs
← 上一题 下一题 →

A9328 | Sereja and Stairs

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Sereja loves integer sequences very much. He especially likes stairs.

Sequence $a_{1},a_{2},...,a_{|a|}$ ( $|a|$ is the length of the sequence) is stairs if there is such index $i$ $(1<=i<=|a|)$ , that the following condition is met:

$a_{1}<a_{2}<...<a_{i-1}<a_{i}>a_{i+1}>...>a_{|a|-1}>a_{|a|}.$ For example, sequences \[1, 2, 3, 2\] and \[4, 2\] are stairs and sequence \[3, 1, 2\] isn't.

Sereja has $m$ cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?

输入格式

The first line contains integer $m$ $(1<=m<=10^{5})$ — the number of Sereja's cards. The second line contains $m$ integers $b_{i}$ $(1<=b_{i}<=5000)$ — the numbers on the Sereja's cards.

输出格式

In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.

输入输出样例

输入 #1
5
1 2 3 4 5
输出 #1
5
5 4 3 2 1
输入 #2
6
1 1 2 2 3 3
输出 #2
5
1 2 3 2 1
C++ 编辑器
输入
输出