Task
Alessandro is coding his new 3D version of Pac-Man. The game board is described by a three-dimensional grid, some cells are blocked and the others are free. Pac-Man and the ghosts can move to any free cell sharing a face with the current cell.
Alessandro instructed ghosts to move in a very simple way. If a ghost wants to move from cell to cell , it will repeat the following procedure until it reaches its destination or fails:
- If the ghost can decrease the distance along the axis (i.e. ) it will do so by moving one cell along the axis;
- otherwise if it can decrease the distance along the axis (i.e. ) it will do so by moving one cell along the axis;
- otherwise if it can decrease the distance along the axis (i.e. ) it will do so by moving one cell along the axis;
- otherwise it fails.
Alessandro has three arrays , and indexed from to that describe the coordinates of the free cells.
He is wondering whether the strategy above is smart enough to control the ghosts.
Help him by writing a program that determines whether for every pair of cells and a ghost will succeed in reaching cell starting from cell !
Input data
The input file consists of:
- a line containing integer .
- a line containing the integers .
- a line containing the integers .
- a line containing the integers .
Output data
The output file must contain a single line consisting of YES
if ghosts will always succeed in reaching their destinations or NO
otherwise.
Constraints and clarifications
- .
- for each .
# | Points | Constraints |
---|---|---|
1 | 0 | Examples. |
2 | 18 | and |
3 | 19 | and |
4 | 24 | |
5 | 22 | |
6 | 17 | No additional limitations. |
Example 1
stdin
4
0 0 1 1
0 1 1 2
0 0 0 0
stdout
YES
Explanation
In the first sample case, ghosts can always reach their destination.
For example, a ghost can move from cell to cell following path .
Example 2
stdin
8
0 1 2 2 2 1 0 0
0 0 0 1 1 1 1 0
0 0 0 0 1 1 1 1
stdout
NO
Explanation
In the second sample case, ghost can't move from cell to cell .
Example 3
stdin
5
0 0 1 1 2
0 1 1 0 2
0 0 0 0 2
stdout
NO