#include <bits/stdc++.h>
using namespace std;
int n;
char ia[100007][10];
int ix[100007], iy[100007];
vector<int> bb;
long long sum[400007][5], num[400007];
int N = (1 << 17);
void Gao(int what) {
  while (what > 1) {
    what /= 2;
    num[what] = num[what * 2] + num[what * 2 + 1];
    for (int i = 0; i < 5; i++) sum[what][i] = sum[what * 2][i];
    for (int j = 0; j < 5; j++)
      sum[what][(j + num[what * 2]) % 5] += sum[what * 2 + 1][j];
  }
}
void add(int what) {
  what += N;
  num[what] = 1;
  sum[what][0] = bb[what - N];
  Gao(what);
}
void del(int what) {
  what += N;
  num[what] = 0;
  sum[what][0] = 0;
  Gao(what);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", ia[i]);
    if (ia[i][0] == 's')
      ix[i] = -1;
    else {
      scanf("%d", ix + i);
      bb.push_back(ix[i]);
    }
  }
  sort(bb.begin(), bb.end());
  bb.resize(unique(bb.begin(), bb.end()) - bb.begin());
  for (int i = 0; i < n; i++)
    iy[i] = lower_bound(bb.begin(), bb.end(), ix[i]) - bb.begin();
  for (int i = 0; i < n; i++) {
    if (!strcmp(ia[i], "sum"))
      cout << sum[1][2] << endl;
    else if (!strcmp(ia[i], "add"))
      add(iy[i]);
    else
      del(iy[i]);
  }
  return 0;
}
