K. Another Ordering Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kyousuke is ordering sushi for Kirino. Sushi is free, but toppings cost money. The menu has $$$n$$$ toppings, each represented with a number $$$i$$$, where $$$i$$$ is a number from $$$1$$$ to $$$n$$$. Each topping has some price $$$a_i$$$. However, Kirino has a rule for each topping, where if Kyousuke orders some topping $$$i$$$ on the sushi he can't put some other topping $$$b_i$$$ on the sushi, because Kirino will slap him. What is the most expensive sushi Kyousuke can order that can satisfy Kirino?

Input

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$).

The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i \le 10^9$$$, $$$1 \le b_i \le n$$$) $$$-$$$ the price and the topping that doesn't go with the $$$i$$$th sushi, respectively.

There are $$$20$$$ tests. Each test is worth $$$\frac{100}{20}$$$ points.

Output

Print one integer $$$-$$$ the most expensive sushi Kyousuke can order.

Example
Input
4
9 3
9 1
9 1
9 3
Output
18
Note

photographer: Hoshinomiya Yuna

Problem Idea: thehunterjames

Problem Preparation: thehunterjames

Occurrences: Novice 11, Advanced 5