In one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five consecutive elements and find the median of each five. A median is called the middle element of a sorted array (it's the third largest element for a group of five). To increase the algorithm's performance speed on a modern video card, you should be able to find a sum of medians in each five of the array.

A sum of medians of a sorted k-element set S = {a1, a2, ..., ak}, where a1 < a2 < a3 < ... < ak, will be understood by as 

<image>

The <image> operator stands for taking the remainder, that is <image> stands for the remainder of dividing x by y.

To organize exercise testing quickly calculating the sum of medians for a changing set was needed.

Input

The first line contains number n (1 ≤ n ≤ 105), the number of operations performed.

Then each of n lines contains the description of one of the three operations: 

  * add x — add the element x to the set; 
  * del x — delete the element x from the set; 
  * sum — find the sum of medians of the set. 



For any add x operation it is true that the element x is not included in the set directly before the operation.

For any del x operation it is true that the element x is included in the set directly before the operation.

All the numbers in the input are positive integers, not exceeding 109.

Output

For each operation sum print on the single line the sum of medians of the current set. If the set is empty, print 0.

Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams (also you may use the %I64d specificator).

Examples

Input

6
add 4
add 5
add 1
add 2
add 3
sum


Output

3


Input

14
add 1
add 7
add 2
add 5
sum
add 6
add 8
add 9
add 3
add 4
add 10
sum
del 1
sum


Output

5
11
13
import java.util.InputMismatchException;
import java.util.Random;
import java.io.*;
import java.util.Arrays;

/**
 * Generated by Contest helper plug-in
 * Actual solution is at the bottom
 */
public class Main {
    public static void main(String[] args) {
        InputReader in = new StreamInputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        run(in, out);
    }

    public static void run(InputReader in, PrintWriter out) {
        Solver solver = new tascD();
        solver.solve(1, in, out);
        Exit.exit(in, out);
    }
}

abstract class InputReader {
    private boolean finished = false;

    public abstract int read();

    public int nextInt() {
        return Integer.parseInt(nextToken());
    }
    public String readString() {
        return readLine();
    }


    public String readLine() {
        StringBuffer res = new StringBuffer();
        int c = read();
        while (c != '\n' && c != -1) {
            if (c != '\r')
                res.appendCodePoint(c);
            c = read();
        }
        return res.toString();
    }
    public String nextToken() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }
    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public void setFinished(boolean finished) {
        this.finished = finished;
    }

    public abstract void close();
}

class StreamInputReader extends InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar, numChars;

    public StreamInputReader(InputStream stream) {
        this.stream = stream;
        curChar = 0;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    @Override
    public void close() {
        try {
            stream.close();
        } catch (IOException ignored) {
        }
    }
}

class Exit {
    private Exit() {
    }

    public static void exit(InputReader in, PrintWriter out) {
        in.setFinished(true);
        in.close();
        out.close();
    }
}

interface Solver {
    public void solve(int testNumber, InputReader in, PrintWriter out);
}

class tascD implements Solver {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        random = new Random(398257235L);
        Treap treap = new Treap();
        int q = in.nextInt();
        for (int i = 0; i < q; ++i) {
            String token = in.nextToken();
            if (token.equals("add")) {
                treap.add(in.nextInt());
            } else if (token.equals("del")) {
                treap.delete(in.nextInt());
            } else out.println(treap.getMedian());
           // treap.out(treap.root, out);
           // out.println();
        }


    }
    Random random;

    class Treap {
        long getMedian() {
            return getSum(root, 2);
        }
        Node root;
        public Treap() {
            root = null;
        }
        void add(int value) {
            Node [] tmp = split(root, value);
            root = merge(tmp[0], new Node(value));
            root = merge(root, tmp[1]);
        }
        void delete(int value) {
            Node [] tmp = split(root, value + 1);
            Node [] p = split(tmp[0], value);
            root = merge(p[0], tmp[1]);
        }
        private class Node {
            int value;
            int pr;
            int cnt;
            long f[];
            Node left;
            Node right;
            public Node(int x) {
                this.value = x;
                pr = random.nextInt();
                cnt = 1;
                f = new long[5];
                f[0] = x;
                left = null;
                right = null;
            }
        }
        int getCnt(Node node) {
            return node == null ? 0 : node.cnt;
        }
        long getSum(Node node, int i) {
            return node == null? 0 : node.f[i];
        }

        public void update(Node node) {
            if (node != null) {
                node.cnt = getCnt(node.left) + getCnt(node.right) + 1;
                for (int i = 0; i < 5; ++i) {
                    node.f[i] = 0;
                }
                for (int i = 0; i < 5; ++i) {
                    node.f[i] = getSum(node.left, i);
                }
                int cntLeft = getCnt(node.left);
                node.f[cntLeft % 5] += node.value;
                for (int i = 0; i < 5; ++i) {
                    node.f[(cntLeft + i + 1) % 5] += getSum(node.right, i);
                }
            }
        }

        Node merge(Node left, Node right) {
            if (left == null) return right;
            if (right == null) return left;
            if (left.pr < right.pr) {
                right.left = merge(left, right.left);
                update(right);
                return right;
            } else {
                left.right = merge(left.right, right);
                update(left);
                return left;
            }
        }
        Node[] split(Node tree, int x) {
            if (tree == null)
                return new Node[] {null, null};
            if (tree.value < x) {
                Node[] tmp = split(tree.right, x);
                tree.right = tmp[0];
                update(tree);
                return new Node[] {tree, tmp[1]};
            } else {
                Node[] tmp = split(tree.left, x);
                tree.left = tmp[1];
                update(tree);
                return new Node[] {tmp[0], tree};
            }
        }

    }
}
