시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB84322344.231%

문제

Charlie acquired airline transport company and to stay in business he needs to lower the expenses by any means possible.

There are N pilots working for his company (N is even) and N/2 plane crews needs to be made. A plane crew consists of two pilots - a captain and his assistant. A captain must be older than his assistant. Each pilot has a contract granting him two possible salaries - one as a captain and the other as an assistant. A captain's salary is larger than assistant's for the same pilot. However, it is possible that an assistant has larger salary than his captain.

Write a program that will compute the minimal amount of money Charlie needs to give for the pilots' salaries if he decides to spend some time to make the optimal (i.e. the cheapest) arrangement of pilots in crews.

입력

The first line of input contains integer N, 2 ≤ N ≤ 10,000, N is even, the number of pilots working for the Charlie's company.

The next N lines of input contain pilots' salaries. The lines are sorted by pilot's age, the salaries of the youngest pilot are given the first. Each of those N lines contains two integers separated by a space character, X i Y, 1 ≤ Y < X ≤ 100,000, a salary as a captain (X) and a salary as an assistant (Y).

출력

The first and only line of output should contain the minimal amount of money Charlie needs to give for the pilots' salaries. 

예제 입력 1

4
5000 3000
6000 2000
8000 1000
9000 6000

예제 출력 1

19000

예제 입력 2

6
10000 7000
9000 3000
6000 4000
5000 1000
9000 3000
8000 6000

예제 출력 2

32000

예제 입력 3

6
5000 3000
4000 1000
9000 7000
11000 5000
7000 3000
8000 6000

예제 출력 3

33000