Problem: Annie has gotten bored of winning every coding contest and farming unlimited rating. Today, she is going to farm potatoes instead.

Annie's garden is an infinite 2D plane. She has n potatoes to plant, and the i-th potato must be planted at (x_i,y_i). Starting at the point (0, 0), Annie begins walking, in one step she can travel one unit right or up (increasing her x or y coordinate by 1 respectively). At any point (X,Y) during her walk she can plant some potatoes at arbitrary points using her potato gun, consuming max(|X-x|,|Y-y|) units of energy in order to plant a potato at (x,y). Find the minimum total energy required to plant every potato.

Note that Annie may plant any number of potatoes from any point.

Input

The first line contains the integer n (1 ≤ n ≤ 800 000).

The next n lines contain two integers x_i and y_i (0 ≤ x_i,y_i ≤ 10^9), representing the location of the i-th potato. It is possible that some potatoes should be planted in the same location.

Output

Print the minimum total energy to plant all potatoes.

Examples

Input


2
1 1
2 2


Output


0


Input


2
1 1
2 0


Output


1


Input


3
5 5
7 7
4 9


Output


2


Input


10
5 1
4 0
9 6
0 2
10 1
9 10
3 10
0 10
8 9
1 5


Output


19


Input


10
1 1
2 2
2 0
4 2
4 0
2 0
0 2
4 0
4 2
5 1


Output


6

Note

In example 1, Annie can travel to each spot directly and plant a potato with no energy required.

In example 2, moving to (1,0), Annie plants the second potato using 1 energy. Next, she travels to (1,1) and plants the first potato with 0 energy.

Solution (in CPP):

Solution:
#include <algorithm>
#include <cassert>
#include <iostream>
#include <limits>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

// Slope trick: fast operations for convex piecewise-linear functions
//
// Implementation idea:
// - https://maspypy.com/slope-trick-1-%E8%A7%A3%E8%AA%AC%E7%B7%A8
// - https://ei1333.github.io/library/structure/others/slope-trick.cpp
template <class T, T INF = std::numeric_limits<T>::max() / 2> class slope_trick {
    T min_f;
    T displacement_l, displacement_r;
    std::priority_queue<T, std::vector<T>, std::less<T>> L;
    std::priority_queue<T, std::vector<T>, std::greater<T>> R;
    void pushR(const T &a) { R.push(a - displacement_r); }
    T topR() const { return R.empty() ? INF : R.top() + displacement_r; }
    T popR() {
        auto ret = topR();
        if (R.size()) R.pop();
        return ret;
    }
    void pushL(const T &a) { L.push(a + displacement_l); }
    T topL() const { return L.empty() ? -INF : L.top() - displacement_l; }
    T popL() {
        auto ret = topL();
        if (L.size()) L.pop();
        return ret;
    }
    int size() const { return L.size() + R.size8(); }

public:
    // Initialize: f(x) = 0
    slope_trick() : min_f(0), displacement_l(0), displacement_r(0) { static_assert(INF > 0); }
    int sizeL() const { return L.size(); }
    int sizeR() const { return R.size(); }
    // argmin f(x), min f(x)
    using Q = struct { T min, lo, hi; };
    Q get_min() const { return {min_f, topL(), topR()}; }
    // f(x) += b
    void add_const(const T &b) { min_f += b; }
    // f(x) += max(x - a, 0)  _/
    void add_relu(const T &a) { min_f += std::max(T(0), topL() - a), pushL(a), pushR(popL()); }
    // f(x) += max(a - x, 0)  \_
    void add_irelu(const T &a) { min_f += std::max(T(0), a - topR()), pushR(a), pushL(popR()); }
    // f(x) += |x - a|  \/
    void add_abs(const T &a) { add_relu(a), add_irelu(a); }
    // f(x) <- min_{0 <= y <= w} f(x + y)  .\ -> \_
    void move_left_curve(const T &w) { assert(w >= 0), displacement_l += w; }
    // f(x) <- min_{0 <= y <= w} f(x - y)  /. -> _/
    void move_right_curve(const T &w) { assert(w >= 0), displacement_r += w; }
    // f(x) <- f(x - dx) \/. -> .\/
    void translate(const T &dx) { displacement_l -= dx, displacement_r += dx; }
    // return f(x), f destructive
    T get_destructive(const T &x) {
        T ret = get_min().min;
        while (L.size()) ret += std::max(T(0), popL() - x);
        while (R.size()) ret += std::max(T(0), x - popR());
        return ret;
    }
    // f(x) += g(x), g destructive
    void merge_destructive(slope_trick<T, INF> &g) {
        if (sizeL() + sizeR() > g.sizeL() + g.sizeR()) {
            std::swap(min_f, g.min_f);
            std::swap(displacement_l, g.displacement_l);
            std::swap(displacement_r, g.displacement_r);
            std::swap(L, g.L);
            std::swap(R, g.R);
        }
        min_f += g.get_min().min;
        while (g.L.size()) add_irelu(g.popL());
        while (g.R.size()) add_relu(g.popR());
    }
};

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<int, int>> sumy(N);
    for (auto &[x, y] : sumy) cin >> x >> y, x += y;
    sort(sumy.begin(), sumy.end());
    int now = 0;
    slope_trick<long long> dp;
    for (auto [sum, y] : sumy) {
        auto dt = sum - now;
        now = sum;
        dp.move_right_curve(dt);
        dp.add_abs(y);
    }
    cout << dp.get_min().min << endl;
}