import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { int size; int[][] visited; boolean found; int minlenght; Solution(int n){ size = n; visited = new int[n][n]; } boolean hasValue(int x, int y){ if(visited[x][y] == 0){ return false; }else return true; } int getValue(int x, int y){ return visited[x][y]; } void setVisited(int x, int y, int num){ visited[x][y]= num; } class Coords { int x; int y; public boolean equals(Object o) { Coords c = (Coords) o; return c.x == x && c.y == y; } public Coords(int x, int y) { super(); this.x = x; this.y = y; } public int hashCode() { return new Integer(x + "0" + y); } public String toString(){ return new String(x+","+y); } } private static int minimum(int a1 ,int a2 ,int a3 ,int a4 ,int a5 ,int a6 ,int a7 ,int a8){ List t = new ArrayList<>(); boolean allMax= true; if(a1 !=-1){t.add(a1);allMax= false;} if(a2 !=-1){t.add(a2);allMax= false;} if(a3 !=-1){t.add(a3);allMax= false;} if(a4 !=-1){t.add(a4);allMax= false;} if(a5 !=-1){t.add(a5);allMax= false;} if(a6 !=-1){t.add(a6);allMax= false;} if(a7 !=-1){t.add(a7);allMax= false;} if(a8 !=-1){t.add(a8);allMax= false;} if(allMax) return -1; return Collections.min(t); } public int min(int a, int b, int n, int m, ArrayList path){ //if(n==m) System.out.print(n+","+m+" "); if((n>=size||m>=size||n<0||m<0)){ return -1; } Coords current = new Coords(n,m); if ((n==a && m ==b)||(n==b && m ==a)){ //found = true; //path.add(current); //if(path.size()=minlenght && found) // return -1; path.add(current); } if(hasValue(n,m)){ return getValue(n,m); } int answ = minimum (min(a, b, n+a ,m+b ,path),min(a, b, n+a ,m-b ,path),min(a, b, n-a ,m+b ,path),min(a, b, n-a ,m-b ,path),min(a, b, n+b ,m+a ,path),min(a, b, n+b ,m-a ,path),min(a, b, n-b ,m+a ,path),min(a, b, n-b ,m-a ,path)); if (answ == -1){ //setVisited(n, m , answ); return answ; }else{ answ++; setVisited(n, m , answ); return answ; } } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); // your code goes here // Solution s = new Solution(n); // System.out.print(s.min(1,1,n-1,n-1, new ArrayList<>())); for(int i = 1; i())-2); else System.out.print(s.min(i,j,n-1,n-1, new ArrayList<>())); if(j!=n-1) System.out.print(" "); } if(i!=n-1) System.out.println(); } } }