Roller Coaster Railroad#7976

Roller Coaster Railroad

1 second
128 megabytes
Hard

Anna is working in an amusement park and she is in charge of building the railroad for a new roller coaster. She has already designed special sections (conveniently numbered from to n - 1 that affect the speed of a roller coaster train. She now has to put them together and propose a final design of the roller coaster. For the purpose of this problem you may assume that the length of the train is zero.

For each between and n - 1, inclusive, special section has two properties:

The finished roller coaster is a single railroad line that contains the special sections in some order. Each of the sections should be used exactly once. Consecutive sections are connected with tracks. Anna should choose the order of the sections and then decide the lengths of the tracks. The length of a track is measured in meters and may be equal to any non-negative integer (possibly zero).

Each meter of the track between two special sections slows the train down by km/h. At the beginning of the ride, the train enters the first special section in the order selected by Anna, going at km/h.

The final design must satisfy the following requirements:

Your task is to find the minimum possible total length of tracks between sections.

Input

First line contains number n~(2 \le n \le 2 \cdot 10^5). Each of the next lines contains numbers s_i and t_i~(1 \le i \le n, 1 \le s_i, t_i \le 10^9).

Output

Print the minimum possible total length of all tracks between sections.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading