problems / 111

One Shot Through the Origin

easy geometry hashing math 1000 ms · 256 MB

One Shot Through the Origin

Alice is standing at the origin of an infinite practice range with a laser pointer. When she picks a direction and fires, the beam travels as a full straight line through the origin — it shoots out both forwards and backwards, hitting every target that lies anywhere on that line (on either side of her).

There are n targets scattered around the range, given by their integer coordinates. A target standing exactly at the origin is hit no matter which direction Alice fires in, since the line always passes through her feet.

Bob challenges Alice to line up as many targets as possible with a single shot. Help Alice find the largest number of targets that one shot (one line through the origin) can hit.

Input

The first line contains one integer n (1 ≤ n ≤ 2·10^5) — the number of targets.

Each of the next n lines contains two integers x_i and y_i (-10^9 ≤ x_i, y_i ≤ 10^9) — the coordinates of a target. Several targets may share the same coordinates, and several targets may be at the origin.

Output

Print a single integer — the maximum number of targets Alice can hit with one shot.

Notes

In the first example, the targets at (1, 1), (2, 2) and (-1, -1) all lie on the same line through the origin (the beam hits (1, 1) and (2, 2) going one way and (-1, -1) going the other way), and the target at (0, 0) is hit by every shot, for a total of 4. The remaining target, (3, 1), lies on a different line and cannot be added.

Watch out for direction keys that only normalize the sign, not the magnitude, or only the magnitude, not the sign: (2, 4), (-1, -2) and (1, 2) all describe the very same line through the origin and must be counted together.

Example 1

Input

5
0 0
1 1
2 2
-1 -1
3 1

Output

4

Example 2

Input

5
2 4
-1 -2
3 -6
-2 4
5 0

Output

2

Hints · reveal one at a time if you're stuck

Hint 1

Targets at the origin lie on every line, so count them separately and add them to the best direction. For the rest, two points share a line through the origin exactly when their coordinates are proportional.

Hint 2

Give each non-origin target a canonical direction key using integer arithmetic: divide both coordinates by their gcd, then fix the sign so that opposite directions get the same key. Count keys with a hash map and take the largest count, handling zero coordinates in the gcd.

report an issue Prefer your own editor? sooks prep 111 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.