#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
int n;
pair<pair<int, int>, int> p[N];
map<int, int> mp;
int ans[N], seg[N << 2];
vector<int> v;
int get(int n, int s, int e, int l, int r) {
  if (s > r || e < l) return 0;
  if (s >= l && e <= r) return seg[n];
  int mid = s + e >> 1;
  return get(n << 1, s, mid, l, r) + get(n << 1 | 1, mid + 1, e, l, r);
}
void update(int n, int s, int e, int idx) {
  if (s == e) {
    seg[n]++;
    return;
  }
  int mid = s + e >> 1;
  if (idx <= mid)
    update(n << 1, s, mid, idx);
  else
    update(n << 1 | 1, mid + 1, e, idx);
  seg[n] = seg[n << 1] + seg[n << 1 | 1];
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    scanf("%d%d", &p[i].first.second, &p[i].first.first), p[i].second = i;
  sort(p, p + n);
  for (int i = 0; i < n; i++) v.push_back(p[i].first.second);
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) mp[v[i]] = i;
  for (int idx, i = 0; i < n; i++) {
    idx = mp[p[i].first.second];
    ans[p[i].second] = get(1, 0, n - 1, idx, n);
    update(1, 0, n - 1, idx);
  }
  for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
}

### Prompt

Please provide a Cpp coded solution 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;
const int N = 2e5 + 10;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
int n;
pair<pair<int, int>, int> p[N];
map<int, int> mp;
int ans[N], seg[N << 2];
vector<int> v;
int get(int n, int s, int e, int l, int r) {
  if (s > r || e < l) return 0;
  if (s >= l && e <= r) return seg[n];
  int mid = s + e >> 1;
  return get(n << 1, s, mid, l, r) + get(n << 1 | 1, mid + 1, e, l, r);
}
void update(int n, int s, int e, int idx) {
  if (s == e) {
    seg[n]++;
    return;
  }
  int mid = s + e >> 1;
  if (idx <= mid)
    update(n << 1, s, mid, idx);
  else
    update(n << 1 | 1, mid + 1, e, idx);
  seg[n] = seg[n << 1] + seg[n << 1 | 1];
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    scanf("%d%d", &p[i].first.second, &p[i].first.first), p[i].second = i;
  sort(p, p + n);
  for (int i = 0; i < n; i++) v.push_back(p[i].first.second);
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) mp[v[i]] = i;
  for (int idx, i = 0; i < n; i++) {
    idx = mp[p[i].first.second];
    ans[p[i].second] = get(1, 0, n - 1, idx, n);
    update(1, 0, n - 1, idx);
  }
  for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
}

```