Land Division#184

Land Division

1 second
64 megabytes
Medium
prb184

The war between the orcs and the Alliance forces ended in a decisive victory for the Horde. Lordaeron lies in ruins—bloodthirsty orc hordes, led by Orgrim Doomhammer, swept through the provinces of Lordaeron and the dwarven kingdom of Khaz Modan, leaving destruction behind. Now, the lands of Azeroth are ruled by the Horde. At last, the time has come to divide the conquered lands among the clans of the Horde. The generals, representing different clans, have gathered around a map, drawing straight lines that will become the boundaries of new administrative regions.

Your task is to write a program to determine how many distinct lands (regions) these lines create on the map of Lordaeron.

Input

The first line contains the dimensions of the map, and (the bottom-left corner is at coordinates , and the top-right corner is at (W, H)), and the number of lines drawn, (1 \leq W, H \leq 100, 1 \leq N \leq 1000). Each of the next lines contains three integers , , and — the coefficients for the equation of a line a x + b y + c = 0 (-1000 \leq a, b \leq 1000, -10^6 \leq c \leq 10^6, |a| + |b| \neq 0). All numbers in the input are integers.

Output

Output the number of distinct lands (regions) formed on the map.

Examples

Example 1

Loading
Loading