

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