#include <bits/stdc++.h>
using namespace std;
int st[int(4e5 + 5)];
long long sum[int(4e5 + 5)][5];
string type[int(1e5 + 5)];
long long a[int(1e5 + 5)];
set<long long> Unique;
long long b[int(1e5 + 5)];
map<long long, int> Pos;
void update(int node, int seg_l, int seg_r, int pos, int val) {
  if (seg_l == pos && seg_r == pos) {
    sum[node][0] += val * b[pos];
    st[node] += val;
  } else {
    int seg_mid = (seg_l + seg_r) / 2;
    if (seg_l <= pos && pos <= seg_mid)
      update(node * 2, seg_l, seg_mid, pos, val);
    if (seg_mid + 1 <= pos && pos <= seg_r)
      update(node * 2 + 1, seg_mid + 1, seg_r, pos, val);
    st[node] = st[node * 2] + st[node * 2 + 1];
    for (int i = 0; i < 5; ++i) {
      int cur = ((i - st[node * 2]) % 5 + 5) % 5;
      sum[node][i] = sum[node * 2][i] + sum[node * 2 + 1][cur];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    cin >> type[i];
    if (type[i] != "sum") {
      cin >> a[i];
      Unique.insert(a[i]);
    }
  }
  int i = 0;
  for (auto x : Unique) {
    b[++i] = x;
  }
  for (int i = 1; i <= Unique.size(); ++i) {
    if (b[i] > 0) {
      Pos[b[i]] = i;
    }
  }
  for (int i = 1; i <= q; ++i) {
    if (type[i] == "add") {
      update(1, 1, Unique.size(), Pos[a[i]], 1);
    } else if (type[i] == "del") {
      update(1, 1, Unique.size(), Pos[a[i]], -1);
    } else {
      cout << sum[1][2] << "\n";
    }
  }
}
