#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int el;
  long long sum[11];
} T;
T t[4 * 100005];
int ad[100005][3];
int ar[100005], sor[100005];
map<int, int> m;
T update(int at, int lo, int hi, int n, int val) {
  if (lo == hi && lo == n) {
    t[at].el = 1;
    t[at].sum[1] = val;
    t[at].sum[2] = 0;
    t[at].sum[3] = 0;
    t[at].sum[4] = 0;
    t[at].sum[0] = 0;
    return t[at];
  }
  int mid;
  mid = (lo + hi) / 2;
  T i, j;
  i.el = 0;
  j.el = 0;
  for (int a = 0; a <= 4; a++) i.sum[a] = j.sum[a] = 0;
  if (mid < n) {
    j = update(2 * at + 1, mid + 1, hi, n, val);
    i = t[2 * at];
  } else {
    i = update(2 * at, lo, mid, n, val);
    j = t[2 * at + 1];
  }
  t[at] = i;
  t[at].el = t[at].el + j.el;
  int b;
  b = (i.el + 1) % 5;
  for (int a = 1; a <= 5; a++) {
    t[at].sum[(b + a - 1 + 5) % 5] = t[at].sum[(b + a - 1 + 5) % 5] + j.sum[a];
  }
  return t[at];
}
T del(int at, int lo, int hi, int n, int val) {
  if (lo == hi && lo == n) {
    t[at].el = 0;
    t[at].sum[1] = 0;
    t[at].sum[2] = 0;
    t[at].sum[3] = 0;
    t[at].sum[4] = 0;
    t[at].sum[0] = 0;
    return t[at];
  }
  int mid;
  mid = (lo + hi) / 2;
  T i, j;
  i.el = 0;
  j.el = 0;
  for (int a = 0; a <= 4; a++) i.sum[a] = j.sum[a] = 0;
  if (mid < n) {
    j = del(2 * at + 1, mid + 1, hi, n, val);
    i = t[2 * at];
    t[at] = i;
    t[at].el = t[at].el + j.el;
    int b;
    b = (i.el + 1) % 5;
    for (int a = 1; a <= 5; a++) {
      t[at].sum[(b + a - 1 + 5) % 5] =
          t[at].sum[(b + a - 1 + 5) % 5] + j.sum[a];
    }
    return t[at];
  }
  i = del(2 * at, lo, mid, n, val);
  j = t[2 * at + 1];
  int z;
  z = 1;
  for (int a = 1; a <= 5; a++) {
    if (i.sum[a % 5]) {
      if (z == 5) {
        t[at].sum[0] = i.sum[a % 5];
      } else
        t[at].sum[z] = i.sum[a % 5];
      z++;
    }
  }
  t[at].el = z - 1;
  t[at].el = t[at].el + j.el;
  int b;
  b = (z) % 5;
  for (int a = 1; a <= 5; a++) {
    t[at].sum[(b + a - 1 + 5) % 5] = i.sum[(b + a - 1 + 5) % 5] + j.sum[a];
  }
  return t[at];
}
int main() {
  int a, b, c, d, e, x, y, z, n;
  string ch;
  cin >> n;
  z = 1;
  for (a = 1; a <= n; a++) {
    cin >> ch;
    if (ch == "sum") ad[a][1] = 0;
    if (ch == "add") {
      ad[a][1] = 1;
      cin >> ad[a][2];
      ar[z] = ad[a][2];
      z++;
    }
    if (ch == "del") {
      ad[a][1] = 2;
      cin >> ad[a][2];
    }
  }
  sort(ar + 1, ar + z);
  for (a = 1; a < z; a++) m[ar[a]] = a;
  T j;
  for (a = 1; a <= n; a++) {
    if (ad[a][1] == 1) {
      j = update(1, 1, z - 1, m[ad[a][2]], ad[a][2]);
    }
    if (ad[a][1] == 2) {
      del(1, 1, z - 1, m[ad[a][2]], ad[a][2]);
    }
    if (ad[a][1] == 0) cout << t[1].sum[3] << endl;
  }
  return 0;
}
