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?
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.
Print one integer $$$-$$$ the most expensive sushi Kyousuke can order.
49 39 19 19 3
18
photographer: Hoshinomiya Yuna
—
Problem Idea: thehunterjames
Problem Preparation: thehunterjames
Occurrences: Novice 11, Advanced 5