Problem: You are given positions (X_i, Y_i) of N enemy rooks on an infinite chessboard. No two rooks attack each other (at most one rook per row or column).

You're going to replace one rook with a king and then move the king repeatedly to beat as many rooks as possible.

You can't enter a cell that is being attacked by a rook. Additionally, you can't move diagonally to an empty cell (but you can beat a rook diagonally).

(So this king moves like a superpawn that beats diagonally in 4 directions and moves horizontally/vertically in 4 directions.)

For each rook, consider replacing it with a king, and find the minimum possible number of moves needed to beat the maximum possible number of rooks.

Constraints

* 2 \leq N \leq 200\,000
* 1 \leq X_i, Y_i \leq 10^6
* X_i \neq X_j
* Y_i \neq Y_j
* All values in input are integers.

Input

Input is given from Standard Input in the following format.


N
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N


Output

Print N lines. The i-th line is for scenario of replacing the rook at (X_i, Y_i) with your king. This line should contain one integer: the minimum number of moves to beat M_i rooks where M_i denotes the maximum possible number of beaten rooks in this scenario (in infinite time).

Examples

Input

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


Output

5
0
7
5
0
0


Input

5
5 5
100 100
70 20
81 70
800 1


Output

985
985
1065
1034
0


Input

10
2 5
4 4
13 12
12 13
14 17
17 19
22 22
16 18
19 27
25 26


Output

2
2
9
9
3
3
24
5
0
25

Solution (in CPP):

Solution:
#include <cstdio> 
#include <vector>
#include <climits>
#include <algorithm>
#include <functional> 
using namespace std;

struct Rook {
    int x, y, id;
    bool operator <(const Rook& other) const {
        return x < other.x;
    }
};

long long hack;

template<class C>
void min_self (C &a, C &&b) {
    a = min(a, b);
};

int main() {
    int n;
    scanf("%d", &n);
    vector<Rook> rooks(n);
    for(int i = 0; i < n; ++i) {
        rooks[i].id = i;
        scanf("%d%d", &rooks[i].x, &rooks[i].y);
    }
    sort(rooks.begin(), rooks.end());
    vector<int> ys{INT_MIN, INT_MAX}; // two sentinels for convenience
    for(int i = 0; i < n; ++i) {
        ys.push_back(rooks[i].y);
    }
    sort(ys.begin(), ys.end());
    vector< pair<long long, long long> > answer(n, {-1, -1});
    for(int start = 0; start < n; ++start) {
        if(answer[rooks[start].id].first != -1) {
            continue;
        }

        int start_y = lower_bound(ys.begin(), ys.end(), rooks[start].y) - ys.begin();
        int y1 = start_y - 1, y2 = start_y + 1;

        int L = start, R = start;
        int prev_dir = -1;
        vector< pair<int, int> > intervals;
        while(true) {
            bool found = false;
            for(int i : {L - 1, R + 1}) {
                if(0 <= i && i < n) {
                    bool prev_y = (ys[y1] == rooks[i].y);
                    bool next_y = (ys[y2] == rooks[i].y);
                    if(prev_y || next_y) {
                        int direction = (prev_y == (i == L - 1));
                        if(prev_dir == -1) {
                            prev_dir = direction;
                        }
                        if(prev_dir != direction) {
                            intervals.emplace_back(L, R);
                            prev_dir = direction;
                        }
                        prev_y ? y1-- : y2++;
                        i == L-1 ? L-- : R++;
                        found = true;
                        break;
                    }
                }
            }
            if(!found) {
                break;
            }
        }
        if(intervals.empty() || intervals.back() != make_pair(L, R)) {
            intervals.emplace_back(L, R);
        }
        const int s = intervals.size();

        const long long INF = 1e18L + 5;
        
        auto f = [&] (int i, int j) {
            return abs(rooks[i].x - rooks[j].x) + abs(rooks[i].y - rooks[j].y);
        };
        
        vector< vector<long long> > dp(s, vector<long long>(2, INF));
        dp[s-1][0] = dp[s-1][1] = 0;
        for(int who = s - 1; who >= 1; --who) {
            int L1 = intervals[who].first;
            int L2 = intervals[who-1].first;
            int R1 = intervals[who-1].second;
            int R2 = intervals[who].second;
            hack += (long long) (L2 - L1) * (R2 - R1);
            min_self(dp[who-1][0], dp[who][0] + (R1 == R2 ? f(L1, L2) : f(L1, R2) + f(R2, L2)));
            min_self(dp[who-1][1], dp[who][0] + f(L1, R2) + f(R2, R1));
            min_self(dp[who-1][0], dp[who][1] + f(R2, L1) + f(L1, L2));
            min_self(dp[who-1][1], dp[who][1] + (L1 == L2 ? f(R1, R2) : f(R2, L1) + f(L1, R1)));
        }
        int low = intervals[0].first, high = intervals[0].second;
        for(int i = low; i <= high; ++i) {
            answer[rooks[i].id] = {
                R - L,
                min(dp[0][0] + f(low, high) + f(high, i), dp[0][1] + f(high, low) + f(low, i))
            };
        }
    }
    for(auto p : answer) {
        printf("%lld\n", p.second - p.first);
    }
}