#include #include #include #include #include #include using namespace std; int n, a, b; const int MAX = 25; bool used[MAX][MAX]; int dist[MAX][MAX]; void preprocess() { for (int k = 0; k < n; k++) for (int j = 0; j < n; j++) { used[k][j] = false; dist[k][j] = 0; } } bool ok(int k, int j) { return (0 <= k and k < n and 0 <= j and j < n and !used[k][j]); } void print() { for (int k = 0; k < n; k++) { for (int j = 0; j < n; j++) cout << dist[k][j] << " "; cout << endl; } cout << endl; } void dfs(int k_start, int j_start) { queue< pair > q; used[k_start][j_start] = true; q.push(make_pair(k_start, j_start)); int k, j, new_k, new_j; while (!q.empty()) { k = q.front().first; j = q.front().second; q.pop(); for (int da = -1; da <= 1; da += 2) { for (int db = -1; db <= 1; db += 2) { new_k = k + a*da; new_j = j + b*db; if (ok(new_k, new_j)) { used[new_k][new_j] = true; dist[new_k][new_j] = dist[k][j] + 1; q.push(make_pair(new_k, new_j)); } new_k = k + b*db; new_j = j + a*da; if (ok(new_k, new_j)) { used[new_k][new_j] = true; dist[new_k][new_j] = dist[k][j] + 1; q.push(make_pair(new_k, new_j)); } } } // print(); } } int main() { cin >> n; int d; for (a = 1; a < n; a++) { for (b = 1; b < n; b++) { preprocess(); dfs(0, 0); d = dist[n-1][n-1]; cout << (d == 0 ? -1 : d) << " "; } cout << endl; } return 0; }