#include <bits/stdc++.h>
using namespace std;
const int maxint = 0x7FFFFFFF;
template <class T>
void show(T a, int n) {
  for (int i = 0; i < n; ++i) cout << a[i] << ' ';
  cout << endl;
}
template <class T>
void show(T a, int r, int l) {
  for (int i = 0; i < r; ++i) show(a[i], l);
  cout << endl;
}
struct Sum {
  int a[1000], c[1000], ret;
  int n;
  void init(int i) {
    memset(a, 0, sizeof(a));
    memset(c, 0, sizeof(c));
    n = i;
  }
  void update(int i, int v) {
    for (a[i++] += v; i <= n; c[i - 1] += v, i += ((i) & ((i) ^ ((i)-1))))
      ;
  }
  int query(int i) {
    for (ret = 0, ++i; i; ret += c[i - 1], i ^= ((i) & ((i) ^ ((i)-1))))
      ;
    return ret;
  }
} cnt;
const int maxn = 100010;
const int M = 320;
int n;
struct node {
  long long sum[8];
  int num[M + 10];
  int size;
  node() : size(0) {}
  void calc() {
    memset(sum, 0, sizeof(sum));
    for (int i = 0; i < size; ++i) {
      sum[i % 5] += num[i];
    }
  }
  void insert(int x) {
    int i = size - 1;
    for (; i >= 0; --i) {
      if (num[i] > x) {
        num[i + 1] = num[i];
        continue;
      }
      break;
    }
    num[++i] = x;
    ++size;
    calc();
  }
  void del(int x) {
    int pos = lower_bound(num, num + size, x) - num;
    for (int i = pos; i < size; ++i) {
      num[i] = num[i + 1];
    }
    --size;
    calc();
  }
} d[512];
vector<int> ls;
char oper[maxn], tmp[110];
int num[maxn];
void insert(int x) {
  int pos = lower_bound(ls.begin(), ls.end(), x) - ls.begin();
  int k = pos / M;
  cnt.update(k + 1, 4);
  d[k].insert(x);
}
void del(int x) {
  int pos = lower_bound(ls.begin(), ls.end(), x) - ls.begin();
  int k = pos / M;
  cnt.update(k + 1, -4);
  d[k].del(x);
}
long long calc() {
  long long ret = 0;
  for (int i = 0; i <= (ls.size() / M + 1); ++i) {
    int t = (2 + cnt.query(i)) % 5;
    ret += d[i].sum[t];
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  cnt.init(512);
  for (int i = 0; i < n; ++i) {
    scanf("%s", tmp);
    oper[i] = tmp[0];
    if (tmp[0] == 'a' || tmp[0] == 'd') {
      scanf("%d", &num[i]);
      ls.push_back(num[i]);
    }
  }
  sort(ls.begin(), ls.end());
  ls.erase(unique(ls.begin(), ls.end()), ls.end());
  for (int i = 0; i < n; ++i) {
    if (oper[i] == 'a')
      insert(num[i]);
    else if (oper[i] == 'd')
      del(num[i]);
    else
      printf("%I64d\n", calc());
  }
  return 0;
}
