#D4229. Move on Ice
Move on Ice
Move on Ice
Problem
The penguins Fluoro is in an infinitely wide ice cube (, ). There is a hole in the trout (, ) through which water can enter. There are lumps of ice on the ice, each in the square (, ).
Fluoro can move up, down, left and right in four directions. It's slippery on the ice, so when you move it keeps moving until it hits a block of ice. When it hits a lump of ice, it stops just before the square with the lump of ice. You can enter the hole by passing through the square of the hole.
Fluoro can stop in the middle by stepping on it only once.
It hurts when it hits a lump of ice, so I want to reduce the number of hits as much as possible. Find the minimum number of hits before moving to a square with a hole (, ). If you can't reach it, print 1.
Constraints
The input satisfies the following conditions.
- , , , , ,
- All given coordinates are different
Input
The input is given in the following format.
...
All inputs are given as integers. The coordinates of the cell where Fluoro is on the first line are given separated by blanks. The coordinates of the cells with holes in the second line are given separated by blanks. The third line gives the number of ice cubes . The coordinates of the square with the ice block on the following line are given, separated by blanks.
Output
Output the minimum number of hits before moving to a hole. If you can't reach it, print 1.
Examples
Input
0 0 13 33 2 0 34 14 0
Output
0
Input
0 1 5 0 4 2 1 1 3 4 2 3 0
Output
4
Input
0 0 0 2 1 0 1
Output
-1
inputFormat
input satisfies the following conditions.
- , , , , ,
- All given coordinates are different
Input
The input is given in the following format.
...
All inputs are given as integers. The coordinates of the cell where Fluoro is on the first line are given separated by blanks. The coordinates of the cells with holes in the second line are given separated by blanks. The third line gives the number of ice cubes . The coordinates of the square with the ice block on the following line are given, separated by blanks.
outputFormat
Output
Output the minimum number of hits before moving to a hole. If you can't reach it, print 1.
Examples
Input
0 0 13 33 2 0 34 14 0
Output
0
Input
0 1 5 0 4 2 1 1 3 4 2 3 0
Output
4
Input
0 0 0 2 1 0 1
Output
-1
样例
0 0
0 2
1
0 1
-1