#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
void chmax(int &x, int y) {
  if (x < y) x = y;
}
void chmin(int &x, int y) {
  if (x > y) x = y;
}
int n;
struct segtree {
  long long sum[5][262200];
  int siz[262200], n;
  void build(int nn) {
    n = 1;
    while (n <= nn) n <<= 1;
  }
  void update(int k, int a) {
    k += n - 1;
    sum[0][k] = a;
    siz[k] = (a ? 1 : 0);
    while (k > 0) {
      k = (k - 1) / 2;
      siz[k] = siz[(k << 1) + 1] + siz[(k << 1) + 2];
      for (int(i) = (0); (i) <= (4); (i)++)
        sum[i][k] = sum[i][(k << 1) + 1] +
                    sum[(i + 5555555 - siz[(k << 1) + 1]) % 5][(k << 1) + 2];
    }
  }
} seg;
vector<pair<char, int>> v;
map<int, int> mp;
int cnt;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int(i) = (1); (i) <= (n); (i)++) {
    string a;
    int b = 0;
    cin >> a;
    if (a[0] != 's') cin >> b;
    v.push_back(make_pair(a[0], b));
    mp[b] = 0;
  }
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)
    it->second = ++cnt;
  seg.build(cnt);
  for (int(i) = (0); (i) < (n); (i)++) {
    if (v[i].first == 'a') {
      int pos = mp[v[i].second];
      seg.update(pos, v[i].second);
    } else if (v[i].first == 'd') {
      int pos = mp[v[i].second];
      seg.update(pos, 0);
    } else {
      cout << seg.sum[2][0] << '\n';
    }
  }
  return 0;
}
