#K67587. L-Shaped Moves

    ID: 32675 Type: Default 1000ms 256MiB

L-Shaped Moves

L-Shaped Moves

You are given an N x M grid representing an arena. Each cell in the arena is either free (denoted by '.') or blocked (denoted by '#'). You are also given a starting position (sx, sy) and a target position (tx, ty). You can only move in L-shaped moves (similar to a knight move in chess). An L-shaped move is defined by the following eight possible moves:

\(\{(-2,-1), (-2,1), (2,-1), (2,1), (-1,-2), (-1,2), (1,-2), (1,2)\}\)

Your task is to determine the minimum number of L-shaped moves required to get from the starting position to the target position. If it is not possible to reach the target due to obstacles or board boundaries, print -1.

inputFormat

The input is read from standard input and has the following format:
The first line contains two integers \(N\) and \(M\), the number of rows and columns (\(1 \leq N, M \leq 1000\)).
The next \(N\) lines each contain a string of length \(M\) representing the arena, where each character is either '.' (free) or '#' (blocked).
The last line contains four integers: \(sx\), \(sy\), \(tx\), \(ty\) representing the starting coordinates and target coordinates (0-indexed).

outputFormat

Output a single integer representing the minimum number of L-shaped moves required to move from the starting position to the target position. If it is impossible to do so, output -1.

## sample
5 5
.....
.....
.###.
.....
.....
0 0 4 4
4