from sys import setrecursionlimit setrecursionlimit(10 ** 6) N = int(input()) result = [[-1] * N for _ in range(N)] usedT = [[False] * N for _ in range(N)] usedY = [[False] * N for _ in range(N)] result[0][1] = N usedT[1][N - 1] = True usedY[0][N - 1] = True for i in range(2, N): result[0][i] = i usedT[i][i - 1] = True usedY[0][i - 1] = True result[1][0] = N - 1 usedT[0][N - 2] = True usedY[1][N - 2] = True result[2][0] = N usedT[0][N - 1] = True usedY[2][N - 1] = True for i in range(3, N): result[i][0] = i - 1 usedT[0][i - 2] = True usedY[i][i - 2] = True def dfs(i, j): if result[i][j] != -1: if i == N - 1 and j == N - 1: return True elif j == N - 1: return dfs(i + 1, 0) else: return dfs(i, j + 1) for k in range(N): if usedT[j][k]: continue if usedY[i][k]: continue result[i][j] = k + 1 usedT[j][k] = True usedY[i][k] = True if j == N - 1: t = dfs(i + 1, 0) else: t = dfs(i, j + 1) if t: return True else: result[i][j] = -1 usedT[j][k] = False usedY[i][k] = False return False for i in range(N): result[i][i] = i + 1 usedT[i][i] = True usedY[i][i] = True dfs(0, 1) for i in range(N): print(*result[i])