Strange Antennas

No attempts yetTime limit5sMemory limit256 MB

Problem

The president wants to survey the whole country. The territory is a grid of n×nn \times n cells, and every corner of a cell is a grid point. Rows and columns of grid points are numbered from 00 to nn. The president can install an antenna at any grid point.

An antenna sends a signal in one of four directions: south-east, south-west, north-east, north-west. The signal covers an isosceles right triangle. Its right angle sits at the grid point of the antenna, and the two equal sides run along the vertical component and the horizontal component of that direction, each with a length equal to the power pp of the antenna. The two sides of a south-east antenna, for example, run south and east from the antenna.

A cell counts as covered by a signal when the triangle overlaps it in a region of positive area. Touching only at a corner or along an edge is not coverage.

These antennas are strange. When two signals overlap in a cell, they cancel each other. A cell is surveyed only when the number of signals covering it is odd.

Given the aa antennas that are already installed, count the surveyed cells.

Consider n=10n = 10 with two antennas. Antenna X stands at row 00, column 00 and sends a signal of power 44 to the south-east. Antenna Y stands at row 11, column 55 and sends a signal of power 44 to the south-west.

x x x x - - - - - -
x o o y y - - - - -
x x y y y - - - - -
x - - y y - - - - -
- - - - y - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -

Here x is a cell covered by X only, y is a cell covered by Y only, and o is a cell where the two signals cancel. 16 cells are surveyed.

Input

The first line contains nn, the number of cells along one side of the grid. The second line contains aa, the number of antennas. Each of the next aa lines contains the row position, the column position, the power pp, and the direction of one antenna, separated by spaces. The direction is 00 for south-west, 11 for south-east, 22 for north-east, 33 for north-west.

0<n300000 < n \le 30000, 0a1000 \le a \le 100, 0<p2n0 < p \le 2n, and the row and column positions are integers between 00 and nn.

Output

Print the number of surveyed cells on one line.