Pac-Man

Time limit: 3s Memory limit: 256MB Input: Output:

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 AA to cell BB, it will repeat the following procedure until it reaches its destination or fails:

  • If the ghost can decrease the distance along the xx axis (i.e. AxBx|A_x - B_x|) it will do so by moving one cell along the xx axis;
  • otherwise if it can decrease the distance along the yy axis (i.e. AyBy|A_y - B_y|) it will do so by moving one cell along the yy axis;
  • otherwise if it can decrease the distance along the zz axis (i.e. AzBz|A_z - B_z|) it will do so by moving one cell along the zz axis;
  • otherwise it fails.

Alessandro playing a classic game of Pac-Man.\text{Alessandro playing a classic game of Pac-Man.}

Alessandro has three arrays XiX_i, YiY_i and ZiZ_i indexed from 00 to N1N-1 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 AA and BB a ghost will succeed in reaching cell BB starting from cell AA!

Input data

The input file consists of:

  • a line containing integer NN.
  • a line containing the NN integers X0,,XN1X_{0}, \, \ldots, \, X_{N-1}.
  • a line containing the NN integers Y0,,YN1Y_{0}, \, \ldots, \, Y_{N-1}.
  • a line containing the NN integers Z0,,ZN1Z_{0}, \, \ldots, \, Z_{N-1}.

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

  • 1N100 0001 \le N \le 100 \ 000.
  • 0Xi,Yi,Zi<100 0000 \le X_i, Y_i, Z_i < 100 \ 000 for each i=0N1i=0 \ldots N-1.
# Points Constraints
1 0 Examples.
2 18 N100N \le 100 and Xi,Yi,Zi<100X_i, Y_i, Z_i < 100
3 19 N7500N \le 7500 and Xi,Yi,Zi<100X_i, Y_i, Z_i < 100
4 24 Zi=0Z_i = 0
5 22 Xi,Yi,Zi<100X_i, Y_i, Z_i < 100
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 A=(0,0,0)A = (0, 0, 0) to cell B=(1,2,0)B = (1, 2, 0) following path (0,0,0)(0,1,0)(1,1,0)(1,2,0)(0, 0, 0) \rightarrow (0, 1, 0) \rightarrow (1, 1, 0) \rightarrow (1, 2, 0).

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 A=(1,0,0)A = (1, 0, 0) to cell B=(1,1,1)B = (1, 1, 1).

Example 3

stdin

5
0 0 1 1 2
0 1 1 0 2
0 0 0 0 2

stdout

NO

Log in or sign up to be able to send submissions!