import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 1; i < n; ++i) { for (int j = 1; j < n; ++j) { System.out.print(countMoves(n, i, j) + " "); } System.out.println(); } } public static int countMoves(int n, int i, int j) { int[][] count = new int[n][n]; for (int x = 0; x < n; ++x) { for (int y = 0; y < n; ++y) { count[x][y] = -1; } } LinkedList xQueue = new LinkedList(); LinkedList yQueue = new LinkedList(); xQueue.add(0); yQueue.add(0); count[0][0] = 0; while (!xQueue.isEmpty()) { int x = xQueue.pollFirst(); int y = yQueue.pollFirst(); if (x == n-1 && y == n-1) { return count[x][y]; } int nextCount = count[x][y] + 1; nextNodeSubroutine(count, xQueue, yQueue, n, nextCount, x+i, y+j); nextNodeSubroutine(count, xQueue, yQueue, n, nextCount, x-i, y+j); nextNodeSubroutine(count, xQueue, yQueue, n, nextCount, x+i, y-j); nextNodeSubroutine(count, xQueue, yQueue, n, nextCount, x-i, y-j); nextNodeSubroutine(count, xQueue, yQueue, n, nextCount, x+j, y+i); nextNodeSubroutine(count, xQueue, yQueue, n, nextCount, x-j, y+i); nextNodeSubroutine(count, xQueue, yQueue, n, nextCount, x+j, y-i); nextNodeSubroutine(count, xQueue, yQueue, n, nextCount, x-j, y-i); } return -1; } public static void nextNodeSubroutine(int[][] count, LinkedList xQueue, LinkedList yQueue, int n, int nextCount, int x2, int y2) { if (x2 >= 0 && y2 >= 0 && x2 < n && y2 < n && (count[x2][y2] == -1 || count[x2][y2] > nextCount)) { count[x2][y2] = nextCount; xQueue.add(x2); yQueue.add(y2); } } }