Under construction

Still being built. Things may change

Harry Potter and the Battle for Hogwarts

Interview

Time limit2sMemory limit1024 MB

Summary
Apply k passes of bubble sort to a permutation of 1 to n and print the array after those passes.
Level

Medium6 of 10

Topics
Array, Implementation
Solved
No attempts yet

Passes

The decisive battle for Hogwarts is coming. All nn of its inhabitants have gathered in the hall to repel the enemy's attack. Each defender of Hogwarts has a magic power, which is a natural number from 11 to nn. All defenders have different magic powers.

Harry decided that the line of defenders would best repel the attack if the magic power increases from left to right. However, the defenders are already standing in a line that may not satisfy this condition.

To repel the attack, Harry wants to rearrange the defenders in increasing order of magic power. He uses the following algorithm. He walks from left to right and looks at each pair of neighboring defenders. If the left defender is stronger than the right one, he swaps them.

From the course "Fundamentals of Muggle Informatics", Harry knows that after n−1n-1 such passes, all defenders will be in increasing order of magic power. However, time is short, so Harry can only make kk passes.

Help Harry find the order in which the defenders will meet the enemy army.

Input

The first line contains an integer nn (1≤n≤2000001 \le n \le 200000), the number of defenders, and an integer kk (0≤k≤n−10 \le k \le n-1), the number of passes Harry can make. The second line contains nn integers aia_i (1≤ai≤n1 \le a_i \le n), the magic powers of the defenders in the original line from left to right.

Output

Print nn integers bib_i on a single line, the magic powers of the defenders from left to right after Harry makes kk passes.

Examples2

  1. Example 1

    Input
    4 1
    4 1 3 2
    
    Expected output
    1 3 2 4
    
  2. Example 2

    Input
    5 2
    4 2 1 5 3
    
    Expected output
    1 2 3 4 5