#include <bits/stdc++.h>
using namespace std;
int n, x;
string s;
pair<string, int> W[100021];
vector<int> V;
map<int, int> M;
int ilosc[262163];
long long D[262163][5];
void Dzewo(int p, string c, int x) {
  p += 131071;
  if (c == "add") {
    D[p][0] = x;
    ilosc[p] = 1;
    while (p > 1) {
      p /= 2;
      ilosc[p]++;
      for (int i = 0; i < 5; i++)
        D[p][i] = D[p * 2][i] + D[p * 2 + 1][((i - ilosc[p * 2]) % 5 + 5) % 5];
    }
  } else {
    D[p][0] = 0;
    ilosc[p] = 0;
    while (p > 1) {
      p /= 2;
      ilosc[p]--;
      for (int i = 0; i < 5; i++)
        D[p][i] = D[p * 2][i] + D[p * 2 + 1][((i - ilosc[p * 2]) % 5 + 5) % 5];
    }
  }
}
int main() {
  V.push_back(-1);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "add") {
      cin >> x;
      W[i] = {"add", x};
      V.push_back(x);
    }
    if (s == "del") {
      cin >> x;
      W[i] = {"del", x};
    }
  }
  sort(V.begin(), V.end());
  int l = 0;
  for (int i = 1; i < V.size(); i++) {
    if (V[i] != V[i - 1]) {
      l++;
      M[V[i]] = l;
    }
  }
  for (int i = 0; i < n; i++) {
    if (W[i].first == "add" || W[i].first == "del") {
      Dzewo(M[W[i].second], W[i].first, W[i].second);
    } else {
      cout << D[1][2] << "\n";
    }
  }
}
