Under construction

Still being built. Things may change

Vitcoin Lottery at Moloco (Easy)

Interview

Time limit2sMemory limit512 MB

Summary
Order n tickets with prizes w_i and continuation probabilities p_i to maximize the expected sum of collected prizes, breaking ties by the lexicographically smallest permutation.
Level

Medium6 of 10

Topics
Greedy, Sorting, Math, Probability
Solved
No attempts yet

Problem

At the end of every month Moloco runs a simple lottery for extra employee perks.

You receive nn lottery tickets, and ticket ii pays a prize of wiw_i Vitcoins (wi>0w_i > 0).

Each ticket is paired with its own coin. The coin of ticket ii comes up heads with probability pip_i and tails with probability 1−pi1 - p_i (0<pi<10 < p_i < 1). All coin flips are independent.

At each step you choose one ticket you have not chosen yet and claim its prize immediately. Then you flip the coin paired with that ticket. On heads the lottery continues and you choose another ticket, repeating until you run out of tickets. On tails the lottery ends at once and you keep every Vitcoin you have collected so far.

You know all values wiw_i and pip_i. Find an order of picking the tickets that maximizes the expected number of Vitcoins you win.

Input

The first line contains an integer nn (1≤n≤10001 \le n \le 1000).

Each of the next nn lines contains two integers wiw_i and qiq_i (1≤wi≤100001 \le w_i \le 10000, 0<qi<100000 < q_i < 10000). The probability is defined as pi=qi/10000p_i = q_i / 10000.

Output

Print, on a single line, the permutation that describes the order in which you pick the tickets. The permutation has length nn, consists of the integers from 11 to nn, and its entries are separated by single spaces.

If several permutations maximize the expected number of Vitcoins, print the one that comes first lexicographically, so the smaller index must come earlier.

Note

Picking the tickets in the order π\pi wins the following expected number of Vitcoins.

∑k=1nwπk∏j<kpπj\sum_{k=1}^{n} w_{\pi_k} \prod_{j < k} p_{\pi_j}

In the first example the order (1,2,3)(1, 2, 3) has expectation 2+0.3×5+0.15×7=4.552 + 0.3 \times 5 + 0.15 \times 7 = 4.55. The order (2,3,1)(2, 3, 1) maximizes the expectation at 8.78.7.

In the third example the orders (2,3,1)(2, 3, 1) and (3,2,1)(3, 2, 1) have the same expectation, and (2,3,1)(2, 3, 1) comes first lexicographically.

Examples5

  1. Example 1

    Input
    3
    2 3000
    5 5000
    7 2000
    
    Expected output
    2 3 1
    
  2. Example 2

    Input
    3
    3 5000
    5 1500
    7 2000
    
    Expected output
    3 1 2
    
  3. Example 3

    Input
    3
    1 4000
    1 5000
    1 5000
    
    Expected output
    2 3 1
    
  4. Example 4

    Input
    1
    10000 9999
    
    Expected output
    1
    
  5. Example 5

    Input
    5
    7 3000
    7 3000
    7 3000
    7 3000
    7 3000
    
    Expected output
    1 2 3 4 5