Under construction

Still being built. Things may change

Countries

Time limit1sMemory limit128 MB

Summary
For each city, compute which other city exerts the strongest gravity-like influence on it, then label it king, democracy, or trace the chain of surrender to find its ultimate capital.
Level

Medium4 of 10

Topics
Simulation, Math, Implementation
Solved
No attempts yet

Problem

This problem explores how mighty countries arise from humble beginnings. Consider a two-dimensional map. On the map there are nn cities. Each city ii sits at a distinct location with integer coordinates (xi,yi)(x_i, y_i) and holds a garrison of sis_i soldiers commanded by a general.

The influence that city ii exerts on a location (x,y)(x, y) equals sis_i divided by the squared distance between (xi,yi)(x_i, y_i) and (x,y)(x, y) — as if the mass of soldiers in city ii pulled on every surrounding location like gravity.

City ii is threatened by another city jj when the influence city jj exerts on city ii's own location (xi,yi)(x_i, y_i) is strictly greater than sis_i; then city jj could send enough soldiers to overpower every defender of city ii.

  • If no other city threatens city ii, its grateful citizens crown its general as king and make the city the capital of his kingdom.
  • If exactly one threatening city jj exerts strictly more influence on (xi,yi)(x_i, y_i) than every other city, city ii has no choice but to surrender. From then on city ii obeys the same capital that city jj obeys (its sis_i soldiers do not join anyone's army).
  • Otherwise city ii is saved by the mutual distrust of two or more equally strongest threateners: whichever attacked first would in turn be overpowered by the others. But because its general failed to keep the city safe, the citizens cannot crown him; instead the city becomes the capital of a democracy.

For every city, report which of the three outcomes applies.

Input

The first line contains one integer nn (1≤n≤10001 \le n \le 1000), the number of cities. Each of the next nn lines describes one city: line i+1i+1 contains three integers xix_i, yiy_i, sis_i (0≤xi,yi,si≤10000 \le x_i, y_i, s_i \le 1000) separated by single spaces. All cities occupy distinct locations.

Output

Print nn lines. Line ii gives the outcome for city ii:

  • K if city ii is the capital of a kingdom.
  • D if city ii is the capital of a democracy.
  • Otherwise the index jj (1≤j≤n1 \le j \le n) of the city that city ii ultimately obeys as its capital, following the chain of surrenders.

Note

Consider the map below, where each dot is a city and its number of soldiers is written above it:

Number the five cities from top to bottom, then left to right. City 3 at (3,2)(3, 2) is the capital of a kingdom that also contains city 4 at (1,1)(1, 1) and city 5 at (2,1)(2, 1). City 1 at (2,5)(2, 5) forms a kingdom by itself, and city 2 at (2,3)(2, 3) forms a democracy by itself.

Examples5

  1. Example 1

    Input
    5
    2 5 14
    2 3 2
    3 2 7
    1 1 2
    2 1 3
    
    Expected output
    K
    D
    K
    3
    3
    
  2. Example 2

    Input
    1
    5 5 10
    
    Expected output
    K
    
  3. Example 3

    Input
    2
    0 0 1
    0 1 100
    
    Expected output
    2
    K
    
  4. Example 4

    Input
    2
    0 0 5
    0 1 5
    
    Expected output
    K
    K
    
  5. Example 5

    Input
    3
    1 0 1
    0 0 10
    2 0 10
    
    Expected output
    D
    K
    K