//
//  main.cpp
//
//  Under GPLv3 license
//

// #pragma GCC diagnostic error "-std=c++14"
// #pragma GCC optimize("O3")
// #pragma comment(linker, "/STACK:1024000000,1024000000")

#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

#define pb push_back
#define pf push_front
#define mp make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int INF = (1 << 30) - 1;
const LL LINF = (1LL << 61) - 1;
const double EPS = 1e-10;

int n;

class Treap {
 private:
  struct Node {
    int size;
    int val, sum[5], fix;

    Node *ch[2];

    inline int getsize(Node *p) {
      if (p == NULL) return 0;
      return p->size;
    }

    inline int getsum(Node *p, int i) {
      if (p == NULL) return 0;
      return p->sum[i];
    }

    Node(int key) {
      memset(sum, 0, sizeof sum);
      size = 1;
      val = sum[0] = key;
      fix = rand() * rand();
      ch[0] = ch[1] = NULL;
    }

    inline void maintain() {
      memset(sum, 0, sizeof sum);

      size = 1 + getsize(ch[0]) + getsize(ch[1]);
      for (int i = 0; i < 5; i++) sum[i] = getsum(ch[0], i);
      sum[getsize(ch[0]) % 5] += val;
      for (int i = 0; i < 5; i++) {
        sum[(i + getsize(ch[0]) + 1) % 5] += getsum(ch[1], i);
      }
    }
  };

  Node *root = NULL;

  void rotate(Node *&t, int d) {
    Node *k = t->ch[d ^ 1];
    t->ch[d ^ 1] = k->ch[d];
    k->ch[d] = t;

    t->maintain();
    k->maintain();

    t = k;
  }

  void insert(Node *&t, int val) {
    if (t == NULL) {
      t = new Node(val);
    } else {
      t->size++;
      bool d = t->val < val;
      insert(t->ch[d], val);
      if (t->ch[d]->fix > t->fix) rotate(t, d ^ 1);
      t->maintain();
    }
  }

  Node *merge(Node *a, Node *b) {
    if (a == NULL || b == NULL) return a == NULL ? a : b;
    if (a->fix > b->fix) {
      a->ch[1] = merge(a->ch[1], b);
      a->maintain();
      return a;
    } else {
      b->ch[0] = merge(a, b->ch[0]);
      b->maintain();
      return b;
    }
  }

  bool erase(Node *&t, int val) {
    if (t == NULL) {
      return false;
    }

    if (t->val == val) {
      Node *k = t;
      t = merge(t->ch[0], t->ch[1]);
      delete k;
      return true;
    }

    if (erase(t->ch[t->val < val], val)) {
      t->size--;
      t->maintain();
      return true;
    } else {
      return false;
    }
  }

 public:
  void insert(int val) { insert(root, val); }

  void erase(int val) { erase(root, val); }

  int getmedian() { return root == NULL ? 0 : root->sum[2]; }

  /*
  void show(Node *p) {
    if(p->ch[0]) show(p->ch[0]);
    cout<<p->val<<" : ";
    for(int i=0;i<5;i++) {
      cout<<p->sum[i]<<' ';
    }
    cout<<endl;
    if(p->ch[1]) show(p->ch[1]);
  }

  void show() {
    show(root);
  }
   */
} treap;

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);

  srand((int)time(0));

#ifndef ONLINE_JUDGE
  clock_t __start_time = clock();
#endif

  // insert code here
  cin >> n;
  for (int i = 0; i < n; i++) {
    string type;
    int val;
    cin >> type;
    if (type == "sum") {
      cout << treap.getmedian() << endl;
    } else {
      cin >> val;
      if (type == "add") {
        treap.insert(val);
      } else {
        treap.erase(val);
      }
    }

    // treap.show();
  }

#ifndef ONLINE_JUDGEß
  cout << double(clock() - __start_time) * 0.001 << endl;
#endif

  return 0;
}
