#include <bits/stdc++.h>
using namespace std;
char outp[64];
template <typename T>
inline void read(T &x) {
  char ch = 0;
  x = 0;
  bool sign = false;
  while (ch < '0' || '9' < ch) sign |= ch == '-', ch = getchar();
  while ('0' <= ch && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  x = sign ? -x : x;
}
template <typename T>
inline void print(T x) {
  if (!x) {
    putchar('0');
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  int tot = 0;
  while (x) outp[tot++] = x % 10 + '0', x /= 10;
  while (tot) putchar(outp[--tot]);
}
namespace Name1 {
vector<int> Set;
inline void add(int x) {
  Set.insert(lower_bound(Set.begin(), Set.end(), x), x);
}
inline void del(int x) { Set.erase(lower_bound(Set.begin(), Set.end(), x)); }
inline long long sum() {
  long long ret = 0;
  int lth = Set.size();
  for (register int i = 2; i < lth; i += 5) {
    ret += Set[i];
  }
  return ret;
}
}  // namespace Name1
const int sqrn = 350;
namespace Name2 {
struct Node {
  long long eac[6];
  Node() { memset(eac, 0, sizeof(eac)); }
};
const int MAXN = 1e5 + 64;
vector<vector<int> > vec;
vector<Node> eve;
inline int search(int x) {
  int lth = vec.size();
  int l = 0, r = lth, ans = 0;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (x < vec[mid].back())
      r = ans = mid;
    else
      l = mid + 1;
  }
  if (!lth) {
    vec.push_back(vector<int>(0));
    eve.push_back(Node());
  }
  return ans;
}
inline void rcount(int wei) {
  int lth = vec[wei].size();
  memset(eve[wei].eac, 0, sizeof(eve[wei].eac));
  for (register int i = 0; i != lth; ++i) {
    eve[wei].eac[i % 5] += vec[wei][i];
  }
}
inline void add(int x) {
  int wei = search(x);
  vec[wei].insert(lower_bound(vec[wei].begin(), vec[wei].end(), x), x);
  int lth = vec[wei].size();
  if (lth > sqrn << 1) {
    int rsize = lth >> 1;
    vector<int> step;
    for (register int i = rsize; i != lth; ++i) {
      step.push_back(vec[wei][i]);
    }
    vec[wei].resize(rsize);
    vec.insert(vec.begin() + wei + 1, step);
    eve.insert(eve.begin() + wei + 1, Node());
    rcount(wei), rcount(wei + 1);
  } else
    rcount(wei);
}
inline void del(int x) {
  int wei = search(x);
  vec[wei].erase(lower_bound(vec[wei].begin(), vec[wei].end(), x));
  int tot = vec.size();
  int lth = vec[wei].size();
  if (lth < sqrn >> 1) {
    if (wei > 0 && (int)vec[wei - 1].size() < (sqrn >> 1)) {
      vec[wei - 1].insert(vec[wei - 1].end(), vec[wei].begin(), vec[wei].end());
      vec.erase(vec.begin() + wei);
      eve.erase(eve.begin() + wei);
      rcount(wei - 1);
    } else if (wei + 1 < tot && (int)vec[wei + 1].size() < (sqrn >> 1)) {
      vec[wei].insert(vec[wei].end(), vec[wei + 1].begin(), vec[wei + 1].end());
      vec.erase(vec.begin() + wei + 1);
      eve.erase(eve.begin() + wei + 1);
      rcount(wei);
    } else
      rcount(wei);
  } else
    rcount(wei);
}
inline long long sum() {
  int tot = 0;
  int lth = vec.size();
  long long ret(0);
  for (register int i = 0; i != lth; ++i) {
    ret += eve[i].eac[(tot + 2) % 5];
    tot += vec[i].size();
  }
  return ret;
}
}  // namespace Name2
using namespace Name2;
int main() {
  int n, ope;
  char s[8];
  read(n);
  for (register int i = 0; i != n; ++i) {
    memset(s, 0, sizeof(s));
    scanf("%s", s);
    if (s[0] == 'a')
      read(ope), add(ope);
    else if (s[0] == 'd')
      read(ope), del(ope);
    else if (s[0] == 's')
      print(sum()), putchar('\n');
  }
  return 0;
}
