//package yandex2011.r1;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class D {
	Scanner in;
	PrintWriter out;
//	String INPUT = "6\r\n" +
//			"add 4\r\n" +
//			"add 5\r\n" +
//			"add 1\r\n" +
//			"add 2\r\n" +
//			"add 3\r\n" +
//			"sum";
//	String INPUT = "14\r\n" +
//			"add 1\r\n" +
//			"add 7\r\n" +
//			"add 2\r\n" +
//			"add 5\r\n" +
//			"sum\r\n" +
//			"add 6\r\n" +
//			"add 8\r\n" +
//			"add 9\r\n" +
//			"add 3\r\n" +
//			"add 4\r\n" +
//			"add 10\r\n" +
//			"sum\r\ndel 1\r\n" +
//			"sum";
//	String INPUT = "28\r\n" +
//			"add 5\r\n" +
//			"sum\r\n" +
//			"sum\r\n" +
//			"add 2\r\n" +
//			"add 10\r\n" +
//			"sum\r\n" +
//			"add 3\r\n" +
//			"add 12\r\n" +
//			"sum\r\n" +
//			"add 1\r\n" +
//			"sum\r\n" +
//			"add 4\r\n" +
//			"sum\r\n" +
//			"del 5\r\n" +
//			"sum\r\n" +
//			"del 2\r\n" +
//			"sum\r\n" +
//			"sum\r\n" +
//			"del 10\r\n" +
//			"sum\r\n" +
//			"del 3\r\n" +
//			"sum\r\n" +
//			"del 12\r\n" +
//			"sum\r\n" +
//			"del 1\r\n" +
//			"sum\r\n" +
//			"del 4\r\n" +
//			"sum";
	String INPUT = "";
	
	void solve()
	{
//		long ss = System.currentTimeMillis();
		int n = ni();
		int[] ope = new int[n];
		int[] num = new int[n];
//		TreeMap<Integer, Integer> tm = new TreeMap<Integer, Integer>();
		Map<Integer, Integer> hm = new HashMap<Integer, Integer>();
		for(int i = 0;i < n;i++){
			String o = in.next();
			if(o.equals("add")){
				ope[i] = 0;
				num[i] = ni();
				hm.put(num[i], 0);
			}else if(o.equals("del")){
				ope[i] = 1;
				num[i] = ni();
				hm.put(num[i], 0);
			}else{
				ope[i] = 2;
			}
		}
		int p = 0;
//		for(Map.Entry<Integer, Integer> e : tm.entrySet()){
//			e.setValue(p);
//			imap[p] = e.getKey();
//			p++;
//		}
		int[] imap = new int[hm.size()];
		for(int v : hm.keySet())imap[p++] = v;
		Arrays.sort(imap);
		for(int i = 0;i < imap.length;i++)hm.put(imap[i], i);
		
//		tr(System.currentTimeMillis() - ss);
		
		int q = (int)Math.sqrt(p)+1;
		long[][] sq = new long[q][5];
		
		int count = 0;
		int[] ft = new int[p+1];
		for(int i = 0;i < n;i++){
			if(ope[i] == 0){
				count++;
				int o = hm.get(num[i]);
				int ord = sumFenwick(ft, o+1);
				addFenwick(ft, o+1, 1);
				
//				tr(ord);
				int b = ord / q;
				Arrays.fill(sq[b], 0);
				for(int j = b*q+1;j <= (b+1)*q && j <= count;j++){
					int ind = findGFenwick(ft, j-1)+1;
//					tr(ft);
//					tr(b,q,j,p,ind);
					if(ind < 0)break;
//					tr(ind, imap[ind-1]);
					sq[b][j%5] += imap[ind-1];
				}
				for(int j = b+1;j*q+1 <= count;j++){
					long d = sq[j][4];
					for(int k = 3;k >= 0;k--){
						sq[j][k+1] = sq[j][k];
					}
					sq[j][0] = d;
					int newer = findGFenwick(ft, j*q+1-1)+1;
					if(newer >= 0)sq[j][(j*q+1)%5] += imap[newer-1];
					if((j+1)*q+1 <= count){
						int older = findGFenwick(ft, (j+1)*q+1-1)+1;
						if(older >= 0)sq[j][((j+1)*q+1)%5] -= imap[older-1];
					}
				}
			}else if(ope[i] == 1){
				count--;
				int o = hm.get(num[i]);
				addFenwick(ft, o+1, -1);
				int ord = sumFenwick(ft, o+1);
				
//				tr(ord);
				int b = ord / q;
				Arrays.fill(sq[b], 0);
				for(int j = b*q+1;j <= (b+1)*q && j <= count;j++){
					int ind = findGFenwick(ft, j-1)+1;
//					tr(ft);
//					tr(b,q,j,p,ind);
					if(ind < 0)break;
//					tr(ind, imap[ind-1]);
					sq[b][j%5] += imap[ind-1];
				}
				for(int j = b+1;j*q+1 <= count;j++){
					long d = sq[j][0];
					for(int k = 0;k <= 3;k++){
						sq[j][k] = sq[j][k+1];
					}
					sq[j][4] = d;
					if((j+1)*q <= count){
						int newer = findGFenwick(ft, (j+1)*q-1)+1;
						if(newer >= 0)sq[j][((j+1)*q)%5] += imap[newer-1];
					}
					int older = findGFenwick(ft, j*q-1)+1;
					if(older >= 0)sq[j][(j*q)%5] -= imap[older-1];
				}
			}else{
				long ret = 0;
				for(int j = 0;j < q;j++){
					ret += sq[j][3];
				}
				out.println(ret);
			}
//			if(ope[i] < 2){
//				tr(ope[i], num[i]);
//				tr(sq);
//			}
		}
//		tr(q);
//		tr(System.currentTimeMillis() - ss);

	}
	
	public int findGFenwick(int[] ft, int v)
	{
		int i = 0;
		int n = ft.length;
		for(int b = Integer.highestOneBit(n);b != 0 && i < n;b >>= 1){
			int t = i + b;
			if(t >= n)continue;
			if(v >= ft[t]){
				i = t;
				v -= ft[t];
			}
		}
		return v != 0 ? -(i+1) : i;
	}
	
	public static int sumFenwick(int[] ft, int i)
	{
		int sum = 0;
		for(;i > 0;i -= i&-i)sum += ft[i];
		return sum;
	}
	
	public static void addFenwick(int[] ft, int i, int v)
	{
		int n = ft.length;
		for(;i < n;i += i&-i)ft[i] += v;
	}
	
	void run() throws Exception
	{
//		int n = 100000;
//		StringBuilder sb = new StringBuilder(n + " ");
//		for(int i = 0;i < n;i++){
//			sb.append("add " + (101012000 + i) + " ");
//		}
//		INPUT = sb.toString();
//
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}
	
	
	public static void main(String[] args) throws Exception
	{
		new D().run();
	}
	
	int ni() { return Integer.parseInt(in.next()); }
	double nd() { return Double.parseDouble(in.next()); }
	void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
