#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
pair<int, pair<int, int> > p[200005];
int ans[200005], len, s[400005], k[200005];
int get(int x) {
  int re = 0;
  while (x) {
    re += s[x];
    x -= x & -x;
  }
  return re;
}
void update(int x, int y) {
  while (x <= len) {
    s[x] += y;
    x += x & -x;
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].first >> p[i].second.first;
    v.emplace_back(p[i].first);
    v.emplace_back(p[i].second.first);
    p[i].second.second = i;
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  len = v.size();
  for (int i = 1; i <= n; i++) {
    p[i].first = lower_bound(v.begin(), v.end(), p[i].first) - v.begin() + 1;
    p[i].second.first =
        lower_bound(v.begin(), v.end(), p[i].second.first) - v.begin() + 1;
  }
  sort(p + 1, p + n + 1);
  for (int i = 1; i <= n; i++) {
    ans[i] = -get(p[i].second.first);
    update(p[i].second.first + 1, 1);
  }
  for (int i = 1; i <= n; i++) {
    ans[i] += get(p[i].second.first);
    k[p[i].second.second] = ans[i];
  }
  for (int i = 1; i <= n; i++) cout << k[i] << '\n';
  return 0;
}

### Prompt

Create a solution in CPP for 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>
#pragma GCC optimize("Ofast")
using namespace std;
pair<int, pair<int, int> > p[200005];
int ans[200005], len, s[400005], k[200005];
int get(int x) {
  int re = 0;
  while (x) {
    re += s[x];
    x -= x & -x;
  }
  return re;
}
void update(int x, int y) {
  while (x <= len) {
    s[x] += y;
    x += x & -x;
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].first >> p[i].second.first;
    v.emplace_back(p[i].first);
    v.emplace_back(p[i].second.first);
    p[i].second.second = i;
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  len = v.size();
  for (int i = 1; i <= n; i++) {
    p[i].first = lower_bound(v.begin(), v.end(), p[i].first) - v.begin() + 1;
    p[i].second.first =
        lower_bound(v.begin(), v.end(), p[i].second.first) - v.begin() + 1;
  }
  sort(p + 1, p + n + 1);
  for (int i = 1; i <= n; i++) {
    ans[i] = -get(p[i].second.first);
    update(p[i].second.first + 1, 1);
  }
  for (int i = 1; i <= n; i++) {
    ans[i] += get(p[i].second.first);
    k[p[i].second.second] = ans[i];
  }
  for (int i = 1; i <= n; i++) cout << k[i] << '\n';
  return 0;
}

```