#include <bits/stdc++.h>
using namespace std;
int lsb(int val) { return val & ((val ^ (val - 1))); }
pair<int, pair<int, int> > a[600666];
int Arb[600666], SEG[600666], result[600666];
bool comp(pair<int, pair<int, int> > i1, pair<int, pair<int, int> > i2) {
  return i1.second.second < i2.second.second;
}
int query(int pos) {
  if (pos) return Arb[pos] + query(pos - lsb(pos));
  return 0;
}
void update(int pos, int n) {
  if (pos > n) return;
  Arb[pos]++;
  update(pos + lsb(pos), n);
}
int bs(int value, int n, int A[]) {
  int left = 1, right = n + 1;
  while (left < right - 1) {
    int mid = (right + left) / 2;
    if (A[mid] <= value)
      left = mid;
    else
      right = mid;
  }
  return left;
}
int main() {
  cin.sync_with_stdio(false);
  int n, i, nr_seg = 0;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> a[i].second.first >> a[i].second.second;
    a[i].first = i;
    SEG[++nr_seg] = a[i].second.first;
    SEG[++nr_seg] = a[i].second.second;
  }
  sort(SEG + 1, SEG + nr_seg + 1);
  sort(a + 1, a + n + 1, comp);
  for (i = 1; i <= n; ++i) {
    a[i].second.first = bs(a[i].second.first, nr_seg, SEG);
    a[i].second.second = bs(a[i].second.second, nr_seg, SEG);
  }
  for (i = 1; i <= n; ++i) {
    result[a[i].first] = query(a[i].second.second) - query(a[i].second.first);
    update(a[i].second.first, n * 2);
  }
  for (i = 1; i <= n; ++i) cout << result[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;
int lsb(int val) { return val & ((val ^ (val - 1))); }
pair<int, pair<int, int> > a[600666];
int Arb[600666], SEG[600666], result[600666];
bool comp(pair<int, pair<int, int> > i1, pair<int, pair<int, int> > i2) {
  return i1.second.second < i2.second.second;
}
int query(int pos) {
  if (pos) return Arb[pos] + query(pos - lsb(pos));
  return 0;
}
void update(int pos, int n) {
  if (pos > n) return;
  Arb[pos]++;
  update(pos + lsb(pos), n);
}
int bs(int value, int n, int A[]) {
  int left = 1, right = n + 1;
  while (left < right - 1) {
    int mid = (right + left) / 2;
    if (A[mid] <= value)
      left = mid;
    else
      right = mid;
  }
  return left;
}
int main() {
  cin.sync_with_stdio(false);
  int n, i, nr_seg = 0;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> a[i].second.first >> a[i].second.second;
    a[i].first = i;
    SEG[++nr_seg] = a[i].second.first;
    SEG[++nr_seg] = a[i].second.second;
  }
  sort(SEG + 1, SEG + nr_seg + 1);
  sort(a + 1, a + n + 1, comp);
  for (i = 1; i <= n; ++i) {
    a[i].second.first = bs(a[i].second.first, nr_seg, SEG);
    a[i].second.second = bs(a[i].second.second, nr_seg, SEG);
  }
  for (i = 1; i <= n; ++i) {
    result[a[i].first] = query(a[i].second.second) - query(a[i].second.first);
    update(a[i].second.first, n * 2);
  }
  for (i = 1; i <= n; ++i) cout << result[i] << '\n';
  return 0;
}

```