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)] 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 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 usedT[i][i] = True usedY[i][i] = True dfs(0, 1) for i in range(N): print(*result[i])