Under construction

Still being built. Things may change

Communication Stations

Time limit1.5sMemory limit1024 MB

Summary
Count the lattice points in an N by M map that lie within Manhattan distance p_i of at least one of K stations.
Level

Medium6 of 10

Topics
Prefix sum, Geometry, Implementation
Solved
No attempts yet

Problem

The Republic of Korea Air Force installed communication stations at several locations so that it could communicate smoothly with fighter jets in flight and with ground units. So far, KK stations have been placed. Station ii sits at (yi,xi)(y_i, x_i) and emits a signal with strength pip_i. Any fighter jet at an integer lattice point (y,x)(y, x) that satisfies ∣yi−y∣+∣xi−x∣≤pi|y_i - y| + |x_i - x| \leq p_i can communicate with that station. When signals from different stations overlap, each keeps its original strength.

Given the map height NN, the map width MM, and the positions and strengths of the KK stations, count the integer lattice points (y,x)(y, x) inside the map where a fighter jet can communicate with at least one station.

Input

The first line contains three integers NN, MM, and KK, separated by spaces. (1≤N,M≤30001 \leq N, M \leq 3000, 1≤K≤3000001 \leq K \leq 300000)

From line 2 to line K+1K+1, each line contains three integers yiy_i, xix_i, and pip_i, separated by spaces, which are the row position, column position, and signal strength of station ii. (1≤yi≤N1 \leq y_i \leq N, 1≤xi≤M1 \leq x_i \leq M, 1≤pi≤30001 \leq p_i \leq 3000)

No two stations share the same position.

Output

Print the number of integer lattice points inside the map where a fighter jet can communicate with at least one station.

Examples1

  1. Example 1

    Input
    6 7 4
    2 6 2
    3 3 1
    6 1 3
    5 6 2
    
    Expected output
    35