#907
Gold III
CESTARINE
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

In a single day, N of Luka's trucks travel a specific highway. The highway has a number of exits and entrances. An exit with a particular number is in the same location as the entrance with that number. Upon entering the highway, a truck driver receives a ticket which indicates the entrance he used. When exiting, the driver pays a toll equal to the absolute difference of the entrance and exit numbers. For example, if a ticket says he used entrance 30, then exiting at exit 12 will cost him 18. Luka has figured out a way to save toll money that his company daily spends. Any two drivers can meet on the highway and exchange tickets, even if their routes don't overlap. Tickets can be exchanged an arbitrary number of times. However, a driver cannot use an exit if his ticket says he used the same entrance, since that would be suspicious. Write a program that calculates the least total amount of tolls that the drivers can achieve by exchanging tickets.

입력

The first line contains the integer N (1 ≤ N ≤ 100 000), the number of trucks. Each of the following N lines contains two distinct integers between 1 and 1 000 000. These are in order the entrance and exit numbers of one truck. No two trucks will use the same highway entrance or the same exit.

출력

Output the least total amount of tolls Luka's company must pay. Note: use 64-bit integer types (long long in C/C++, int64 in Pascal).

예제 입력 1

3
3 65
45 10
60 25

예제 출력 1

32

예제 입력 2

3
5 5
6 7
8 8

예제 출력 2

5
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Gold III1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.