Sweet Candies
Limits: 2 sec., 256 MiB
Marichka likes candies a lot and Zenyk for sure knows it. And because he loves her very much, he decided to present her \(n\) candies. He placed all of the candies on a table, one by one in a row, and the \(i\)-th candy is of type \(t_i\).
While waiting for Marichka, he suddenly realized that she won’t accept the gift if there are no \(k\) consecutive candies of the same type. Since he started panicking, it’s your task to help him and reshuffle the candies in such a way that Marichka accepts the gift. In case it’s not possible, print \(\texttt{``Oh sh*t''}\) (without quotes).
Input
The first line of the input contains pair of integers \(n\) and \(k\) – the number of candies on the table and the least required number of consecutive candies of the same type. The next line contains \(n\) space-separated integers \(t_i\), which denote the types of candies in the order they were initially placed on the table.
Output
If the answer exists, print \(n\) space-separated integers – reshuffled types of candies in the order Marichka accepts. In case multiple answers exist, print any one of them. If the answer does not exist, print the single line: \(\texttt{``Oh sh*t''}\) (without quotes).
Constraints
\(1 \le n, k, t_i \le 10^5\).
Samples
Input (stdin) | Output (stdout) |
---|---|
4 3 4 4 7 4 | 7 4 4 4 |
Input (stdin) | Output (stdout) |
---|---|
7 3 3 2 1 7 4 2 1 | Oh sh*t |
Submit a solution
Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
---|
Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
---|