#include <bits/stdc++.h>
using namespace std;
long long n;
vector<pair<pair<long long, long long>, long long> > massiv;
vector<pair<long long, long long> > nuj;
long long sorthus(pair<pair<long long, long long>, long long> a,
                  pair<pair<long long, long long>, long long> b) {
  return a.first.first > b.first.first;
}
long long sorthuss(pair<pair<long long, long long>, long long> a,
                   pair<pair<long long, long long>, long long> b) {
  return a.first.second < b.first.second;
}
long long fen[400010];
long long fenn[400010];
long long ans[200010];
void add1(long long pos, long long x) {
  for (; pos <= 2 * n; pos |= (pos + 1)) {
    fen[pos] += x;
  }
}
long long f1(long long pos) {
  long long sum = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    sum += fen[pos];
  }
  return sum;
}
long long query1(long long l, long long r) { return f1(r) - f1(l - 1); }
void add2(long long pos, long long x) {
  for (; pos <= 2 * n; pos |= (pos + 1)) {
    fenn[pos] += x;
  }
}
long long f2(long long pos) {
  long long sum = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    sum += fenn[pos];
  }
  return sum;
}
long long query2(long long l, long long r) { return f2(r) - f2(l - 1); }
int main() {
  ios_base::sync_with_stdio(0);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long x, y;
    cin >> x >> y;
    nuj.push_back(make_pair(x, i));
    nuj.push_back(make_pair(y, i));
    ans[i] = LLONG_MAX;
  }
  massiv.resize(n + 1);
  sort((nuj).begin(), (nuj).end());
  long long cnt = 1;
  for (long long i = 0; i < 2 * n; i++) {
    long long x = nuj[i].first;
    long long y = nuj[i].second;
    if (massiv[y - 1].first.first == 0) {
      massiv[y - 1].first.first = cnt;
    } else if (massiv[y - 1].first.second == 0) {
      massiv[y - 1].first.second = cnt;
    }
    massiv[y - 1].second = y;
    cnt++;
  }
  for (long long i = 0; i < n; i++) {
    if (massiv[i].first.first > massiv[i].first.second)
      swap(massiv[i].first.first, massiv[i].first.second);
  }
  sort(massiv.begin(), massiv.begin() + n, sorthus);
  for (long long i = 0; i < n; i++) {
    long long x = massiv[i].first.first;
    long long y = massiv[i].first.second;
    long long z = massiv[i].second;
    long long nujs = query1(x + 1, 2 * n);
    ans[z] = min(ans[z], nujs);
    add1(x, 1);
    nujs = query2(1, y - 1);
    ans[z] = min(ans[z], nujs);
    add2(y, 1);
  }
  for (long long i = 1; i <= n; i++) cout << ans[i] << "\n";
  return 0;
}

### Prompt

Develop a solution in CPP to the problem described below:

You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains.

Input

The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line.

Each of the next n lines contains two integers li and ri ( - 109 ≤ li < ri ≤ 109) — the coordinates of the left and the right ends of the i-th segment. It is guaranteed that there are no ends of some segments that coincide.

Output

Print n lines. The j-th of them should contain the only integer aj — the number of segments contained in the j-th segment.

Examples

Input

4
1 8
2 3
4 7
5 6


Output

3
0
1
0


Input

3
3 4
1 5
2 6


Output

0
1
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<pair<pair<long long, long long>, long long> > massiv;
vector<pair<long long, long long> > nuj;
long long sorthus(pair<pair<long long, long long>, long long> a,
                  pair<pair<long long, long long>, long long> b) {
  return a.first.first > b.first.first;
}
long long sorthuss(pair<pair<long long, long long>, long long> a,
                   pair<pair<long long, long long>, long long> b) {
  return a.first.second < b.first.second;
}
long long fen[400010];
long long fenn[400010];
long long ans[200010];
void add1(long long pos, long long x) {
  for (; pos <= 2 * n; pos |= (pos + 1)) {
    fen[pos] += x;
  }
}
long long f1(long long pos) {
  long long sum = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    sum += fen[pos];
  }
  return sum;
}
long long query1(long long l, long long r) { return f1(r) - f1(l - 1); }
void add2(long long pos, long long x) {
  for (; pos <= 2 * n; pos |= (pos + 1)) {
    fenn[pos] += x;
  }
}
long long f2(long long pos) {
  long long sum = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    sum += fenn[pos];
  }
  return sum;
}
long long query2(long long l, long long r) { return f2(r) - f2(l - 1); }
int main() {
  ios_base::sync_with_stdio(0);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long x, y;
    cin >> x >> y;
    nuj.push_back(make_pair(x, i));
    nuj.push_back(make_pair(y, i));
    ans[i] = LLONG_MAX;
  }
  massiv.resize(n + 1);
  sort((nuj).begin(), (nuj).end());
  long long cnt = 1;
  for (long long i = 0; i < 2 * n; i++) {
    long long x = nuj[i].first;
    long long y = nuj[i].second;
    if (massiv[y - 1].first.first == 0) {
      massiv[y - 1].first.first = cnt;
    } else if (massiv[y - 1].first.second == 0) {
      massiv[y - 1].first.second = cnt;
    }
    massiv[y - 1].second = y;
    cnt++;
  }
  for (long long i = 0; i < n; i++) {
    if (massiv[i].first.first > massiv[i].first.second)
      swap(massiv[i].first.first, massiv[i].first.second);
  }
  sort(massiv.begin(), massiv.begin() + n, sorthus);
  for (long long i = 0; i < n; i++) {
    long long x = massiv[i].first.first;
    long long y = massiv[i].first.second;
    long long z = massiv[i].second;
    long long nujs = query1(x + 1, 2 * n);
    ans[z] = min(ans[z], nujs);
    add1(x, 1);
    nujs = query2(1, y - 1);
    ans[z] = min(ans[z], nujs);
    add2(y, 1);
  }
  for (long long i = 1; i <= n; i++) cout << ans[i] << "\n";
  return 0;
}

```