Illumination

Given lamps on an n by n grid, decide whether each lamp can point along its row or column so that no cell gets same-direction light from two lamps.

Medium7GraphUnion-findMathImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

You inherited a haunted house. Its floor plan is an n×nn \times n square grid with no interior walls, and ll lamps sit at fixed cells.

Each lamp lights either the row it stands in or the column it stands in, never both at once. The light reaches rr cells in both directions along the chosen line, so a lamp that no exterior wall blocks lights as many as 2r+12r + 1 cells, counting its own.

If one cell is lit by two lamps that both light a row, or by two lamps that both light a column, the bright spot drives the ghosts away for good and your property loses value. A cell lit by one lamp that lights a row together with one lamp that lights a column causes no trouble.

Decide whether every lamp can be given a row or a column without driving the ghosts away.

Input

The first line contains three positive integers nn, rr and ll (1n,r,l10001 \le n, r, l \le 1000).

Each of the next ll lines contains two positive integers rir_i and cic_i (1ri,cin1 \le r_i, c_i \le n), meaning that a lamp stands in row rir_i and column cic_i.

All lamp positions are distinct.

Output

Print 1 on a single line if such an assignment exists, and 0 otherwise.