## COCI '09 Contest 3 #3 Sort

View as PDF

Points: 5
Time limit: 1.0s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Mirko is a great code breaker. He knows any cipher in the world can be broken by frequency analysis. He has completely the wrong idea what frequency analysis is, however.

He intercepted an enemy message. The message consists of numbers, smaller than or equal to . Mirko believes freqency analysis consists of sorting this sequence so that more frequent numbers appear before less frequent ones.

Formally, the sequence must be sorted so that given any two numbers and , appears before if the number of times appears in the original sequence is larger than the number of time does. If the number of appearances is equal, the number whose value appears sooner in the input should appear sooner in the sorted sequence.

Help Mirko by creating a "frequency sorter".

#### Input Specification

First line of input contains two integers, , length of message, and , the number from task description.

Next line contains integers smaller than or equal to , message itself.

#### Output Specification

First and only line of output should contain numbers, the sorted sequence.

#### Sample Input 1

5 2
2 1 2 1 2

#### Sample Output 1

2 2 2 1 1

#### Sample Input 2

9 3
1 3 3 3 2 2 2 1 1

#### Sample Output 2

1 1 1 3 3 3 2 2 2

#### Sample Input 3

9 77
11 33 11 77 54 11 25 25 33

#### Sample Output 3

11 11 11 33 33 25 25 77 54