#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
template <class T>
T sqr(T a) {
  return a * a;
}
struct node {
  int x;
  long long key, sum;
  node *left, *right;
};
node pool[110000];
int pc;
node *h[5];
node *lh[5];
node *rh[5];
void update(node *t) {
  if (!t) return;
  t->sum = t->key;
  if (t->left) t->sum += t->left->sum;
  if (t->right) t->sum += t->right->sum;
}
node *merge(node *t1, node *t2) {
  if (!t1) return t2;
  if (!t2) return t1;
  if (t1->x < t2->x) {
    t1->right = merge(t1->right, t2);
    update(t1);
    return t1;
  } else {
    t2->left = merge(t1, t2->left);
    update(t2);
    return t2;
  }
}
void split(node *t, node **l, node **r, int key) {
  if (!t)
    *l = *r = 0;
  else if (key < t->key) {
    split(t->left, l, &(t->left), key);
    *r = t;
  } else {
    split(t->right, &(t->right), r, key);
    *l = t;
  }
  update(t);
}
void add(node **t, int key) {
  node *pp = &pool[pc++];
  pp->key = key;
  pp->x = rand();
  pp->sum = key;
  node *p = *t;
  node *q;
  while (p && pp->x > p->x) {
    q = p;
    if (key < p->key)
      p = p->left;
    else
      p = p->right;
  }
  if (p == *t)
    *t = pp;
  else if (key < q->key)
    q->left = pp;
  else
    q->right = pp;
  split(p, &(pp->left), &(pp->right), key);
}
void remove(node **t, int key) {
  node *p = *t;
  node *q = 0;
  while (p && p->key != key) {
    q = p;
    if (key < p->key)
      p = p->left;
    else
      p = p->right;
  }
  if (p) {
    p = merge(p->left, p->right);
    if (!q)
      *t = p;
    else if (key < q->key)
      q->left = p;
    else
      q->right = p;
  }
}
long long getmax(node *t) {
  if (t->right) return max(t->key, getmax(t->right));
  return t->key;
}
int main() {
  int q;
  cin >> q;
  node *p;
  for (int i = 0; i < q; i++) {
    string scmd;
    cin >> scmd;
    if (scmd == "add") {
      int arg;
      cin >> arg;
      int mi = 4, mv = -1;
      for (int i = 0; i < 5; i++) {
        split(h[i], &lh[i], &rh[i], arg);
        if (lh[i]) {
          int cur = getmax(lh[i]);
          if (cur > mv) {
            mi = i;
            mv = cur;
          }
        }
      }
      for (int i = 0; i < 5; i++)
        h[(i + 1) % 5] = merge(lh[(i + 1) % 5], rh[i]);
      add(&h[(mi + 1) % 5], arg);
    } else if (scmd == "del") {
      int arg;
      cin >> arg;
      for (int i = 0; i < 5; i++) remove(&h[i], arg);
      for (int i = 0; i < 5; i++) split(h[i], &lh[i], &rh[i], arg);
      for (int i = 0; i < 5; i++) h[i] = merge(lh[i], rh[(i + 1) % 5]);
    } else {
      if (h[2])
        cout << h[2]->sum << endl;
      else
        cout << 0 << endl;
    }
  }
  return 0;
}
