#include <bits/stdc++.h>
using namespace std;
map<int, int> Map;
long long Tree[2 * (1 << 17)][5];
long long Sum[2 * (1 << 17)];
pair<int, int> Input[(1 << 17)];
int N, M;
void Set(long long val, bool add) {
  int pos = Map[val] + (1 << 17);
  if (add) {
    Sum[pos] = 1;
    Tree[pos][0] += val;
  } else {
    Sum[pos] = 0;
    Tree[pos][0] -= val;
  }
  for (int k = 0; k < (17); k++) {
    pos /= 2;
    int left = 2 * pos + 0;
    int right = 2 * pos + 1;
    Sum[pos] = Sum[left] + Sum[right];
    for (int i = 0; i < (5); i++) Tree[pos][i] = Tree[left][i];
    for (int i = 0; i < (5); i++)
      Tree[pos][(i + Sum[left]) % 5] += Tree[right][i];
  }
}
int main() {
  char buffer[256];
  scanf("%d\n", &N);
  for (int i = 0; i < (N); i++) {
    scanf("%s", buffer);
    if (!strcmp(buffer, "add")) {
      Input[i].first = +1;
      scanf("%d", &Input[i].second);
      Map[Input[i].second] = 0;
    }
    if (!strcmp(buffer, "del")) {
      Input[i].first = -1;
      scanf("%d", &Input[i].second);
      Map[Input[i].second] = 0;
    }
  }
  int M = 0;
  for (typeof(Map.begin()) it = Map.begin(); it != Map.end(); ++it) {
    it->second = M++;
  }
  for (int i = 0; i < (N); i++) {
    switch (Input[i].first) {
      case 0:
        cout << Tree[1][2] << endl;
        break;
      case +1:
        Set(Input[i].second, true);
        break;
      case -1:
        Set(Input[i].second, false);
        break;
    }
  }
  return 0;
}
