human
Can you solve the below in CPP?
Nikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer x on the top of the stack, and operation pop() deletes the top integer from the stack, i. e. the last added. If the stack is empty, then the operation pop() does nothing.

Nikita made m operations with the stack but forgot them. Now Nikita wants to remember them. He remembers them one by one, on the i-th step he remembers an operation he made pi-th. In other words, he remembers the operations in order of some permutation p1, p2, ..., pm. After each step Nikita wants to know what is the integer on the top of the stack after performing the operations he have already remembered, in the corresponding order. Help him!

Input

The first line contains the integer m (1 ≤ m ≤ 105) — the number of operations Nikita made.

The next m lines contain the operations Nikita remembers. The i-th line starts with two integers pi and ti (1 ≤ pi ≤ m, ti = 0 or ti = 1) — the index of operation he remembers on the step i, and the type of the operation. ti equals 0, if the operation is pop(), and 1, is the operation is push(x). If the operation is push(x), the line also contains the integer xi (1 ≤ xi ≤ 106) — the integer added to the stack.

It is guaranteed that each integer from 1 to m is present exactly once among integers pi.

Output

Print m integers. The integer i should equal the number on the top of the stack after performing all the operations Nikita remembered on the steps from 1 to i. If the stack is empty after performing all these operations, print -1.

Examples

Input

2
2 1 2
1 0

Output

2
2

Input

3
1 1 2
2 1 3
3 0

Output

2
3
2

Input

5
5 0
4 0
3 1 1
2 1 1
1 1 2

Output

-1
-1
-1
-1
2

Note

In the first example, after Nikita remembers the operation on the first step, the operation push(2) is the only operation, so the answer is 2. After he remembers the operation pop() which was done before push(2), answer stays the same.

In the second example, the operations are push(2),...
assistant
#Here is Python program to print m integers.

#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1 << 17;
const int def = 0;
const int INF = 1 << 25;
struct MaxSegTree2 {
  int n;
  long long segMax[2 * MAX_N - 1], segAdd[2 * MAX_N - 1];
  void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    for (int i = 0; i < 2 * n - 1; i++) segMax[i] = def;
  }
  void add(int a, int b, long long x) { add(a, b, x, 0, 0, n); }
  void add(int a, int b, long long x, int k, int l, int r) {
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      segAdd[k] += x;
      return;
    }
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);
    segMax[k] = max(segMax[k * 2 + 1] + segAdd[k * 2 + 1],
                    segMax[k * 2 + 2] + segAdd[k * 2 + 2]);
  }
  long long query(int a, int b) { return query(a, b, 0, 0, n); }
  long long query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return def;
    if (a <= l && r <= b) return segMax[k] + segAdd[k];
    long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr) + segAdd[k];
  }
};
MaxSegTree2 st;
int x[100010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int m;
  cin >> m;
  st.init(100010);
  int last_t = 0, last_op = 0;
  for (int i = 0; i < m; i++) {
    int t, op;
    cin >> t >> op;
    if (op == 0) {
      st.add(0, t + 1, -1);
    } else {
      cin >> x[t];
      st.add(0, t + 1, 1);
    }
    if (last_t < t) {
      last_t = t;
      last_op = op;
    }
    if (last_op == 1) {
      cout << x[last_t] << endl;
    } else {
      if (st.query(0, m + 1) <= 0) {
        cout << -1 << endl;
      } else {
        int lb = 0, ub = m + 1;
        while (abs(lb - ub) > 1) {
          int mid = (lb + ub) / 2;
          int sum = st.query(mid, m + 1);
          if (sum > 0)
            lb = mid;
          else
            ub = mid;
        }
        cout << x[lb] << endl;
      }
    }
  }
}