Lottery for Vitcoins at Moloco (Hard)

Order the tickets to maximize the expected sum of prizes, where ticket i stops the lottery with probability 1 - p_i, and break ties by the lexicographically smallest permutation.

Medium7GreedySortingMathProbabilityNo attempts yetTime limit2sMemory limit512 MB

Problem

At the end of each month, Moloco employees take part in a simple lottery for extra employee perks.

As a valuable employee of Moloco, you receive nn lottery tickets. Ticket ii pays a prize of wi>0w_i > 0 Vitcoins.

Each ticket ii is also paired with a coin. That coin flips heads with probability pip_i and tails with probability 1pi1 - p_i, where 0<pi<10 < p_i < 1. Every coin flip is independent.

At each step you choose a ticket among those 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 pick another ticket, and this repeats until you run out of tickets. On tails the lottery ends immediately, and you keep all the Vitcoins you have collected so far.

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

Input

The first line contains one integer nn (1n10000001 \le n \le 1\,000\,000).

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

Output

Print, on a single line and separated by spaces, a permutation of length nn whose elements are the integers from 11 to nn. It describes the order in which you pick the lottery tickets.

If several permutations maximize the expected number of Vitcoins, print the one that comes first lexicographically.

Note

The expected number of Vitcoins for the order σ1,σ2,,σn\sigma_1, \sigma_2, \dots, \sigma_n is k=1nwσkj<kpσj\sum_{k=1}^{n} w_{\sigma_k} \prod_{j < k} p_{\sigma_j}.

In the first example the order (1,2,3)(1, 2, 3) yields 4.554.55, and the maximum is 8.78.7, reached by the order (2,3,1)(2, 3, 1). In the third example the orders (2,3,1)(2, 3, 1) and (3,2,1)(3, 2, 1) yield the same expectation, and (2,3,1)(2, 3, 1) comes first lexicographically.