#include <bits/stdc++.h>
using namespace std;
const unsigned long long BIGEST = 1000000000000000000 + 1000000000000000000;
const long long BIGER = 1000000000000000000;
const int BIG = 1000000000;
const int MOD = 1000000007;
const long long LMOD = 1000000007;
int n;
vector<int> nm;
struct seg {
  long long sm[800001][5];
  long long sz[800001];
  int add(int x, int l = 1, int r = n, int k = 1) {
    if (r < l) return 0;
    if (r < x || x < l) return 0;
    if (l != r) {
      add(x, l, (l + r) / 2, k * 2);
      add(x, (l + r) / 2 + 1, r, k * 2 + 1);
      for (int i = 0; i < 5; i++)
        sm[k][i] = sm[k * 2][i] + sm[k * 2 + 1][(5 + i - sz[k * 2]) % 5];
      sz[k] = sz[k * 2] + sz[k * 2 + 1];
    } else {
      sm[k][1] += nm[x - 1];
      sz[k] = 1;
    }
    return 0;
  }
  int del(int x, int l = 1, int r = n, int k = 1) {
    if (r < l) return 0;
    if (r < x || x < l) return 0;
    if (l != r) {
      del(x, l, (l + r) / 2, k * 2);
      del(x, (l + r) / 2 + 1, r, k * 2 + 1);
      for (int i = 0; i < 5; i++)
        sm[k][i] = sm[k * 2][i] + sm[k * 2 + 1][(5 + i - sz[k * 2]) % 5];
      sz[k] = sz[k * 2] + sz[k * 2 + 1];
    } else {
      sm[k][1] -= nm[x - 1];
      sz[k] = 0;
    }
    return 0;
  }
} T;
vector<pair<string, int> > v;
map<int, int> mp;
int main() {
  int t;
  string cmd;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> cmd;
    if (cmd == "sum") {
    } else {
      scanf("%d", &t);
      nm.push_back(t);
    }
    v.push_back(make_pair(cmd, t));
  }
  sort(nm.begin(), nm.end());
  for (int i = 0; i < nm.size(); i++) mp[nm[i]] = i + 1;
  for (int i = 0; i < n; i++) v[i].second = mp[v[i].second];
  for (int i = 0; i < n; i++) {
    if (v[i].first == "sum") {
      printf("\n%I64d", T.sm[1][3]);
    } else if (v[i].first == "del") {
      T.del(v[i].second);
    } else if (v[i].first == "add") {
      T.add(v[i].second);
    };
  }
  return 0;
}
