def main(): import sys sys.setrecursionlimit(10**6) from random import shuffle N = int(input()) ans = [[-1]*N for _ in range(N)] for i in range(N): ans[i][i] = i+1 B = [i for i in range(1, N+1)] def dfs(i, j, ans): if i == j: if i == N-1: written = True return written, ans else: return dfs(i, j+1, ans) canuse = [True]*(N+1) for k in range(N): if ans[i][k] != -1: canuse[ans[i][k]] = False if ans[k][j] != -1: canuse[ans[k][j]] = False written = False shuffle(B) if any(c for c in canuse): for v in B: if not written and canuse[v]: ans[i][j] = v if j+1 < N: written, ans = dfs(i, j+1, ans) else: written, ans = dfs(i+1, 0, ans) if not written: ans[i][j] = -1 return written, ans _, ans = dfs(0, 0, ans) for i in range(N): print(*ans[i]) if __name__ == '__main__': main()