#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10;
int n;
map<int, int> m;
string s[MAXN];
int a[MAXN];
struct segtree {
  int siz;
  long long arz[MAXN * 4];
  int num[MAXN * 4];
  long long mod[MAXN * 4][5];
  void Make(int n = 0) {
    siz = 1;
    for (; siz < n * 2; siz *= 2)
      ;
  }
  void Add(int a, int val) {
    int c = m[a] + siz / 2;
    arz[c] = val * a;
    num[c] = val;
    mod[c][1] = arz[c];
    c /= 2;
    while (c) {
      num[c] = num[c * 2] + num[c * 2 + 1];
      for (__typeof(5) i = (0); i < (5); ++i) {
        int x = ((i - num[c * 2]) % 5 + 5) % 5;
        mod[c][i] = mod[c * 2][i] + mod[c * 2 + 1][x];
      }
      c /= 2;
    }
  }
  int find(int a) { return mod[1][a]; }
} seg;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  seg.Make(n);
  for (__typeof(n) i = (0); i < (n); ++i) {
    cin >> s[i];
    if (s[i] != "sum") {
      cin >> a[i];
      m[a[i]] = 0;
    }
  }
  int cur = 0;
  for (__typeof((m).begin()) it = (m).begin(); it != (m).end(); ++it) {
    it->second = cur;
    ++cur;
  }
  for (__typeof(n) i = (0); i < (n); ++i) {
    if (a[i])
      seg.Add(a[i], (s[i] == "add") ? 1 : 0);
    else {
      cout << seg.find(3) << endl;
    }
  }
  return 0;
}
