#include <bits/stdc++.h>
using namespace std;
namespace io {
static streambuf *inbuf = cin.rdbuf();
static streambuf *outbuf = cout.rdbuf();
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline char gc() {
  return (p1 == p2 && (p2 = (p1 = buf) + inbuf->sgetn(buf, 1 << 21), p1 == p2)
              ? EOF
              : *p1++);
}
inline void pc(const char x) { outbuf->sputc(x); }
inline void ps(const char *x) { outbuf->sputn(x, sizeof(x)), pc(10); }
inline int read() {
  register int _s = 0, _f = 1;
  register char _ch = gc();
  for (; !isdigit(_ch); _ch = gc())
    if (_ch == '-') _f = -1;
  for (; isdigit(_ch); _ch = gc()) _s = _s * 10 + _ch - '0';
  return _s * _f;
}
template <typename T>
inline void write(T _x1) {
  if (_x1 < 0) pc('-');
  static char _sta[15];
  int _p = 0;
  do {
    _sta[_p++] = _x1 % 10 ^ 48;
    _x1 /= 10;
  } while (_x1);
  while (_p--) pc(_sta[_p]);
}
string _s;
inline string readstr() {
  _s.clear();
  register char _ch = gc();
  while (isspace(_ch)) _ch = gc();
  for (; !isspace(_ch); _ch = gc()) _s += _ch;
  return _s;
}
inline void writestr(string _s) {
  for (unsigned i = 0; i < _s.size(); ++i) pc(_s[i]);
}
inline void writeln(int _x) {
  write(_x);
  pc(10);
}
inline void writesp(int _x) {
  write(_x);
  pc(' ');
}
}  // namespace io
using namespace io;
int n;
vector<int> a;
int main() {
  n = read();
  while (n--) {
    string s = readstr();
    int x;
    if (s != "sum") x = read();
    if (s == "add") a.insert((upper_bound(a.begin(), a.end(), x)), x);
    if (s == "del") a.erase((lower_bound(a.begin(), a.end(), x)));
    if (s == "sum") {
      long long res = 0;
      for (unsigned i = 2; i < a.size(); i += 5) res += 1ll * a[i];
      printf("%lld\n", res);
    }
  }
  return 0;
}
