#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmax(T &x, T y) {
  x = x > y ? x : y;
  return;
}
template <class T>
void chmin(T &x, T y) {
  x = x < y ? x : y;
  return;
}
const int inf = 1000000000;
const int mod = 1000000007;
const int maxn = 100005;
int m, n;
int num[maxn], x[maxn], op[maxn];
char str[25];
vector<int> v;
long long sum[maxn * 4][5];
int cnt[maxn * 4];
void add(int p, int l, int r, int pos, int f, int number) {
  if (l == r) {
    sum[p][1] += number * f;
    cnt[p] += f;
    return;
  }
  int mid = (l + r) >> 1;
  if (l <= pos && pos <= mid)
    add(p + p, l, mid, pos, f, number);
  else
    add(p + p + 1, mid + 1, r, pos, f, number);
  for (int i = 0; i < 5; i++) {
    int id = i - cnt[p + p] % 5;
    if (id < 0) id += 5;
    sum[p][i] = sum[p + p][i] + sum[p + p + 1][id];
  }
  cnt[p] = cnt[p + p] + cnt[p + p + 1];
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str);
    if (str[0] == 'a') {
      scanf("%d", &x[i]);
      v.push_back(x[i]);
      op[i] = 1;
    } else if (str[0] == 'd') {
      scanf("%d", &x[i]);
      op[i] = 2;
    } else
      op[i] = 3;
    num[i] = x[i];
  }
  sort((v).begin(), (v).end());
  unique((v).begin(), (v).end());
  for (int i = 1; i <= n; i++) {
    if (op[i] == 3) continue;
    x[i] = lower_bound((v).begin(), (v).end(), x[i]) - v.begin() + 1;
    m = max(m, x[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (op[i] == 1)
      add(1, 1, m, x[i], 1, num[i]);
    else if (op[i] == 2)
      add(1, 1, m, x[i], -1, num[i]);
    else
      printf("%lld\n", sum[1][3]);
  }
  return 0;
}
