#include #include #include #include #include #include #include using namespace std; int answer[26][26]; int dp[26][26]; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n = 0; cin >> n; for(int i = 1; i < n; i++){ for(int j = 1; j < n; j++){ for(int x1 = 0; x1 < n+1; x1++){ for(int y1 = 0; y1 < n+1; y1++){ dp[x1][y1]=1000000009; } } dp[0][0]=0; queue > s; s.push(make_pair(0, 0)); int xs[] = {i, i, -i, -i, j, j, -j, -j}; int ys[] = {j, -j, j, -j, i, -i, i, -i}; while(!s.empty()){ pair p1 = s.front(); int x1 = p1.first; int y1 = p1.second; s.pop(); for(int k = 0; k < 8; k++){ int x2 = x1 + xs[k]; int y2 = y1 + ys[k]; if(x2 < n && x2 >= 0 && y2 < n && y2 >=0 && dp[x2][y2]==1000000009){ dp[x2][y2]=dp[x1][y1]+1; s.push(make_pair(x2, y2)); } } } if(dp[n-1][n-1]==1000000009){ answer[i][j]=-1; } else{ answer[i][j] = dp[n-1][n-1]; } } } for(int i = 1; i < n; i++){ for(int j = 1; j < n; j++){ cout << answer[i][j]; if(j < n-1){ cout << " "; }else{ cout << endl; } } } return 0; }