Highway

Time limit1sMemory limit128 MB

Problem

Sanggeun runs a truck delivery company. The company has N trucks, and every truck travels on the same highway.

The highway has interchanges numbered from 1 to 1,000,000. When a truck enters the highway, the driver receives a ticket marked with the entry interchange number. When the truck exits, the toll is the absolute difference between the number on the ticket and the actual exit interchange number.

To reduce the total toll, Sanggeun lets drivers exchange tickets while they are on the highway. Two drivers may exchange tickets even if their routes do not overlap, and the same ticket may be exchanged any number of times. Therefore, only the final assignment of tickets to exiting trucks matters.

However, to avoid suspicion, a truck may not exit through an interchange whose number is equal to the number written on its ticket.

Find the minimum possible total toll after assigning all tickets to trucks.

Input

The first line contains the number of trucks N. (1 <= N <= 100,000)

Each of the next N lines contains two integers: the interchange number where a truck entered and the interchange number where it must exit.

Every interchange number is a positive integer between 1 and 1,000,000, inclusive. No two trucks enter through the same numbered interchange, and no two trucks exit through the same numbered interchange.

Output

Print the minimum possible sum of tolls the company must pay.

The answer may exceed the range of a 32-bit integer, so use a 64-bit integer type.