Under construction

Still being built. Things may change

Hamiltonian Circuit

Time limit1sMemory limit2048 MB

Level

Not classified yet

Solved
No attempts yet

Problem

You are given nn pairs of integers (ai,bi)(a_i, b_i).

Consider a weighted directed complete graph GG with nn vertices, where the weight of the edge from ii (1≤i≤n1 \leq i \leq n) to jj (1≤j≤n1 \leq j \leq n) is ∣ai−bj∣|a_i - b_j|.

Find a Hamiltonian circuit in GG whose total edge weight is maximized, and print this maximum value.

Input

The first line contains an integer nn (2≤n≤1052 \leq n \leq 10^5), the number of pairs.

Each of the next nn lines contains two integers aia_i and bib_i (0≤ai,bi≤1090 \leq a_i, b_i \leq 10^9), describing one pair.

You may assume that all 2n2n integers aia_i and bib_i are pairwise distinct.

Output

Print a single integer on one line: the maximum total weight of a Hamiltonian circuit.

Hint

Take the circuit 1→2→3→11 \to 2 \to 3 \to 1 in the example. Its edge weights are ∣1−2∣+∣8−5∣+∣4−10∣=10|1-2| + |8-5| + |4-10| = 10. No Hamiltonian circuit has a total weight above 10, so the answer is 10.

Examples1

  1. Example 1

    Input
    3
    1 10
    8 2
    4 5
    
    Expected output
    10