1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <bits/stdc++.h>

using namespace std;

const int N = 250005, BASE = (1 << 18);

const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};

int t[N], whereIs[N];
int tree[2 * BASE + 5];
int n;
int x[N], y[N], xtmp[N], ytmp[N];
int from[N], to[N];

bool cmp(int a, int b) {
    return x[a] < x[b];
}

void insert(int posa, int posb, int val) {
    if (posa > posb) return;
    posa += BASE;
    posb += BASE;
    tree[posa] += val;
    if (posa != posb) {
        tree[posb] += val;
    }
    while (posa / 2 != posb / 2) {
        if (posa % 2 == 0) {
            tree[posa + 1] += val;
        } 
        if (posb % 2 == 1) {
            tree[posb - 1] += val;
        }
        posa /= 2;
        posb /= 2;
    }
}

int query(int pos) {
    pos += BASE;
    int ret = 0;
    while (pos >= 1) {
        ret += tree[pos];
        pos /= 2;
    }
    return ret;
}

int getEqualLeft(int w) {
    int low = 0;
    int high = w;
    int res = w;
    int myValue = query(w);
    while (low <= high) {
        int mid = (low + high) / 2;
        if (query(mid) == myValue) {
            res = mid;
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }
    return res;
}

int getEqualRight(int w) {
    int low = w;
    int high = n - 2;
    int res = w;
    int myValue = query(w);
    while (low <= high) {
        int mid = (low + high) / 2;
        if (query(mid) == myValue) {
            res = mid;
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }
    return res;
}

vector<long long> ans2;
vector<int> subtask(int sleepy, int *x) {
    vector<int> t;
    for (int i = 0; i < n - 1; i++) {
        insert(i, i, -query(i));
    }
    for (int i = 1; i <= n; i++) {
        if (i == sleepy) continue;
        t.push_back(i);
    }
    sort(t.begin(), t.end(), [&](int a, int b){return x[a] < x[b];});
    for (int i = 0; i < t.size(); i++) {
        whereIs[t[i]] = i;
        insert(i, i, x[t[i]]);
    }

    for (int i = 1; i <= n; i++) {
        if (sleepy == i) continue;
        int pos = whereIs[i];
        int firstEqual = getEqualLeft(pos);
        int lastEqual = getEqualRight(pos);

        insert(0, firstEqual - 1, 1);
        insert(lastEqual + 1, n - 2, -1);
    }
    
    vector<int> ret;
    for (int i = 1; i <= n; i++) {
        if (sleepy == i) {
            ret.push_back(x[i]);
        } else {
            ret.push_back(query(whereIs[i]));
        }
    }
    return ret;
}

int main() {
    
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d %d", &x[i], &y[i]);
    }
    
    for (int i = 1; i <= n; i++) {
        auto v1 = subtask(i, x);
        auto v2 = subtask(i, y);
        long long ans = 0;
        for (int i = 0; i < v1.size(); i++) {
            ans += (long long)v1[i] * v2[i];
        }
        printf("%lld\n", ans);
    }

    return 0;
}