#include <bits/stdc++.h>
using namespace std;
int sz;
int bit[400008];
map<int, int> m;
bool comp(pair<int, pair<int, int> > &a, pair<int, pair<int, int> > &b) {
  if (a.first == b.first) return a.second.first > b.second.first;
  return a.first < b.first;
}
int query(int idx) {
  int tot = 0;
  while (idx > 0) {
    tot += bit[idx];
    idx -= idx & (-idx);
  }
  return tot;
}
void update(int x, int data) {
  while (x < sz) {
    bit[x] += data;
    x += (x & (-x));
  }
}
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> aux(2 * n);
  vector<pair<int, pair<int, int> > > arr(n);
  vector<int> ans(n);
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    arr[i].first = a;
    arr[i].second.first = b;
    arr[i].second.second = i;
    aux[2 * i] = a;
    aux[2 * i + 1] = b;
  }
  sort(aux.begin(), aux.end());
  int count = 1;
  for (int i = 0; i < 2 * n; i++) {
    if (m.find(aux[i]) == m.end()) {
      m[aux[i]] = count;
      count++;
    }
  }
  sz = count;
  memset(bit, 0, sizeof bit);
  for (int i = 0; i < n; i++) {
    arr[i].first = m[arr[i].first];
    arr[i].second.first = m[arr[i].second.first];
    update(arr[i].second.first, 1);
  }
  sort(arr.begin(), arr.end(), comp);
  for (int i = 0; i < n; i++) {
    int k = query(arr[i].second.first);
    k--;
    ans[arr[i].second.second] = k;
    update(arr[i].second.first, -1);
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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;
int sz;
int bit[400008];
map<int, int> m;
bool comp(pair<int, pair<int, int> > &a, pair<int, pair<int, int> > &b) {
  if (a.first == b.first) return a.second.first > b.second.first;
  return a.first < b.first;
}
int query(int idx) {
  int tot = 0;
  while (idx > 0) {
    tot += bit[idx];
    idx -= idx & (-idx);
  }
  return tot;
}
void update(int x, int data) {
  while (x < sz) {
    bit[x] += data;
    x += (x & (-x));
  }
}
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> aux(2 * n);
  vector<pair<int, pair<int, int> > > arr(n);
  vector<int> ans(n);
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    arr[i].first = a;
    arr[i].second.first = b;
    arr[i].second.second = i;
    aux[2 * i] = a;
    aux[2 * i + 1] = b;
  }
  sort(aux.begin(), aux.end());
  int count = 1;
  for (int i = 0; i < 2 * n; i++) {
    if (m.find(aux[i]) == m.end()) {
      m[aux[i]] = count;
      count++;
    }
  }
  sz = count;
  memset(bit, 0, sizeof bit);
  for (int i = 0; i < n; i++) {
    arr[i].first = m[arr[i].first];
    arr[i].second.first = m[arr[i].second.first];
    update(arr[i].second.first, 1);
  }
  sort(arr.begin(), arr.end(), comp);
  for (int i = 0; i < n; i++) {
    int k = query(arr[i].second.first);
    k--;
    ans[arr[i].second.second] = k;
    update(arr[i].second.first, -1);
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

```