Land Division
The war between the orcs and the Alliance forces has concluded with a decisive victory for the Horde. Lordaeron is in ruins, as Orgrim Doomhammer's bloodthirsty orc hordes have ravaged the provinces of Lordaeron and the dwarven kingdom of Khaz Modan, leaving destruction in their path. Now, the lands of Azeroth are under Horde control. It is time to allocate the conquered territories among the Horde clans. The generals, representing different clans, are gathered around a map, drawing straight lines to establish the boundaries of the new administrative divisions.
Your task is to write a program that determines how many separate lands these lines will create on the map of Lordaeron.
Input
The first line of the input file provides the dimensions of the map, W and H (where the bottom-left corner is at coordinates (0,0) and the top-right corner is at (W,H)), along with the number of lines drawn, N (1 ≤ W,H ≤ 100, 1 ≤ N ≤ 1000). Each of the following N lines contains the coefficients a, b, c for the equation of the corresponding line ax+by+c=0 (−1000 ≤ a,b ≤ 1000, −10^6 ≤ c ≤ 10^6, and |a|+|b|≠0). All numbers in the input are integers.
Output
The output file should contain the number of distinct lands formed on the map.