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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader sc = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, sc, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader sc, PrintWriter out) throws IOException {
        	SegTree sgt=new SegTree((int)1e5);
        	int[] buf1=new int[(int)1e5+10];
        	int[] buf2=new int[(int)1e5+10];
        	int[] buf3=new int[(int)1e5+10];
        	char[] opt=new char[(int)1e5+10];
        	
        	while(sc.hasNext()) {
        		int n=sc.nextInt();
        		
        		int index1=0;
        		int index2=0;
        		
        		for(int i=1;i<=n;i++) {
        			opt[i]=sc.next().charAt(0);
        			if(opt[i]!='s') {
        				buf1[++index1]=sc.nextInt();
        			}
        		}
                System.arraycopy(buf1, 1, buf3, 1, index1+1);
        		Arrays.sort(buf3,1,index1+1);
        		buf2[++index2]=buf3[1];
        		for(int i=2;i<=index1;i++)
        			if(buf3[i]!=buf3[i-1])
        				buf2[++index2]=buf3[i];
        	  /*  for(int i=1;i<=index2;i++)
        	    	System.out.print(buf2[i]+" ");
        	    System.out.println();*/
        		//SegTree sgt=new SegTree(index2,buf2);
        		sgt.build(1, 1, index2);
        		sgt.setBuf(buf2);
        		for(int i=1,j=0;i<=n;i++) {
        			if(opt[i]=='s')
        				out.println(sgt.t[1].sum[3]);
        			else {
        				int index=Arrays.binarySearch(buf2, 1, index2+1, buf1[++j]);
        				//System.out.println(buf2[index]+" "+buf1[j]);
        				if(opt[i]=='a')
        					sgt.change(1, index, 1);
        				else
        					sgt.change(1, index, -1);
        			}
        		}
        	}
        }
    }
    
    static class SegTree{
    	class Node{
    		int l;
    		int r;
    		int cnt;
    		long[] sum;
    		
    		public Node(int l,int r) {
        		this.l=l;
        		this.r=r;
        		this.sum=new long[5];
        	}
    	}
    	public Node[] t;
    	public int[] buf;
    	
    	public SegTree(int n) {
    		this.t=new Node[(n+5)<<2];
    	}
    	
    	public SegTree(int n,int[] buf) {
    		this.t=new Node[(n+10)<<2];
    		this.buf=buf;
    	}
    	
    	public void setBuf(int[] buf) {
    		this.buf=buf;
    	}
    	
    	public void pushUp(int p) {
    		t[p].cnt=t[p*2].cnt+t[p*2+1].cnt;
    		for(int i=0;i<5;i++) {
    			t[p].sum[i]=t[p*2].sum[i]+t[p*2+1].sum[(i-(t[p*2].cnt%5)+5)%5];
    		}
    	}
    	
    	public void build(int p,int l,int r) {
    		if(t[p]==null)
    			t[p]=new Node(l,r);
    		else {
    			t[p].l=l;
    			t[p].r=r;
    			t[p].cnt=0;
    			t[p].sum[0]=t[p].sum[1]=t[p].sum[2]=t[p].sum[3]=t[p].sum[4]=0;
    		}
    		if(l==r)
    			return ;
    		int mid=(l+r)>>1;
    		build(p*2,l,mid);
    		build(p*2+1,mid+1,r);
    	}
    	
    	public void change(int p,int index,int val) {
    		if(t[p].l==t[p].r) {
    			t[p].cnt+=val;
    			t[p].sum[1]+=1l*val*buf[t[p].l];
    			return ;
    		}
    		int mid=(t[p].l+t[p].r)>>1;
        	if(index<=mid)
        		change(p*2,index,val);
        	else
        		change(p*2+1,index,val);
        	pushUp(p);
    	}
    }
    
    static  class InputReader{
        StreamTokenizer tokenizer;
        public InputReader(InputStream stream){
            tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));
            tokenizer.ordinaryChars(33,126);
            tokenizer.wordChars(33,126);
        }
        public String next() throws IOException {
            tokenizer.nextToken();
            return tokenizer.sval;
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public boolean hasNext() throws IOException {
            int res=tokenizer.nextToken();
            tokenizer.pushBack();
            return res!=tokenizer.TT_EOF;
        }
    }
}