eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Gregory the Grasshopper

Gregory the Grasshopper

\includegraphics{https://static.e-olymp.com/content/85/850e5fa13f9dd4430a31fded72b2c217bd83f8ae.jpg} Gregory is a grasshopper. His favourite food are clover leafs --- he can simply never have enough of them. Whenever he spots such a leaf, he wants to eat it as quickly as possible. Gregory is also lazy, so he wants to move to the leaf with minimal effort. Your task is to help him to find the shortest way to a clover leaf. For simplicity, we will assume that Gregory lives on a rectangular grid consisting of unit squares. As a grasshopper, he prefers to move by jumping (or, more exactly, hopping) from one square to the other. Each hop takes him to a square that is in the adjacent row or column in one direction, and two columns or rows away in the other direction. So, his hops resemble the moves of a knight on a chessboard. \includegraphics{https://static.e-olymp.com/content/60/60c05ae669612fd1837921e3256ec425219053e1.jpg} \InputFile The input consists of several test cases, each of them specified by six integer numbers on one line: \textbf{R}, \textbf{C}, \textbf{GR}, \textbf{GC}, \textbf{LR}, and \textbf{LC}. \textbf{R} and \textbf{C} specify the size of the grid in unit squares, \textbf{1} ≤ \textbf{R}, \textbf{C} ≤ \textbf{100}. Gregory cannot hop outside a rectangle of this size, because it would be too dangerous. The values of \textbf{GR}, \textbf{GC} are the coordinates of the square that Gregory is standing on, and \textbf{LR}, \textbf{LC} are the coordinates of the square with the delicious clover leaf. (\textbf{1} ≤ \textbf{GR}, \textbf{LR} ≤ \textbf{R}, \textbf{1} ≤ \textbf{GC}, \textbf{LC} ≤ \textbf{C}) \OutputFile For each test case, print one integer number --- the minimal number of hops that Gregory needs to reach the square with his beloved delicacy. If it is not possible to reach that square at all, print the word "\textbf{impossible}" instead.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
10 10 10 10 1 1
2 2 1 1 1 2
8 8 1 1 1 2
Выходные данные #1
6
impossible
3