eolymp
bolt
Try our new interface for solving problems
Problems

(p, q) - horse

(p, q) - horse

(\textbf{p}, \textbf{q})-horse - a generalization of the usual chess knight. (\textbf{p}, \textbf{q})-horse moves under its own power on \textbf{p} cells in the same direction, and \textbf{q} - in the other (perpendicular). For example, (\textbf{3}, \textbf{4})-the horse can move with the cells (\textbf{5}, \textbf{6}) cells (\textbf{1}, \textbf{3}), (\textbf{2}, \textbf{2}), (\textbf{2}, \textbf{10}), (\textbf{1}, \textbf{9}), (\textbf{8}, \textbf{10}), (\textbf{9}, \textbf{9}), (\textbf{8}, \textbf{2}) and (\textbf{9}, \textbf{3}). Obviously, the usual chess knight - a (\textbf{2}, \textbf{1})-horse. Your task - to determine the minimum number of moves it takes (\textbf{p}, \textbf{q})-horse to get from one cell checkerboard \textbf{M}×\textbf{N} to the other. Go beyond the board is prohibited. \InputFile One line contains \textbf{8} integers \textbf{M}, \textbf{N}, \textbf{p}, \textbf{q}, \textbf{x_1}, \textbf{y_1}, \textbf{x_2}, \textbf{y_2} (\textbf{1} ≤ \textbf{x_1}, \textbf{x_2} ≤ \textbf{M} ≤ \textbf{100}, \textbf{1} ≤ \textbf{y_1}, \textbf{y_2} ≤ \textbf{N} ≤ \textbf{100}, \textbf{0} ≤ \textbf{p} ≤ \textbf{100}, \textbf{0} ≤ \textbf{q} ≤ \textbf{100}). \OutputFile The first line print the number of moves \textbf{k} it takes (\textbf{p}, \textbf{q})-horse to get out of the cell (\textbf{x_1}, \textbf{y_1}) to the cell (\textbf{x_2}, \textbf{y_2}). Next to follow \textbf{k+1} rows with the provisions of (\textbf{p}, \textbf{q})-horse in this way. If (\textbf{p}, \textbf{q})-horse can not get from (\textbf{x_1}, \textbf{y_1}) to (\textbf{x_2}, \textbf{y_2}), output \textbf{-1}.
Time limit 1 second
Memory limit 122.17 MiB
Input example #1
3 3 1 1 1 1 3 3
Output example #1
2
1 1
2 2
3 3
Input example #2
2 2 1 1 1 1 1 2
Output example #2
-1
Source SСS - 2011 Sevastopol 08/08/2011 d.2 1st League