#include <bits/stdc++.h>
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += 1000000007;
}
inline void add(long long &a, long long b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
template <typename T>
inline T const &MAX(T const &a, T const &b) {
  return a > b ? a : b;
}
template <typename T>
inline T const &MIN(T const &a, T const &b) {
  return a < b ? a : b;
}
inline long long qp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 1000000007;
    a = a * a % 1000000007, b >>= 1;
  }
  return ans;
}
inline long long qp(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % c;
    a = a * a % c, b >>= 1;
  }
  return ans;
}
using namespace std;
const unsigned long long ba = 233;
const double eps = 1e-8;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 400000 + 10, maxn = 10000000 + 10, inf = 0x3f3f3f3f;
struct info {
  int l, r, id;
  void read() { scanf("%d%d", &l, &r); }
  bool operator<(const info &rhs) const {
    return l < rhs.l || (l == rhs.l && r < rhs.r);
  }
} a[N];
int b[N], cnt;
struct bit {
  int sum[N];
  void update(int i, int v) {
    for (; i < N; i += i & (-i)) sum[i] += v;
  }
  int query(int i) {
    int ans = 0;
    for (; i; i -= i & (-i)) ans += sum[i];
    return ans;
  }
} c;
int ans[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    a[i].read(), a[i].id = i, b[cnt++] = a[i].l, b[cnt++] = a[i].r;
  sort(b, b + cnt);
  cnt = unique(b, b + cnt) - b;
  sort(a + 1, a + 1 + n);
  for (int i = n; i >= 1; i--) {
    a[i].l = lower_bound(b, b + cnt, a[i].l) - b + 1;
    a[i].r = lower_bound(b, b + cnt, a[i].r) - b + 1;
    ans[a[i].id] = c.query(a[i].r);
    c.update(a[i].r, 1);
  }
  for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
  return 0;
}

### Prompt

Generate 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>
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += 1000000007;
}
inline void add(long long &a, long long b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
template <typename T>
inline T const &MAX(T const &a, T const &b) {
  return a > b ? a : b;
}
template <typename T>
inline T const &MIN(T const &a, T const &b) {
  return a < b ? a : b;
}
inline long long qp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 1000000007;
    a = a * a % 1000000007, b >>= 1;
  }
  return ans;
}
inline long long qp(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % c;
    a = a * a % c, b >>= 1;
  }
  return ans;
}
using namespace std;
const unsigned long long ba = 233;
const double eps = 1e-8;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 400000 + 10, maxn = 10000000 + 10, inf = 0x3f3f3f3f;
struct info {
  int l, r, id;
  void read() { scanf("%d%d", &l, &r); }
  bool operator<(const info &rhs) const {
    return l < rhs.l || (l == rhs.l && r < rhs.r);
  }
} a[N];
int b[N], cnt;
struct bit {
  int sum[N];
  void update(int i, int v) {
    for (; i < N; i += i & (-i)) sum[i] += v;
  }
  int query(int i) {
    int ans = 0;
    for (; i; i -= i & (-i)) ans += sum[i];
    return ans;
  }
} c;
int ans[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    a[i].read(), a[i].id = i, b[cnt++] = a[i].l, b[cnt++] = a[i].r;
  sort(b, b + cnt);
  cnt = unique(b, b + cnt) - b;
  sort(a + 1, a + 1 + n);
  for (int i = n; i >= 1; i--) {
    a[i].l = lower_bound(b, b + cnt, a[i].l) - b + 1;
    a[i].r = lower_bound(b, b + cnt, a[i].r) - b + 1;
    ans[a[i].id] = c.query(a[i].r);
    c.update(a[i].r, 1);
  }
  for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
  return 0;
}

```