#include <bits/stdc++.h>
using namespace std;
int N, Cnt, Tot;
int Num[100005];
int Next[100005];
long long S[100005][5];
pair<int, int> Target[100005];
void Calc(int t) {
  memset(S[t], 0, sizeof(S[t]));
  for (int i = Target[t].first; i <= Target[t].second; ++i)
    S[t][(i - Target[t].first + 1) % 5] += Num[i];
}
void Break(int X, int &p, int &q) {
  p = 0, q = Next[0];
  for (int i = Next[0]; i != 0; i = Next[i]) {
    if (Num[Target[i].first] <= X && X <= Num[Target[i].second]) {
      ++Cnt;
      Target[Cnt] = make_pair(Target[i].second + 1, Target[i].second);
      while (Target[i].first <= Target[i].second && X <= Num[Target[i].second])
        Target[Cnt].first = Target[i].second, --Target[i].second;
      Next[Cnt] = Next[i];
      p = i, q = Cnt;
      break;
    }
    if (Num[Target[i].second] < X) p = i, q = Next[i];
  }
}
void Add(int X) {
  int p, q;
  Break(X, p, q);
  Num[++Tot] = X;
  Target[++Cnt] = make_pair(Tot, Tot);
  Next[p] = Cnt;
  Next[Cnt] = q;
  Calc(p);
  Calc(Tot);
  Calc(q);
}
void Del(int X) {
  int p, q;
  Break(X, p, q);
  while (Target[q].first > Target[q].second) q = Next[q];
  ++Target[q].first;
  Next[p] = q;
  Calc(p);
  Calc(q);
}
long long Sum() {
  long long Result = 0;
  for (int i = Next[0], j = 3; i != 0; i = Next[i]) {
    Result += S[i][j];
    j -= (Target[i].second - Target[i].first + 1);
    j = (j % 5 + 5) % 5;
  }
  return Result;
}
void Merge() {
  vector<int> New;
  New.clear();
  for (int i = Next[0]; i != 0; i = Next[i])
    for (int j = Target[i].first; j <= Target[i].second; ++j)
      New.push_back(Num[j]);
  Tot = New.size();
  Cnt = (Tot + 400 - 1) / 400;
  for (int i = 1; i <= Tot; ++i) Num[i] = New[i - 1];
  for (int i = 1; i <= Cnt; ++i) {
    Next[i - 1] = i;
    Target[i] = make_pair((i - 1) * 400 + 1, min(i * 400, Tot));
    Calc(i);
  }
  Next[Cnt] = 0;
}
int main() {
  cin >> N;
  Next[0] = 0;
  for (int i = 1; i <= N; ++i) {
    string Str;
    int X;
    cin >> Str;
    if (Str == "add") {
      cin >> X;
      Add(X);
    }
    if (Str == "del") {
      cin >> X;
      Del(X);
    }
    if (Str == "sum") cout << Sum() << endl;
    if (Cnt > 400) Merge();
  }
  return 0;
}
