using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); bool[,] visited; Queue queue; Temp temp = null; bool found; for(int i = 1; i < n; i++) { for(int j = 1; j < n; j++) { queue = new Queue(); visited = new bool[n,n]; queue.Enqueue(new Temp{X = 0, Y = 0, Moves = 0}); visited[0, 0] = true; found = false; while(queue.Count != 0) { temp = queue.Dequeue(); if(temp.X == n - 1 && temp.Y == n - 1) { found = true; break; } if(temp.X + i < n) { if(temp.Y + j < n && !visited[temp.X + i, temp.Y + j]) { visited[temp.X + i, temp.Y + j] = true; queue.Enqueue(new Temp{X = temp.X + i, Y = temp.Y + j, Moves = temp.Moves + 1}); } if(temp.Y - j >= 0 && !visited[temp.X + i, temp.Y - j]) { visited[temp.X + i, temp.Y - j] = true; queue.Enqueue(new Temp{X = temp.X + i, Y = temp.Y - j, Moves = temp.Moves + 1}); } } if(temp.X - i >= 0) { if(temp.Y + j < n && !visited[temp.X - i, temp.Y + j]) { visited[temp.X - i, temp.Y + j] = true; queue.Enqueue(new Temp{X = temp.X - i, Y = temp.Y + j, Moves = temp.Moves + 1}); } if(temp.Y - j >= 0 && !visited[temp.X - i, temp.Y - j]) { visited[temp.X - i, temp.Y - j] = true; queue.Enqueue(new Temp{X = temp.X - i, Y = temp.Y - j, Moves = temp.Moves + 1}); } } if(temp.Y + i < n) { if(temp.X + j < n && !visited[temp.X + j, temp.Y + i]) { visited[temp.X + j, temp.Y + i] = true; queue.Enqueue(new Temp{X = temp.X + j, Y = temp.Y + i, Moves = temp.Moves + 1}); } if(temp.X - j >= 0 && !visited[temp.X - j, temp.Y + i]) { visited[temp.X - j, temp.Y + i] = true; queue.Enqueue(new Temp{X = temp.X - j, Y = temp.Y + i, Moves = temp.Moves + 1}); } } if(temp.Y - i >= 0) { if(temp.X + j < n && !visited[temp.X + j, temp.Y - i]) { visited[temp.X + j, temp.Y - i] = true; queue.Enqueue(new Temp{X = temp.X + j, Y = temp.Y - i, Moves = temp.Moves + 1}); } if(temp.X - j >= 0 && !visited[temp.X - j, temp.Y - i]) { visited[temp.X - j, temp.Y - i] = true; queue.Enqueue(new Temp{X = temp.X - j, Y = temp.Y - i, Moves = temp.Moves + 1}); } } } Console.Write((found ? temp.Moves : -1) + " "); } Console.WriteLine(); } } } class Temp { public int X { get; set; } public int Y { get; set; } public int Moves { get; set; } }