ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

1506. Columns of Numbers

Time limit: 1.0 second
Memory limit: 64 MB
Every New Russian has to look through long columns of numbers for analyzing market trends and planning his investments. Psychologists assure that the longer is a column of numbers, the more difficult it is to perceive it. Therefore, it is better to print numbers not in one long column, but in several columns so that their height would be minimal. Transform a given sequence of numbers to a format that is psychologically more convenient for perception.


The first line contains two integers: N (1 ≤ N ≤ 100), which shows how many numbers must be analyzed, and K (1 ≤ K ≤ N), which is the desired number of columns. The second line contains N integer numbers in the range from 0 to 999.


Output the N numbers given in the input in K columns in such a way that the number of lines is minimal and the columns have the same height with the possible exception of the last column, which may be shorter. The width of each column must be 4 symbols; the numbers must be aligned to the right edge and padded with spaces to the required width. The numbers must be given in the same order as in the input, but in columns: the first column from the top to the bottom, then the second column from the top to the bottom, and so on. All nonempty lines must end with a line break; there must be no end spaces in the lines. It is guaranteed that solution is always exist.


7 3
1 2 30 40 50 600 700
   1  40 700
   2  50
  30 600
Problem Author: Stanislav Vasilyev
Problem Source: Quarter-Final of XXXI ACM ICPC - Yekaterinburg - 2006