#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 2 * (1e5) + 10;
const int up = 2 * N;
struct node {
  int l, r, id, ans;
} p[N];
int c[up + 10];
map<int, int> mp;
int cmp(node a, node b) { return a.l < b.l; }
int cmp2(node a, node b) { return a.id < b.id; }
int lowbit(int x) { return x & -x; }
int sum(int x) {
  int ret = 0;
  while (x > 0) {
    ret += c[x];
    x -= lowbit(x);
  }
  return ret;
}
void add(int x, int d) {
  while (x <= up) {
    c[x] += d;
    x += lowbit(x);
  }
}
int x[up + 10];
int main() {
  int i, n, cnt, l, r;
  scanf("%d", &n);
  for (i = 0; i <= up; i++) c[up] = 0;
  cnt = 0;
  for (i = 0; i < n; i++) {
    scanf("%d%d", &l, &r);
    p[i].l = l;
    p[i].r = r;
    p[i].id = i;
    x[cnt] = l;
    cnt++;
    x[cnt] = r;
    cnt++;
  }
  mp.clear();
  sort(x, x + cnt);
  sort(p, p + n, cmp);
  for (i = 0; i < cnt; i++) {
    mp[x[i]] = i + 1;
  }
  for (i = 0; i < n; i++) {
    p[i].l = mp[p[i].l];
    p[i].r = mp[p[i].r];
    add(p[i].r, 1);
  }
  for (i = 0; i < n; i++) {
    l = p[i].l;
    r = p[i].r;
    if (r - l < 2)
      p[i].ans = 0;
    else
      p[i].ans = sum(r - 1) - sum(l);
    add(p[i].r, -1);
  }
  sort(p, p + n, cmp2);
  for (i = 0; i < n; i++) printf("%d\n", p[i].ans);
  return 0;
}

### 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 long long mod = 1000000007;
const int N = 2 * (1e5) + 10;
const int up = 2 * N;
struct node {
  int l, r, id, ans;
} p[N];
int c[up + 10];
map<int, int> mp;
int cmp(node a, node b) { return a.l < b.l; }
int cmp2(node a, node b) { return a.id < b.id; }
int lowbit(int x) { return x & -x; }
int sum(int x) {
  int ret = 0;
  while (x > 0) {
    ret += c[x];
    x -= lowbit(x);
  }
  return ret;
}
void add(int x, int d) {
  while (x <= up) {
    c[x] += d;
    x += lowbit(x);
  }
}
int x[up + 10];
int main() {
  int i, n, cnt, l, r;
  scanf("%d", &n);
  for (i = 0; i <= up; i++) c[up] = 0;
  cnt = 0;
  for (i = 0; i < n; i++) {
    scanf("%d%d", &l, &r);
    p[i].l = l;
    p[i].r = r;
    p[i].id = i;
    x[cnt] = l;
    cnt++;
    x[cnt] = r;
    cnt++;
  }
  mp.clear();
  sort(x, x + cnt);
  sort(p, p + n, cmp);
  for (i = 0; i < cnt; i++) {
    mp[x[i]] = i + 1;
  }
  for (i = 0; i < n; i++) {
    p[i].l = mp[p[i].l];
    p[i].r = mp[p[i].r];
    add(p[i].r, 1);
  }
  for (i = 0; i < n; i++) {
    l = p[i].l;
    r = p[i].r;
    if (r - l < 2)
      p[i].ans = 0;
    else
      p[i].ans = sum(r - 1) - sum(l);
    add(p[i].r, -1);
  }
  sort(p, p + n, cmp2);
  for (i = 0; i < n; i++) printf("%d\n", p[i].ans);
  return 0;
}

```