Time limit
2s
Memory limit
64 MB
Dasom likes to go out onto the terrace every snowy morning and leave footprints. The teaching assistant wakes up late and can only guess who walked where by looking at the footprints that remain. One morning, the assistant wanted to find Dasom's trail, but many students had already crossed the terrace, so separating the traces was difficult.
One thing is certain: every student walks in a straight line, and the distance between consecutive steps of the same student is constant.



As shown above, the students, including Dasom, may have different directions and different stride lengths.

Students enter from outside the terrace, follow one straight line, and step on the snow at a fixed stride.
![]() | ![]() |
| Figure 3 | Figure 4 |
As in Figure 3, several students may enter from different directions and pass through in different directions. Multiple students may also step on the same cell. The assistant who overslept can see only the final footprint pattern, as in Figure 4.
From the state in Figure 4, it is still possible to reconstruct how many students entered, and for each student, the direction and stride with which they left footprints. However, consider only routes that leave at least three footprints on the snow. In Figure 4, one possible reconstruction has the three student routes shown in Figure 3. Other reconstructions may also be possible.
A vertical route starting from the first column could be a student's route with stride 4, but it is ignored because it contains only two footprints. Also, the points at row 2 column 3, row 3 column 4, and row 6 column 7 lie on one straight line and contain three footprints, but their gaps are not equal, so they are not accepted as one student's route.
Other students' footprints may lie on the same line as a student's route. For example, in the figure above, (2, 1), (2, 3), (2, 5), and (2, 7) form one student's route, while (2, 6) on the same line may have been left by another student. Some footprints may even be old traces from a previous snowfall rather than footprints left this time.
Dasom is known to leave the most footprints. Given the final state, find the maximum number of footprints in a route that could be attributed to Dasom. For Figure 4, the answer is 7, because a student who stepped on all seven cells horizontally along the sixth row can be considered Dasom.
The first line contains two integers R and C, the number of rows and columns of the terrace. (1 ≤ R, C ≤ 5000)
The second line contains an integer N, the number of cells that contain footprints. (3 ≤ N ≤ 5000)
Each of the next N lines contains one footprint coordinate. Each line has two integers separated by a space: the row coordinate and the column coordinate. The coordinates are at least 1 and at most R and C respectively. Even if several students stepped on the same cell, that coordinate appears only once.
Output the largest number of footprints in any route that could be attributed to Dasom. If no student route satisfies the conditions, output 0.