#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 100005;
#define ll __int64
#define LL(x) (x << 1) 
#define RR(x) (x << 1 | 1)

struct Node {
    int l, r;
    int size;
    ll sum[5];
    int mid () {
        return (l + r) >> 1;
    }
} T[N * 4];

void build(int u, int l, int r) {
    T[u].l = l;
    T[u].r = r;
    T[u].size = 0;
    for (int i = 0; i < 5; i++) {
        T[u].sum[i] = 0;
    }
    if (l == r) return;
    int mid = T[u].mid();
    build(LL(u), l, mid);
    build(RR(u), mid + 1, r);
}

inline void Up(int u) {
    T[u].size = T[LL(u)].size + T[RR(u)].size;
    for (int i = 0; i < 5; i++) {
        T[u].sum[i] = T[LL(u)].sum[i];
    }
    for (int i = 0; i < 5; i++) {
        T[u].sum[(T[LL(u)].size + i) % 5] += T[RR(u)].sum[i];
    }
}
int a[N];
void modify(int u, int pos, int d) {
    if (T[u].l == T[u].r) {
        if (d > 0) {
            T[u].sum[T[u].size % 5] += a[pos];
            T[u].size++;
        } else if (T[u].size > 0) {
            T[u].sum[T[u].size % 5] -= a[pos];
            T[u].size--;
        }
        return;
    }
    int mid = T[u].mid();
    if (pos <= mid) {
        modify(LL(u), pos, d);
    } else {
        modify(RR(u), pos, d);
    }
    Up(u);
}

struct Ask {
    char str[5];
    int val;
} op[N];

int main() {
    int n;
    int cnt = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", op[i].str);
        if (op[i].str[0] == 'a' || op[i].str[0] == 'd') {
            scanf("%d", &op[i].val);
            a[cnt++] = op[i].val;
        }
    }
    sort(a, a + cnt);
    cnt = unique(a, a + cnt) - a;
    build(1, 0, cnt - 1);
    
    int pos;
    for (int i = 0; i < n; i++) {
        if (op[i].str[0] == 'a') {
            pos = lower_bound(a, a + cnt, op[i].val) - a;
            modify(1, pos, 1);
        } else if (op[i].str[0] == 'd') {
            pos = lower_bound(a, a + cnt, op[i].val) - a;
            modify(1, pos, -1);
        } else {
            ll ret = T[1].sum[2];
            cout << ret << endl;
        }
    }
}