MemSQL Start[c]UP 2.0 - Round 2
C
Elections
Codeforces
2100
原题
← BD →
翻译中…

You 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.

翻译中…

样例

Input #1
5
1 2
1 2
1 2
2 1
0 0
Output #1
3
InputCopy OutputCopy
Input #2
4
1 2
1 2
2 1
0 0
Output #2
2
InputCopy OutputCopy
Input #3
1
100000 0
Output #3
0
InputCopy OutputCopy
题目信息
题号
457C
时间限制
2 s
内存限制
256 MB
标签
暴力

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。