#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5, SQRT = 317;
int n, q;
int Arr[MAX_N];
pair<int, int> Query[MAX_N];
int sum[SQRT][5];
bool in[MAX_N];
int NUM[SQRT];
int Map(int tmp) { return lower_bound(Arr, Arr + n, tmp) - Arr; }
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> q;
  for (int i = 0; i < q; i++) {
    string type;
    cin >> type;
    if (type == "add") {
      int tmp;
      cin >> tmp;
      Query[i] = {0, tmp};
      Arr[n++] = tmp;
    }
    if (type == "del") {
      int tmp;
      cin >> tmp;
      Query[i] = {1, tmp};
    }
    if (type == "sum") Query[i] = {2, -1};
  }
  sort(Arr, Arr + n);
  n = unique(Arr, Arr + n) - Arr;
  for (int i = 0; i < q; i++) {
    if (Query[i].first == 0) {
      int tmp = Map(Query[i].second);
      in[tmp] = true;
      int num = 1;
      for (int j = 0; j < 5; j++) sum[tmp / SQRT][j] = 0;
      for (int j = tmp - tmp % SQRT; j % SQRT || j == tmp - tmp % SQRT; j++)
        if (in[j]) sum[tmp / SQRT][num++ % 5] += Arr[j];
      NUM[tmp / SQRT] = num;
    }
    if (Query[i].first == 1) {
      int tmp = Map(Query[i].second);
      in[tmp] = false;
      int num = 1;
      for (int j = 0; j < 5; j++) sum[tmp / SQRT][j] = 0;
      for (int j = tmp - tmp % SQRT; j % SQRT || j == tmp - tmp % SQRT; j++)
        if (in[j]) sum[tmp / SQRT][num++ % 5] += Arr[j];
      NUM[tmp / SQRT] = num;
    }
    if (Query[i].first == 2) {
      int cnt = 0, ans = 0;
      for (int j = 0; j < SQRT; j++) {
        if (cnt % 5 == 0) ans += sum[j][3];
        if (cnt % 5 == 1) ans += sum[j][4];
        if (cnt % 5 == 2) ans += sum[j][0];
        if (cnt % 5 == 3) ans += sum[j][1];
        if (cnt % 5 == 4) ans += sum[j][2];
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
