Under construction

Still being built. Things may change

Serious Cow Tag

Time limit1sMemory limit128 MB

Summary
Simulate the elimination game where each active cow tags her nearest remaining cow, and report the last cow standing.
Level

Easy3 of 10

Topics
Simulation, Geometry, Implementation, Array
Solved
No attempts yet

Problem

Farmer John's NN cows (1≤N≤10001 \le N \le 1000), numbered 11 through NN, are playing a game called Serious Cow Tag. Each cow stands on a distinct grid point in the pasture with integer coordinates satisfying −7500≤X≤7500-7500 \le X \le 7500 and −7500≤Y≤7500-7500 \le Y \le 7500. The positions are chosen so that the distances between every pair of cows are all different.

The cows take turns in order: cow 11 first, then cow 22, then cow 33, and so on. After cow NN the order wraps back to cow 11 and repeats. A cow that has already been tagged is skipped and never takes a turn again.

On her turn, the active cow looks at every cow still in the game, walks to the closest one, tags her, and returns to her own spot. The tagged cow is immediately out of the game. Because all pairwise distances are distinct, the closest remaining cow is always unique.

The game continues until only one cow is left; that cow is declared the winner.

Farmer John wants to know the winner in advance. Given the cows' positions, determine which cow wins.

Input

  • The first line contains a single integer NN, the number of cows.
  • Each of the next NN lines contains two space-separated integers XX and YY, the coordinates of cow ii (for ii from 11 to NN).

Output

  • Print a single line containing the number of the winning cow.

Hint

With three cows, cow 11 goes first and tags her nearest neighbor, cow 22, who is eliminated and therefore never takes a turn. Cow 33 then tags the only other remaining cow, cow 11. Cow 33 is the last one standing, so she wins.

Examples3

  1. Example 1

    Input
    3
    0 0
    0 3
    4 3
    
    Expected output
    3
    
  2. Example 2

    Input
    1
    100 -100
    
    Expected output
    1
    
  3. Example 3

    Input
    4
    0 0
    2 0
    0 50
    3 50
    
    Expected output
    1