( Exception ) these are the four corner points for which the minimum steps is 4.
if ( ( x == 1 and y == 1 and tx == 2 and ty == 2 ) or ( x == 2 and y == 2 and tx == 1 and ty == 1 ) ) : NEW_LINE INDENT ans = 4 ; NEW_LINE DEDENT elif ( ( x == 1 and y == n and tx == 2 and ty == n - 1 ) or ( x == 2 and y == n - 1 and tx == 1 and ty == n ) ) : NEW_LINE INDENT ans = 4 ; NEW_LINE DEDENT elif ( ( x == n and y == 1 and tx == n - 1 and ty == 2 ) or ( x == n - 1 and y == 2 and tx == n and ty == 1 ) ) : NEW_LINE INDENT ans = 4 ; NEW_LINE DEDENT elif ( ( x == n and y == n and tx == n - 1 and ty == n - 1 ) or ( x == n - 1 and y == n - 1 and tx == n and ty == n ) ) : NEW_LINE INDENT ans = 4 ; NEW_LINE DEDENT else : NEW_LINE