import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
					exit(999);
				}
			}
		}, "kek", 1 << 23).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	
	final int maxS = 1000 * 100 + 1;
	
	class Node{
		Node left, right;
		int size, key;
		double value;
		long sum[];
		public Node(int z, double val) {
			sum = new long[5];
			key = z;
			value = val;
			left = right = null;
			size = 1;
		}
	}
	int getSize(Node e){
		return e == null ? 0 : e.size;
	}
	private long getSum(Node v, int i) {
		return v == null ? 0 : v.sum[i];
	}
	
	
	Node[] split(Node root, int x){
		if(root == null) return new Node[] {null, null};
		Node ret[] = null;
		if(root.key < x){
			Node ch[] = split(root.right, x);
			root.right = ch[0];
			ret = new Node[] {root, ch[1]};
		}
		if(x < root.key){
			Node ch[] = split(root.left, x);
			root.left = ch[1];
			ret = new Node[] {ch[0], root};
		}
		if(x == root.key)
			ret = new Node[]{root.left, root.right};
		upd(ret[0]);
		upd(ret[1]);
		return ret;
	}
	
	private Node upd(Node v) {
		if(v == null) return v;
		for(int i = 0; i < 5; i++)
			v.sum[i] = getSum(v.left, i);
		int offset = getSize(v.left) % 5;
		v.sum[offset] += v.key;
		offset = (offset + 1) % 5;
		for(int i = 0; i < 5; i++)
			v.sum[(i + offset) % 5] += getSum(v.right, i);
		v.size = getSize(v.left) + getSize(v.right) + 1;
		return v;
	}



	Node merge(Node le, Node ri){
		if(le == null) return ri;
		if(ri == null) return le;
		Node ret;
		if(le.value  > ri.value){
			le.right = merge(le.right, ri);
			ret = le;
		} else {
			ri.left = merge(le, ri.left);
			ret = ri;
		}
		upd(ret);
		return ret;
	}
	
	
	
	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		in.close();
		out.close();
	}
	
	Random rnd = new Random(777);
	private void solve() throws IOException{
		Node root = null;
		int n = nextInt();
		for(int i = 0; i < n; i++){
			String s = nextToken();
			if(s.equals("add")){
				int z = nextInt();
				Node node = new Node(z, rnd.nextDouble());
				Node ch[] = split(root, z);
				root = merge(merge(ch[0], node), ch[1]);
			}
			if(s.equals("sum")){
				out.println(root.sum[2]);
			}
			if(s.equals("del")){
				int z = nextInt();
				Node ch[] = split(root, z);
				root = merge(ch[0], ch[1]);
			}
		}
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}
