#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 100;
int l[maxn], r[maxn], ans[maxn], seg[4 * maxn];
vector<pair<int, int> > v[maxn];
void add(int idx, int val, int L = 0, int R = maxn, int id = 1) {
  if (L == R - 1) {
    seg[id] += val;
    return;
  }
  int mid = (L + R) >> 1;
  if (idx < mid)
    add(idx, val, L, mid, id * 2 + 0);
  else
    add(idx, val, mid, R, id * 2 + 1);
  seg[id] = seg[id * 2 + 0] + seg[id * 2 + 1];
}
int get(int l, int r, int L = 0, int R = maxn, int id = 1) {
  if (l == L && r == R) return seg[id];
  int mid = (L + R) >> 1, ret = 0;
  if (l < mid) ret += get(l, min(mid, r), L, mid, id * 2 + 0);
  if (r > mid) ret += get(max(l, mid), r, mid, R, id * 2 + 1);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
  vector<int> all;
  for (int i = 0; i < n; i++) {
    all.push_back(l[i]);
    all.push_back(r[i]);
  }
  sort(all.begin(), all.end());
  all.resize(unique(all.begin(), all.end()) - all.begin());
  for (int i = 0; i < n; i++) {
    l[i] = lower_bound(all.begin(), all.end(), l[i]) - all.begin();
    r[i] = lower_bound(all.begin(), all.end(), r[i]) - all.begin();
  }
  for (int i = 0; i < n; i++) {
    v[l[i]].push_back(make_pair(r[i], i));
    add(r[i], 1);
  }
  for (int i = 0; i < maxn; i++) sort(v[i].begin(), v[i].end());
  for (int i = 0; i < maxn; i++) {
    for (int j = 0; j < v[i].size(); j++) add(v[i][j].first, -1);
    for (int j = 0; j < v[i].size(); j++)
      ans[v[i][j].second] = get(0, v[i][j].first);
  }
  for (int i = 0; i < n; i++) cout << ans[i] << '\n';
  return 0;
}

### Prompt

Please formulate 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 = 4e5 + 100;
int l[maxn], r[maxn], ans[maxn], seg[4 * maxn];
vector<pair<int, int> > v[maxn];
void add(int idx, int val, int L = 0, int R = maxn, int id = 1) {
  if (L == R - 1) {
    seg[id] += val;
    return;
  }
  int mid = (L + R) >> 1;
  if (idx < mid)
    add(idx, val, L, mid, id * 2 + 0);
  else
    add(idx, val, mid, R, id * 2 + 1);
  seg[id] = seg[id * 2 + 0] + seg[id * 2 + 1];
}
int get(int l, int r, int L = 0, int R = maxn, int id = 1) {
  if (l == L && r == R) return seg[id];
  int mid = (L + R) >> 1, ret = 0;
  if (l < mid) ret += get(l, min(mid, r), L, mid, id * 2 + 0);
  if (r > mid) ret += get(max(l, mid), r, mid, R, id * 2 + 1);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
  vector<int> all;
  for (int i = 0; i < n; i++) {
    all.push_back(l[i]);
    all.push_back(r[i]);
  }
  sort(all.begin(), all.end());
  all.resize(unique(all.begin(), all.end()) - all.begin());
  for (int i = 0; i < n; i++) {
    l[i] = lower_bound(all.begin(), all.end(), l[i]) - all.begin();
    r[i] = lower_bound(all.begin(), all.end(), r[i]) - all.begin();
  }
  for (int i = 0; i < n; i++) {
    v[l[i]].push_back(make_pair(r[i], i));
    add(r[i], 1);
  }
  for (int i = 0; i < maxn; i++) sort(v[i].begin(), v[i].end());
  for (int i = 0; i < maxn; i++) {
    for (int j = 0; j < v[i].size(); j++) add(v[i][j].first, -1);
    for (int j = 0; j < v[i].size(); j++)
      ans[v[i][j].second] = get(0, v[i][j].first);
  }
  for (int i = 0; i < n; i++) cout << ans[i] << '\n';
  return 0;
}

```