#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct cok {
  int first;
  int second;
  int id;
};
cok a[N];
vector<int> num[N << 2];
int ans[N];
void build(int p, int l, int r) {
  num[p].resize(r - l + 1);
  if (l == r) {
    num[p][0] = a[l].second;
    return;
  }
  int mid = (l + r) >> 1;
  build(p + p, l, mid);
  build(p + p + 1, mid + 1, r);
  merge(num[p + p].begin(), num[p + p].end(), num[p + p + 1].begin(),
        num[p + p + 1].end(), num[p].begin());
}
int find(int p, int l, int r, int u, int v) {
  if (u <= a[l].first && a[r].first <= v)
    return upper_bound(num[p].begin(), num[p].end(), v) -
           lower_bound(num[p].begin(), num[p].end(), u);
  if (v < a[l].first || a[r].first < u) return 0;
  int mid = (l + r) >> 1;
  return find(p + p, l, mid, u, v) + find(p + p + 1, mid + 1, r, u, v);
}
bool cmp(cok l, cok r) {
  if (l.first != r.first) return l.first < r.first;
  return l.second < r.second;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i].first, &a[i].second);
    a[i].id = i;
  }
  sort(a, a + n, cmp);
  build(1, 0, n - 1);
  for (int i = 0; i < n; i++) {
    ans[a[i].id] = find(1, 0, n - 1, a[i].first + 1, a[i].second - 1);
  }
  for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
  return 0;
}

### Prompt

Your challenge is to write a CPP solution to the following problem:

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 N = 2e5 + 5;
struct cok {
  int first;
  int second;
  int id;
};
cok a[N];
vector<int> num[N << 2];
int ans[N];
void build(int p, int l, int r) {
  num[p].resize(r - l + 1);
  if (l == r) {
    num[p][0] = a[l].second;
    return;
  }
  int mid = (l + r) >> 1;
  build(p + p, l, mid);
  build(p + p + 1, mid + 1, r);
  merge(num[p + p].begin(), num[p + p].end(), num[p + p + 1].begin(),
        num[p + p + 1].end(), num[p].begin());
}
int find(int p, int l, int r, int u, int v) {
  if (u <= a[l].first && a[r].first <= v)
    return upper_bound(num[p].begin(), num[p].end(), v) -
           lower_bound(num[p].begin(), num[p].end(), u);
  if (v < a[l].first || a[r].first < u) return 0;
  int mid = (l + r) >> 1;
  return find(p + p, l, mid, u, v) + find(p + p + 1, mid + 1, r, u, v);
}
bool cmp(cok l, cok r) {
  if (l.first != r.first) return l.first < r.first;
  return l.second < r.second;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i].first, &a[i].second);
    a[i].id = i;
  }
  sort(a, a + n, cmp);
  build(1, 0, n - 1);
  for (int i = 0; i < n; i++) {
    ans[a[i].id] = find(1, 0, n - 1, a[i].first + 1, a[i].second - 1);
  }
  for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
  return 0;
}

```