Ringo is at a carnival in Singapore. He has some prize tickets in his bag, which he would like to use at the prize game stall. Each ticket comes in one of n colours and has a non-negative integer printed on it. The integers printed on different tickets might be the same. Due to a quirk in the carnival rules, n is guaranteed to be even.
Ringo has m tickets of each colour in his bag, that is a total of n⋅m tickets. The ticket j of the colour i has the integer x\[i]\[j] printed on it (0≤i≤n−1 and 0≤j≤m−1).
The prize game is played in k rounds, numbered from 0 to k−1. Each round is played in the following order:
The remaining tickets in Ringo's bag after k rounds of the game are discarded.
By watching closely, Ringo realized that the prize game is rigged! There is actually a printer inside the lucky draw box. In each round, the game master finds an integer b that minimizes the value of the prize of that round. The value chosen by the game master is printed on the special card for that round.
Having all this information, Ringo would like to allocate tickets to the rounds of the game. That is, he wants to select the ticket set to use in each round in order to maximize the total value of the prizes.