문제
Each of Bessie’s () bovine buddies (conveniently labeled ) owns her own farm. For each , buddy wants to visit buddy ().
Given a permutation of , the visits occur as follows.
For each from up to :
If buddy has already departed her farm, then buddy remains at her own farm.Otherwise, buddy departs her farm to visit buddy ’s farm. This visit results in a joyful "moo" being uttered times ().
Compute the maximum possible number of moos after all visits, over all possible permutations .
입력
The first line contains .
For each , the -st line contains two space-separated integers and .
출력
A single integer denoting the answer.
Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).
예제 입력 1
4
2 10
3 20
4 30
1 40
예제 출력 1
90
점수
Test cases 2-3 satisfy for all .Test cases 4-7 satisfy .Test cases 8-11 satisfy no additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인