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};
            }
        }

    }
}
