#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
long long bigmod(long long b, long long p, long long m) {
  if (p == 0) return 1;
  long long my = bigmod(b, p / 2, m);
  my *= my;
  my %= m;
  if (p & 1) my *= b, my %= m;
  return my;
}
int setb(int n, int pos) { return n = n | (1 << pos); }
int resb(int n, int pos) { return n = n & ~(1 << pos); }
bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }
struct query {
  int t, x;
  query() {}
  query(int tt, int xx) {
    t = tt;
    x = xx;
  }
};
query q[100005];
map<int, int> mp;
vector<int> v;
int n;
struct info {
  long long t, a[5];
  void Print1() {
    printf("%lld:", t);
    for (int i = 0; i < 5; i++) printf(" %lld", a[i]);
    printf("\n");
  }
};
info tree[400005];
info Merge(info A, info B) {
  info ret;
  ret.t = A.t + B.t;
  for (int i = 0; i < 5; i++) {
    int baki = A.t % 5;
    int id = 5 - baki;
    id = (id + i) % 5;
    ret.a[i] = A.a[i] + B.a[id];
  }
  return ret;
}
void U(int ind, int b, int e, int i, int x) {
  if (b == e) {
    if (x)
      tree[ind].t = 1;
    else
      tree[ind].t = 0;
    for (int i = 0; i < 5; i++) tree[ind].a[i] = 0;
    if (x) tree[ind].a[0] = v[b - 1];
    return;
  }
  int mid = (b + e) / 2, l = 2 * ind, r = l + 1;
  if (i <= mid)
    U(l, b, mid, i, x);
  else
    U(r, mid + 1, e, i, x);
  tree[ind] = Merge(tree[l], tree[r]);
}
int main() {
  int x, t, i, j;
  char ins[10];
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", ins);
    if (ins[0] == 'a') {
      t = 1;
      scanf("%d", &x);
      if (mp.find(x) == mp.end()) {
        mp[x] = 1;
        v.push_back(x);
      }
    } else if (ins[0] == 'd') {
      t = 2;
      scanf("%d", &x);
    } else {
      t = 3;
      x = 0;
    }
    q[i] = query(t, x);
  }
  sort(v.begin(), v.end());
  for (i = 0; i < v.size(); i++) mp[v[i]] = i + 1;
  int N = v.size();
  for (i = 1; i <= n; i++) {
    int t = q[i].t;
    int x = q[i].x;
    x = mp[x];
    if (t == 1) U(1, 1, N, x, 1);
    if (t == 2) U(1, 1, N, x, 0);
    if (t == 3) {
      info my = tree[1];
      long long ret = my.a[2];
      printf("%lld", ret);
      printf("\n");
    }
  }
  return 0;
}
