#include <bits/stdc++.h>
using namespace std;
struct node {
  int p;
  long long q[5];
} a[800000];
int f[800000][2], n, m = 0;
map<int, int> mp;
void init(int x, int l, int r) {
  a[x].p = 0;
  for (int i = 0; i < 5; i++) a[x].q[i] = 0;
}
inline void back(int x) {
  a[x].p = a[x * 2].p + a[x * 2 + 1].p;
  for (int i = 0; i < 5; i++)
    a[x].q[i] = a[x * 2].q[i] + a[x * 2 + 1].q[(i + 5 - a[x * 2].p % 5) % 5];
}
void push(int x, int l, int r, int p, int v) {
  if (l == r) {
    a[x].q[0] = (long long)v;
    a[x].p = 1;
    return;
  } else {
    int h = (l + r) / 2;
    if (p <= h)
      push(x * 2, l, h, p, v);
    else
      push(x * 2 + 1, h + 1, r, p, v);
    back(x);
  }
}
void gone(int x, int l, int r, int p) {
  if (l == r) {
    a[x].q[0] = 0;
    a[x].p = 0;
    return;
  } else {
    int h = (l + r) / 2;
    if (p <= h)
      gone(x * 2, l, h, p);
    else
      gone(x * 2 + 1, h + 1, r, p);
    back(x);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    char s[100];
    cin >> s;
    if (s[0] != 's') {
      cin >> f[i][1];
      mp[f[i][1]] = 1;
    }
    if (s[0] == 'a')
      f[i][0] = 1;
    else if (s[0] == 'd')
      f[i][0] = 2;
    else
      f[i][0] = 3;
  }
  for (map<int, int>::iterator i = mp.begin(); i != mp.end(); i++) {
    m++;
    (i->second) = m;
  }
  init(1, 1, m);
  for (int i = 0; i < n; i++)
    if (f[i][0] == 1)
      push(1, 1, m, mp[f[i][1]], f[i][1]);
    else if (f[i][0] == 2)
      gone(1, 1, m, mp[f[i][1]]);
    else
      cout << a[1].q[2] << endl;
  return 0;
}
