( Exception ) these are the four corner points for which the minimum steps is 4.
if ( ( x == 1 && y == 1 && tx == 2 && ty == 2 ) || ( x == 2 && y == 2 && tx == 1 && ty == 1 ) ) ans = 4 ; else if ( ( x == 1 && y == n && tx == 2 && ty == n - 1 ) || ( x == 2 && y == n - 1 && tx == 1 && ty == n ) ) ans = 4 ; else if ( ( x == n && y == 1 && tx == n - 1 && ty == 2 ) || ( x == n - 1 && y == 2 && tx == n && ty == 1 ) ) ans = 4 ; else if ( ( x == n && y == n && tx == n - 1 && ty == n - 1 ) || ( x == n - 1 && y == n - 1 && tx == n && ty == n ) ) ans = 4 ; else {