codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

381B.md (1299B)


      1 Source: https://codeforces.com/problemset/problem/381/B
      2 
      3 B. Sereja and Stairs
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Sereja loves integer sequences very much. He especially likes stairs.
     22 
     23 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:
     24 
     25 *a*1 < *a*2 < ... < *a**i* - 1 < *a**i* > *a**i* + 1 > ... > *a*|*a*| - 1 > *a*|*a*|.
     26 
     27 For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.
     28 
     29 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?
     30 
     31 Input
     32 
     33 The first line contains integer *m* (1 ≤ *m* ≤ 105) — 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.
     34 
     35 Output
     36 
     37 In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 5  
     45 1 2 3 4 5
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 5  
     52 5 4 3 2 1
     53 ```
     54 
     55 Input
     56 
     57 ```
     58 6  
     59 1 1 2 2 3 3
     60 ```
     61 
     62 Output
     63 
     64 ```
     65 5  
     66 1 2 3 2 1
     67 ```