Problem: 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

Solution (in JAVA):

Solution:
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());
        }
    }
}