Time limit
2s
Memory limit
128 MB
A Shom square is an N x N square determined by two natural numbers N and D. Each cell contains one integer from 0 through D-1.
A valid Shom square must satisfy this rule: every row and every column contains each integer 0, 1, ..., D-1 at least once.
Given N and D, print the lexicographically smallest valid Shom square. Lexicographic order compares the numbers from left to right in the first row, then continues row by row.
The first line contains N and D. N is a natural number at most 10, and D is a natural number at most N.
Print the Shom square in N lines. Separate adjacent numbers in a row with one space.