#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
set<int> mySet;
typedef struct {
  int left;
  int right;
  int ind;
  int val;
} command;
int tree[8000000];
int n;
command c;
vector<command> commands;
bool sortByLeft(command b, command a) { return b.left > a.left; }
bool sortByInd(command b, command a) { return b.ind < a.ind; }
void update(int ind, int s, int e, int num) {
  if (s == e && s == num) {
    tree[ind]++;
    return;
  }
  if (s > num || e < num) {
    return;
  }
  int mid = (s + e) / 2;
  update(2 * ind, s, mid, num);
  update(2 * ind + 1, mid + 1, e, num);
  tree[ind] = tree[2 * ind] + tree[2 * ind + 1];
}
int query(int ind, int s, int e, int num) {
  if (s > num) {
    return 0;
  }
  if (e <= num) {
    return tree[ind];
  }
  int mid = (s + e) / 2;
  int l = query(2 * ind, s, mid, num);
  int r = query(2 * ind + 1, mid + 1, e, num);
  return l + r;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &c.left, &c.right);
    c.ind = i;
    commands.push_back(c);
    mySet.insert(c.left);
    mySet.insert(c.right);
  }
  int i = 0;
  for (set<int>::iterator it = mySet.begin(); it != mySet.end(); it++) {
    mp[*it] = i;
    i++;
  }
  int lastIndex = mySet.size() - 1;
  sort(commands.begin(), commands.end(), sortByLeft);
  for (int i = 0; i < n; i++) {
    update(1, 0, lastIndex, mp[commands[i].right]);
    int tmp = query(1, 0, lastIndex, mp[commands[i].right]) - 1;
    if (tmp == -1) tmp = 0;
    commands[i].val = tmp;
  }
  sort(commands.begin(), commands.end(), sortByInd);
  for (int i = 0; i < n; i++) {
    cout << commands[i].val << endl;
  }
  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;
map<int, int> mp;
set<int> mySet;
typedef struct {
  int left;
  int right;
  int ind;
  int val;
} command;
int tree[8000000];
int n;
command c;
vector<command> commands;
bool sortByLeft(command b, command a) { return b.left > a.left; }
bool sortByInd(command b, command a) { return b.ind < a.ind; }
void update(int ind, int s, int e, int num) {
  if (s == e && s == num) {
    tree[ind]++;
    return;
  }
  if (s > num || e < num) {
    return;
  }
  int mid = (s + e) / 2;
  update(2 * ind, s, mid, num);
  update(2 * ind + 1, mid + 1, e, num);
  tree[ind] = tree[2 * ind] + tree[2 * ind + 1];
}
int query(int ind, int s, int e, int num) {
  if (s > num) {
    return 0;
  }
  if (e <= num) {
    return tree[ind];
  }
  int mid = (s + e) / 2;
  int l = query(2 * ind, s, mid, num);
  int r = query(2 * ind + 1, mid + 1, e, num);
  return l + r;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &c.left, &c.right);
    c.ind = i;
    commands.push_back(c);
    mySet.insert(c.left);
    mySet.insert(c.right);
  }
  int i = 0;
  for (set<int>::iterator it = mySet.begin(); it != mySet.end(); it++) {
    mp[*it] = i;
    i++;
  }
  int lastIndex = mySet.size() - 1;
  sort(commands.begin(), commands.end(), sortByLeft);
  for (int i = 0; i < n; i++) {
    update(1, 0, lastIndex, mp[commands[i].right]);
    int tmp = query(1, 0, lastIndex, mp[commands[i].right]) - 1;
    if (tmp == -1) tmp = 0;
    commands[i].val = tmp;
  }
  sort(commands.begin(), commands.end(), sortByInd);
  for (int i = 0; i < n; i++) {
    cout << commands[i].val << endl;
  }
  return 0;
}

```