#include <bits/stdc++.h>
using namespace std;
int n, tmp;
int v[100005];
int R[4 * 100005];
long long T[7][4 * 100005];
char s[100005][4];
map<int, int> M;
void upd(int x, int y, int l, int r, int node) {
  if (l == r) {
    R[node] = !R[node];
    T[1][node] = R[node] * y;
    return;
  }
  if (x <= (l + r) / 2)
    upd(x, y, l, (l + r) / 2, node * 2);
  else
    upd(x, y, (l + r) / 2 + 1, r, node * 2 + 1);
  R[node] = R[node * 2] + R[node * 2 + 1];
  int k = R[node * 2] % 5;
  for (int i = 0; i < 5; i++)
    T[i][node] = T[i][node * 2] + T[(5 - k + i) % 5][node * 2 + 1];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i]);
    if (s[i][0] != 's') scanf("%d", &v[i]), M[v[i]] = 1;
  }
  for (auto i : M) M[i.first] = ++tmp;
  for (int i = 1; i <= n; i++) {
    if (s[i][0] != 's')
      upd(M[v[i]], v[i], 1, tmp, 1);
    else
      printf("%lld\n", T[3][1]);
  }
}
