The Saracen Defence

5

1 votes
Medium
Problem

The Saboteurs have cemented their places in the mighty Saracen’s Army. The Saracens are under attack by the Byzantines and the King of the Saracens requires your help to defend his territory. He gives you the following task:-

Consider the infinite 2-D plane with X and Y axes. You are given N distinct integer points such that each one of them lies either on X axis or Y axis. You are also given K other distinct integer points that do not lie on either of the axes. A line segment joining any two points among the N + K points is said to be valid if both the end points do not lie on the same axis, i.e, both end points cannot lie on X axis or both end points cannot lie on Y axis. All other combinations of the end points are considered valid. Your task is to print the maximum number of integer points (including the end points) through which any valid line segment passes.

What are you waiting for? Defend your territory!

Input Format

The first line contains two space separated integers N and K as described in the problem statement. The next N + K lines contain two space separated integers x and y denoting the coordinates. It is guaranteed that either x or y is 0 for the first N points. It is also guaranteed that neither x nor y is 0 for the next K points. Note that the origin will not be given as a point in the input.

Output Format

Print a single integer denoting the answer.

Constraints

1KN

1NK106

106x,y106

Note that the origin will not be given as a point in the input.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

There are 3 valid line segments.

The line segment joining the points (3, 0) and (1, 1) does not pass through any intermediate integer points. The line segment joining the points (0, 3) and (1, 1) does not pass through any intermediate integer points. So the answer for each of those line segments is 2.

The line segment joining the points (3, 0) and (0, 3) passes through (2, 1) and (1, 2). Hence, the answer for this line segment is 4.

The maximum among {2, 2, 4} is 4. Hence, the answer.

Editor Image

?