#include <bits/stdc++.h>
using namespace std;
int SET(int n, int pos) { return n = n | (1 << pos); }
int RESET(int n, int pos) { return n = n & ~(1 << pos); }
int CHECK(int n, int pos) { return (bool)(n & (1 << pos)); }
int str2int(string s) {
  stringstream ss(s);
  int x;
  ss >> x;
  return x;
}
string int2str(int a) {
  stringstream ss;
  ss << a;
  string str = ss.str();
  return str;
}
string char2str(char a) {
  stringstream ss;
  ss << a;
  string str = ss.str();
  return str;
}
long long int bigMod(long long int n, long long int power, long long int MOD) {
  if (power == 0) return 1;
  if (power % 2 == 0) {
    long long int ret = bigMod(n, power / 2, MOD);
    return ((ret % MOD) * (ret % MOD)) % MOD;
  } else
    return ((n % MOD) * (bigMod(n, power - 1, MOD) % MOD)) % MOD;
}
long long int modInverse(long long int a, long long int m) {
  long long int m0 = m, t, q;
  long long int x0 = 0, x1 = 1;
  if (m == 1) return 0;
  while (a > 1) {
    q = a / m;
    t = m;
    m = a % m, a = t;
    t = x0;
    x0 = x1 - q * x0;
    x1 = t;
  }
  if (x1 < 0) x1 += m0;
  return x1;
}
int POW(int x, int y) {
  int res = 1;
  for (; y;) {
    if ((y & 1)) {
      res *= x;
    }
    x *= x;
    y >>= 1;
  }
  return res;
}
int inverse(int x) {
  double p = ((double)1.0) / x;
  return (p) + 1e-9;
}
int gcd(int a, int b) {
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}
int nC2(int n) { return n * (n - 1) / 2; }
long long int MOD(long long int n, long long int mod) {
  if (n >= 0)
    return n % mod;
  else if (-n == mod)
    return 0;
  else
    return mod + (n % mod);
}
struct type {
  int cnt;
  long long int sum[5];
} tree[4 * 100005];
int n;
vector<pair<long long int, int> > queryList;
vector<long long int> data;
void update(int node, int b, int e, int i, long long int val, int queryType) {
  if (b == e) {
    tree[node].cnt += queryType;
    tree[node].sum[0] += val;
    return;
  }
  int l = 2 * node;
  int r = l + 1;
  int mid = (b + e) / 2;
  if (i <= mid)
    update(l, b, mid, i, val, queryType);
  else
    update(r, mid + 1, e, i, val, queryType);
  tree[node].cnt = tree[l].cnt + tree[r].cnt;
  for (int index = 0; index < 5; index++) {
    tree[node].sum[(index + tree[l].cnt) % 5] =
        tree[l].sum[(index + tree[l].cnt) % 5] + tree[r].sum[index];
  }
}
int main() {
  int t, cas = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    getchar();
    char ss[8];
    scanf("%s", ss);
    long long int p;
    if (ss[0] == 'a') {
      scanf("%lld", &p);
      queryList.push_back(make_pair(p, 1));
      data.push_back(p);
    } else if (ss[1] == 'd') {
      scanf("%lld", &p);
      queryList.push_back(make_pair(p, -1));
      data.push_back(p);
    } else {
      queryList.push_back(make_pair(1, 0));
    }
  }
  sort(data.begin(), data.end());
  for (int i = 0; i < n; i++) {
    if (queryList[i].second == 0) {
      long long int ans = tree[1].sum[2];
      printf("%lld\n", ans);
    } else {
      int pos = lower_bound(data.begin(), data.end(), queryList[i].first) -
                data.begin();
      update(1, 0, n - 1, pos, queryList[i].first * queryList[i].second,
             queryList[i].second);
    }
  }
  return 0;
}
