#P7316. Grass Restoration in a Wheat Field Under UFO Attacks

    ID: 20515 Type: Default 1000ms 256MiB

Grass Restoration in a Wheat Field Under UFO Attacks

Grass Restoration in a Wheat Field Under UFO Attacks

Given an $N \times M$ rectangular wheat field where every cell initially contains $1$ unit of grass, a circular UFO lands over the field on each of $K$ days. On the $i$-th day, a UFO lands at position $(X_i, Y_i)$ with a radius $R_i$, and clears the grass in every cell that satisfies $$ (X_i - x)^2 + (Y_i - y)^2 \le R_i^2. $$ At the beginning of a new day, every cell’s grass quantity increases by $1$ unit. Determine the sum of all grass amounts in the field on the evening of the $K$-th day.

inputFormat

The first line contains three integers $N$, $M$, and $K$, representing the number of rows, columns, and days respectively.

Each of the next $K$ lines contains three integers $X_i$, $Y_i$, and $R_i$, indicating that on the $i$-th day a UFO lands at cell $(X_i, Y_i)$ with radius $R_i$. It is guaranteed that $1 \le X_i \le N$ and $1 \le Y_i \le M$.

outputFormat

Output a single integer — the sum of the grass amounts in all cells on the evening of the $K$-th day.

sample

3 3 1
2 2 1
4