Puzzle

시간 제한2초메모리 제한1024 MB

문제

Once a puzzle has been gifted to Taja, and she still has no idea how to solve it.

The puzzle is a grid $n \times n$, with each row and each column containing exactly one separator, which is diagonal segment which starts in upper left corner and ends at lower right corner. Puzzle has a launch button, which launches the balls at integer time moments from the tubes, which are positioned at the boundary of the grid. Per one moment a ball moves to an adjacent cell. When a ball collides a separator it changes direction by $90^\circ$. A ball disappears if it crosses border line.

To solve a puzzle, one needs to rotate some separators $90^\circ$ around their centers, in such a way that no two balls will ever collide inside the grid.

Two balls collide if:

  1. They are at the same cell at the same moment (if the cell contains separator, then both balls should be at the same side).

  1. They collided at the cells' boundary (boundary of the whole grid counts as well).

In this problem you are to find any solution of this puzzle.

입력

First line of input contains single integer $n$ ($1 \leq n \leq 500$) --- grid size.

Second line contains $n$ integers ($1 \leq c_i \leq n$) --- column number of $i$th separator, which has $i$ as a row number. All column numbers are different.

Third line conatins single integer $m$ ($1 \leq m \leq 10^4$) --- number of balls.

Each of the following $m$ lines contains $3$ integers $x_i$, $y_i$, $t_i$ ($0 \leq t_i \leq 10^8$), describing moments of balls' launches --- at the moment $t_i$ a ball will appear at $(x_i, y_i)$ cell, which shares common side with the boundary of the grid. Moments are given in non-decreasing order of $t_i$. Coordinates ($x_i, y_i$) can be at one of the four following areas:

  1. $x_i = 0$, $1 \leq y_i \leq n$;
  2. $1 \leq x_i \leq n$, $y_i = 0$;
  3. $x_i = n + 1$, $1 \leq y_i \leq n$;
  4. $1 \leq x_i \leq n$, $y_i = n + 1$.

It is guaranteed that solution always exists.

출력

Output should contain single line of $0$ and $1$. $i$th symbol is $0$, if $i$th separator doesn't require rotation, $1$ --- otherwise.

힌트

Below are shown sample positions of the balls along the time.

0123
4567