Codeforces Round 223 (Div. 2)
B
Sereja and Stairs
Codeforces
1100
原题
← AC →
翻译中…

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?

翻译中…

Input

翻译中…

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.

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
5
1 2 3 4 5
Output #1
5
5 4 3 2 1
InputCopy OutputCopy
Input #2
6
1 1 2 2 3 3
Output #2
5
1 2 3 2 1
InputCopy OutputCopy
题目信息
题号
381B
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。