测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A9328. Sereja and Stairs

编程题 普及/提高-

题目描述

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
上一题 去做题 下一题