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;
struct work {
  int l, r, t, e, diff, id;
};
int inf = (int)2e9;
struct node {
  int to_min, to_max, e, to_sub;
  node() { to_min = to_max = e = to_sub = 0; }
};
struct Tree {
  vector<node> tree;
  int st, d;
  Tree(int n) {
    st = 1;
    d = 0;
    while (st < n) {
      st *= 2;
      d++;
    }
    tree.resize(st * 2);
  }
  void flush(int v) {
    if (tree[v].to_min != inf) {
      tree[v].to_min -= tree[v].to_sub;
    }
    tree[v].e -= tree[v].to_sub;
    tree[v].to_sub = 0;
  }
  void fix(int v) {
    if (tree[v].to_sub) {
      if (v < st) {
        int l = v * 2, r = l + 1;
        tree[l].to_sub += tree[v].to_sub;
        tree[r].to_sub += tree[v].to_sub;
      }
      flush(v);
    }
  }
  void recalc(int v) {
    int l = v * 2, r = l + 1;
    tree[v].to_min = min(tree[l].to_min, tree[r].to_min);
    tree[v].to_max = max(tree[l].to_max, tree[r].to_max);
  }
  void fix_down(int i) {
    int v = 1, x = d - 1;
    while (v != i) {
      int f = (i >> x) & 1;
      x--;
      fix(v);
      v = v * 2 + f;
    }
    fix(v);
  }
  void go(int v, int vl, int vr, int l, int r, int x) {
    if (r < vl || vr < l) {
      fix(v);
      return;
    }
    if (l <= vl && vr <= r) {
      tree[v].to_sub += x;
      fix(v);
      return;
    }
    int nl = v * 2, nr = nl + 1, vc = (vl + vr) / 2;
    go(nl, vl, vc, l, r, x);
    go(nr, vc + 1, vr, l, r, x);
    recalc(v);
  }
  void sub(int l, int r, int x) { go(1, 0, st - 1, l, r, x); }
  pair<int, int> get(int v, int vl, int vr, int l, int r) {
    if (r < vl || vr < l) {
      return make_pair(inf, 0);
    }
    fix(v);
    if (l <= vl && vr <= r) {
      return make_pair(tree[v].to_min, tree[v].to_max);
    }
    int nl = v * 2, nr = nl + 1, vc = (vl + vr) / 2;
    pair<int, int> a = get(nl, vl, vc, l, r), b = get(nr, vc + 1, vr, l, r);
    return make_pair(min(a.first, b.first), max(a.second, b.second));
  }
  pair<int, int> get(int l, int r) { return get(1, 0, st - 1, l, r); }
  node &operator[](int i) {
    i += st;
    fix_down(i);
    return tree[i];
  }
  void fix_up(int v) {
    v += st;
    while (v != 1) {
      int u = v ^ 1;
      fix(u);
      v /= 2;
      recalc(v);
    }
  }
};
void fix(work &a, work &b) {
  b.e = max(a.e, b.l) + b.t;
  b.diff = b.r == inf ? inf : b.e - b.t - b.l;
}
int reset(Tree *tree, int i, int j, const work &work_j) {
  int ne = max((*tree)[i].e, work_j.l) + work_j.t;
  node *nd = &(*tree)[j];
  nd->to_min = work_j.r == inf ? inf : ne - work_j.t - work_j.l;
  nd->to_max = work_j.t;
  nd->e = ne;
  tree->fix_up(j);
  return ne;
}
int main(void) {
  int work_n;
  scanf("%d", &work_n);
  vector<work> works(work_n);
  for (int i = 0; i < work_n; i++) {
    scanf("%d %d %d", &works[i].l, &works[i].r, &works[i].t);
    works[i].r++;
    works[i].id = i + 1;
  }
  vector<int> ids(work_n + 1);
  int res_i = 0;
  Tree tree(work_n + 1);
  work empty;
  empty.l = 1, empty.r = inf;
  empty.t = 0;
  empty.diff = inf;
  empty.e = 1;
  node *nd = &tree[0];
  nd->to_min = inf;
  nd->to_max = 0;
  nd->e = 1;
  tree.fix_up(0);
  for (int i = 0; i < work_n; i++) {
    ids[res_i + 1] = works[i].id;
    int ne = reset(&tree, res_i, res_i + 1, works[i]);
    bool new_f = ne <= works[i].r;
    if (ne <= works[i].r) {
      res_i++;
      printf("0 ");
      continue;
    }
    int best_j = -1, old_ans = tree[res_i].e, x_ans = tree[res_i + 1].e,
        best_sub = 0;
    int l = 1, r = res_i + 1, rx = -1;
    while (l + 1 < r) {
      int c = (l + r) / 2;
      int a = tree.get(c + 1, res_i + 1).first, b = tree.get(c, res_i).second;
      if (a > b) {
        rx = min(a, b);
        r = c;
      } else {
        l = c;
      }
    }
    if (r == res_i + 1) {
      r--;
      rx = min(tree.get(r + 1, res_i + 1).first, tree.get(r, res_i).second);
      ;
    } else {
      int px = -1;
      if (r > 1) {
        px = min(tree.get(r - 1 + 1, res_i + 1).first,
                 tree.get(r - 1, res_i).second);
        ;
      }
      if (px > rx) {
        r--;
        rx = px;
      } else {
        for (int d = 1 << 20; d >= 1; d >>= 1) {
          int t = r + d;
          if (t <= res_i) {
            int tx = min(tree.get(t + 1, res_i + 1).first,
                         tree.get(t, res_i).second);
            ;
            if (tx == rx) {
              rx = tx;
              r = t;
            }
          }
        }
      }
    }
    best_sub = rx;
    best_j = r;
    if (x_ans - best_sub >= old_ans) {
      printf("-1 ");
    } else {
      res_i++;
      printf("%d ", ids[best_j]);
      reset(&tree, best_j - 1, best_j, empty);
      tree.sub(best_j + 1, res_i, best_sub);
    }
  }
  return 0;
}