#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<pair<int, int>, int> > v;
map<int, int> m;
set<int> s;
bool f(pair<pair<int, int>, int>& x, pair<pair<int, int>, int>& y) {
  return x.first.first > y.first.first;
}
int dp[200000 * 6];
int get(int l, int r, int idx = 1, int b = 1, int e = s.size() + 10) {
  if (b >= l && r >= e) return dp[idx];
  if (b > r || l > e || b > e) return 0;
  int mid = (b + e) / 2;
  return get(l, r, idx * 2, b, mid) + get(l, r, idx * 2 + 1, mid + 1, e);
}
void insert(int g, int idx = 1, int b = 1, int e = s.size() + 10) {
  if (b == e && b == g) {
    dp[idx] = 1;
    return;
  }
  if (g > e || b > g || b > e) return;
  int mid = (b + e) / 2;
  insert(g, idx * 2, b, mid);
  insert(g, idx * 2 + 1, mid + 1, e);
  dp[idx] = dp[idx * 2] + dp[idx * 2 + 1];
}
int res[200010];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first.first >> v[i].first.second;
    v[i].second = i;
    s.insert(v[i].first.first);
    s.insert(v[i].first.second);
  }
  sort(v.begin(), v.end(), f);
  int j = 1;
  for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
    m[*it] = j++;
  }
  for (int i = 0; i < n; i++) {
    res[v[i].second] = get(1, m[v[i].first.second]);
    insert(m[v[i].first.second]);
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << endl;
  }
}

### 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;
int n;
vector<pair<pair<int, int>, int> > v;
map<int, int> m;
set<int> s;
bool f(pair<pair<int, int>, int>& x, pair<pair<int, int>, int>& y) {
  return x.first.first > y.first.first;
}
int dp[200000 * 6];
int get(int l, int r, int idx = 1, int b = 1, int e = s.size() + 10) {
  if (b >= l && r >= e) return dp[idx];
  if (b > r || l > e || b > e) return 0;
  int mid = (b + e) / 2;
  return get(l, r, idx * 2, b, mid) + get(l, r, idx * 2 + 1, mid + 1, e);
}
void insert(int g, int idx = 1, int b = 1, int e = s.size() + 10) {
  if (b == e && b == g) {
    dp[idx] = 1;
    return;
  }
  if (g > e || b > g || b > e) return;
  int mid = (b + e) / 2;
  insert(g, idx * 2, b, mid);
  insert(g, idx * 2 + 1, mid + 1, e);
  dp[idx] = dp[idx * 2] + dp[idx * 2 + 1];
}
int res[200010];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first.first >> v[i].first.second;
    v[i].second = i;
    s.insert(v[i].first.first);
    s.insert(v[i].first.second);
  }
  sort(v.begin(), v.end(), f);
  int j = 1;
  for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
    m[*it] = j++;
  }
  for (int i = 0; i < n; i++) {
    res[v[i].second] = get(1, m[v[i].first.second]);
    insert(m[v[i].first.second]);
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << endl;
  }
}

```