MianKing is playing a game. In this game, he has n insects, and each insect has two integer attributes: type and level. The type and level of the i-th insect are type_i and level_i, respectively.
Initially, each of these n insects has a "seed" buff. When an insect with a "seed" buff is eliminated, let L 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 D from \[1,n] arbitrarily and add a new insect of type D and level L. 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, the maximum total level that he can get by eliminating at most K insects.
The first line has one integer n (1≤n≤105).
Then there are n lines, where the i-th line contains two integers type_i and level_i (1≤type_i≤n, 1≤level_i≤107).
Output n lines, such that the i-th line has one integer ans_i.