#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 1000 * 100 + 10;
const double EPS = 1e-9;
const long long MOD = 1000 * 1000 * 1000 + 7;
int dfs_up(int v, bool root, vector<vector<int> >& g, int p = -1) {
  map<int, int> ts;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (to == p) continue;
    int result = dfs_up(to, false, g, v) + 1;
    ts[result]++;
    if (ts.size() > 1 && !root) {
      cout << -1;
      exit(0);
    }
    if (ts.size() > 2) {
      cout << -1;
      exit(0);
    }
  }
  if (!root) {
    if (ts.size() == 0) return 0;
    return ts.begin()->first;
  }
  if (root) {
    if (ts.size() == 1) {
      return ts.begin()->first;
    } else {
      return ts.begin()->first + (ts.rbegin()->first);
    }
  }
}
int main(int argc, char* argv[]) {
  int n;
  scanf("%d", &n);
  vector<pair<pair<int, int>, int> > p(n);
  for (int i = 0; i < n; ++i)
    scanf("%d%d", &p[i].first.first, &p[i].first.second);
  map<int, int> mp;
  set<int> ss;
  for (int i = 0; i < n; ++i) {
    p[i].second = i;
    ss.insert(p[i].first.second);
  }
  for (auto it : ss) {
    mp[it] = mp.size();
  }
  vector<int> answer(n);
  sort((p).begin(), (p).end());
  vector<int> FW(n + 1);
  for (int i = n - 1; i >= 0; --i) {
    int tmp = 0;
    int r_pos = mp[p[i].first.second];
    for (int j = r_pos; j >= 0; j -= (j + 1) & -(j + 1)) {
      tmp += FW[j];
    }
    answer[p[i].second] = tmp;
    for (int j = r_pos; j < FW.size(); j += (j + 1) & -(j + 1)) {
      FW[j]++;
    }
  }
  for (int i = 0; i < n; ++i) printf("%d\n", answer[i]);
  return 0;
}

### Prompt

Your task is to create 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 MAXN = 2 * 1000 * 100 + 10;
const double EPS = 1e-9;
const long long MOD = 1000 * 1000 * 1000 + 7;
int dfs_up(int v, bool root, vector<vector<int> >& g, int p = -1) {
  map<int, int> ts;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (to == p) continue;
    int result = dfs_up(to, false, g, v) + 1;
    ts[result]++;
    if (ts.size() > 1 && !root) {
      cout << -1;
      exit(0);
    }
    if (ts.size() > 2) {
      cout << -1;
      exit(0);
    }
  }
  if (!root) {
    if (ts.size() == 0) return 0;
    return ts.begin()->first;
  }
  if (root) {
    if (ts.size() == 1) {
      return ts.begin()->first;
    } else {
      return ts.begin()->first + (ts.rbegin()->first);
    }
  }
}
int main(int argc, char* argv[]) {
  int n;
  scanf("%d", &n);
  vector<pair<pair<int, int>, int> > p(n);
  for (int i = 0; i < n; ++i)
    scanf("%d%d", &p[i].first.first, &p[i].first.second);
  map<int, int> mp;
  set<int> ss;
  for (int i = 0; i < n; ++i) {
    p[i].second = i;
    ss.insert(p[i].first.second);
  }
  for (auto it : ss) {
    mp[it] = mp.size();
  }
  vector<int> answer(n);
  sort((p).begin(), (p).end());
  vector<int> FW(n + 1);
  for (int i = n - 1; i >= 0; --i) {
    int tmp = 0;
    int r_pos = mp[p[i].first.second];
    for (int j = r_pos; j >= 0; j -= (j + 1) & -(j + 1)) {
      tmp += FW[j];
    }
    answer[p[i].second] = tmp;
    for (int j = r_pos; j < FW.size(); j += (j + 1) & -(j + 1)) {
      FW[j]++;
    }
  }
  for (int i = 0; i < n; ++i) printf("%d\n", answer[i]);
  return 0;
}

```