
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.math.*;
import java.util.*;
public class Main {
    private class Scanner {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        public boolean hasNext() {
            return sc.hasNext();
        }
        public String next() {
            return sc.next();
        }
        public BigDecimal nextBigDecimal() {
            return new BigDecimal(sc.next());
        }
        public BigInteger nextBigInteger() {
            return new BigInteger(sc.next());
        }
        public double nextDouble() {
            return Double.valueOf(sc.next());
        }
        public int nextInt() {
            return Integer.valueOf(sc.next());
        }
        public long nextLong() {
            return Long.valueOf(sc.next());
        }
    }
    public static void main(String[] args) {
        new Main().run();
    }
    static void debug(Object... os) {
        System.err.println(deepToString(os));
    }
    Scanner sc = new Scanner();
    int T = 1<<17;
    void run() {
        int n=sc.nextInt();
        int[] type=new int[n];
        int[] val=new int[n];
        for(int i=0;i<n;i++){
            char c=sc.next().charAt(0);
            if(c=='s')type[i]=2;
            else{
                type[i]=c=='a'?1:0;
                val[i]=sc.nextInt();
            }
        }
        int[] dic = val.clone();
        sort(dic);
        int[][] sum=new int[2*T][5];
        int[] cnt=new int[2*T];
        for(int i=0;i<n;i++){
//          debug(sum[1]);
            if(type[i]==2)System.out.println(sum[1][2]);
            else{
                int p=T+binarySearch(dic,val[i]);
                cnt[p] = type[i];
                sum[p][0] = cnt[p] * val[i];
                for(int j=p/2;j>=1;j/=2){
                    int left=j*2,right=j*2+1;
                    cnt[j] = cnt[left] + cnt[right];
                    for(int k=0;k<5;k++)sum[j][k] = sum[left][k] + sum[right][((k-cnt[left])%5+5)%5];
                }
            }
        }
    }
}
