#P9890. Knight Duel Tournament Scheduling

    ID: 23035 Type: Default 1000ms 256MiB

Knight Duel Tournament Scheduling

Knight Duel Tournament Scheduling

DreamGrid, the king of Gridland, is organizing a knight tournament. There are nn knights, numbered from 1 to nn, participating in the tournament. The tournament consists of kk rounds. In each round, every knight must participate in exactly one duel, and each duel is fought by exactly two knights. Moreover, every pair of knights may duel each other at most once over all kk rounds.

In addition, the following condition must hold: For any two distinct rounds ii and jj and any four distinct knights aa, bb, cc, and dd, if in round ii knight aa fights knight bb and knight cc fights knight dd, and in round jj knight aa fights knight cc, then in round jj knight bb must fight knight dd.

Your task is to output an arrangement of duels for the kk rounds that satisfies all of the rules above. It is guaranteed that nn is even and 1kn11\le k\le n-1, so that a valid arrangement exists. A standard round-robin (circle) scheduling algorithm will satisfy all the conditions.

inputFormat

The input consists of a single line containing two space-separated integers: nn and kk, where:

  • nn is an even integer representing the total number of knights.
  • kk is the number of rounds (1kn11\le k\le n-1).

outputFormat

Output exactly kk lines. Each line corresponds to one round and should contain exactly n/2n/2 pairs of knights. For each pair, output the two knight numbers separated by a space. Different pairs on the same line should also be separated by a space. The schedule must satisfy all tournament rules described above.

sample

4 3
1 4 2 3

1 3 4 2 1 2 3 4

</p>