URI Online Judge | 3090


By Guilherme Londe, PUC Goiás BR Brazil

Timelimit: 1

An epic battle between two armies is about to start. Both armies are distributed in a battlefield and are separated by a river that crosses the field.

The field is a rectangle of length n and width m. The river is a line segment with extremities on points (0, 0) and (nm) and its thickness should be neglected. A soldier is defined by his skill hi and the coordinates xi and yi of his initial location. A soldier belongs to the first army if he is located above the river, i.e. is inside the triangle {(0, 0), (0, m), (nm)}, otherwise he belongs to the second army. It is guaranteed that no soldier is on the river at the initial moment.

The skill level of an army is the sum of the skills of all soldiers that belongs to this army. Write a program that, given the descriptions of the field and the soldiers, prints the skill level of both armies.


The first line of the input contains three integers n, m and s (1 ≤ n, m ≤ 109, 0 ≤ s ≤ 105), where n and m means the length and the width of the field, respectively, and s is the number of soldiers on the field at the initial moment. Each of the next s lines contains three integers, where the i-th line contains the values xi, yand hi (0 ≤ x≤ n; 0 ≤ yi ≤ m; 0 ≤ hi ≤ 104).


Print a line that contains two integers: the skill level of the first army followed by the skill level of the second army, both separated by a whitespace.

Input Samples Output Samples

3 2 3
0 1 3
1 1 4
2 1 2

7 2

5 9 7
4 8 3
3 0 5
0 8 4
2 4 2
2 3 6
4 7 9
5 8 1

9 21