A kunai (a throwing blade) is a finely made, dagger-like weapon used by ninjas, who attack by throwing it at their enemies.
There is a grid of $H$ rows and $W$ columns of unit squares, holding $N$ ninjas. Every ninja stands at the center of a square, and each square holds at most one ninja. Each ninja carries one kunai and faces one of four directions: right, up, left, or down. At time $0$, every ninja throws its kunai in the direction it is facing.
Every kunai flies in a straight line at a speed of one square per unit of time. If more than one kunai arrives at the same point at the same instant, those kunai collide and disappear. A kunai is small enough that its size can be ignored. The ninjas move so fast that they are never hit by a kunai. Unless it collides with another kunai, a kunai keeps moving in the same direction at the same speed and never slows down. Note that a collision may happen partway between two squares, not only at a square's center.
After enough time has passed, count how many of the $W \times H$ squares have been passed through by at least one kunai.
The first line contains two integers $W$ and $H$, separated by a single space, giving the size of the grid ($1 \le W \le 10^9$, $1 \le H \le 10^9$).
The second line contains one integer $N$, the number of ninjas ($1 \le N \le 10^5$).
Each of the next $N$ lines contains three integers $X_i$, $Y_i$, $D_i$ describing ninja $i$, who stands in the $X_i$-th column from the left and the $Y_i$-th row from the top ($1 \le X_i \le W$, $1 \le Y_i \le H$). No two ninjas occupy the same square. The direction ninja $i$ faces is given by $D_i$:
Print the number of squares of the $W \times H$ grid that have been passed through by a kunai after enough time has passed.
Take the sample input. Let "kunai $i$" be the kunai thrown by ninja $i$. At time $0.5$, kunai $2$ and kunai $3$ meet between their squares and disappear. At time $2$, kunai $1$ and kunai $5$ collide and disappear. After time $2$ there are no further collisions. In the end, exactly $11$ squares have been passed through by a kunai, so the answer is $11$.