#include <bits/stdc++.h>
using namespace std;
long long tr[262144][5];
int sum[262144];
pair<int, int> P[262144];
string s[262144];
int ii[262144];
map<int, int> sav;
void upd(int t, int l, int r, int ind, int c) {
  if (ind < l || r < ind) return;
  if (l == r) {
    if (c)
      tr[t][0] = P[ind].first;
    else
      tr[t][0] = 0;
    if (c)
      sum[t]++;
    else
      sum[t]--;
    return;
  }
  upd(2 * t, l, (l + r) / 2, ind, c);
  upd(2 * t + 1, (l + r) / 2 + 1, r, ind, c);
  for (int i = 0; i < 5; i++)
    tr[t][i] = tr[2 * t][i] + tr[2 * t + 1][(i + 5 - sum[2 * t] % 5) % 5];
  sum[t] = sum[2 * t] + sum[2 * t + 1];
}
int m, n, x;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    if (s[i] != "sum") {
      scanf("%d", &x);
      if (s[i] == "add") {
        m++;
        P[m].first = x;
        P[m].second = i;
        sav[x] = i;
      } else
        ii[i] = sav[x];
    }
  }
  sort(P + 1, P + m + 1);
  for (int i = 1; i <= m; i++) ii[P[i].second] = i;
  for (int i = 1; i <= n; i++) {
    if (s[i] == "sum") {
      printf("%I64d\n", tr[1][2]);
      continue;
    }
    if (s[i] == "add")
      upd(1, 1, m, ii[i], 1);
    else
      upd(1, 1, m, ii[i], 0);
  }
  cin >> n;
}
