using System; using System.Collections.Generic; class Solution { internal struct Move { public static Move Empty = new Move( -1, -1, -1 ); public Move( int x, int y, int cnt ) { X = x; Y = y; Cnt = cnt; } public int X { get; } public int Y { get; } public int Cnt { get; } public override string ToString() => $"{X},{Y} - {Cnt}"; } private static bool TryMove( bool[,] board, int n, int i, int j, int cnt, out Move move, out bool found ) { move = Move.Empty; found = i == n - 1 && j == n - 1; if( i < 0 || j < 0 ) return false; if( i > n - 1 || j > n - 1 ) return false; if( board[i, j] ) return false; board[i, j] = true; move = new Move( i, j, cnt ); return true; } private static int Solve( int n, int a, int b ) { bool[,] board = new bool[n, n]; bool found = false; var queue = new Queue(); Move next = new Move( 0, 0, 0 ); queue.Enqueue( next ); board[0, 0] = true; while( queue.Count != 0 ) { var current = queue.Dequeue(); var x = current.X; var y = current.Y; var cnt = current.Cnt; if( TryMove( board, n, x + b, y - a, cnt + 1, out next, out found ) ) { if( found ) break; queue.Enqueue( next ); } if( TryMove( board, n, x + a, y - b, cnt + 1, out next, out found ) ) { if( found ) break; queue.Enqueue( next ); } if( TryMove( board, n, x + a, y + b, cnt + 1, out next, out found ) ) { if( found ) break; queue.Enqueue( next ); } if( TryMove( board, n, x - b, y + a, cnt + 1, out next, out found ) ) { if( found ) break; queue.Enqueue( next ); } if( TryMove( board, n, x + b, y + a, cnt + 1, out next, out found ) ) { if( found ) break; queue.Enqueue( next ); } if( TryMove( board, n, x - a, y + b, cnt + 1, out next, out found ) ) { if( found ) break; queue.Enqueue( next ); } if( TryMove( board, n, x - a, y - b, cnt + 1, out next, out found ) ) { if( found ) break; queue.Enqueue( next ); } if( TryMove( board, n, x - b, y - a, cnt + 1, out next, out found ) ) { if( found ) break; queue.Enqueue( next ); } } return found ? next.Cnt : -1; } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); for( int a = 1; a < n; a++ ) { for( int b = 1; b < n; b++ ) Console.Write( Solve( n, a, b ) + " " ); Console.WriteLine(); } } }