King Kog got annoyed of the usual laxity of his knights — they can break into his hall without prior notice! Thus, the King decided to build a reception with a queue where each knight chooses in advance the time when he will come and how long the visit will take. The knights are served in the order of the recorded time, but each knight has to wait until the visits of all the knights before him are finished.

Princess Keabeanie wants to see her father. However, she does not want to interrupt the knights so she joins the queue. Unfortunately, the knights change their minds very often — they can join the queue or cancel their visits. Please help the princess to understand how long she will have to wait until she sees her father if she enters the queue at the specified moments of time given the records at the reception.

Input

The first line of the input contains a single integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of events. An event can be of three types: join, cancel, or query.

  * Join "+ t d" (1 ≤ t, d ≤ 10^6) — a new knight joins the queue, where t is the time when the knight will come and d is the duration of the visit.
  * Cancel "- i" (1 ≤ i ≤ q) — the knight cancels the visit, where i is the number (counted starting from one) of the corresponding join event in the list of all events.
  * Query "? t" (1 ≤ t ≤ 10^6) — Keabeanie asks how long she will wait if she comes at the time t. 



It is guaranteed that after each event there are no two knights with the same entrance time in the queue. Cancel events refer to the previous joins that were not cancelled yet.

Keabeanie can come at the same time as some knight, but Keabeanie is very polite and she will wait for the knight to pass.

Output

For each query write a separate line with the amount of time Keabeanie will have to wait.

Example

Input


19
? 3
+ 2 2
? 3
? 4
+ 5 2
? 5
? 6
+ 1 2
? 2
? 3
? 4
? 5
? 6
? 7
? 9
- 8
? 2
? 3
? 6


Output


0
1
0
2
1
3
2
1
2
1
0
0
2
1
1
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class Task {

    public static void main(String[] args) throws IOException {

        new Task().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Task() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws IOException {

        int t = 1;
        while (t > 0) {
            solve();
            //out.println();
            t--;
        }

        out.flush();
        out.close();
    }

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    ArrayList<Integer>[] g;
    int[] a;

    void solve() throws IOException {

        int n = in.nextInt();

        int maxt = 1000010;
        SegmentTree st = new SegmentTree(maxt);

        ArrayList<Pair> adds = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            String s = in.next();
            if (s.equals("?")) {
                int t = in.nextInt();
                long max = st.max(1, 0, maxt-1, 0, t);
                long sum = st.sum(1, 0, maxt-1, t+1, maxt-1);
                long ans = Math.max(t, max - sum);
                //System.err.println(max + " " + sum);
                adds.add(new Pair(t, 0));
                out.println(ans - t);
            }
            else if (s.equals("+")) {
                int t = in.nextInt();
                int d = in.nextInt();
                st.add(1, 0, maxt-1, 0, t, d);
                st.updMax(1, 0, maxt-1, t, t);
                st.updSum(1, 0, maxt-1, t, d);
                adds.add(new Pair(t, d));
            }
            else {
                int pos = in.nextInt();
                int t = adds.get(pos - 1).a;
                int d = adds.get(pos - 1).b;
                st.add(1, 0, maxt-1, 0, t, -d);
                st.updSum(1, 0, maxt-1, t, -d);
                st.updMax(1, 0, maxt - 1, t, -t);
                adds.add(new Pair(t, d));
            }
        }

    }

    class SegmentTree {

        long[] sum;
        long[] max;
        long[] f;

        SegmentTree(int n) {
            sum = new long[n * 4];
            max = new long[n * 4];
            f = new long[n * 4];
        }

        void push(int v) {
            f[v*2] += f[v];
            f[v*2+1] += f[v];
            f[v] = 0;
        }

        void updMax(int v, int tl, int tr, int i, int x) {

            if (tl == tr) {
                max[v] += x;
                return;
            }

            push(v);
            int tm = (tl + tr) / 2;
            if (i <= tm)
                updMax(v * 2, tl, tm, i, x);
            else
                updMax(v * 2 + 1, tm + 1, tr, i, x);
            max[v] = Math.max(max[v * 2] + f[v * 2], max[v * 2 + 1] + f[v * 2 + 1]);
        }

        void add(int v, int tl, int tr, int l, int r, int x) {

            if (l > r)
                return;

            if (tl == l && tr == r) {
                f[v] += x;
                return;
            }

            push(v);
            int tm = (tl + tr) / 2;
            add(v * 2, tl, tm, l, Math.min(r, tm), x);
            add(v * 2 + 1, tm+1, tr, Math.max(tm + 1, l), r, x);
            max[v] = Math.max(max[v * 2] + f[v * 2], max[v * 2 + 1] + f[v * 2 + 1]);
        }

        void updSum(int v, int tl, int tr, int i, int x) {

            if (tl == tr) {
                sum[v] += x;
                return;
            }

            int tm = (tl + tr) / 2;
            if (i <= tm)
                updSum(v * 2, tl, tm, i, x);
            else
                updSum(v * 2 + 1, tm + 1, tr, i, x);
            sum[v] = sum[v * 2] + sum[v * 2 + 1];
        }

        long sum(int v, int tl, int tr, int l, int r) {

            if (l > r)
                return 0;

            if (tl == l && tr == r) {
                return sum[v];
            }

            int tm = (tl + tr) / 2;

            return sum(v * 2, tl, tm, l, Math.min(r, tm))
                    + sum(v * 2 + 1, tm + 1, tr, Math.max(tm+1, l), r);
        }

        long max(int v, int tl, int tr, int l, int r) {

            if (l > r)
                return 0;

            if (tl == l && tr == r) {
                return max[v] + f[v];
            }

            int tm = (tl + tr) / 2;
            long mx1 = max(v * 2, tl, tm, l, Math.min(r, tm));
            long mx2 = max(v * 2 + 1, tm + 1, tr, Math.max(tm+1, l), r);
            return Math.max(mx1, mx2) + f[v];
        }

    }

    int gcd(int a, int b){
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {
            if (a > p.a) return 1;
            if (a < p.a) return -1;
            if (b > p.b) return 1;
            if (b < p.b) return -1;
            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }


        String nextLine() throws IOException {
            return br.readLine();
        }

    }

}