import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { int [][] board; static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // Print the distance along with the sequence of moves. String [] moves = {"UR", "UL", "LR", "LL", "L", "R"}; int new_i = 0; int new_j = 0; for(String move: moves) { if(move.equals("UR")) { new_i = i_start - 2; new_j = j_start + 1; } else if (move.equals("UL")) { new_i = i_start - 2; new_j = j_start - 1; } else if (move.equals("LL")) { new_i = i_start + 2; new_j = j_start - 1; } else if (move.equals("LR")) { new_i = i_start + 2; new_j = j_start + 1; } else if (move.equals("L")) { new_i = i_start; new_j = j_start - 2; } else if (move.equals("R")) { new_i = i_start; new_j = j_start + 2; } if(isValidMove(new_i, new_j, n)) { board[new_i][new_j] = Math.min(board[new_i][new_j],board[i_start][j_start]+1); } } } public static boolean isValidMove(int new_i, int new_j, int n) { if(new_i <0 || new_i >=n|| new_j<0|| new_j>= n) return false; return true; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int i_start = in.nextInt(); int j_start = in.nextInt(); int i_end = in.nextInt(); int j_end = in.nextInt(); board = new int[n][n]; for(int [] row: board) { Arrays.fill(row, Integer.MAX_VALUE); } board[i_start][j_start] = 0; printShortestPath(n, i_start, j_start, i_end, j_end); in.close(); } }