import java.util.*;
import java.io.*;

public class D_as {
    FastScanner in;
    PrintWriter out;

    static class Tree {
        int x;
        int y;
        long sum;
        int max;
        Tree l;
        Tree r;

        Tree(int x, int y) {
            this.x = x;
            this.y = y;
            this.sum = x;
            this.max = x;
        }

        void update() {
            sum = x;
            max = x;
            if (l != null) {
                sum += l.sum;
            }
            if (r != null) {
                sum += r.sum;
                max = r.max;
            }
        }
    }

    Tree[] tmp;
    Tree[] split(Tree t, int x) {
        if (t == null) {
            tmp[0] = tmp[1] = null;
            return tmp;
        }

        if (t.x <= x) {
            Tree[] res = split(t.r, x);
            t.r = res[0];
            t.update();
            res[0] = t;
            return res;
        } else {
            Tree[] res = split(t.l, x);
            t.l = res[1];
            t.update();
            res[1] = t;
            return res;
        }
    }

    Tree merge(Tree a, Tree b) {
        if (a == null) {
            return b;
        }
        if (b == null) {
            return a;
        }
        if (a.y < b.y) {
            a.r = merge(a.r, b);
            a.update();
            return a;
        } else {
            b.l = merge(a, b.l);
            b.update();
            return b;
        }
    }

    public void solve() throws IOException {
        Random rnd = new Random();
        Tree[] t = new Tree[5];
        Tree[] tt = new Tree[5];
        tmp = new Tree[2];
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String op = in.next();
            if (op.equals("sum")) {
                if (t[2] != null) {
                    out.println(t[2].sum);
                } else {
                    out.println(0);
                }
            } else if (op.equals("add")) {
                int x = in.nextInt();

                int best = -1;
                int bestp = -1;
                for (int j = 0; j < 5; j++) {
                    Tree[] res = split(t[j], x);
                    t[j] = res[0];
                    tt[j] = res[1];
                    if (res[0] != null && res[0].max > best) {
                        best = res[0].max;
                        bestp = j;
                    }
                }
                bestp = (bestp + 1) % 5;
                t[bestp] = merge(t[bestp], new Tree(x, rnd.nextInt()));
                for (int j = 0; j < 5; j++) {
                    t[(j + 1) % 5] = merge(t[(j + 1) % 5], tt[j]);
                }
            } else if (op.equals("del")) {
                int x = in.nextInt();

                int best = -1;
                int bestp = 0;
                for (int j = 0; j < 5; j++) {
                    Tree[] res = split(t[j], x);
                    t[j] = res[0];
                    tt[j] = res[1];
                    if (res[0] != null && res[0].max > best) {
                        best = res[0].max;
                        bestp = j;
                    }
                }
                t[bestp] = split(t[bestp], x - 1)[0];
                for (int j = 0; j < 5; j++) {
                    t[j] = merge(t[j], tt[(j + 1) % 5]);
                }
            }
        }
    }

    public void run() {
        try {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);

            solve();

            in.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] arg) {
        new D_as().run();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    System.err.println(e);
                    return "";
                }
            }
            return st.nextToken();
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
            }
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}