#include <bits/stdc++.h>
using namespace std;
const int maxn = 400000 + 10;
int N, lim, bit[maxn];
void update(int idx, int val) {
  for (; idx <= lim; idx += idx & -idx) bit[idx] += val;
}
int query(int idx) {
  int res = 0;
  for (; idx; idx -= idx & -idx) res += bit[idx];
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N;
  vector<pair<pair<int, int>, int> > A(N);
  vector<int> B;
  for (int i = 0; i < N; i++) {
    cin >> A[i].first.first >> A[i].first.second;
    A[i].second = i;
    B.push_back(A[i].first.first);
    B.push_back(A[i].first.second);
  }
  sort((B).begin(), (B).end());
  B.erase(unique((B).begin(), (B).end()), B.end());
  sort((A).begin(), (A).end(),
       [&](pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
         if (a.first.first == b.first.first)
           return a.first.second < b.first.second;
         return a.first.first < b.first.first;
       });
  for (int i = 0; i < N; i++) {
    A[i].first.first =
        lower_bound((B).begin(), (B).end(), A[i].first.first) - B.begin() + 1;
    lim = max(lim, A[i].first.first);
    A[i].first.second =
        lower_bound((B).begin(), (B).end(), A[i].first.second) - B.begin() + 1;
    lim = max(lim, A[i].first.second);
  }
  vector<int> res(N);
  for (int i = N - 1; i >= 0; i--) {
    int a = A[i].first.first;
    int b = A[i].first.second;
    res[A[i].second] = query(b);
    update(b, 1);
  }
  for (int i = 0; i < N; i++) cout << res[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;
const int maxn = 400000 + 10;
int N, lim, bit[maxn];
void update(int idx, int val) {
  for (; idx <= lim; idx += idx & -idx) bit[idx] += val;
}
int query(int idx) {
  int res = 0;
  for (; idx; idx -= idx & -idx) res += bit[idx];
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N;
  vector<pair<pair<int, int>, int> > A(N);
  vector<int> B;
  for (int i = 0; i < N; i++) {
    cin >> A[i].first.first >> A[i].first.second;
    A[i].second = i;
    B.push_back(A[i].first.first);
    B.push_back(A[i].first.second);
  }
  sort((B).begin(), (B).end());
  B.erase(unique((B).begin(), (B).end()), B.end());
  sort((A).begin(), (A).end(),
       [&](pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
         if (a.first.first == b.first.first)
           return a.first.second < b.first.second;
         return a.first.first < b.first.first;
       });
  for (int i = 0; i < N; i++) {
    A[i].first.first =
        lower_bound((B).begin(), (B).end(), A[i].first.first) - B.begin() + 1;
    lim = max(lim, A[i].first.first);
    A[i].first.second =
        lower_bound((B).begin(), (B).end(), A[i].first.second) - B.begin() + 1;
    lim = max(lim, A[i].first.second);
  }
  vector<int> res(N);
  for (int i = N - 1; i >= 0; i--) {
    int a = A[i].first.first;
    int b = A[i].first.second;
    res[A[i].second] = query(b);
    update(b, 1);
  }
  for (int i = 0; i < N; i++) cout << res[i] << '\n';
  return 0;
}

```