404343: GYM101484 D Joaozao, The Digit Maker

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Joaozao, The Digit Makertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Joaozao is a famous digit maker in the city of Sao Carlos. He owns a shop downtown where he receives orders to create numbers. Nicoleta, his friend and a very recent hire, is trying to learn this fancy art of digit making.

Joaozao is specialized in making numbers in base B. A number in base B is a sequence of digits written in the following way:

xb = d1d2d3... dm, 

where 0 ≤ di < B for i = 1, 2, ... m.

Joaozao received an order to build an n-digit number in base B. It is a lot of work for one day, so he decided to ask Nicoleta, who is still learning, to help him.

The process of building the number is the following: First Joaozao creates 2n digits in base B. After that, Joaozao gives pairs of digits to Nicoleta, one after the other. As Nicoleta receives them, he adds these two digits together and takes the remainder of the division by B, creating a new digit z. Finally, Nicoleta attaches z to the beginning of the number they are building, making z its most significant digit. After n steps, they will have an n-digit number written in base B.

Joaozao has already created 2n digits in base B and they will soon start the next step of the process. They are wondering what is the largest number they can build (the larger the number, the more valuable it is). Nicoleta really wants to impress Joaozao, so he asked you to help him with this task.

Input

The first line of the input contains two integers n (1 ≤ n ≤ 105) and B (1 ≤ B ≤ 109), indicating respectively the number of digits of the number Nicoleta will build and its base.

The second line contains 2n integers di representing the digits Joaozao has already created. (0 ≤ di ≤ B - 1).

Output

Output n space separated integers: the digits of the largest number in base B that Joaozao and Nicoleta can build, from most significant to least significant.

If this number has leading zeros, output them anyway.

ExamplesInput
3 10
1 2 3 4 5 6
Output
9 9 3 
Input
2 19
1 2 16 17
Output
18 18 
Note

A number xb = d1d2...dm is larger than yb = r1r2...rp. If, and only if,

Source/Category

加入题单

上一题 下一题 算法标签: