Under construction

Still being built. Things may change

Laser Trap

Time limit2sMemory limit1024 MB

Summary
Find the fewest generators to remove so that the origin lies outside the convex hull of the remaining points.
Level

Medium6 of 10

Topics
Geometry, Sorting, Two pointers
Solved
No attempts yet

Problem

BaoBao is playing the famous game Elden Ring these days. It is an open-world game in which you control your character to travel between places. However, your character can also fall into a trap, and you need to figure out how to escape. Right now, BaoBao's character is stuck in a 2-dimensional plane with deadly lasers. There are nn laser generators, and each generator is a point. Every pair of generators shoots a laser beam between them, so there are n(n−1)2\frac{n(n-1)}{2} beams in total. Each beam starts and ends at generator points and does not extend to infinity.

Starting at (0,0)(0, 0), BaoBao wants to escape to (1010101010,1010101010)(10^{10^{10^{10^{10}}}}, 10^{10^{10^{10^{10}}}}) without touching any laser beam or generator. To do so, BaoBao can ask her friend DreamGrid to remove any number of generators, along with every beam that starts or ends at a removed generator. Find the minimum number of generators that must be removed for the escape. BaoBao does not need to move in a fixed direction, and her escape route can be a curve if needed.

Input

There are multiple test cases. The first line contains an integer TT, the number of test cases. Each test case is given as follows.

The first line contains an integer nn (1≤n≤1061 \le n \le 10^6), the number of laser generators. The next nn lines contain two integers xix_i and yiy_i (−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9), the location of the ii-th generator.

No two generators coincide, and no laser beam or generator touches (0,0)(0, 0). The sum of nn over all test cases does not exceed 10610^6.

Output

For each test case, output one line containing the minimum number of generators that must be removed.

Hint

The figures for the second and third test cases are shown below. Solid dots and solid lines are the remaining generators and beams. Hollow dots and dashed lines are the removed generators and beams. The arrow is the escape route.

Examples1

  1. Example 1

    Input
    3
    2
    1 0
    2 0
    3
    1 0
    0 1
    -1 -1
    5
    2 -1
    1 2
    -1 2
    -2 -1
    0 -2
    
    Expected output
    0
    1
    2