#!/bin/python3 import sys def min_path(n, a, b): m = [] processed = [] for i in range(n): m.append([-1] * n) processed.append([False] * n) m[0][0] = 0 while True: #for i in range(n): # print(m[i]) #print(processed) #find next not '-1' min number mn = -1 mni = -1 mnj = -1 for i in range(n): for j in range(n): if m[i][j] != -1 and not processed[i][j]: if mn == -1 or m[i][j] < mn: mn = m[i][j] mni = i mnj = j #print(mn, mni, mnj) if mni == -1 and mnj == -1: break dirs = [[1, 1], [1, -1], [-1, 1], [-1, -1]] for d in dirs: ii = mni + d[0] * a jj = mnj + d[1] * b if ii >= 0 and ii < n and jj >= 0 and jj < n: if m[ii][jj] == -1: m[ii][jj] = mn + 1 else: m[ii][jj] = min(mn + 1, m[ii][jj]) ii = mni + d[0] * b jj = mnj + d[1] * a if ii >= 0 and ii < n and jj >= 0 and jj < n: if m[ii][jj] == -1: m[ii][jj] = mn + 1 else: m[ii][jj] = min(mn + 1, m[ii][jj]) processed[mni][mnj] = True if mni == n - 1 and mnj == n - 1: break #print(m) return m[n - 1][n - 1] #print(min_path(5, 1, 1)) N = int(input()) for i in range(1, N): for j in range(1, N): print(min_path(N, i, j), end=" ") print() #n = int(input().strip()) # your code goes here