#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
long long IT[maxn * 4][5];
int sum[maxn * 4], n, m;
vector<int> a;
vector<pair<int, int> > query;
void updateIT(int i, int l, int r, int pos) {
  if (pos < l || pos > r) return;
  if (l == r) {
    if (sum[i])
      sum[i] = IT[i][0] = 0;
    else
      sum[i] = 1, IT[i][0] = a[pos];
    return;
  }
  int mid = (l + r) / 2;
  updateIT(i * 2, l, mid, pos);
  updateIT(i * 2 + 1, mid + 1, r, pos);
  sum[i] = (sum[i * 2] + sum[i * 2 + 1]) % 5;
  for (int k = 0, _a = (5); k < _a; ++k)
    IT[i][k] = IT[i * 2][k] + IT[i * 2 + 1][(k - sum[i * 2] + 5) % 5];
}
int main() {
  char s[5];
  int v;
  scanf("%d", &n);
  for (int i = 0, _a = (n); i < _a; ++i) {
    scanf("%s", &s);
    if (s[0] == 's')
      query.push_back(pair<int, int>(0, 0));
    else {
      scanf("%d\n", &v);
      query.push_back(pair<int, int>(1, v));
      a.push_back(v);
    }
  }
  sort(a.begin(), a.end());
  vector<int>::iterator it = unique(a.begin(), a.end());
  a.resize(it - a.begin());
  m = it - a.begin();
  for (int i = 0, _a = (n); i < _a; ++i)
    if (query[i].first) {
      v = lower_bound(a.begin(), a.end(), query[i].second) - a.begin();
      updateIT(1, 0, m - 1, v);
    } else
      printf("%I64d\n", IT[1][2]);
  return 0;
}
