Problem: Polycarpus has many tasks. Each task is characterized by three integers li, ri and ti. Three integers (li, ri, ti) mean that to perform task i, one needs to choose an integer si (li ≤ si; si + ti - 1 ≤ ri), then the task will be carried out continuously for ti units of time, starting at time si and up to time si + ti - 1, inclusive. In other words, a task is performed for a continuous period of time lasting ti, should be started no earlier than li, and completed no later than ri.

Polycarpus's tasks have a surprising property: for any task j, k (with j < k) lj < lk and rj < rk.

Let's suppose there is an ordered set of tasks A, containing |A| tasks. We'll assume that aj = (lj, rj, tj) (1 ≤ j ≤ |A|). Also, we'll assume that the tasks are ordered by increasing lj with the increase in number.

Let's consider the following recursive function f, whose argument is an ordered set of tasks A, and the result is an integer. The function f(A) is defined by the greedy algorithm, which is described below in a pseudo-language of programming.

  * Step 1. <image>, ans = 0. 
  * Step 2. We consider all tasks in the order of increasing of their numbers in the set A. Lets define the current task counter i = 0. 
  * Step 3. Consider the next task: i = i + 1. If i > |A| fulfilled, then go to the 8 step. 
  * Step 4. If you can get the task done starting at time si = max(ans + 1, li), then do the task i: si = max(ans + 1, li), ans = si + ti - 1, <image>. Go to the next task (step 3). 
  * Step 5. Otherwise, find such task <image>, that first, task ai can be done at time si = max<image>, and secondly, the value of <image> is positive and takes the maximum value among all bk that satisfy the first condition. If you can choose multiple tasks as bk, choose the one with the maximum number in set A. 
  * Step 6. If you managed to choose task bk, then <image>, <image>. Go to the next task (step 3). 
  * Step 7. If you didn't manage to choose task bk, then skip task i. Go to the next task (step 3). 
  * Step 8. Return ans as a result of executing f(A). 



Polycarpus got entangled in all these formulas and definitions, so he asked you to simulate the execution of the function f, calculate the value of f(A).

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 105) — the number of tasks in set A. 

Then n lines describe the tasks. The i-th line contains three space-separated integers li, ri, ti (1 ≤ li ≤ ri ≤ 109, 1 ≤ ti ≤ ri - li + 1) — the description of the i-th task.

It is guaranteed that for any tasks j, k (considering that j < k) the following is true: lj < lk and rj < rk.

Output

For each task i print a single integer — the result of processing task i on the i-th iteration of the cycle (step 3) in function f(A). In the i-th line print:

  * 0 — if you managed to add task i on step 4. 
  * -1 — if you didn't manage to add or replace task i (step 7). 
  * resi (1 ≤ resi ≤ n) — if you managed to replace the task (step 6): resi equals the task number (in set A), that should be chosen as bk and replaced by task ai. 

Examples

Input

5
1 8 5
2 9 3
3 10 3
8 11 4
11 12 2


Output

0 0 1 0 -1 

Input

13
1 8 5
2 9 4
3 10 1
4 11 3
8 12 5
9 13 5
10 14 5
11 15 1
12 16 1
13 17 1
14 18 3
15 19 3
16 20 2


Output

0 0 0 2 -1 -1 0 0 0 0 7 0 12 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n;
const int MAXN = 1 << 18;
struct Node {
  int a, b, p;
  Node(int a = 0, int b = 0, int p = 0) : a(a), b(b), p(p) {}
} A[MAXN];
int d[MAXN];
void renew(int u, int t) { A[u].a += t, d[u] += t; }
Node merge(Node l, Node r) {
  return Node(max(l.a, r.a), max(l.b, r.b), (l.b > r.b ? l.p : r.p));
}
void down(int u) {
  if (!d[u]) return;
  renew(u + u, d[u]);
  renew(1 + u + u, d[u]);
  d[u] = 0;
}
void up(int u) { A[u] = merge(A[u + u], A[u + u + 1]); }
void build(int u, int l, int r) {
  A[u].a = A[u].b = d[u] = 0, A[u].p = r;
  if (l == r) return;
  int mid = l + r >> 1;
  build(u + u, l, mid), build(u + u + 1, mid + 1, r);
}
void add(int u, int l, int r, int ll, int rr, int t) {
  if (ll <= l && r <= rr) {
    renew(u, t);
    return;
  }
  int mid = l + r >> 1;
  down(u);
  if (ll <= mid) add(u + u, l, mid, ll, rr, t);
  if (mid < rr) add(u + u + 1, mid + 1, r, ll, rr, t);
  up(u);
}
void update(int u, int l, int r, int x, int t) {
  if (l == r) {
    A[u].b = t;
    return;
  }
  int mid = l + r >> 1;
  down(u);
  if (x <= mid)
    update(u + u, l, mid, x, t);
  else
    update(u + u + 1, mid + 1, r, x, t);
  up(u);
}
Node get(int u, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) return A[u];
  int mid = l + r >> 1;
  down(u);
  Node ret;
  if (ll <= mid) ret = merge(ret, get(u + u, l, mid, ll, rr));
  if (mid < rr) ret = merge(ret, get(u + u + 1, mid + 1, r, ll, rr));
  return ret;
}
bool check(int mid) {
  Node r = get(1, 1, n, mid + 1, n);
  int rhs = (r.p == n ? 0 : get(1, 1, n, r.p + 1, n).a);
  int lhs = get(1, 1, n, 1, r.p - 1).a - r.b;
  return lhs > rhs;
}
int L[MAXN], R[MAXN], T[MAXN];
int main() {
  scanf("%d", &n);
  int ans = 1;
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &L[i], &R[i], &T[i]), R[i]++;
    if (ans + T[i] <= R[i]) {
      printf("%d ", 0);
      ans = max(L[i], ans) + T[i];
      add(1, 1, n, 1, i, T[i]);
      add(1, 1, n, i, i, L[i]);
      update(1, 1, n, i, T[i]);
      continue;
    }
    if (L[i] + T[i] >= ans) {
      printf("%d ", -1);
      continue;
    }
    int lo = 0, hi = i;
    while (hi - lo > 1) {
      int mid = lo + hi >> 1;
      if (check(mid))
        hi = mid;
      else
        lo = mid;
    }
    if (hi == i) {
      printf("%d ", -1);
      continue;
    }
    int now = min(R[i], ans) - T[i], ret = 0;
    Node rhs = get(1, 1, n, hi + 1, n);
    if (rhs.b > 0) {
      int temp = max(0, get(1, 1, n, 1, rhs.p - 1).a - rhs.b);
      if (temp < now) now = temp, ret = rhs.p;
    }
    if (T[hi] > 0) {
      int temp = get(1, 1, n, hi + 1, n).a;
      if (temp < now) now = temp, ret = hi;
    }
    if (!ret) {
      printf("%d ", -1);
      continue;
    }
    add(1, 1, n, 1, ret, -T[ret]);
    add(1, 1, n, ret, ret, -L[ret]);
    update(1, 1, n, ret, 0);
    add(1, 1, n, 1, i, T[i]);
    add(1, 1, n, i, i, L[i]);
    update(1, 1, n, i, T[i]);
    ans = max(now, L[i]) + T[i];
    printf("%d ", ret);
  }
  puts("");
  return 0;
}