#include <bits/stdc++.h>
using namespace std;
int N;
set<int> S;
string p[100100];
int tree[100100 * 3];
long long s[100100 * 3][5];
int key[100100];
int val[100100];
map<int, int> ID;
ifstream fin("fin.txt");
streambuf *old = cin.rdbuf(fin.rdbuf());
int size;
void update(int flag, int target, int rt = 1, int L = 1, int R = size) {
  if (L == R) {
    tree[rt] += flag;
    for (int i = 0; i < 5; i++) s[rt][i] = 0;
    if (tree[rt]) s[rt][0] = val[L];
    return;
  }
  int m = (L + R) >> 1;
  if (target <= m)
    update(flag, target, rt << 1, L, m);
  else
    update(flag, target, rt << 1 | 1, m + 1, R);
  tree[rt] = tree[rt << 1] + tree[rt << 1 | 1];
  for (int i = 0; i < 5; i++)
    s[rt][i] =
        s[rt << 1][i] + s[rt << 1 | 1][((i - tree[rt << 1]) % 5 + 5) % 5];
}
void input() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> p[i];
    if (p[i] != "sum") {
      cin >> key[i];
      S.insert(key[i]);
    }
  }
  vector<int> P(S.begin(), S.end());
  size = P.size();
  for (int i = 1; i <= size; i++) {
    val[i] = P[i - 1];
    ID[P[i - 1]] = i;
  }
  for (int i = 1; i <= N; i++) {
    if (p[i] == "add")
      update(1, ID[key[i]]);
    else if (p[i] == "del")
      update(-1, ID[key[i]]);
    else
      cout << s[1][2] << endl;
  }
}
int main() {
  input();
  return 0;
}
