#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
using namespace std;
int n,cnt,sz[400005],rev[100005];
long long sgt[400005][5];
pair<string,int> q[100005];
map<int,int> disc;
void modify(int x,int l,int r,int t,int v){
	if(l==r){
		sgt[x][1]=v*rev[t];
		sz[x]=v;
		return;
	}
	int mid=(l+r)>>1;
	if(t<=mid)modify(x*2+1,l,mid,t,v);
	else modify(x*2+2,mid+1,r,t,v);
	sz[x]=sz[x*2+1]+sz[x*2+2];
	for(int i=0;i<5;i++){
		sgt[x][i]=sgt[x*2+1][i]+sgt[x*2+2][(i-sz[x*2+1]%5+5)%5];
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>q[i].first;
		if(q[i].first[0]!='s')cin>>q[i].second;
		disc[q[i].second];
	}
	for(auto &i:disc){
		i.second=++cnt;
		rev[cnt]=i.first;
	}
	for(int i=0;i<n;i++){
		if(q[i].first[0]=='a')modify(0,1,cnt,disc[q[i].second],1);
		else if(q[i].first[0]=='d')modify(0,1,cnt,disc[q[i].second],0);
		else cout<<sgt[0][3]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
using namespace std;
int n;
struct node{
	int v,r,sz;
	node* ch[2];
	long long sum[5];
	void maintain(){
		int pre=0,s=1;
		if(ch[0]!=NULL)s+=ch[0]->sz;
		pre=s;
		if(ch[1]!=NULL)s+=ch[1]->sz;
		sz=s;
		set0(sum);
		sum[(pre%5)]=v;
		for(int i=0;i<5;i++){
			if(ch[0]!=NULL)sum[i]+=ch[0]->sum[i];
			if(ch[1]!=NULL)sum[(pre+i)%5]+=ch[1]->sum[i];
		}
	}
	node(int x){
		this->v=x;
		this->r=rand();
		this->sz=1;
		this->ch[0]=this->ch[1]=NULL;
		set0(sum);
		this->sum[1]=x;
	}
};
node* rt;
void rotate(node* &x,int d){
	node* k=x->ch[d^1];
	x->ch[d^1]=k->ch[d];
	k->ch[d]=x;
	x->maintain();
	k->maintain();
	x=k;
}
void add(node* &x,int v){
	if(x==NULL){
		x=new node(v);
		return;
	}
	bool nxt=v>(x->v);
	add(x->ch[nxt],v);
	if((x->ch[nxt]->r)>(x->r))rotate(x,nxt^1);
	if(x!=NULL)x->maintain();
}
void del(node* &x,int v){
	if((x->v)==v){
		if(x->ch[0]!=NULL && x->ch[1]!=NULL){
			bool nxt=(x->ch[0]->r)>(x->ch[1]->r);
			rotate(x,nxt);
			del(x->ch[nxt],v);
			if(x!=NULL)x->maintain();
		}
		else if(x->ch[0]!=NULL)x=x->ch[0];
		else x=x->ch[1];
	}
	else{
		del(x->ch[v>(x->v)],v);
		if(x!=NULL)x->maintain();
	}
}
int main(){
	srand((unsigned)time(NULL));
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	while(n--){
		string opt;
		cin>>opt;
		if(opt[0]=='s'){
			if(rt==NULL)cout<<"0\n";
			else cout<<(rt->sum[3])<<endl;
		}
		else{
			int x;
			cin>>x;
			if(opt[0]=='a')add(rt,x);
			else del(rt,x);
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

template <typename M>
struct SegTree {
    using Op = function<M(const M&, const M&)>;
    M ID; // monoid identity
    Op op; // associative operation
    int N; // 2^lg space, for non-commutative
    vector<M> a;

    SegTree(int n, M leaf_default, M _ID, Op _op) : ID(_ID), op(_op) {
        init_space(n);
        fill(a.begin() + N, a.begin() + N + n, leaf_default);
        build();
    }
    SegTree(const vector<M> leaves, M _ID, Op _op) : ID(_ID), op(_op) {
        int n = leaves.size();
        init_space(n);
        copy(leaves.begin(), leaves.end(), a.begin() + N);
        build();
    }
    void init_space(int n) {
        N = 1; while (N < n) N<<=1;
        a.assign(N<<1, ID);
    }
    inline void pull(int i) { a[i] = op(a[i<<1], a[i<<1|1]); }
    void build() { for (int i = N-1; i >= 1; i--) pull(i); }

    void assign(int p, M val) {
        assert(0 <= p && p < N);
        for (a[p += N] = val; p >>= 1;) pull(p);
    }
    M query(int l, int r) const {
        assert(0 <= l && r <= N);
        M resl(ID), resr(ID);
        for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
            if (l & 1) resl = op(resl, a[l++]);
            if (r & 1) resr = op(a[--r], resr);
        }
        return op(resl, resr);
    }
    M query_point(int p) const {
        assert(0 <= p && p < N);
        return a[p + N];
    }
    M query_all() const { return a[1]; }
};

template <typename T=int>
struct Compress {
    map<T, int> id;
    vector<T> num;

    Compress(vector<T> v) {
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        num = v;
        for (int i = 0; i < (int)num.size(); i++) {
            id[num[i]] = i;
        }
    }

    inline int get_id(T x) {
        assert(id.count(x));
        return id[x];
    }
    inline T get_num(int i) {
        assert(0 <= i && i < num.size());
        return num[i];
    }
};
void solve() {
    int q; cin >> q;
    vector<int> qrs(q);
    vector<int> Xs;
    for (int _ = 0; _ < q; _++) {
        string s; int x = 0;
        cin >> s;
        if (s[0]!='s') {
            cin >> x;
            Xs.push_back(x);
            if (s[0]=='d') x*=-1;
        }
        qrs[_] = x;
    }
    Compress<> cx(Xs);
using ll=long long ;
    using M = array<ll,6>;
    int n = cx.num.size();
    SegTree<M> sum (n, {0,0,0,0,0,0}, {0,0,0,0,0,0},
            [](M u, M v){
            M r = u;
            for (int i = 0; i < 5; i++) {
                r[(i + u[5])%5] += v[i];
            }
            r[5] += v[5];
            return r;
            }
            );
    for (auto& x: qrs) {
        if (x == 0) {
            ll res = sum.query_all()[2];
            cout << res << '\n';
        } else if (x > 0) {
            int i = cx.get_id(x);
            sum.assign(i, {x,0,0,0,0,1});
        } else {
            int i = cx.get_id(-x);
            sum.assign(i, {0,0,0,0,0,0});
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template <typename M>
struct SegTree {
    using Op = function<M(const M&, const M&)>;
    M ID; // monoid identity
    Op op; // associative operation
    int N; // 2^lg space, for non-commutative
    vector<M> a;

    SegTree(int n, M leaf_default, M _ID, Op _op) : ID(_ID), op(_op) {
        init_space(n);
        fill(a.begin() + N, a.begin() + N + n, leaf_default);
        build();
    }
    SegTree(const vector<M> leaves, M _ID, Op _op) : ID(_ID), op(_op) {
        int n = leaves.size();
        init_space(n);
        copy(leaves.begin(), leaves.end(), a.begin() + N);
        build();
    }
    void init_space(int n) {
        N = 1; while (N < n) N<<=1;
        a.assign(N<<1, ID);
    }
    inline void pull(int i) { a[i] = op(a[i<<1], a[i<<1|1]); }
    void build() { for (int i = N-1; i >= 1; i--) pull(i); }

    void assign(int p, M val) {
        assert(0 <= p && p < N);
        for (a[p += N] = val; p >>= 1;) pull(p);
    }
    M query(int l, int r) const {
        assert(0 <= l && r <= N);
        M resl(ID), resr(ID);
        for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
            if (l & 1) resl = op(resl, a[l++]);
            if (r & 1) resr = op(a[--r], resr);
        }
        return op(resl, resr);
    }
    M query_point(int p) const {
        assert(0 <= p && p < N);
        return a[p + N];
    }
    M query_all() const { return a[1]; }
};

template <typename T=int>
struct Compress {
    map<T, int> id;
    vector<T> num;

    Compress(vector<T> v) {
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        num = v;
        for (int i = 0; i < (int)num.size(); i++) {
            id[num[i]] = i;
        }
    }

    inline int get_id(T x) {
        assert(id.count(x));
        return id[x];
    }
    inline T get_num(int i) {
        assert(0 <= i && i < num.size());
        return num[i];
    }
};
void solve() {
    int q; cin >> q;
    vector<int> qrs(q);
    vector<int> Xs;
    for (int _ = 0; _ < q; _++) {
        string s; int x = 0;
        cin >> s;
        if (s[0]!='s') {
            cin >> x;
            Xs.push_back(x);
            if (s[0]=='d') x*=-1;
        }
        qrs[_] = x;
    }
    Compress<> cx(Xs);

    using M = array<int,6>;
    int n = cx.num.size();
    SegTree<M> sum (n, {0,0,0,0,0,0}, {0,0,0,0,0,0},
            [](M u, M v){
            M r = u;
            for (int i = 0; i < 5; i++) {
                r[(i + u[5])%5] += v[i];
            }
            r[5] += v[5];
            return r;
            }
            );
    for (auto& x: qrs) {
        if (x == 0) {
            int res = sum.query_all()[2];
            cout << res << '\n';
        } else if (x > 0) {
            int i = cx.get_id(x);
            sum.assign(i, {x,0,0,0,0,1});
        } else {
            int i = cx.get_id(-x);
            sum.assign(i, {0,0,0,0,0,0});
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int msz = 1e5, bsz = 333;
int sz, m, val[msz + 5];
string cmd[msz + 5];
vector<int> dat, id;

struct sqrt_buc {
    int sum[5];
    vector<int> dat;
    void inline init() {
        loop (i, 5) {
            sum[i] = 0;
        }
        loop (i, dat.size()) {
            sum[i % 5] += dat[i];
        }
    }
};
sqrt_buc b[bsz + 5];

int inline read() {
    int res = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar());
    for (; isdigit(c); res *= 10, res += c ^ 48, c = getchar());
    return res;
}

string inline readstr() {
    string res;
    char c = getchar();
    for (; !isalpha(c); c = getchar());
    for (; isalpha(c); res += c, c = getchar());
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    m = read();
    cont (i, m) {
        cmd[i] = readstr();
        if (cmd[i] != "sum") {
            val[i] = read();
            dat.push_back(val[i]);
        }
    }
    sort(all(dat));
    dat.erase(unique(all(dat)), dat.end());
    sz = (int) dat.size() / bsz + 1;
    cont (i, m) {
        if (cmd[i] == "add") {
            int id = (int) (lower_bound(all(dat), val[i]) - dat.begin()), bid = id / bsz;
            auto pos = lower_bound(all(b[bid].dat), val[i]);
            b[bid].dat.insert(pos, val[i]);
            b[bid].init();
        } else if (cmd[i] == "del") {
            int id = (int) (lower_bound(all(dat), val[i]) - dat.begin()), bid = id / bsz;
            auto pos = lower_bound(all(b[bid].dat), val[i]);
            b[bid].dat.erase(pos);
            b[bid].init();
        } else if (cmd[i] == "sum") {
            int cur = 0;
            num res = 0;
            circ (i, 0, sz) {
                res += b[i].sum[cur % 5 + 2];
                cur += b[i].dat.size();
            }
            cout << res << endl;
        }
    }
}


#include <bits/stdc++.h>

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int msz = 1e5;
int m, sz, cmd[msz + 5], val[msz + 5];
map<int, int> to;

struct segment_tree {
    int cnt[4 * msz + 5];
    num sum[4 * msz + 5][5];

    void inline up(int u) {
        cnt[u] = cnt[u << 1] + cnt[u << 1 | 1];
        loop (i, 5) {
            sum[u][i] = sum[u << 1][i] + sum[u << 1 | 1][(i + cnt[u << 1]) % 5];
        }
    }

    // 0 0
    // 0 1
    // 0 1 0 1
    // 0 1 2 3

    void upd(int el, int er, num val, int d, int u = 1, int l = 1, int r = sz) {
        if (l >= el && r <= er) {
            cnt[u] += d;
            sum[u][0] += val;
            return;
        }
        int mid = (l + r) >> 1;
        if (el <= mid) {
            upd(el, er, val, d, u << 1, l, mid);
        }
        if (er >= mid + 1) {
            upd(el, er, val, d, u << 1 | 1, mid + 1, r);
        }
        up(u);
    }

    num qry(int el, int er, int id, int u = 1, int l = 1, int r = sz) {
        if (l >= el && r <= er)  return sum[u][id];
        int mid = (l + r) >> 1;
        num res = 0;
        if (el <= mid) {
            res += qry(el, er, id, u << 1, l, mid);
        }
        if (er >= mid + 1) {
            res += qry(el, er, (id - cnt[u << 1] + 5) % 5, u << 1 | 1, mid + 1, r);
        }
        return res;
    }
};
segment_tree tr;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> m;
    cont (i, m) {
        string tmp;
        cin >> tmp;
        if (tmp == "sum") {
            cmd[i] = 2;
        } else {
            cin >> val[i];
            to[val[i]] = 0;
            cmd[i] = tmp == "del";
        }
    }
    foreach (it, to) {
        it->second = ++sz;
    }
    cont (i, m) {
        if (cmd[i] == 0) {
            int pos = to[val[i]];
            tr.upd(pos, pos, val[i], 1);
        } else if (cmd[i] == 1) {
            int pos = to[val[i]];
            tr.upd(pos, pos, -val[i], -1);
        } else if (cmd[i] == 2) {
            cout << tr.qry(1, sz, 3) << endl;
        }
    }
}


#include <bits/stdc++.h>

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int msz = 1e5;
int m, sz, cmd[msz + 5], val[msz + 5];
map<int, int> to;

struct segment_tree {
    int cnt[4 * msz + 5];
    num sum[4 * msz + 5][5];

    void inline up(int u) {
        cnt[u] = cnt[u << 1] + cnt[u << 1 | 1];
        loop (i, 5) {
            sum[u][i] = sum[u << 1][i] + sum[u << 1 | 1][(i + cnt[u << 1]) % 5];
        }
    }

    void upd(int el, int er, num val, bool d, int u = 1, int l = 1, int r = sz) {
        if (l >= el && r <= er) {
            cnt[u] = d;
            sum[u][0] = d * val;
            return;
        }
        int mid = (l + r) >> 1;
        if (el <= mid) {
            upd(el, er, val, d, u << 1, l, mid);
        }
        if (er >= mid + 1) {
            upd(el, er, val, d, u << 1 | 1, mid + 1, r);
        }
        up(u);
    }

    num qry(int el, int er, int id, int u = 1, int l = 1, int r = sz) {
        if (l >= el && r <= er)  return sum[u][id];
        int mid = (l + r) >> 1;
        num res = 0;
        if (el <= mid) {
            res += qry(el, er, id, u << 1, l, mid);
        }
        if (er >= mid + 1) {
            res += qry(el, er, (id - cnt[u << 1] + 5) % 5, u << 1 | 1, mid + 1, r);
        }
        return res;
    }
};
segment_tree tr;

int inline read() {
    int res = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar());
    for (; isdigit(c); res *= 10, res += c ^ 48, c = getchar());
    return res;
}

string inline readstr() {
    string res;
    char c = getchar();
    for (; !isalpha(c); c = getchar());
    for (; isalpha(c); res += c, c = getchar());
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    m = read();
    cont (i, m) {
        string tmp = readstr();
        if (tmp == "sum") {
            cmd[i] = 2;
        } else {
            val[i] = read();
            to[val[i]] = 0;
            cmd[i] = tmp == "del";
        }
    }
    foreach (it, to) {
        it->second = ++sz;
    }
    cont (i, m) {
        if (cmd[i] == 0) {
            int pos = to[val[i]];
            tr.upd(pos, pos, val[i], 1);
        } else if (cmd[i] == 1) {
            int pos = to[val[i]];
            tr.upd(pos, pos, val[i], 0);
        } else if (cmd[i] == 2) {
            cout << tr.qry(1, sz, 3) << endl;
        }
    }
}


#include <bits/stdc++.h>

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int msz = 1e5, bsz = 333;
int sz, m, val[msz + 5];
string cmd[msz + 5];
vector<int> dat, id;

struct sqrt_buc {
    int sum[5];
    vector<int> dat;
    void inline init() {
        loop (i, 5) {
            sum[i] = 0;
        }
        loop (i, dat.size()) {
            sum[i % 5] += dat[i];
        }
    }
};
sqrt_buc b[bsz + 5];

int inline read() {
    int res = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar());
    for (; isdigit(c); res *= 10, res += c ^ 48, c = getchar());
    return res;
}

string inline readstr() {
    string res;
    char c = getchar();
    for (; !isalpha(c); c = getchar());
    for (; isalpha(c); res += c, c = getchar());
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    m = read();
    cont (i, m) {
        cmd[i] = readstr();
        if (cmd[i] != "sum") {
            val[i] = read();
            dat.push_back(val[i]);
        }
    }
    sort(all(dat));
    dat.erase(unique(all(dat)), dat.end());
    sz = (int) dat.size() / bsz + 1;
    cont (i, m) {
        if (cmd[i] == "add") {
            int bid = val[i] / bsz;
            auto pos = lower_bound(all(b[bid].dat), val[i]);
            b[bid].dat.insert(pos, val[i]);
            b[bid].init();
        } else if (cmd[i] == "del") {
            int bid = val[i] / bsz;
            auto pos = lower_bound(all(b[bid].dat), val[i]);
            b[bid].dat.erase(pos);
            b[bid].init();
        } else if (cmd[i] == "sum") {
            int cur = 0;
            num res = 0;
            circ (i, 0, sz) {
                res += b[i].sum[cur % 5 + 2];
                cur += b[i].dat.size();
            }
            cout << res << endl;
        }
    }
}


#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;

int n,x;
char c[10];
set<int> st;

int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%s",c);
		if(c[0]=='a'){
			scanf("%d",&x);
			st.insert(x);
		}else if(c[0]=='d'){
			scanf("%d",&x);
			st.erase(st.find(x));
		}else{
			set<int>::iterator it=st.begin();it++;it++;
			int siz=st.size();
			long long ans=0;
			int cnt=2;
			for(;cnt<siz;it++,it++,it++,it++,it++,cnt+=5) ans+=(*it);
			printf("%lld\n",ans);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;

int n,x;
char c[10];
set<int> st;

int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%s",c);
		if(c[0]=='a'){
			scanf("%d",&x);
			st.insert(x);
		}else if(c[0]=='d'){
			scanf("%d",&x);
			st.erase(st.find(x));
		}else{
			set<int>::iterator it=st.begin();
			long long ans=0;
			int cnt=0;
			for(;it!=st.end();it++,cnt++) if(cnt%5==2) ans+=(*it);
			printf("%lld\n",ans);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;

const int N=100005;
const int LEN=300;
int x[N],z[N],t[N],tot[N/LEN+1],s[N/LEN+1][5],k[N/LEN+1][LEN];
pair<int,int> y[N];
int n,o;
char c[10];

void add(int p,int nx){
	for(int i=tot[p];i>=0;i--)
		if(i>0&&k[p][i-1]>nx) k[p][i]=k[p][i-1];
		else{
			k[p][i]=nx;
			break;
		}
	tot[p]++;
	for(int i=0;i<5;i++) s[p][i]=0;
	for(int i=0;i<tot[p];i++) s[p][i%5]+=k[p][i];
}

void del(int p,int nx){
	for(int i=0;i<tot[p];i++) if(k[p][i]==nx){
		for(int j=i;j<tot[p]-1;j++) k[p][j]=k[p][j+1];
		break;
	}
	tot[p]--;
	for(int i=0;i<5;i++) s[p][i]=0;
	for(int i=0;i<tot[p];i++) s[p][i%5]+=k[p][i];
}

long long cal(){
	int nowp=0;
	long long ans=0;
	for(int i=0;i<o;i++){
		ans+=s[i][(7-nowp)%5];
		nowp=(nowp+tot[i])%5;
	}
	return ans;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",c);
		if(c[0]=='a') t[i]=1;
		else if(c[0]=='d') t[i]=2;
		else t[i]=0;
		if(t[i]){
			scanf("%d",x+i);
			y[i]=make_pair(x[i],i);
		}
	}
	sort(y,y+n);
	o=(n+LEN-1)/LEN;
	int r=0;
	for(int i=0;i<n;i++){
		if(i>0&&y[i].first!=y[i-1].first) r++;
		z[y[i].second]=r;
	}
	for(int i=0;i<n;i++){
		if(t[i]==1) add(z[i]/LEN,x[i]);
		else if(t[i]==2) del(z[i]/LEN,x[i]);
		else printf("%I64d\n",cal());
	}
	return 0;
}


#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;

const int N=100005;
const int LEN=300;
int x[N],z[N],t[N],tot[N/LEN+1],k[N/LEN+1][LEN];
long long s[N/LEN+1][5];
pair<int,int> y[N];
int n,o;
char c[10];

void add(int p,int nx){
	for(int i=tot[p];i>=0;i--)
		if(i>0&&k[p][i-1]>nx) k[p][i]=k[p][i-1];
		else{
			k[p][i]=nx;
			break;
		}
	tot[p]++;
	for(int i=0;i<5;i++) s[p][i]=0;
	for(int i=0;i<tot[p];i++) s[p][i%5]+=k[p][i];
}

void del(int p,int nx){
	for(int i=0;i<tot[p];i++) if(k[p][i]==nx){
		for(int j=i;j<tot[p]-1;j++) k[p][j]=k[p][j+1];
		break;
	}
	tot[p]--;
	for(int i=0;i<5;i++) s[p][i]=0;
	for(int i=0;i<tot[p];i++) s[p][i%5]+=k[p][i];
}

long long cal(){
	int nowp=0;
	long long ans=0;
	for(int i=0;i<o;i++){
		ans+=s[i][(7-nowp)%5];
		nowp=(nowp+tot[i])%5;
	}
	return ans;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",c);
		if(c[0]=='a') t[i]=1;
		else if(c[0]=='d') t[i]=2;
		else t[i]=0;
		if(t[i]){
			scanf("%d",x+i);
			y[i]=make_pair(x[i],i);
		}
	}
	sort(y,y+n);
	o=(n+LEN-1)/LEN;
	int r=0;
	for(int i=0;i<n;i++){
		if(i>0&&y[i].first!=y[i-1].first) r++;
		z[y[i].second]=r;
	}
	for(int i=0;i<n;i++){
		if(t[i]==1) add(z[i]/LEN,x[i]);
		else if(t[i]==2) del(z[i]/LEN,x[i]);
		else printf("%I64d\n",cal());
	}
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define inf 0x7f7f7f7f
#define maxn 1000005
#define N 200005
#define P 2
typedef long long ll;

int n, k, a[maxn], cnt;

string s[maxn];
int val[maxn];

struct Tree {
    int cnt, mod[5];
} tree[4 * maxn];

void push_up(int x) {
    for (int i = 0; i < 5; i++)
        tree[x].mod[i] = tree[x << 1].mod[i] + tree[x << 1 | 1].mod[((i - tree[x << 1].cnt) % 5 + 5) % 5];
}

void build(int x, int l, int r) {
    tree[x].cnt = 0;
    if (l == r) {
        memset(tree[x].mod, 0, sizeof(tree[x].mod));
        return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    push_up(x);
}

void update(int l, int r, int x, int pos, int val) {
    tree[x].cnt += val;
    if (l == r) {
        if (tree[x].cnt == 0)
            tree[x].mod[1] = 0;
        else tree[x].mod[1] = a[pos];
        return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)update(l, mid, x << 1, pos, val);
    else update(mid + 1, r, x << 1 | 1, pos, val);
    push_up(x);
}

int main() {
    while (scanf("%d", &n) != EOF) {
        for (int i = 1; i <= n; i++) {
            cin >> s[i];
            if (s[i] != "sum") {
                scanf("%d",&val[i]);
                a[++cnt] = val[i];
            }
        }
        sort(a + 1, a + 1 + cnt);
        int len = unique(a + 1, a + 1 + cnt) - a - 1;
        if(len == 0)len = 1;
        build(1, 1, len);
        for (int i = 1; i <= n; i++) {
            string ty = s[i];
            if (ty == "add") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, 1);
            } else if (ty == "del") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, -1);
            } else cout << tree[1].mod[3] << endl;
            cout << tree[1].mod[3] << endl;
        }
    }
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define inf 0x7f7f7f7f
#define maxn 500005
#define N 200005
#define P 2
typedef long long ll;

int n, k, a[maxn], cnt;

string s[maxn];
int val[maxn];

struct Tree {
    int cnt, mod[5];
} tree[4 * maxn];

void push_up(int x) {
    for (int i = 0; i < 5; i++)
        tree[x].mod[i] = tree[x << 1].mod[i] + tree[x << 1 | 1].mod[((i - tree[x << 1].cnt) % 5 + 5) % 5];
}

void build(int x, int l, int r) {
    tree[x].cnt = 0;
    if (l == r) {
        memset(tree[x].mod, 0, sizeof(tree[x].mod));
        return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    push_up(x);
}

void update(int l, int r, int x, int pos, int val) {
    tree[x].cnt += val;
    if (l == r) {
        if (tree[x].cnt == 0)
            tree[x].mod[1] = 0;
        else tree[x].mod[1] = a[pos];
        return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)update(l, mid, x << 1, pos, val);
    else update(mid + 1, r, x << 1 | 1, pos, val);
    push_up(x);
}

int main() {
    while (scanf("%d", &n) != EOF) {
        for (int i = 1; i <= n; i++) {
            cin >> s[i];
            if (s[i] != "sum") {
                scanf("%d",&val[i]);
                a[++cnt] = val[i];
            }
        }
        sort(a + 1, a + 1 + cnt);
        int len = unique(a + 1, a + 1 + cnt) - a - 1;
        build(1, 1, len);
        for (int i = 1; i <= n; i++) {
            string ty = s[i];
            if (ty == "add") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, 1);
            } else if (ty == "del") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, -1);
            } else cout << tree[1].mod[3] << endl;
        }
    }
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define inf 0x7f7f7f7f
#define maxn 100005
#define N 200005
#define P 2
typedef long long ll;

int n, k, a[maxn], cnt;

struct Op {
    string s;
    int val;
} op[maxn];

struct Tree {
    int l, r, cnt, mod[7];
} tree[4 * maxn];

void push_up(int x) {
    for (int i = 0; i < 5; i++)
        tree[x].mod[i] = tree[x << 1].mod[i] + tree[x << 1 | 1].mod[((i - tree[x].cnt) % 5 + 5) % 5];
}

void build(int x, int l, int r) {
    tree[x].l = l, tree[x].r = r,  tree[x].cnt = 0;
    if (l == r) {
        memset(tree[x].mod,0,sizeof(tree[x].mod));
        return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    push_up(x);
}

void update(int x, int pos, int val) {
    tree[x].cnt += val;
    int l = tree[x].l, r = tree[x].r;
    if (l == r){
        if (tree[x].cnt == 0)
            tree[x].mod[0] = 0;
        else tree[x].mod[0] = a[pos];
        return ;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)update(x << 1, pos ,val);
    else update(x << 1 | 1, pos, val);
    push_up(x);
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        cin >> op[i].s;
        if (op[i].s != "sum") {
            cin >> op[i].val;
            a[++cnt] = op[i].val;
        }
    }
    sort(a + 1, a + 1 + cnt);
    int len = unique(a + 1, a + 1 + cnt) - a - 1;
    build(1, 1, len);
    for (int i = 1; i <= n; i++) {
        string ty = op[i].s;
        if (ty == "add") {
            int pos = lower_bound(a + 1, a + 1 + len, op[i].val) - a;
            update(1, pos, 1);
        }else if (ty == "del"){
            int pos = lower_bound(a + 1, a + 1 + len, op[i].val) - a;
            update(1, pos, -1);
        }else cout << tree[1].mod[3] << endl;
    }
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define inf 0x7f7f7f7f
#define maxn 1000005
#define N 200005
#define P 2
typedef long long ll;

int n, k, a[maxn], cnt;

string s[maxn];
int val[maxn];

struct Tree {
    ll cnt, mod[5];
} tree[4 * maxn];

void push_up(int x) {
    for (int i = 0; i < 5; i++)
        tree[x].mod[i] = tree[x << 1].mod[i] + tree[x << 1 | 1].mod[((i - tree[x << 1].cnt) % 5 + 5) % 5];
}

void build(int x, int l, int r) {
    tree[x].cnt = 0;
    if (l == r) {
        memset(tree[x].mod, 0, sizeof(tree[x].mod));
        return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    push_up(x);
}

void update(int l, int r, int x, int pos, int val) {
    tree[x].cnt += val;
    if (l == r) {
        if (tree[x].cnt == 0)
            tree[x].mod[1] = 0;
        else tree[x].mod[1] = a[pos];
        return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)update(l, mid, x << 1, pos, val);
    else update(mid + 1, r, x << 1 | 1, pos, val);
    push_up(x);
}

int main() {
    while (scanf("%d", &n) != EOF) {
        for (int i = 1; i <= n; i++) {
            cin >> s[i];
            if (s[i] != "sum") {
                scanf("%d",&val[i]);
                a[++cnt] = val[i];
            }
        }
        sort(a + 1, a + 1 + cnt);
        int len = unique(a + 1, a + 1 + cnt) - a - 1;
        if(len == 0)len = 1;
        build(1, 1, len);
        for (int i = 1; i <= n; i++) {
            string ty = s[i];
            if (ty == "add") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, 1);
            } else if (ty == "del") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, -1);
            } else cout << tree[1].mod[3] << endl;
        }
    }
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define inf 0x7f7f7f7f
#define maxn 1000005
#define N 200005
#define P 2
typedef long long ll;

int n, k, a[maxn], cnt;

string s[maxn];
int val[maxn];

struct Tree {
    int cnt, mod[5];
} tree[4 * maxn];

void push_up(int x) {
    for (int i = 0; i < 5; i++)
        tree[x].mod[i] = tree[x << 1].mod[i] + tree[x << 1 | 1].mod[((i - tree[x << 1].cnt) % 5 + 5) % 5];
}

void build(int x, int l, int r) {
    tree[x].cnt = 0;
    if (l == r) {
        memset(tree[x].mod, 0, sizeof(tree[x].mod));
        return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    push_up(x);
}

void update(int l, int r, int x, int pos, int val) {
    tree[x].cnt += val;
    if (l == r) {
        if (tree[x].cnt == 0)
            tree[x].mod[1] = 0;
        else tree[x].mod[1] = a[pos];
        return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)update(l, mid, x << 1, pos, val);
    else update(mid + 1, r, x << 1 | 1, pos, val);
    push_up(x);
}

int main() {
    while (scanf("%d", &n) != EOF) {
        for (int i = 1; i <= n; i++) {
            cin >> s[i];
            if (s[i] != "sum") {
                scanf("%d",&val[i]);
                a[++cnt] = val[i];
            }
        }
        sort(a + 1, a + 1 + cnt);
        int len = unique(a + 1, a + 1 + cnt) - a - 1;
        if(len == 0)len = 1;
        build(1, 1, len);
        for (int i = 1; i <= n; i++) {
            string ty = s[i];
            if (ty == "add") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, 1);
            } else if (ty == "del") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, -1);
            } else cout << tree[1].mod[3] << endl;
        }
    }
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define inf 0x7f7f7f7f
#define maxn 1000005
#define N 200005
#define P 2
typedef long long ll;

int n, k, a[maxn], cnt;

string s[maxn];
int val[maxn];

struct Tree {
    int cnt, mod[5];
} tree[4 * maxn];

void push_up(int x) {
    for (int i = 0; i < 5; i++)
        tree[x].mod[i] = tree[x << 1].mod[i] + tree[x << 1 | 1].mod[((i - tree[x << 1].cnt) % 5 + 5) % 5];
}

void build(int x, int l, int r) {
    tree[x].cnt = 0;
    if (l == r) {
        memset(tree[x].mod, 0, sizeof(tree[x].mod));
        return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    push_up(x);
}

void update(int l, int r, int x, int pos, int val) {
    tree[x].cnt += val;
    if (l == r) {
        if (tree[x].cnt == 0)
            tree[x].mod[1] = 0;
        else tree[x].mod[1] = a[pos];
        return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)update(l, mid, x << 1, pos, val);
    else update(mid + 1, r, x << 1 | 1, pos, val);
    push_up(x);
}

int main() {
    while (scanf("%d", &n) != EOF) {
        for (int i = 1; i <= n; i++) {
            cin >> s[i];
            if (s[i] != "sum") {
                scanf("%d",&val[i]);
                a[++cnt] = val[i];
            }
        }
        sort(a + 1, a + 1 + cnt);
        int len = unique(a + 1, a + 1 + cnt) - a - 1;
        build(1, 1, len);
        for (int i = 1; i <= n; i++) {
            string ty = s[i];
            if (ty == "add") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, 1);
            } else if (ty == "del") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, -1);
            } else cout << tree[1].mod[3] << endl;
        }
    }
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define inf 0x7f7f7f7f
#define maxn 100005
#define N 200005
#define P 2
typedef long long ll;

int n, k, a[maxn], cnt;

string s[maxn];
int val[maxn];

struct Tree {
    int cnt, mod[5];
} tree[4 * maxn];

void push_up(int x) {
    for (int i = 0; i < 5; i++)
        tree[x].mod[i] = tree[x << 1].mod[i] + tree[x << 1 | 1].mod[((i - tree[x << 1].cnt) % 5 + 5) % 5];
}

void build(int x, int l, int r) {
    tree[x].cnt = 0;
    if (l == r) {
        memset(tree[x].mod, 0, sizeof(tree[x].mod));
        return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    push_up(x);
}

void update(int l, int r, int x, int pos, int val) {
    tree[x].cnt += val;
    if (l == r) {
        if (tree[x].cnt == 0)
            tree[x].mod[1] = 0;
        else tree[x].mod[1] = a[pos];
        return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)update(l, mid, x << 1, pos, val);
    else update(mid + 1, r, x << 1 | 1, pos, val);
    push_up(x);
}

int main() {
    while (scanf("%d", &n) != EOF) {
        for (int i = 1; i <= n; i++) {
            cin >> s[i];
            if (s[i] != "sum") {
                scanf("%d",&val[i]);
                a[++cnt] = val[i];
            }
        }
        sort(a + 1, a + 1 + cnt);
        int len = unique(a + 1, a + 1 + cnt) - a - 1;
        build(1, 1, len);
        for (int i = 1; i <= n; i++) {
            string ty = s[i];
            if (ty == "add") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, 1);
            } else if (ty == "del") {
                int pos = lower_bound(a + 1, a + 1 + len, val[i]) - a;
                update(1, len, 1, pos, -1);
            } else cout << tree[1].mod[3] << endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int N = 100100;
long long segtree[N<<2][5];
int lazy[N<<2];
int num[N<<2];
vector<int> id;
int n;
int getid(int x){return lower_bound(id.begin(),id.end(),x)-id.begin()+1;}
struct ope{
    char t[10];
    int x;
}op[N];

void pushup(int rt){
    segtree[rt][0]=segtree[rt<<1][0]+segtree[rt<<1|1][0];
    segtree[rt][1]=segtree[rt<<1][1]+segtree[rt<<1|1][1];
    segtree[rt][2]=segtree[rt<<1][2]+segtree[rt<<1|1][2];
    segtree[rt][3]=segtree[rt<<1][3]+segtree[rt<<1|1][3];
    segtree[rt][4]=segtree[rt<<1][4]+segtree[rt<<1|1][4];
}

void pushdown(int rt){
    if(lazy[rt]!=0){
        lazy[rt<<1]+=lazy[rt]; lazy[rt<<1]%=5;
        lazy[rt<<1|1]+=lazy[rt]; lazy[rt<<1|1]%=5;
        while(lazy[rt]){
            swap(segtree[rt<<1][0],segtree[rt<<1][1]); swap(segtree[rt<<1][0],segtree[rt<<1][2]);
            swap(segtree[rt<<1][0],segtree[rt<<1][3]); swap(segtree[rt<<1][0],segtree[rt<<1][4]);

            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][1]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][2]);
            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][3]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][4]);
            lazy[rt]--;
        }
    }
}

void change(int x,int v,int l,int r,int rt){
    if(l==r){
        num[rt]+=v;
        return ;
    }
    int m=l+r>>1;
    if(x<=m) change(x,v,lson);
    else change(x,v,rson);
    num[rt]=num[rt<<1]+num[rt<<1|1];
}

int getnum(int L,int R,int l,int r,int rt){
    if(L<=l&&R>=r) return num[rt];
    int m=l+r>>1,ans=0;
    if(L<=m) ans+=getnum(L,R,lson);
    if(R>m) ans+=getnum(L,R,rson);
    return ans;
}

void update(int x,int op,int num,int l,int r,int rt){
    if(l==r){
       // printf("%d %d\n",l,id[l-1]);
        segtree[rt][(num+1)%5]+=op*id[l-1];
        return ;
    }
    pushdown(rt);
    int m=l+r>>1;
    if(m>=x){
        update(x,op,num,lson);
        if(op==1){
            lazy[rt<<1|1]++; lazy[rt<<1|1]%=5;
            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][1]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][2]);
            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][3]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][4]);
        }
        else{
            lazy[rt<<1|1]+=4; lazy[rt<<1|1]%=5;
            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][4]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][3]);
            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][2]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][1]);
        }

    }
    else{
        update(x,op,num,rson);
    }
    pushup(rt);
    return ;
}

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s",op[i].t);
        if(op[i].t[0]=='a'||op[i].t[0]=='d'){
            scanf("%d",&op[i].x);
            id.push_back(op[i].x);
        }
    }
    sort(id.begin(),id.end()),id.erase(unique(id.begin(),id.end()),id.end());
    for(int i=0;i<n;i++){
        if(op[i].t[0]=='s')
            printf("%lld\n",segtree[1][3]);
        else if(op[i].t[0]=='a'){
            int x=getid(op[i].x);
           // printf("www%d\n",x);
            update(x,1,getnum(1,x,1,id.size(),1),1,id.size(),1);
            change(x,1,1,id.size(),1);
        }
        else{
            int x=getid(op[i].x);
            update(x,-1,getnum(1,x,1,id.size(),1),1,id.size(),1);
            change(x,-1,1,id.size(),1);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int N = 100100;
long long segtree[N<<2][5];
int lazy[N<<2];
int num[N<<2];
vector<int> id;
int n;
int getid(int x){return lower_bound(id.begin(),id.end(),x)-id.begin()+1;}
struct ope{
    char t[10];
    int x;
}op[N];

void pushup(int rt){
    segtree[rt][0]=segtree[rt<<1][0]+segtree[rt<<1|1][0];
    segtree[rt][1]=segtree[rt<<1][1]+segtree[rt<<1|1][1];
    segtree[rt][2]=segtree[rt<<1][2]+segtree[rt<<1|1][2];
    segtree[rt][3]=segtree[rt<<1][3]+segtree[rt<<1|1][3];
    segtree[rt][4]=segtree[rt<<1][4]+segtree[rt<<1|1][4];
}

void pushdown(int rt){
    if(lazy[rt]!=0){
        lazy[rt<<1]+=lazy[rt]; lazy[rt<<1]%=5;
        lazy[rt<<1|1]+=lazy[rt]; lazy[rt<<1|1]%=5;
        while(lazy[rt]){
            swap(segtree[rt<<1][0],segtree[rt<<1][1]); swap(segtree[rt<<1][0],segtree[rt<<1][2]);
            swap(segtree[rt<<1][0],segtree[rt<<1][3]); swap(segtree[rt<<1][0],segtree[rt<<1][4]);

            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][1]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][2]);
            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][3]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][4]);
            lazy[rt]--;
        }
    }
}

void change(int x,int v,int l,int r,int rt){
    if(l==r){
        num[rt]+=v;
        return ;
    }
    int m=l+r>>1;
    if(x<=m) change(x,v,lson);
    else change(x,v,rson);
    num[rt]=num[rt<<1]+num[rt<<1|1];
}

int getnum(int L,int R,int l,int r,int rt){
    if(L<=l&&R>=r) return num[rt];
    int m=l+r>>1,ans=0;
    if(L<=m) ans+=getnum(L,R,lson);
    if(R>m) ans+=getnum(L,R,rson);
    return ans;
}

void update(int x,int op,int num,int l,int r,int rt){
    if(l==r){
        if(op==1)
            segtree[rt][(num+1)%5]+=op*id[l-1];
        else segtree[rt][(num)%5]+=op*id[l-1];
        return ;
    }
    pushdown(rt);
    int m=l+r>>1;
    if(m>=x){
        update(x,op,num,lson);
        if(op==1){
            lazy[rt<<1|1]++; lazy[rt<<1|1]%=5;
            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][1]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][2]);
            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][3]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][4]);
        }
        else{
            lazy[rt<<1|1]+=4; lazy[rt<<1|1]%=5;
            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][4]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][3]);
            swap(segtree[rt<<1|1][0],segtree[rt<<1|1][2]); swap(segtree[rt<<1|1][0],segtree[rt<<1|1][1]);
        }

    }
    else update(x,op,num,rson);
    pushup(rt);
    return ;
}

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s",op[i].t);
        if(op[i].t[0]=='a'||op[i].t[0]=='d'){
            scanf("%d",&op[i].x);
            id.push_back(op[i].x);
        }
    }
    sort(id.begin(),id.end()),id.erase(unique(id.begin(),id.end()),id.end());
    for(int i=0;i<n;i++){
        if(op[i].t[0]=='s')
            printf("%lld\n",segtree[1][3]);
        else if(op[i].t[0]=='a'){
            int x=getid(op[i].x);
            update(x,1,getnum(1,x,1,id.size(),1),1,id.size(),1);
            change(x,1,1,id.size(),1);
        }
        else{
            int x=getid(op[i].x);
            update(x,-1,getnum(1,x,1,id.size(),1),1,id.size(),1);
            change(x,-1,1,id.size(),1);
        }
    }
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
struct treap
{
	long long ls,rs,w,zhi,sz;
	long long rnd;
}tr[1000005];
long long n,m,i,j,x,y,gen,cnt,ch,k,p,pos,ans;
string st;
void setsz(long long k)
{
	tr[k].sz=tr[tr[k].ls].sz+tr[tr[k].rs].sz;
}
void lzhuan(long long &k)
{
	long long rs=tr[k].rs;
	tr[k].rs=tr[rs].ls;
	tr[rs].ls=k;
	tr[rs].sz=tr[k].sz;
	setsz(k);
	k=rs;
}
void rzhuan(long long &k)
{
	long long ls=tr[k].ls;
	tr[k].ls=tr[ls].rs;
	tr[ls].rs=k;
	tr[ls].sz=tr[k].sz;
	setsz(k);
	k=ls;
}
void insert(long long &k,long long zhi)
{
	if (!k)
	{
		k=++cnt;
		tr[k].ls=tr[k].rs=0;
		tr[k].rnd=rand();
		tr[k].zhi=zhi;
		tr[k].w=1;
		tr[k].sz=1;
	}
	else
	{
		tr[k].sz++;
		if (zhi<tr[k].zhi)
		{
			insert(tr[k].ls,zhi);
			if (tr[tr[k].ls].rnd<tr[k].rnd) rzhuan(k);
		}
		else
		{
			insert(tr[k].rs,zhi);
			if (tr[tr[k].rs].rnd<tr[k].rnd) lzhuan(k);
		}
	}
}
void erase(long long &k,long long zhi)
{
	if (!k) return;
	if (zhi==tr[k].zhi)
	{
		if (!tr[k].ls||!tr[k].rs) k=tr[k].ls+tr[k].rs;
		else if (tr[tr[k].ls].rnd<tr[tr[k].rs].rnd)
		{
			rzhuan(k);
			erase(k,zhi);
		}
		else
		{
			lzhuan(k);
			erase(k,zhi);
		}
	}
	else if (zhi<tr[k].zhi)
	{
		tr[k].sz--;
		erase(tr[k].ls,zhi);
	}
	else
	{
		tr[k].sz--;
		erase(tr[k].rs,zhi);
	}
}
void zhongxu(long long gen)
{
	if (tr[gen].ls) zhongxu(tr[gen].ls);
	cnt++;
	if (cnt%5==3)
	{
		ans+=tr[gen].zhi;
	}
	if (tr[gen].rs) zhongxu(tr[gen].rs);
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="sum")
		{
			cnt=ans=0;
			zhongxu(gen);
			cout<<ans<<endl;
			continue;
		}
		cin>>x;
		if (st=="add") insert(gen,x);
		if (st=="del") erase(gen,x);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#include<set>
using namespace std;
long long n,m=0,i,j,x,sum,num[1000005],wz;
string st;
int main()
{
	cin>>n;
	for (j=1;j<=n;j++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			//wz=*lower_bound(num+1,num+m+1,x);
			num[++m]=x;
			for (i=m-1;num[i]>=*lower_bound(num+1,num+m+1,x);i--) swap(num[i],num[i+1]);
		}
		if (st=="del")
		{
			cin>>x;
			for (i=m-1;num[i]>=*lower_bound(num+1,num+m+1,x);i--);
			for (i++;i<m;i++) swap(num[i],num[i+1]);
			num[m--]=0;
		}
		if (st=="sum")
		{
			sum=0;
			for (i=3;i<=m;i+=5) sum+=num[i];
			cout<<sum<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#define sqr(x) (x)*(x)
using namespace std;
struct ii
{
	int id,num;
	string zl;
}zl[100005];
bool cmp(ii x,ii y)
{
	return x.num<y.num;
}
bool cmp2(ii x,ii y)
{
	return x.id<y.id;
}
map<int,int> mp,zhi;
int n,m,i,j,cnt,sum[100005][15],sz[100005];
void update(int id,int le,int ri,int pos)
{
	sz[id]++;
	if (le==pos&&ri==pos)
	{
		sum[id][1]+=zhi[pos];
		return;
	}
	if (pos>(le+ri)/2) update(id*2+1,(le+ri)/2+1,ri,pos);
		else update(id*2,le,(le+ri)/2,pos);
	int i;
	for (i=0;i<5;i++)
	{
		sum[id][i]=sum[id*2][i]+sum[id*2+1][((i-sz[id*2]%5)+5)%5];
	}
}
void erase(int id,int le,int ri,int pos)
{
	sz[id]--;
	if (le==pos&&ri==pos)
	{
		sum[id][1]-=zhi[pos];
		return;
	}
	if (pos>(le+ri)/2) erase(id*2+1,(le+ri)/2+1,ri,pos);
		else erase(id*2,le,(le+ri)/2,pos);
	int i;
	for (i=0;i<5;i++)
	{
		sum[id][i]=sum[id*2][i]+sum[id*2+1][((i-sz[id*2]%5)+5)%5];
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		zl[i].id=i;
		cin>>zl[i].zl;
		if (zl[i].zl!="sum") cin>>zl[i].num;
	}
	sort(zl+1,zl+n+1,cmp);
	cnt=0;
	for (i=1;i<=n;i++)
	{
		if (zl[i].zl=="sum") continue;
		if (!mp[zl[i].num])
		{
			mp[zl[i].num]=++cnt;
			zhi[cnt]=zl[i].num;
		}
		zl[i].num=mp[zl[i].num];
	}
	sort(zl+1,zl+n+1,cmp2);
	//for (i=1;i<=n;i++) cerr<<zl[i].zl<<' '<<zl[i].num<<endl;
	for (i=1;i<=n;i++)
	{
		if (zl[i].zl=="add")
		{
			update(1,1,cnt,zl[i].num);
		}
		if (zl[i].zl=="del")
		{
			erase(1,1,cnt,zl[i].num);
		}
		if (zl[i].zl=="sum")
		{
			cout<<sum[1][3]<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long gen,n,m,i,j,x,y,cnt;
string st;
struct treap
{
	long long rnd,zhi,ls,rs,sz,sum[5];
}tr[100005];
void lzhuan(long long &k)
{
	long long p=tr[k].rs;
	tr[k].rs=tr[p].ls;
	tr[p].ls=k;
	tr[p].sz=tr[k].sz;
	k=p;
}
void rzhuan(long long &k)
{
	long long p=tr[k].ls;
	tr[k].ls=tr[p].rs;
	tr[p].rs=k;
	tr[p].sz=tr[k].sz;
	k=p;
}
void getsum(long long k)
{
	if (!k) return;
	tr[k].sz=tr[tr[k].ls].sz+tr[tr[k].rs].sz+1;
	long long i,j=tr[tr[k].ls].sz;
	j%=5;
	for (i=0;i<=4;i++) tr[k].sum[i]=tr[tr[k].ls].sum[i];
	for (i=0;i<=4;i++)
	{
		j=(j+1)%5;
		tr[k].sum[j]+=tr[tr[k].rs].sum[i];
	}
	tr[k].sum[j]+=tr[k].zhi;
}
void insert(long long &k, long long x)
{
	if (tr[k].zhi==x) return;
	if (!k)
	{
		tr[++cnt].zhi=x;
		tr[cnt].ls=tr[cnt].rs=0;
		tr[cnt].rnd=rand();
		long long i;
		for (i=0;i<=4;i++) tr[cnt].sum[i]=0;
		tr[cnt].sum[0]=x;
		tr[cnt].sz=1;
		k=cnt;
		return;
	}
	if (x<tr[k].zhi)
	{
		insert(tr[k].ls,x);
		if (tr[tr[k].ls].rnd>tr[k].rnd)
		{
			rzhuan(k);
			getsum(tr[k].rs);
		}
	}
	else
	{
		insert(tr[k].rs, x);
		if (tr[tr[k].rs].rnd>tr[k].rnd)
		{
			lzhuan(k);
			getsum(tr[k].ls);
		}
	}
	getsum(k);
}
void erase(long long &k, long long x)
{
	if (!k) return;
	if (tr[k].zhi==x)
	{
		if (!tr[k].ls||!tr[k].rs) k=tr[k].ls+tr[k].rs;
		else if (tr[tr[k].ls].rnd<tr[tr[k].rs].rnd)
		{
			rzhuan(k);
			erase(k,x);
		}
		else
		{
			lzhuan(k);
			erase(k,x);
		}
	}
	else if (tr[k].zhi<x) erase(tr[k].rs,x);
	else erase(tr[k].ls,x);
	getsum(k);
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			insert(gen, x);
		}
		if (st=="del")
		{
			cin>>x;
			erase(gen,x);
		}
		if (st=="sum") cout<<tr[gen].sum[2]<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,x,y,rt=0,sz,lst=22,mod=1e9+7,e=123456789;
string st;
struct treap
{
	long long sz,zhi,fix,lch,rch,sum[5];
}tr[100005];
void getsum(long long &x)
{
	if (x==0) return;
	tr[0].sz=0;
	tr[x].sz=tr[tr[x].lch].sz+tr[tr[x].rch].sz+1;
	long long i,j;
	for (i=0;i<=4;i++) tr[x].sum[i]=tr[tr[x].lch].sum[i];
	j=tr[tr[x].lch].sz%5;
	tr[x].sum[j]+=tr[x].zhi;
	j++;j%=5;
	for (i=0;i<=4;i++,j++,j%=5)
	{
		tr[x].sum[j]+=tr[tr[x].rch].sum[i];
	}
}
void tor(long long &x)
{
	long long tmp=x;
	x=tr[x].lch;
	tr[tmp].lch=tr[x].rch;
	tr[x].rch=tmp;
	getsum(tmp);
	getsum(x);
}
void tol(long long &x)
{
	long long tmp=x;
	x=tr[x].rch;
	tr[tmp].rch=tr[x].lch;
	tr[x].lch=tmp;
	getsum(tmp);
	getsum(x);
}
void insert(long long &x,long long zhi)
{
	if (tr[x].zhi==zhi) return;
	if (!x)
	{
		x=++sz;
		tr[x].sz=1;
		memset(tr[x].sum,0,sizeof(tr[x].sum));
		tr[x].zhi=tr[x].sum[0]=zhi;
		tr[x].fix=lst=lst*e%mod;
		tr[x].lch=tr[x].rch=0;
		return;
	}
	if (zhi<tr[x].zhi)
	{
		insert(tr[x].lch,zhi);
		if (tr[x].fix<tr[tr[x].lch].fix) tor(x);
	}
	else
	{
		insert(tr[x].rch,zhi);
		if (tr[x].fix<tr[tr[x].rch].fix) tol(x);
	}
	getsum(x);
}
void erase(long long &x,long long zhi)
{
	if (!x) return;
	if (tr[x].zhi==zhi)
	{
		if (!(tr[x].lch||tr[x].rch))
		{
			x=0;
			return;
		}
		if (!tr[x].lch)
		{
			x=tr[x].rch;
			return;
		}
		if (!tr[x].rch)
		{
			x=tr[x].lch;
			return;
		}
		if (tr[tr[x].lch].fix>tr[tr[x].rch].fix)
		{
			tor(x);
			erase(x,zhi);
			return;
		}
		else
		{
			tol(x);
			erase(x,zhi);
			return;
		}
	}
	if (zhi<tr[x].zhi) erase(tr[x].lch,zhi);
		else erase(tr[x].rch,zhi);
	getsum(x);
}
long long query(long long &x)
{
	return tr[x].sum[2];
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			insert(rt,x);
		}
		if (st=="del")
		{
			cin>>x;
			erase(rt,x);
		}
		if (st=="sum")
		{
			cout<<query(rt)<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int ans,cnt,n,x,y,i,geshu;
struct treap
{
	treap *ls=NULL,*rs=NULL;
	int zhi,rnd,sz=1;
	long long sum[5];
};
typedef treap* tre;
string st;
treap nodes[100005];
tre gen=NULL;
int getsz(tre &cur)
{
	if(cur==NULL) return 0;
	return cur->sz;
}
void getsum(tre &cur)
{
	int i,cnt;
	if (cur)
	{
		cur->sz=getsz(cur->ls)+getsz(cur->rs)+1;
		int t=0;
		if (cur->ls)
		{
			for (i=0;i<5;i++) cur->sum[i]=cur->ls->sum[i];
			t=cur->ls->sz%5;
		}
		else
		{
			for (i=0;i<5;i++) cur->sum[i]=0;
		}
		cur->sum[t]+=cur->zhi;
		t++;
		t%=5;
		if (cur->rs)
		{
			for (i=0;i<5;i++)
			{
				cur->sum[(t+i)%5]+=cur->rs->sum[i];
			}
		}
	}
}
void make(tre a,tre b,tre &c)
{
	if (!b||!a)
	{
		c=b?b:a;
		return;
	}
	if (a->rnd>b->rnd)
	{
		make(a->rs,b,a->rs);
		c=a;
	}
	else
	{
		make(a,b->ls,b->ls);
		c=b;
	}
	getsum(c);
}
void split(tre t,tre &a,tre &b,int f)
{
	if (!t)
	{
		a=b=NULL;
		return;
	}
	if(f<t->zhi)
	{
		split(t->ls,a,t->ls,f);
		b=t;
	}
	else
	{
		split(t->rs,t->rs,b,f);
		a=t;
	}
	getsum(t);
}
void insert(int zhi)
{
	tre a,b,c;
	split(gen,a,c,zhi);
	nodes[cnt].zhi=zhi;
	nodes[cnt].rnd=rand();
	b=nodes+cnt;
	cnt++;
	getsum(b);
	make(a,b,gen);
	make(gen,c,gen);
}
void erase(tre &cur,int zhi)
{
	if (cur->zhi==zhi)
	{
		make(cur->ls,cur->rs,cur);
	}
	else if (zhi<cur->zhi)
	{
		erase(cur->ls,zhi);
	}
	else erase(cur->rs,zhi);
	getsum(cur);
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			geshu++;
			insert(x);
		}
		if (st=="del")
		{
			cin>>x;
			geshu--;
			erase(gen,x);
		}
		if (st=="sum")
		{
			if (geshu<=0)
			{
				cout<<'0'<<endl;
				continue;
			}
			cout<<gen->sum[2]<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
struct treap
{
	int ls,rs,w,zhi,sz;
	int rnd;
}tr[1000005];
int n,m,i,j,x,y,gen,cnt,ch,k,p,pos;
int ans;
string st;
inline void setsz(int k)
{
	tr[k].sz=tr[tr[k].ls].sz+tr[tr[k].rs].sz;
}
inline void lzhuan(int &k)
{
	int rs=tr[k].rs;
	tr[k].rs=tr[rs].ls;
	tr[rs].ls=k;
	tr[rs].sz=tr[k].sz;
	setsz(k);
	k=rs;
}
inline void rzhuan(int &k)
{
	int ls=tr[k].ls;
	tr[k].ls=tr[ls].rs;
	tr[ls].rs=k;
	tr[ls].sz=tr[k].sz;
	setsz(k);
	k=ls;
}
inline void insert(int &k,int zhi)
{
	if (!k)
	{
		k=++cnt;
		tr[k].ls=tr[k].rs=0;
		tr[k].rnd=rand();
		tr[k].zhi=zhi;
		tr[k].w=1;
		tr[k].sz=1;
	}
	else
	{
		tr[k].sz++;
		if (zhi<tr[k].zhi)
		{
			insert(tr[k].ls,zhi);
			if (tr[tr[k].ls].rnd<tr[k].rnd) rzhuan(k);
		}
		else
		{
			insert(tr[k].rs,zhi);
			if (tr[tr[k].rs].rnd<tr[k].rnd) lzhuan(k);
		}
	}
}
inline void erase(int &k,int zhi)
{
	if (!k) return;
	if (zhi==tr[k].zhi)
	{
		if (!tr[k].ls||!tr[k].rs) k=tr[k].ls+tr[k].rs;
		else if (tr[tr[k].ls].rnd<tr[tr[k].rs].rnd)
		{
			rzhuan(k);
			erase(k,zhi);
		}
		else
		{
			lzhuan(k);
			erase(k,zhi);
		}
	}
	else if (zhi<tr[k].zhi)
	{
		tr[k].sz--;
		erase(tr[k].ls,zhi);
	}
	else
	{
		tr[k].sz--;
		erase(tr[k].rs,zhi);
	}
}
inline void zhongxu(int gen)
{
	if (tr[gen].ls) zhongxu(tr[gen].ls);
	cnt++;
	if (cnt%5==3)
	{
		ans+=tr[gen].zhi;
	}
	if (tr[gen].rs) zhongxu(tr[gen].rs);
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="sum")
		{
			cnt=ans=0;
			zhongxu(gen);
			cout<<ans<<endl;
			continue;
		}
		cin>>x;
		if (st=="add") insert(gen,x);
		if (st=="del") erase(gen,x);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<deque>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
vector<int> seq;
int n,m,i,j,x;
string op;
long long ans;
int main()
{
	scanf("%d",&n);
	while (n--)
	{
		scanf(" ");
		rdst(op,3);
		if (op=="add")
		{
			scanf("%d",&x);
			seq.insert(upper_bound(seq.begin(),seq.end(),x),x);
		}
		if (op=="del")
		{
			scanf("%d",&x);
			seq.erase(lower_bound(seq.begin(),seq.end(),x));
		}
		if (op=="sum")
		{
			ans=0;
			for (i=2;i<seq.size();i+=5) ans+=seq[i];
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#include<set>
using namespace std;
vector<long long> num;
long long n,m,i,j,x,sum;
string st;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add") {cin>>x;num.insert(lower_bound(num.begin(),num.end(),x),x);}
		if (st=="del") {cin>>x;num.erase(lower_bound(num.begin(),num.end(),x));}
		if (st=="sum")
		{
			sum=0;
			for (j=2;j<num.size();j+=5) sum+=num[j];
			cout<<sum<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#define sqr(x) (x)*(x)
using namespace std;
struct ii
{
	long long id,num;
	string zl;
}zl[100005];
bool cmp(ii x,ii y)
{
	return x.num<y.num;
}
bool cmp2(ii x,ii y)
{
	return x.id<y.id;
}
map<long long,long long> mp,zhi;
long long n,m,i,j,cnt,sum[100005][15],sz[100005];
void update(long long id,long long le,long long ri,long long pos)
{
	sz[id]++;
	if (le==pos&&ri==pos)
	{
		sum[id][1]+=zhi[pos];
		return;
	}
	if (pos>(le+ri)/2) update(id*2+1,(le+ri)/2+1,ri,pos);
		else update(id*2,le,(le+ri)/2,pos);
	long long i;
	for (i=0;i<5;i++)
	{
		sum[id][i]=sum[id*2][i]+sum[id*2+1][((i-sz[id*2]%5)+5)%5];
	}
}
void erase(long long id,long long le,long long ri,long long pos)
{
	sz[id]--;
	if (le==pos&&ri==pos)
	{
		sum[id][1]-=zhi[pos];
		return;
	}
	if (pos>(le+ri)/2) erase(id*2+1,(le+ri)/2+1,ri,pos);
		else erase(id*2,le,(le+ri)/2,pos);
	long long i;
	for (i=0;i<5;i++)
	{
		sum[id][i]=sum[id*2][i]+sum[id*2+1][((i-sz[id*2]%5)+5)%5];
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		zl[i].id=i;
		cin>>zl[i].zl;
		if (zl[i].zl!="sum") cin>>zl[i].num;
	}
	sort(zl+1,zl+n+1,cmp);
	cnt=0;
	for (i=1;i<=n;i++)
	{
		if (zl[i].zl=="sum") continue;
		if (!mp[zl[i].num])
		{
			mp[zl[i].num]=++cnt;
			zhi[cnt]=zl[i].num;
		}
		zl[i].num=mp[zl[i].num];
	}
	sort(zl+1,zl+n+1,cmp2);
	//for (i=1;i<=n;i++) cerr<<zl[i].zl<<' '<<zl[i].num<<endl;
	for (i=1;i<=n;i++)
	{
		if (zl[i].zl=="add")
		{
			update(1,1,cnt,zl[i].num);
		}
		if (zl[i].zl=="del")
		{
			erase(1,1,cnt,zl[i].num);
		}
		if (zl[i].zl=="sum")
		{
			cout<<sum[1][3]<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
struct treap
{
	int ls,rs,w,zhi,sz;
	int rnd;
}tr[1000005];
int n,m,i,j,x,y,gen,cnt,ch,k,p,pos;
long long ans;
string st;
void setsz(int k)
{
	tr[k].sz=tr[tr[k].ls].sz+tr[tr[k].rs].sz;
}
void lzhuan(int &k)
{
	int rs=tr[k].rs;
	tr[k].rs=tr[rs].ls;
	tr[rs].ls=k;
	tr[rs].sz=tr[k].sz;
	setsz(k);
	k=rs;
}
void rzhuan(int &k)
{
	int ls=tr[k].ls;
	tr[k].ls=tr[ls].rs;
	tr[ls].rs=k;
	tr[ls].sz=tr[k].sz;
	setsz(k);
	k=ls;
}
void insert(int &k,int zhi)
{
	if (!k)
	{
		k=++cnt;
		tr[k].ls=tr[k].rs=0;
		tr[k].rnd=rand();
		tr[k].zhi=zhi;
		tr[k].w=1;
		tr[k].sz=1;
	}
	else
	{
		tr[k].sz++;
		if (zhi<tr[k].zhi)
		{
			insert(tr[k].ls,zhi);
			if (tr[tr[k].ls].rnd<tr[k].rnd) rzhuan(k);
		}
		else
		{
			insert(tr[k].rs,zhi);
			if (tr[tr[k].rs].rnd<tr[k].rnd) lzhuan(k);
		}
	}
}
void erase(int &k,int zhi)
{
	if (!k) return;
	if (zhi==tr[k].zhi)
	{
		if (!tr[k].ls||!tr[k].rs) k=tr[k].ls+tr[k].rs;
		else if (tr[tr[k].ls].rnd<tr[tr[k].rs].rnd)
		{
			rzhuan(k);
			erase(k,zhi);
		}
		else
		{
			lzhuan(k);
			erase(k,zhi);
		}
	}
	else if (zhi<tr[k].zhi)
	{
		tr[k].sz--;
		erase(tr[k].ls,zhi);
	}
	else
	{
		tr[k].sz--;
		erase(tr[k].rs,zhi);
	}
}
void zhongxu(int gen)
{
	if (tr[gen].ls) zhongxu(tr[gen].ls);
	cnt++;
	if (cnt%5==3)
	{
		ans+=tr[gen].zhi;
	}
	if (tr[gen].rs) zhongxu(tr[gen].rs);
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="sum")
		{
			cnt=ans=0;
			zhongxu(gen);
			cout<<ans<<endl;
			continue;
		}
		cin>>x;
		if (st=="add") insert(gen,x);
		if (st=="del") erase(gen,x);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#include<set>
using namespace std;
vector<long long> num;
long long n,m,i,j,x;
string st;
void sum()
{
	long long su=0;
	for (j=2;j<num.size();j+=5) su+=num[j];
	cout<<su<<endl;
}
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st[0]=='a') {cin>>x;num.insert(lower_bound(num.begin(),num.end(),x),x);}
		if (st[0]=='d') {cin>>x;num.erase(lower_bound(num.begin(),num.end(),x));}
		if (st[0]=='s') sum();
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int ans,cnt,n,x,y,i,geshu;
struct treap
{
	treap *ls=NULL,*rs=NULL;
	int zhi,rnd,sz=1;
	long long sum[5];
};
typedef treap* tre;
string st;
treap nodes[100005];
tre gen=NULL;
int getsz(tre &cur)
{
	if(cur==NULL) return 0;
	return cur->sz;
}
void getsum(tre &cur)
{
	int i,cnt;
	if (cur)
	{
		cur->sz=getsz(cur->ls)+getsz(cur->rs)+1;
		int t=0;
		if (cur->ls)
		{
			for (i=0;i<5;i++) cur->sum[i]=cur->ls->sum[i];
			t=cur->ls->sz%5;
		}
		else
		{
			for (i=0;i<5;i++) cur->sum[i]=0;
		}
		cur->sum[t]+=cur->zhi;
		t++;
		t%=5;
		if (cur->rs)
		{
			for (i=0;i<5;i++)
			{
				cur->sum[(t+i)%5]+=cur->rs->sum[i];
			}
		}
	}
}
void make(tre a,tre b,tre &c)
{
	if (!b||!a)
	{
		c=b?b:a;
		return;
	}
	if (a->rnd>b->rnd)
	{
		make(a->rs,b,a->rs);
		c=a;
	}
	else
	{
		make(a,b->ls,b->ls);
		c=b;
	}
	getsum(c);
}
void split(tre t,tre &a,tre &b,int f)
{
	if (!t)
	{
		a=b=NULL;
		return;
	}
	if(f<t->zhi)
	{
		split(t->ls,a,t->ls,f);
		b=t;
	}
	else
	{
		split(t->rs,t->rs,b,f);
		a=t;
	}
	getsum(t);
}
void insert(int zhi)
{
	tre a,b,c;
	split(gen,a,c,zhi);
	nodes[cnt].zhi=zhi;
	nodes[cnt].rnd=rand();
	b=nodes+cnt;
	cnt++;
	getsum(b);
	make(a,b,gen);
	make(gen,c,gen);
}
void erase(tre &cur,int zhi)
{
	if (cur->zhi==zhi)
	{
		make(cur->ls,cur->rs,cur);
	}
	else if (zhi<cur->zhi)
	{
		erase(cur->ls,zhi);
	}
	else erase(cur->rs,zhi);
	getsum(cur);
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			geshu++;
			insert(x);
		}
		if (st=="del")
		{
			cin>>x;
			geshu--;
			erase(gen,x);
		}
		if (st=="sum") cout<<gen->sum[2]<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<deque>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
vector<long long> seq[505],all;
long long n,m,i,j,b,b2,sum[505][5],x[100005],ans,cnt;
string op[100005];
void rest(int x)
{
	memset(sum[x],0,sizeof(sum[x]));
	int cnt=0;
	llx(seq[x],it)
	{
		sum[x][cnt]+=all[*it];
		(cnt+=1)%=5;
	}
}
int main()
{
	scanf("%I64d",&n);
	for (i=1;i<=n;i++)
	{
		scanf(" ");
		rdst(op[i],3);
		if (op[i]=="sum") x[i]=-1;
		else
		{
			scanf("%I64d",&x[i]);
			all.push_back(x[i]);
		}
	}
	sort(all.begin(),all.end());
	all.resize(unique(all.begin(),all.end())-all.begin());
	b=sqrt((long long)all.size())+1;
	b2=(all.size()-1)/b;
	for (i=1;i<=n;i++)
	{
		if (op[i]=="sum")
		{
			ans=cnt=0;
			for (j=0;j<=b2;j++)
			{
				ans+=sum[j][((2-cnt)%5+5)%5];
				cnt+=seq[j].size();
			}
			printf("%I64d\n",ans);
		}
		x[i]=lower_bound(all.begin(),all.end(),x[i])-all.begin();
		if (op[i]=="add")
		{
			seq[x[i]/b].insert(upper_bound(seq[x[i]/b].begin(),seq[x[i]/b].end(),x[i]),x[i]);
			rest(x[i]/b);
		}
		if (op[i]=="del")
		{
			seq[x[i]/b].erase(upper_bound(seq[x[i]/b].begin(),seq[x[i]/b].end(),x[i]));
			rest(x[i]/b);
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<deque>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
vector<long long> seq[505],all;
long long n,m,i,j,b,b2,sum[505][5],x[100005],ans,cnt;
string op[100005];
void rest(int x)
{
	memset(sum[x],0,sizeof(sum[x]));
	int cnt=0;
	llx(seq[x],it)
	{
		sum[x][cnt]+=all[*it];
		(cnt+=1)%=5;
	}
}
int main()
{
	scanf("%I64d",&n);
	for (i=1;i<=n;i++)
	{
		scanf(" ");
		rdst(op[i],3);
		if (op[i]=="sum") x[i]=-1;
		else
		{
			scanf("%I64d",&x[i]);
			all.push_back(x[i]);
		}
	}
	sort(all.begin(),all.end());
	all.resize(unique(all.begin(),all.end())-all.begin());
	b=sqrt((long long)all.size())+1;
	b2=(all.size()-1)/b;
	for (i=1;i<=n;i++)
	{
		if (op[i]=="sum")
		{
			ans=cnt=0;
			for (j=0;j<=b2;j++)
			{
				ans+=sum[j][((2-cnt)%5+5)%5];
				cnt+=seq[j].size();
			}
			printf("%I64d\n",ans);
		}
		x[i]=lower_bound(all.begin(),all.end(),x[i])-all.begin();
		if (op[i]=="add")
		{
			seq[x[i]/b].insert(upper_bound(seq[x[i]/b].begin(),seq[x[i]/b].end(),x[i]),x[i]);
			rest(x[i]/b);
		}
		if (op[i]=="del")
		{
			seq[x[i]/b].erase(lower_bound(seq[x[i]/b].begin(),seq[x[i]/b].end(),x[i]));
			rest(x[i]/b);
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long gen,n,m,i,j,x,y,cnt;
string st;
struct treap
{
	long long rnd,zhi,ls,rs,sz,sum[5];
}tr[100010];
void lzhuan(long long &k)
{
	long long p=tr[k].rs;
	tr[k].rs=tr[p].ls;
	tr[p].ls=k;
	tr[p].sz=tr[k].sz;
	k=p;
}
void rzhuan(long long &k)
{
	long long p=tr[k].ls;
	tr[k].ls=tr[p].rs;
	tr[p].rs=k;
	tr[p].sz=tr[k].sz;
	k=p;
}
void getsum(long long k)
{
	if (!k) return;
	tr[k].sz=tr[tr[k].ls].sz+tr[tr[k].rs].sz+1;
	long long i,j=tr[tr[k].ls].sz;
	j%=5;
	for (i=0;i<=4;i++) tr[k].sum[i]=tr[tr[k].ls].sum[i];
	for (i=0;i<=4;i++)
	{
		j=(j+1)%5;
		tr[k].sum[j]+=tr[tr[k].rs].sum[i];
	}
	tr[k].sum[j]+=tr[k].zhi;
}
void insert(long long &k, long long x)
{
	if (tr[k].zhi==x) return;
	if (!k)
	{
		tr[++cnt].zhi=x;
		tr[cnt].ls=tr[cnt].rs=0;
		tr[cnt].rnd=rand();
		long long i;
		for (i=0;i<=4;i++) tr[cnt].sum[i]=0;
		tr[cnt].sum[0]=x;
		tr[cnt].sz=1;
		k=cnt;
		return;
	}
	if (x<tr[k].zhi)
	{
		insert(tr[k].ls,x);
		if (tr[tr[k].ls].rnd>tr[k].rnd)
		{
			rzhuan(k);
			getsum(tr[k].rs);
		}
	}
	else
	{
		insert(tr[k].rs, x);
		if (tr[tr[k].rs].rnd>tr[k].rnd)
		{
			lzhuan(k);
			getsum(tr[k].ls);
		}
	}
	getsum(k);
}
void erase(long long &k, long long x)
{
	if (!k) return;
	if (tr[k].zhi==x)
	{
		if (!tr[k].ls||!tr[k].rs) k=tr[k].ls+tr[k].rs;
		else if (tr[tr[k].ls].rnd<tr[tr[k].rs].rnd)
		{
			rzhuan(k);
			erase(k,x);
		}
		else
		{
			lzhuan(k);
			erase(k,x);
		}
	}
	else if (tr[k].zhi<x) erase(tr[k].rs,x);
	else erase(tr[k].ls,x);
	getsum(k);
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			insert(gen, x);
		}
		if (st=="del")
		{
			cin>>x;
			erase(gen,x);
		}
		if (st=="sum") cout<<tr[gen].sum[2]<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
struct treap
{
	long long ls,rs,w,zhi,sz;
	long long rnd,sum[15];
}tr[1000005];
long long n,m,i,j,x,y,gen,cnt,ch,k,p,pos,ans;
string st;
void setsz(long long k)
{
	tr[k].sz=tr[tr[k].ls].sz+tr[tr[k].rs].sz+1;
}
void lzhuan(long long &k)
{
	long long rs=tr[k].rs;
	tr[k].rs=tr[rs].ls;
	tr[rs].ls=k;
	tr[rs].sz=tr[k].sz;
	setsz(k);
	k=rs;
//	setsz(k);
}
void rzhuan(long long &k)
{
	long long ls=tr[k].ls;
	tr[k].ls=tr[ls].rs;
	tr[ls].rs=k;
	tr[ls].sz=tr[k].sz;
	setsz(k);
	k=ls;
//	setsz(k);
}
void getsum(long long gen)
{
	if (!gen) return;
	tr[gen].sz=tr[tr[gen].ls].sz+tr[tr[gen].rs].sz+1;
	long long i,cnt=tr[tr[gen].ls].sz%5;
	for (i=0;i<=4;i++) tr[gen].sum[i]=tr[tr[gen].ls].sum[i];
	for (i=0;i<=4;i++)
	{
		cnt=(cnt+1)%5;
		tr[gen].sum[cnt]+=tr[tr[gen].rs].sum[i];
	}
	tr[gen].sum[cnt]+=tr[gen].zhi;
}
void insert(long long &k,long long zhi)
{
	if (!k)
	{
		k=++cnt;
		tr[k].ls=tr[k].rs=0;
		tr[k].rnd=rand();
		tr[k].zhi=zhi;
		tr[k].w=1;
		tr[k].sz=1;
	}
	else
	{
		tr[k].sz++;
		if (zhi<tr[k].zhi)
		{
			insert(tr[k].ls,zhi);
			if (tr[tr[k].ls].rnd<tr[k].rnd) rzhuan(k);
		}
		else
		{
			insert(tr[k].rs,zhi);
			if (tr[tr[k].rs].rnd<tr[k].rnd) lzhuan(k);
		}
	}
	getsum(k);
}
/*
void erase(long long &k,long long zhi)
{
	if (!k) return;
	if (zhi==tr[k].zhi)
	{
		if (!tr[k].ls||!tr[k].rs) k=tr[k].ls+tr[k].rs;
		else if (tr[tr[k].ls].rnd<tr[tr[k].rs].rnd)
		{
			rzhuan(k);
			erase(k,zhi);
		}
		else
		{
			lzhuan(k);
			erase(k,zhi);
		}
	}
	else if (zhi<tr[k].zhi)
	{
		tr[k].sz--;
		erase(tr[k].ls,zhi);
	}
	else
	{
		tr[k].sz--;
		erase(tr[k].rs,zhi);
	}
	getsum(k);
}*/
void erase(long long zhi,long long &x)
{
	if (tr[x].zhi == zhi)
	{
		if(tr[x].ls && tr[x].rs)
    	{
    		if (tr[tr[x].ls].rnd>tr[tr[x].rs].rnd)
    		{
    			rzhuan(x);
				erase(zhi,tr[x].rs);
			}
			else
			{
    			lzhuan(x);
				erase(zhi,tr[x].ls);
			}
    	}
    	else
    	{
      		if (!tr[x].ls) x=tr[x].rs;
      			else x=tr[x].ls;
    	}
  	}
  	else
  	{
   		tr[x].sz--;
    	if (tr[x].zhi>zhi) erase(zhi,tr[x].ls);
    		else erase(zhi,tr[x].rs);
  	}
  	getsum(x);
}
/*
void zhongxu(long long gen)
{
	if (tr[gen].ls) zhongxu(tr[gen].ls);
	cnt++;
	if (cnt%5==3)
	{
		ans+=tr[gen].zhi;
	}
	if (tr[gen].rs) zhongxu(tr[gen].rs);
}
*/
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="sum")
		{
			//cnt=ans=0;
			//zhongxu(gen);
			cout<<tr[gen].sum[2]<<endl;
			continue;
		}
		cin>>x;
		if (st=="add") insert(gen,x);
		if (st=="del") erase(x,gen);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,sum[1<<19][15],sz[1<<19],cnt;
map<long long,long long> mp,zhi;
struct ii
{
	long long num,id;
	string zl;
}zl[100005];
bool cmp1(ii a,ii b)
{
	if (a.num<b.num) return 1;
	if (a.num>b.num) return 0;
	return a.zl<b.zl;
}
bool cmp2(ii a,ii b)
{
	return a.id<b.id;
}
void update(long long x)
{
	long long i;
	sz[x]=sz[x*2]+sz[x*2+1];
	for (i=0;i<=4;i++)
	{
		sum[x][i]=sum[x*2][i];
	}
	for (i=0;i<=4;i++)
	{
		sum[x][i]+=sum[x*2+1][((i-sz[x*2])%5+5)%5];
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		zl[i].id=i;
		cin>>zl[i].zl;
		if (zl[i].zl!="sum") cin>>zl[i].num;
	}
	sort(zl+1,zl+n+1,cmp1);
	cnt=1;
	for (i=1;i<=n;i++)
	{
		if (zl[i].zl=="add")
		{
			if (!mp[zl[i].num]) mp[zl[i].num]=cnt++;
			zhi[mp[zl[i].num]]=zl[i].num;
			zl[i].num=mp[zl[i].num];
		}
		else if (zl[i].zl=="del")
		{
			zl[i].num=mp[zl[i].num];
		}
	}
	sort(zl+1,zl+n+1,cmp2);
	for (i=1;i<=n;i++)
	{
		if (zl[i].zl=="add")
		{
			j=(1<<18)+zl[i].num;
			sz[j]=1;
			sum[j][0]=zhi[zl[i].num];
			j/=2;
			while (j)
			{
				update(j);
				j/=2;
			}
		}
		if (zl[i].zl=="del")
		{
			j=(1<<18)+zl[i].num;
			sz[j]=0;
			sum[j][0]=0;
			j/=2;
			while (j)
			{
				update(j);
				j/=2;
			}
		}
		if (zl[i].zl=="sum")
		{
			cout<<sum[1][2]<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long gen,n,m,i,j,x,y,cnt=1;
string st;
struct treap
{
	long long rnd,zhi,ls,rs,sz,sum[5];
}tr[100005];
void lzhuan(long long &k)
{
	long long p=tr[k].rs;
	tr[k].rs=tr[p].ls;
	tr[p].ls=k;
	tr[p].sz=tr[k].sz;
	k=p;
}
void rzhuan(long long &k)
{
	long long p=tr[k].ls;
	tr[k].ls=tr[p].rs;
	tr[p].rs=k;
	tr[p].sz=tr[k].sz;
	k=p;
}
void getsum(long long k)
{
	if (!k) return;
	tr[k].sz=tr[tr[k].ls].sz+tr[tr[k].rs].sz+1;
	long long i,j=tr[tr[k].ls].sz;
	j%=5;
	for (i=0;i<=4;i++) tr[k].sum[i]=tr[tr[k].ls].sum[i];
	for (i=0;i<=4;i++)
	{
		j=(j+1)%5;
		tr[k].sum[j]+=tr[tr[k].rs].sum[i];
	}
	tr[k].sum[j]+=tr[k].zhi;
}
void split(long long t,long long &x,long long &y,long long zhi)
{
	if (!t)
	{
		x=0;
		y=0;
		return;
	}
	if (zhi<tr[t].zhi)
	{
		split(tr[t].ls,x,tr[t].ls,zhi);
		y=t;
	}
	else
	{
		split(tr[t].rs,tr[t].rs,y,zhi);
		x=t;
	}
	getsum(t);
}
void make(long long x,long long y,long long &z)
{
	if (!x||!y)
	{
		z=0;
		if (x) z=x;
		if (y) z=y;
		return;
	}
	if (tr[x].rnd>tr[y].rnd)
	{
		make(tr[x].rs,y,tr[x].rs);
		z=x;
	}
	else
	{
		make(x,tr[y].ls,tr[y].ls);
		z=y;
	}
	getsum(z);
}
void insert(long long &k,long long zhi)
{
	long long x,y,z;
	split(k,x,y,zhi);
	tr[cnt].zhi=zhi;
	tr[cnt].rnd=rand();
	z=cnt;
	cnt++;
	getsum(z);
	make(x,z,k);
	make(k,y,k);
}
void erase(long long &k, long long x)
{
	if (!k) return;
	if (tr[k].zhi==x)
	{
		make(tr[k].ls,tr[k].rs,k);
	}
	else if (tr[k].zhi<x) erase(tr[k].rs,x);
	else erase(tr[k].ls,x);
	getsum(k);
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			insert(gen, x);
		}
		if (st=="del")
		{
			cin>>x;
			erase(gen,x);
		}
		if (st=="sum") cout<<tr[gen].sum[2]<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
struct treap
{
	int ls,rs,w,zhi,sz;
	int rnd;
}tr[1000005];
int n,m,i,j,x,y,gen,cnt,ch,k,p,pos;
long long ans;
string st;
inline void setsz(int k)
{
	tr[k].sz=tr[tr[k].ls].sz+tr[tr[k].rs].sz;
}
inline void lzhuan(int &k)
{
	int rs=tr[k].rs;
	tr[k].rs=tr[rs].ls;
	tr[rs].ls=k;
	tr[rs].sz=tr[k].sz;
	setsz(k);
	k=rs;
}
inline void rzhuan(int &k)
{
	int ls=tr[k].ls;
	tr[k].ls=tr[ls].rs;
	tr[ls].rs=k;
	tr[ls].sz=tr[k].sz;
	setsz(k);
	k=ls;
}
inline void insert(int &k,int zhi)
{
	if (!k)
	{
		k=++cnt;
		tr[k].ls=tr[k].rs=0;
		tr[k].rnd=rand();
		tr[k].zhi=zhi;
		tr[k].w=1;
		tr[k].sz=1;
	}
	else
	{
		tr[k].sz++;
		if (zhi<tr[k].zhi)
		{
			insert(tr[k].ls,zhi);
			if (tr[tr[k].ls].rnd<tr[k].rnd) rzhuan(k);
		}
		else
		{
			insert(tr[k].rs,zhi);
			if (tr[tr[k].rs].rnd<tr[k].rnd) lzhuan(k);
		}
	}
}
inline void erase(int &k,int zhi)
{
	if (!k) return;
	if (zhi==tr[k].zhi)
	{
		if (!tr[k].ls||!tr[k].rs) k=tr[k].ls+tr[k].rs;
		else if (tr[tr[k].ls].rnd<tr[tr[k].rs].rnd)
		{
			rzhuan(k);
			erase(k,zhi);
		}
		else
		{
			lzhuan(k);
			erase(k,zhi);
		}
	}
	else if (zhi<tr[k].zhi)
	{
		tr[k].sz--;
		erase(tr[k].ls,zhi);
	}
	else
	{
		tr[k].sz--;
		erase(tr[k].rs,zhi);
	}
}
inline void zhongxu(int gen)
{
	if (tr[gen].ls) zhongxu(tr[gen].ls);
	cnt++;
	if (cnt%5==3)
	{
		ans+=tr[gen].zhi;
	}
	if (tr[gen].rs) zhongxu(tr[gen].rs);
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="sum")
		{
			cnt=ans=0;
			zhongxu(gen);
			cout<<ans<<endl;
			continue;
		}
		cin>>x;
		if (st=="add") insert(gen,x);
		if (st=="del") erase(gen,x);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#include<set>
using namespace std;
vector<long long> num;
long long n,m,i,j,x;
string st;
inline void sum()
{
	long long su=0;
	for (j=2;j<num.size();j+=5) su+=num[j];
	cout<<su<<endl;
}
inline void ins()
{
	cin>>x;
	num.insert(lower_bound(num.begin(),num.end(),x),x);
}
inline void del()
{
	cin>>x;num.erase(lower_bound(num.begin(),num.end(),x));
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie();
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st[0]=='a') ins();
		if (st[0]=='d') del();
		if (st[0]=='s') sum();
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<deque>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
vector<long long> seq[505],all;
long long n,m,i,j,b,b2,sum[505][5],x[100005],ans,cnt;
string op[100005];
void rest(int x)
{
	memset(sum[x],0,sizeof(sum[x]));
	int cnt=0;
	llx(seq[x],it)
	{
		sum[x][cnt]+=all[*it];
		(cnt+=1)%=5;
	}
}
int main()
{
	scanf("%I64d",&n);
	for (i=1;i<=n;i++)
	{
		scanf(" ");
		rdst(op[i],3);
		if (op[i]=="sum") x[i]=-1;
		else
		{
			scanf("%I64d",&x[i]);
			all.push_back(x[i]);
		}
	}
	sort(all.begin(),all.end());
	all.resize(unique(all.begin(),all.end())-all.begin());
	b=sqrt((long long)all.size())+1;
	b2=((long long)all.size()-1)/b;
	for (i=1;i<=n;i++)
	{
		if (op[i]=="sum")
		{
			ans=cnt=0;
			for (j=0;j<=b2;j++)
			{
				ans+=sum[j][((2-cnt)%5+5)%5];
				cnt+=seq[j].size();
			}
			printf("%I64d\n",ans);
		}
		x[i]=lower_bound(all.begin(),all.end(),x[i])-all.begin();
		if (op[i]=="add")
		{
			seq[x[i]/b].insert(upper_bound(seq[x[i]/b].begin(),seq[x[i]/b].end(),x[i]),x[i]);
			rest(x[i]/b);
		}
		if (op[i]=="del")
		{
			seq[x[i]/b].erase(lower_bound(seq[x[i]/b].begin(),seq[x[i]/b].end(),x[i]));
			rest(x[i]/b);
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<deque>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
long long n,m,i,j,b,sum[405][6],x,ans;
deque<long long> dq[405];
string op;
void rst(long long x)
{
	int i;
	memset(sum[x],0,sizeof(sum[x]));
	for (i=0;i<dq[x].size();i++)
	{
		sum[x][(i+1)%5]+=dq[x][i];
	}
}
int main()
{
	scanf("%I64d",&n);
	b=sqrt(n);
	while ((b<1)||(b%5!=0)) b++;
	while (n--)
	{
		scanf(" ");
		rdst(op,3);
		if (op=="add")
		{
			scanf("%I64d",&x);
			for (i=2;!dq[i].empty();i++)
			{
				if (dq[i][0]>x) break;
			}
			i--;
			dq[i].insert(lower_bound(dq[i].begin(),dq[i].end(),x),x);
			rst(i);
			while (dq[i].size()>b)
			{
				long long mem=dq[i].back();
				dq[i].pop_back();
				sum[i][1]-=mem;
				dq[i+1].push_front(mem);
				sum[i+1][5]=sum[i+1][4];
				for (j=4;j;j--) sum[i+1][j]=sum[i+1][j-1];
				sum[i+1][0]=sum[i+1][5];
				sum[i+1][1]+=mem;
				i++;
			}
		}
		if (op=="del")
		{
			scanf("%I64d",&x);
			for (i=1;!dq[i].empty();i++)
			{
				if (dq[i][0]>x) break;
			}
			i--;
			dq[i].erase(lower_bound(dq[i].begin(),dq[i].end(),x));
			rst(i);
			while (!dq[i+1].empty()&&dq[i].size()<b)
			{
				long long mem=dq[i+1].front();
				dq[i+1].pop_front();
				dq[i].push_back(mem);
				sum[i][0]+=mem;
				sum[i+1][1]-=mem;
				sum[i+1][5]=sum[i+1][0];
				for (j=0;j<=4;j++) sum[i+1][j]=sum[i+1][j+1];
				i++;
			}
		}
		if (op=="sum")
		{
			ans=0;
			for (i=1;!dq[i].empty();i++)
			{
				ans+=sum[i][3];
			}
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#include<set>
using namespace std;
long long n,m=0,i,j,x,sum,num[1000005],wz;
string st;
int main()
{
	cin>>n;
	for (j=1;j<=n;j++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			//wz=*lower_bound(num+1,num+m+1,x);
			num[++m]=x;
			for (i=m-1;num[i]>=*lower_bound(num+1,num+m+1,x);i--) swap(num[i],num[i+1]);
		}
		if (st=="del")
		{
			cin>>x;
			for (i=m-1;num[i]>=*lower_bound(num+1,num+m+1,x);i--);
			for (;i<m;i++) swap(num[i],num[i+1]);
			num[m--]=0;
		}
		if (st=="sum")
		{
			sum=0;
			for (i=3;i<=m;i+=5) sum+=num[i];
			cout<<sum<<endl;
		}
	}
	return 0;
}


#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC target("avx")
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<deque>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
vector<int> seq;
int n,m,i,j,x;
string op;
long long ans;
int main()
{
	scanf("%d",&n);
	while (n--)
	{
		scanf(" ");
		rdst(op,3);
		if (op=="add")
		{
			scanf("%d",&x);
			seq.insert(upper_bound(seq.begin(),seq.end(),x),x);
		}
		if (op=="del")
		{
			scanf("%d",&x);
			seq.erase(lower_bound(seq.begin(),seq.end(),x));
		}
		if (op=="sum")
		{
			ans=0;
			for (i=2;i<seq.size();i+=5) ans+=seq[i];
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#include<set>
using namespace std;
set<int> num;
int n,m,i,j,x,sum;
string st;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add") {cin>>x;num.insert(x);}
		if (st=="del") {cin>>x;num.erase(x);}
		if (st=="sum")
		{
			sum=0;
			j=0;
			for (set<int>::iterator it=num.begin();it!=num.end();it++)
			{
				j++;
				if (j%5==3) sum+=*it;
			}
			cout<<sum<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
string st;
long long n,m,i,j,x,y,rt=0,cnt;
struct treap
{
	long long zhi,fix,lch,rch,sz,sum[5];
}tr[100005];
void getsum(long long k)
{
	if (!k) return;
	tr[k].sz=tr[tr[k].lch].sz+tr[tr[k].rch].sz+1;
	long long i,j=tr[tr[k].lch].sz;
	j%=5;
	for (i=0;i<=4;i++) tr[k].sum[i]=tr[tr[k].lch].sum[i];
	for (i=0;i<=4;i++)
	{
		j=(j+1)%5;
		tr[k].sum[j]+=tr[tr[k].rch].sum[i];
	}
	tr[k].sum[j]+=tr[k].zhi;
}
void split(long long x,long long &s,long long &t,long long zhi)
{
	int i;
	if (x==0)
	{
		s=t=0;
		return;
	}
	if (zhi<tr[x].zhi) {split(tr[x].lch,s,tr[x].lch,zhi);t=x;}
	if (zhi>tr[x].zhi) {split(tr[x].rch,tr[x].rch,t,zhi);s=x;}
	getsum(x);
}
void merge(long long s,long long t,long long &x)
{
	if (!s||!t)
	{
		x=s+t;
		return;
	}
	if (tr[x].fix>tr[y].fix)
	{
		merge(tr[s].rch,t,tr[s].rch);
		x=s;
	}
	else
	{
		merge(s,tr[t].lch,tr[t].lch);
		x=t;
	}
	getsum(x);
}
void insert(long long &x,long long zhi)
{
	long long s=0,t=0;
	split(x,s,t,zhi);
	cnt++;
	tr[cnt].zhi=tr[cnt].sum[0]=zhi;
	tr[cnt].lch=tr[cnt].rch=0;
	tr[cnt].fix=rand();
	tr[cnt].sz=1;
	getsum(cnt);
	getsum(s);
	merge(s,cnt,x);
	getsum(x);
	getsum(t);
	merge(x,t,x);
	getsum(x);
}
void erase(long long &x,long long zhi)
{
	if (tr[x].zhi==zhi)
	{
		getsum(tr[x].lch);
		getsum(tr[x].rch);
		merge(tr[x].lch,tr[x].rch,x);
		getsum(x);
		return;
	}
	if (zhi<tr[x].zhi) erase(tr[x].lch,zhi);
	if (zhi>tr[x].zhi) erase(tr[x].rch,zhi);
	getsum(x);
}
long long query()
{
	return tr[rt].sum[2];
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			insert(rt,x);
		}
		if (st=="del")
		{
			cin>>x;
			erase(rt,x);
		}
		if (st=="sum")
		{
			cout<<query()<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#define sqr(x) (x)*(x)
using namespace std;
struct ii
{
	int id,num;
	string zl;
}zl[100005];
bool cmp(ii x,ii y)
{
	return x.num<y.num;
}
bool cmp2(ii x,ii y)
{
	return x.id<y.id;
}
map<int,int> mp,zhi;
int n,m,i,j,cnt,sum[100005][15],sz[100005];
void update(int id,int le,int ri,int pos)
{
	sz[id]++;
	if (le==pos&&ri==pos)
	{
		sum[id][1]+=zhi[pos];
		return;
	}
	if (pos>(le+ri)/2) update(id*2+1,(le+ri)/2+1,ri,pos);
		else update(id*2,le,(le+ri)/2,pos);
	int i;
	for (i=0;i<5;i++)
	{
		sum[id][i]=sum[id*2][i]+sum[id*2+1][((i-sz[id*2]%5)+5)%5];
	}
}
void erase(int id,int le,int ri,int pos)
{
	sz[id]--;
	if (le==pos&&ri==pos)
	{
		sum[id][1]-=zhi[pos];
		return;
	}
	if (pos>(le+ri)/2) erase(id*2+1,(le+ri)/2+1,ri,pos);
		else erase(id*2,le,(le+ri)/2,pos);
	int i;
	for (i=0;i<5;i++)
	{
		sum[id][i]=sum[id*2][i]+sum[id*2+1][((i-sz[id*2]%5)+5)%5];
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		zl[i].id=i;
		cin>>zl[i].zl;
		if (zl[i].zl!="sum") cin>>zl[i].num;
	}
	sort(zl+1,zl+n+1,cmp);
	cnt=0;
	for (i=1;i<=n;i++)
	{
		if (zl[i].zl=="sum") continue;
		if (zl[i].num!=zl[i-1].num)
		{
			mp[zl[i].num]=++cnt;
			zhi[cnt]=zl[i].num;
		}
		zl[i].num=zhi[zl[i].num];
	}
	sort(zl+1,zl+n+1,cmp2);
	for (i=1;i<=n;i++)
	{
		if (zl[i].zl=="add")
		{
			update(1,1,cnt,zl[i].num);
		}
		if (zl[i].zl=="del")
		{
			erase(1,1,cnt,zl[i].num);
		}
		if (zl[i].zl=="sum")
		{
			cout<<sum[1][3]<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#define sqr(x) (x)*(x)
using namespace std;
struct ii
{
	string zl;
	int x,id;
}zl[1000005];
bool cmp1(ii a,ii b)
{
	if (a.x<b.x) return 1;
	if (a.x>b.x) return 0;
	return a.zl<b.zl;
}
bool cmp2(ii a,ii b)
{
	return a.id<b.id;
}
int n,cnt,zhi[1000005],sz[1000005],i;
long long sum[1000005][5],ans;
map<int,int> mp;
void update(int id,int le,int ri,int pos)
{
	sz[id]++;
	if (le==pos&&ri==pos)
	{
		sum[id][1]+=zhi[pos];
		return;
	}
	if (pos>(le+ri)/2) update(id*2+1,(le+ri)/2+1,ri,pos);
		else update(id*2,le,(le+ri)/2,pos);
	int i;
	for (i=0;i<5;i++)
	{
		sum[id][i]=sum[id*2][i]+sum[id*2+1][((i-sz[id*2]%5)+5)%5];
	}
}
void erase(int id,int le,int ri,int pos)
{
	sz[id]--;
	if (le==pos&&ri==pos)
	{
		sum[id][1]-=zhi[pos];
		return;
	}
	if (pos>(le+ri)/2) erase(id*2+1,(le+ri)/2+1,ri,pos);
		else erase(id*2,le,(le+ri)/2,pos);
	int i;
	for (i=0;i<5;i++)
	{
		sum[id][i]=sum[id*2][i]+sum[id*2+1][((i-sz[id*2]%5)+5)%5];
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>zl[i].zl;
		if (zl[i].zl[0]=='s') zl[i].x=0;
		else cin>>zl[i].x;
		zl[i].id=i;
	}
	sort(zl+1,zl+n+1,cmp1);
	cnt=1;
	for (i=1;i<=n;i++)
	{
		if (zl[i].zl[0]=='a')
		{
			if (!mp[zl[i].x]) mp[zl[i].x]=cnt++;
			zhi[mp[zl[i].x]]=zl[i].x;
			zl[i].x=mp[zl[i].x];
		}
		else if (zl[i].zl[0]=='d')
		{
			zl[i].x=mp[zl[i].x];
		}
	}
	sort(zl+1,zl+n+1,cmp2);
	//for (i=1;i<=n;i++) cerr<<zl[i].zl<<' '<<zl[i].num<<endl;
	for (i=1;i<=n;i++)
	{
		if (zl[i].zl=="add") update(1,1,cnt,zl[i].x);
		if (zl[i].zl=="del") erase(1,1,cnt,zl[i].x);
		if (zl[i].zl=="sum") cout<<sum[1][3]<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<deque>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
vector<int> seq;
int n,m,i,j,x;
string op;
long long ans;
int main()
{
	scanf("%d",&n);
	while (n--)
	{
		scanf(" ");
		rdst(op,3);
		if (op=="add")
		{
			scanf("%d",&x);
			seq.insert(upper_bound(seq.begin(),seq.end(),x),x);
		}
		if (op=="del")
		{
			scanf("%d",&x);
			seq.erase(upper_bound(seq.begin(),seq.end(),x));
		}
		if (op=="sum")
		{
			ans=0;
			for (i=2;i<seq.size();i+=5) ans+=seq[i];
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
string st;
long long n,m,i,j,x,y,rt=0,cnt;
struct treap
{
	long long zhi,fix,lch,rch,sz,sum[5];
}tr[100005];
void getsum(long long k)
{
	if (!k) return;
	tr[k].sz=tr[tr[k].lch].sz+tr[tr[k].rch].sz+1;
	long long i,j=tr[tr[k].lch].sz;
	j%=5;
	for (i=0;i<=4;i++) tr[k].sum[i]=tr[tr[k].lch].sum[i];
	for (i=0;i<=4;i++)
	{
		j=(j+1)%5;
		tr[k].sum[j]+=tr[tr[k].rch].sum[i];
	}
	tr[k].sum[j]+=tr[k].zhi;
}
void split(long long x,long long &s,long long &t,long long zhi)
{
	int i;
	if (x==0)
	{
		s=t=0;
		return;
	}
	if (zhi<tr[x].zhi) {split(tr[x].lch,s,tr[x].lch,zhi);t=x;}
	if (zhi>tr[x].zhi) {split(tr[x].rch,tr[x].rch,t,zhi);s=x;}
	getsum(x);
}
void merge(long long s,long long t,long long &x)
{
	if (!s||!t)
	{
		x=s+t;
		return;
	}
	if (tr[x].fix<tr[y].fix)
	{
		merge(tr[s].rch,t,tr[s].rch);
		x=s;
	}
	else
	{
		merge(s,tr[t].lch,tr[t].lch);
		x=t;
	}
	getsum(x);
}
void insert(long long &x,long long zhi)
{
	long long s=0,t=0;
	split(x,s,t,zhi);
	cnt++;
	tr[cnt].zhi=tr[cnt].sum[0]=zhi;
	tr[cnt].lch=tr[cnt].rch=0;
	tr[cnt].fix=rand();
	tr[cnt].sz=1;
	getsum(cnt);
	getsum(s);
	merge(s,cnt,x);
	getsum(x);
	getsum(t);
	merge(x,t,x);
	getsum(x);
}
void erase(long long &x,long long zhi)
{
	if (tr[x].zhi==zhi)
	{
		getsum(tr[x].lch);
		getsum(tr[x].rch);
		merge(tr[x].lch,tr[x].rch,x);
		getsum(x);
		return;
	}
	if (zhi<tr[x].zhi) erase(tr[x].lch,zhi);
	if (zhi>tr[x].zhi) erase(tr[x].rch,zhi);
	getsum(x);
}
long long query()
{
	return tr[rt].sum[2];
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			insert(rt,x);
		}
		if (st=="del")
		{
			cin>>x;
			erase(rt,x);
		}
		if (st=="sum")
		{
			cout<<query()<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#include<set>
using namespace std;
set<long long> num;
long long n,m,i,j,x,sum;
string st;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add") {cin>>x;num.insert(x);}
		if (st=="del") {cin>>x;num.erase(x);}
		if (st=="sum")
		{
			sum=0;
			j=0;
			for (set<long long>::iterator it=num.begin();it!=num.end();it++)
			{
				j++;
				if (j%5==3) sum+=*it;
			}
			cout<<sum<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
vector<long long> num;
long long n,i,x,j;
string s;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for (j=1;j<=n;j++)
	{
		cin>>s;
		if (s[0]=='s')
		{
			long long sum=0;
			for (i=2;i<num.size();i+=5) sum+=num[i];
			cout<<sum<<endl;
		}
		else
		{
			cin>>x;
			if (s[0]=='a') num.insert(lower_bound(num.begin(),num.end(),x),x);
			else num.erase(lower_bound(num.begin(),num.end(),x));
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
struct treap
{
	long long ls,rs,w,zhi,sz;
	long long rnd,sum[15];
}tr[1000005];
long long n,m,i,j,x,y,gen,cnt,ch,k,p,pos,ans;
string st;
void setsz(long long k)
{
	tr[k].sz=tr[tr[k].ls].sz+tr[tr[k].rs].sz+1;
}
void lzhuan(long long &k)
{
	long long rs=tr[k].rs;
	tr[k].rs=tr[rs].ls;
	tr[rs].ls=k;
	tr[rs].sz=tr[k].sz;
	setsz(k);
	k=rs;
	setsz(k);
}
void rzhuan(long long &k)
{
	long long ls=tr[k].ls;
	tr[k].ls=tr[ls].rs;
	tr[ls].rs=k;
	tr[ls].sz=tr[k].sz;
	setsz(k);
	k=ls;
	setsz(k);
}
void getsum(long long gen)
{
	if (!gen) return;
	tr[gen].sz=tr[tr[gen].ls].sz+tr[tr[gen].rs].sz+1;
	long long i,cnt=tr[tr[gen].ls].sz%5;
	for (i=0;i<=4;i++) tr[gen].sum[i]=tr[tr[gen].ls].sum[i];
	for (i=0;i<=4;i++)
	{
		cnt=(cnt+1)%5;
		tr[gen].sum[cnt]+=tr[tr[gen].rs].sum[i];
	}
	tr[gen].sum[cnt]+=tr[gen].zhi;
}
void insert(long long &k,long long zhi)
{
	if (!k)
	{
		k=++cnt;
		tr[k].ls=tr[k].rs=0;
		tr[k].rnd=rand();
		tr[k].zhi=zhi;
		tr[k].w=1;
		tr[k].sz=1;
	}
	else
	{
		tr[k].sz++;
		if (zhi<tr[k].zhi)
		{
			insert(tr[k].ls,zhi);
			if (tr[tr[k].ls].rnd<tr[k].rnd) rzhuan(k);
		}
		else
		{
			insert(tr[k].rs,zhi);
			if (tr[tr[k].rs].rnd<tr[k].rnd) lzhuan(k);
		}
	}
	getsum(k);
}
void erase(long long &k,long long zhi)
{
	if (!k) return;
	if (zhi==tr[k].zhi)
	{
		if (!tr[k].ls||!tr[k].rs) k=tr[k].ls+tr[k].rs;
		else if (tr[tr[k].ls].rnd<tr[tr[k].rs].rnd)
		{
			rzhuan(k);
			erase(k,zhi);
		}
		else
		{
			lzhuan(k);
			erase(k,zhi);
		}
	}
	else if (zhi<tr[k].zhi)
	{
		tr[k].sz--;
		erase(tr[k].ls,zhi);
	}
	else
	{
		tr[k].sz--;
		erase(tr[k].rs,zhi);
	}
	getsum(k);
}
/*
void zhongxu(long long gen)
{
	if (tr[gen].ls) zhongxu(tr[gen].ls);
	cnt++;
	if (cnt%5==3)
	{
		ans+=tr[gen].zhi;
	}
	if (tr[gen].rs) zhongxu(tr[gen].rs);
}
*/
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="sum")
		{
			//cnt=ans=0;
			//zhongxu(gen);
			cout<<tr[gen].sum[2]<<endl;
			continue;
		}
		cin>>x;
		if (st=="add") insert(gen,x);
		if (st=="del") erase(gen,x);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
string st;
long long n,m,i,j,x,y,rt=0,cnt;
struct treap
{
	long long zhi,fix,lch,rch,sz,sum[5];
}tr[100005];
void getsum(long long k)
{
	if (!k) return;
	tr[k].sz=tr[tr[k].lch].sz+tr[tr[k].rch].sz+1;
	long long i,j=tr[tr[k].lch].sz;
	j%=5;
	for (i=0;i<=4;i++) tr[k].sum[i]=tr[tr[k].lch].sum[i];
	for (i=0;i<=4;i++)
	{
		j=(j+1)%5;
		tr[k].sum[j]+=tr[tr[k].rch].sum[i];
	}
	tr[k].sum[j]+=tr[k].zhi;
}
void split(long long x,long long &s,long long &t,long long zhi)
{
	int i;
	if (x==0)
	{
		s=t=0;
		return;
	}
	if (zhi<tr[x].zhi) {split(tr[x].lch,s,tr[x].lch,zhi);t=x;}
	if (zhi>tr[x].zhi) {split(tr[x].rch,tr[x].rch,t,zhi);s=x;}
	getsum(x);
}
void merge(long long s,long long t,long long &x)
{
	if (!s||!t)
	{
		x=s+t;
		return;
	}
	if (tr[s].fix>tr[t].fix)
	{
		merge(tr[s].rch,t,tr[s].rch);
		x=s;
	}
	else
	{
		merge(s,tr[t].lch,tr[t].lch);
		x=t;
	}
	getsum(x);
}
void insert(long long &x,long long zhi)
{
	long long s=0,t=0;
	split(x,s,t,zhi);
	cnt++;
	tr[cnt].zhi=tr[cnt].sum[0]=zhi;
	tr[cnt].lch=tr[cnt].rch=0;
	tr[cnt].fix=rand();
	tr[cnt].sz=1;
	getsum(cnt);
	getsum(s);
	merge(s,cnt,x);
	getsum(x);
	getsum(t);
	merge(x,t,x);
	getsum(x);
}
void erase(long long &x,long long zhi)
{
	if (tr[x].zhi==zhi)
	{
		getsum(tr[x].lch);
		getsum(tr[x].rch);
		merge(tr[x].lch,tr[x].rch,x);
		getsum(x);
		return;
	}
	if (zhi<tr[x].zhi) erase(tr[x].lch,zhi);
	if (zhi>tr[x].zhi) erase(tr[x].rch,zhi);
	getsum(x);
}
long long query()
{
	return tr[rt].sum[2];
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>st;
		if (st=="add")
		{
			cin>>x;
			insert(rt,x);
		}
		if (st=="del")
		{
			cin>>x;
			erase(rt,x);
		}
		if (st=="sum")
		{
			cout<<query()<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#define sqr(x) (x)*(x)
using namespace std;
struct ii
{
	string cz;
	int x,id;
}cz[1000005];
bool cmp1(ii a,ii b)
{
	if (a.x<b.x) return 1;
	if (a.x>b.x) return 0;
	return a.cz<b.cz;
}
bool cmp2(ii a,ii b)
{
	return a.id<b.id;
}
int n,cnt,zhi[1000005],sz[1000005],i;
long long sum[1000005][5],ans;
map<int,int> mp;
void update(int id,int le,int ri,int pos,int add)
{
	sz[id]+=add;
	if (le==pos&&ri==pos)
	{
		sum[id][1]+=add*zhi[pos];
		return;
	}
	if (pos>(le+ri)/2) update(id*2+1,(le+ri)/2+1,ri,pos,add);
		else update(id*2,le,(le+ri)/2,pos,add);
	int i;
	for (i=0;i<5;i++)
	{
		sum[id][i]=sum[id*2][i]+sum[id*2+1][((i-sz[id*2]%5)+5)%5];
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>cz[i].cz;
		//cerr<<cz[i].cz<<endl;
		if (cz[i].cz[0]=='s') cz[i].x=0;
		else cin>>cz[i].x;
		cz[i].id=i;
	}
	sort(cz+1,cz+n+1,cmp1);
	cnt=1;
	for (i=1;i<=n;i++)
	{
		if (cz[i].cz[0]=='a')
		{
			if (!mp[cz[i].x]) mp[cz[i].x]=cnt++;
			zhi[mp[cz[i].x]]=cz[i].x;
			cz[i].x=mp[cz[i].x];
		}
		else if (cz[i].cz[0]=='d')
		{
			cz[i].x=mp[cz[i].x];
		}
	}
	sort(cz+1,cz+n+1,cmp2);
	for (i=1;i<=n;i++)
	{
		if (cz[i].cz[0]=='a') update(1,1,cnt,cz[i].x,1);
			else if (cz[i].cz[0]=='d') update(1,1,cnt,cz[i].x,-1);
				else cout<<sum[1][3]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 400010
using namespace std;
ll n,qx[N],num[N],segt[N][5],maxn;
string qu[N];
vector<ll> nm;
void update(ll fa,ll lft,ll rgt)
{
	ll i;
	num[fa]=num[lft]+num[rgt];
	for(i=0;i<5;i++)
	{
		segt[fa][i]=segt[lft][i];
	}
	for(i=0;i<5;i++)
	{
		segt[fa][(i+num[lft])%5]+=segt[rgt][i];
	}
	return;
}
void gd(ll x,ll tp)
{
	x+=maxn;
	segt[x][0]=nm[x-maxn]*tp;
	num[x]=tp;
	do
	{
		x/=2;
		update(x,x*2,x*2+1);
	}while(x>0);
	return;
}
int main(){
	ll i,x;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>qu[i];
		if(qu[i]!="sum")
		{
			cin>>qx[i];
			nm.push_back(qx[i]);
		}
		else
		{
			qx[i]=-1;
		}
	}
	memset(num,0,sizeof(num));
	memset(segt,0,sizeof(segt));
	sort(nm.begin(),nm.end());
	maxn=1;
	while(maxn<=nm.size())
	{
		maxn*=2;
	}
	for(i=0;i<n;i++)
	{
		if(qu[i]=="sum")
		{
			cout<<segt[1][2]<<endl;
		}
		else
		{
			x=lower_bound(nm.begin(),nm.end(),qx[i])-nm.begin();
			if(qu[i]=="add")
			{
				gd(x,1);
			}
			else
			{
				gd(x,0);
			}
		}
	}
	return 0;
}