Color Balls

No attempts yetTime limit1sMemory limit256 MB

Problem

Jihoon plays a computer game with several players in it. Each player controls one ball that has a fixed color and a fixed size. A player scores by capturing a ball that is strictly smaller than their own ball and has a different color, and the score gained is the size of the captured ball. A ball of the same size cannot be captured even when its color differs. Capturing another ball does not change the color or the size of your own ball.

Consider four balls. Colors are written as numbers for convenience.

BallColorSize
1110
2315
313
448

Ball 2 captures all three other balls. Ball 1 cannot capture ball 2, which is larger, and cannot capture ball 3, which has the same color, so it captures only ball 4.

Given the color and the size of every ball, print for each player the total size of all balls that player can capture.

Input

The first line contains the number of balls NN (1N2000001 \le N \le 200\,000).

Each of the next NN lines contains the color CiC_i and the size SiS_i of the ii-th ball, separated by a space (1CiN1 \le C_i \le N, 1Si20001 \le S_i \le 2\,000). Several balls may share a color, and several balls may share a size.

Output

Print NN lines. The ii-th line contains the total size of all balls that the player controlling the ii-th ball can capture.