No tag edit access

C. Elections

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are running for a governor in a small city in Russia. You ran some polls and did some research, and for every person in the city you know whom he will vote for, and how much it will cost to bribe that person to vote for you instead of whomever he wants to vote for right now. You are curious, what is the smallest amount of money you need to spend on bribing to win the elections. To win elections you need to have strictly more votes than any other candidate.

Input

First line contains one integer *n* (1 ≤ *n* ≤ 10^{5}) — number of voters in the city. Each of the next *n* lines describes one voter and contains two integers *a*_{i} and *b*_{i} (0 ≤ *a*_{i} ≤ 10^{5}; 0 ≤ *b*_{i} ≤ 10^{4}) — number of the candidate that voter is going to vote for and amount of money you need to pay him to change his mind. You are the candidate 0 (so if a voter wants to vote for you, *a*_{i} is equal to zero, in which case *b*_{i} will also be equal to zero).

Output

Print one integer — smallest amount of money you need to spend to win the elections.

Examples

Input

5

1 2

1 2

1 2

2 1

0 0

Output

3

Input

4

1 2

1 2

2 1

0 0

Output

2

Input

1

100000 0

Output

0

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/20/2017 13:52:00 (c4).

Desktop version, switch to mobile version.

User lists

Name |
---|