Insects

아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

MianKing is playing a game. In this game, he has nn insects, and each insect has two integer attributes: type and level. The type and level of the ii-th insect are type_i\mathit{type}\_i and level_i\mathit{level}\_i, respectively.

Initially, each of these nn insects has a "seed"  buff. When an insect with a "seed" buff is eliminated, let LL denote the highest level among the remaining insects (with the seed buff or not) of the same type as the eliminated insect. Then MianKing can choose an integer type DD from \[1,n]\[1, n] arbitrarily and add a new insect of type DD and level LL. And this new insect does not have the "seed" buff.

Notice that if there are no other insects of the same type as the eliminated insect, no new insect can be added.

Now MianKing wants to maximize the total level of all insects on the field by eliminating some insects. The total level is the sum of levels of individual insects. You need to help him to calculate ans_K\mathit{ans}\_K, the maximum total level that he can get by eliminating at most KK insects.

입력

The first line has one integer nn (1n1051 \leq n \leq 10^5).

Then there are nn lines, where the ii-th line contains two integers type_i\mathit{type}\_i and level_i\mathit{level}\_i (1type_in1 \leq \mathit{type}\_i \leq n, 1level_i1071 \leq \mathit{level}\_i \leq 10^7).

출력

Output nn lines, such that the ii-th line has one integer ans_i\mathit{ans}\_i.