import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Random;
import java.util.StringTokenizer;


public class Main {
	private static final String TASKNAME = "d";

	class CartesianTree {
	  private final static int RANDSEED = 566;
	  private final Random rand = new Random(RANDSEED);
	  public Node root = null;
	  
	  public long get3rds() {
	  	return root == null ? 0 : root.sums[2];
	  }

	  public void add(int value) {
	      Node v = new Node(value);
	      Node sentinel = new Node(null, null);
	      split(root, sentinel, value);
	      root = merge(merge(sentinel.left, v), sentinel.right);
	  }
	  
	  public void remove(int value) {
	      Node sentinel = new Node(null, null);
	      split(root, sentinel, value);
	      root = merge(sentinel.left, sentinel.right);
	  }

	  public void printAll() {
	      root.debug();
	  }

	  private void split(Node v, Node sentintel, int x) {
	      if (v == null) {
	          return;
	      }
	      if (x == v.x) {
	      	sentintel.left = v.left;
	      	sentintel.right = v.right;
	      }
	      if (x > v.x) {
	          split(v.right, sentintel, x);
	          v.right = sentintel.left;
	          sentintel.left = v;
	      } else if (x < v.x) {
	          split(v.left, sentintel, x);
	          v.left = sentintel.right;
	          sentintel.right = v;
	      }
	      v.recalc();
	  }

	  private Node merge(Node n1, Node n2) {
	      if (n1 == null) {
	          return n2;
	      } else if (n2 == null) {
	          return n1;
	      }
	      if (n1.y > n2.y) {
	          n1.right = merge(n1.right, n2);
	          n1.recalc();
	          return n1;
	      } else {
	          n2.left = merge(n1, n2.left);
	          n2.recalc();
	          return n2;
	      }
	  }

	  public class Node {
	      private int x;
	      private int y;
	      private Node left, right;
	      private final long[] sums;
	      private int size = 0;

	      public Node(int x) {
	          this.x = x;
	          this.y = rand.nextInt();
	          sums = new long[5];
	          sums[0] += x;
	          size = 1;
	      }

	      public void recalc() {
	      	Arrays.fill(sums, 0);
	      	size = 0;
	      	if (left != null) {
	      		for (int i = 0; i < 5; ++i) {
	      			sums[i] += left.sums[i];
	      		}
	      		size += left.size;
	      	}
	      	sums[size % 5] += x;
	      	++size;
	      	if (right != null) {
	      		for (int i = 0; i < 5; ++i) {
	      			sums[(size + i) % 5] += right.sums[i];
	      		}
	      		size += right.size;
	      	}
				}

	      public Node(Node left, Node right) {
	          this.left = left;
	          this.right = right;
	          sums = null;
	      }

	      public void debug() {
	          if (left != null) {
	              left.debug();
	          }
	          System.err.println(x + " s=" + size);
	          if (right != null) {
	              right.debug();
	          }
	      }
	  }
	}
	private void solve() throws Exception {
//		test();
		int n = nextInt();
		CartesianTree tree = new  CartesianTree();
		for (int i = 0; i < n; ++i) {
			String s = nextToken();
			if ("sum".equals(s)) {
				println(tree.get3rds());
//			tree.root.debug();
//			System.err.println("");
			} else {
				int val = nextInt();
				if ("add".equals(s)) {
					tree.add(val);
				} else {
					tree.remove(val);
				}
			}
		}
	}

	private void test() {
		Random random = new Random(566);
		while (true) {
			HashSet<Integer> els = new HashSet<Integer>();
			ArrayList<Integer> list = new  ArrayList<Integer>();
			CartesianTree tree = new CartesianTree();
			for (int i = 0; i < 8; ++i) {
				int v = random.nextInt(15);
				if (els.add(v)) {
					list.add(v);
					tree.add(v);
					System.err.println("add " + v);
				}
			}
			
			Collections.sort(list);
			for (int i = 0; i < 4 && i < list.size(); ++i) {
				int p = random.nextInt(list.size());
				int v = list.get(p);
				list.remove(p);
				tree.remove(v);
				System.err.println("remove " + v);
			}
			long s1 = tree.get3rds();
			long s2 = 0;
			for (int i = 0; i + 2< list.size(); i += 5) {
				s2 += list.get(i + 2);
			}
			System.err.println(s1 + " " + s2);
			if (s1 != s2) {
				throw new AssertionError();
			}
		}
	}

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(new OutputStreamWriter(System.out));
//			reader = new BufferedReader(new FileReader(TASKNAME + ".in"));
//			writer = new PrintWriter(new File(TASKNAME + ".out"));

			solve();

			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(13);
		}
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new Main().run();
		System.err.printf("%.3f\n", (System.currentTimeMillis() - time) * 1e-3);
	}

	private StringTokenizer tokenizer;
	private PrintWriter writer;
	private BufferedReader reader;

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... args) {
		writer.printf(format, args);
	}
}
