#include #include #include using namespace std; int main(){ int n; cin >> n; int* arrA = new int[n*n]; int* arrB = new int[n*n]; int* turns = new int[n*n]; arrA[0] = 0; arrB[0] = 0; turns[0] = 0; int index = 1; for(int i = 1; i < n*n; i++) { arrA[i] = -1; arrB[i] = -1; } int sum1, sum2, sum3, sum4, sum5, sum6, sum7, sum8; for(int i = 1; i < n; i++) { for(int j = 1; j < n; j++) { index = 1; for(int h = 1; h < n*n; h++) { arrA[h] = -1; arrB[h] = -1; } for(int k = 0; k < n*n; k++) { if(arrA[k] == -1) { cout << "-1 "; break; } sum1 = arrA[k] + i; sum2 = arrA[k] - i; sum3 = arrB[k] + j; sum4 = arrB[k] - j; sum5 = arrA[k] + j; sum6 = arrA[k] - j; sum7 = arrB[k] + i; sum8 = arrB[k] - i; if(sum1 < n && sum1 >= 0 && sum3 < n && sum3 >= 0) { for(int l = 0; l < index; l++) { if(arrA[l] == sum1 && arrB[l] == sum3) { break; } if(l == index - 1) { arrA[index] = sum1; arrB[index] = sum3; turns[index] = turns[k] + 1; index++; break; } } if(sum1 == sum3 && sum1 == n - 1) { cout << turns[index - 1] << ' '; break; } } if(sum1 < n && sum1 >= 0 && sum4 < n && sum4 >= 0) { for(int l = 0; l < index; l++) { if(arrA[l] == sum1 && arrB[l] == sum4) { break; } if(l == index - 1) { arrA[index] = sum1; arrB[index] = sum4; turns[index] = turns[k] + 1; index++; break; } } if(sum1 == sum4 && sum1 == n - 1) { cout << turns[index - 1] << ' '; break; } } if(sum2 < n && sum2 >= 0 && sum3 < n && sum3 >= 0) { for(int l = 0; l < index; l++) { if(arrA[l] == sum2 && arrB[l] == sum3) { break; } if(l == index - 1) { arrA[index] = sum2; arrB[index] = sum3; turns[index] = turns[k] + 1; index++; break; } } if(sum2 == sum3 && sum2 == n - 1) { cout << turns[index - 1] << ' '; break; } } if(sum2 < n && sum2 >= 0 && sum4 < n && sum4 >= 0) { for(int l = 0; l < index; l++) { if(arrA[l] == sum2 && arrB[l] == sum4) { break; } if(l == index - 1) { arrA[index] = sum2; arrB[index] = sum4; turns[index] = turns[k] + 1; index++; break; } } if(sum2 == sum4 && sum2 == n - 1) { cout << turns[index - 1] << ' '; break; } } if(sum5 < n && sum5 >= 0 && sum7 < n && sum7 >= 0) { for(int l = 0; l < index; l++) { if(arrA[l] == sum5 && arrB[l] == sum7) { break; } if(l == index - 1) { arrA[index] = sum5; arrB[index] = sum7; turns[index] = turns[k] + 1; index++; break; } } if(sum5 == sum7 && sum5 == n - 1) { cout << turns[index - 1] << ' '; break; } } if(sum5 < n && sum5 >= 0 && sum8 < n && sum8 >= 0) { for(int l = 0; l < index; l++) { if(arrA[l] == sum5 && arrB[l] == sum8) { break; } if(l == index - 1) { arrA[index] = sum5; arrB[index] = sum8; turns[index] = turns[k] + 1; index++; break; } } if(sum5 == sum8 && sum5 == n - 1) { cout << turns[index - 1] << ' '; break; } } if(sum6 < n && sum6 >= 0 && sum7< n && sum7 >= 0) { for(int l = 0; l < index; l++) { if(arrA[l] == sum6 && arrB[l] == sum7) { break; } if(l == index - 1) { arrA[index] = sum6; arrB[index] = sum7; turns[index] = turns[k] + 1; index++; break; } } if(sum6 == sum7 && sum6 == n - 1) { cout << turns[index - 1] << ' '; break; } } if(sum6 < n && sum6 >= 0 && sum8 < n && sum8 >= 0) { for(int l = 0; l < index; l++) { if(arrA[l] == sum6 && arrB[l] == sum8) { break; } if(l == index - 1) { arrA[index] = sum6; arrB[index] = sum8; turns[index] = turns[k] + 1; index++; break; } } if(sum6 == sum8 && sum6 == n - 1) { cout << turns[index - 1] << ' '; break; } } } } cout << endl; } return 0; }