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.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    FastScanner in;
    PrintWriter out;

    public static void main(String[] args) {
        try {
            (new Main()).run();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void run() throws IOException {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        Tree tree = new Tree(0, 1000_005);
        List<Integer> list = new ArrayList<>();
        int q = in.nextInt();
        while (q-- > 0) {
            char command = in.next().charAt(0);
            int t = in.nextInt();
            list.add(t);
            if (command == '+') {
                int d = in.nextInt();
                tree.set(t, d);
            }
            if (command == '?') {
                out.println(tree.quarry(t));
            }
            if (command == '-') {
                tree.set(list.get(t - 1), -1);
            }
        }
        out.close();
    }

    private class Tree {
        Node root;

        Tree(int l, int r) {
            root = build(l, r);
        }

        public void set(int t, int d) {
            set(root, t, d);
        }

        private void set(Node node, int t, int d) {
            if (t < node.l || t >= node.r) return;
            if (node.isLeaf) {
                if (d > 0) {
                    node.kill = 0;
                    node.generate = d - 1;
                }
                if (d == -1) {
                    node.kill = 1;
                    node.generate = 0;
                }
                return;
            }
            set(node.leftSon, t, d);
            set(node.rightSon, t, d);
            fixNode(node);
        }

        public long quarry(int t) {
            Node current = root;
            long res = 0;
            while (!current.isLeaf) {
                int mid = (current.l + current.r) / 2;
                if (t < mid) {
                    current = current.leftSon;
                } else {
                    res -= current.leftSon.kill;
                    if (res < 0) res = 0;
                    res += current.leftSon.generate;
                    current = current.rightSon;
                }
            }
            res+=current.generate+1-current.kill;
            return res;
        }

        private Node build(int l, int r) {
            if (r - l == 1) {
                return new Node(l, r, 0, 1, true);
            }
            Node node = new Node(l, r, 0, 0, false);
            int mid = (l + r) / 2;
            node.leftSon = build(l, mid);
            node.rightSon = build(mid, r);
            fixNode(node);
            return node;
        }

        private void fixNode(Node node) {
            if (node == null || node.rightSon == null || node.leftSon == null) return;
            node.kill = node.leftSon.kill + Math.max(0, node.rightSon.kill - node.leftSon.generate);
            node.generate = node.rightSon.generate + Math.max(0, node.leftSon.generate - node.rightSon.kill);
        }

        private class Node {
            int l;
            int r;
            long generate;
            long kill;
            boolean isLeaf;
            Node leftSon;
            Node rightSon;

            Node(int l, int r, int generate, long kill, boolean isLeaf) {
                this.l = l;
                this.r = r;
                this.generate = generate;
                this.kill = kill;
                this.isLeaf = isLeaf;
            }
        }
    }

    private class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        FastScanner(InputStream inputStream) {
            this.bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        FastScanner(File file) throws IOException {
            this.bufferedReader = new BufferedReader(new FileReader(file));
        }

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

        public String next() throws IOException {
            while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                String line = bufferedReader.readLine();
                if (line == null) return null;
                stringTokenizer = new StringTokenizer(line);
            }
            return stringTokenizer.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

    }
}