#include <bits/stdc++.h>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))

using namespace std;

typedef long long ll;

struct node
{
    ll cost;
    ll cnt;
    node * to[2];
    node()
    {
        cost = 0, cnt = 0;
        to[0] = 0, to[1] = 0;
    }
};

const int digits_number = 32;


inline unsigned rev(unsigned v)
{
    unsigned r = 0;

    for(int i = 0; i < digits_number; ++i)
    {
        r |= (v & 1) << (digits_number - 1 - i);
        v >>= 1;
    }
    return r;
}


void add(node * root, unsigned cost, ll cnt)
{
    unsigned rev_cost = rev(cost);
    ll add_cost = cnt * cost;
    int it = digits_number;
    while(it--)
    {
        root->cnt += cnt;
        root->cost += add_cost;
        if (!root->to[rev_cost & 1])
            root->to[rev_cost & 1] = new node();
        root = root->to[rev_cost & 1];
        rev_cost >>= 1;
    }
    root->cost += add_cost;
    root->cnt += cnt;
}

inline ll Cnt(node * z)
{
    return z ? z->cnt : 0;
}

inline ll Cost(node * z)
{
    return z ? z->cost : 0;
}

ll GET(node * sell, node * buy)
{
    ll ans = 0;
    ll sell_count = 0, buy_count = 0;
    int it = digits_number;
    unsigned cost = 0;
    while(it--)
    {
        if (sell_count + Cnt(sell->to[0]) == buy_count + Cnt(buy->to[1]))
        {
            ans -= Cost(sell->to[0]) - Cost(buy->to[1]);
            return ans;
        }
        if (sell_count + Cnt(sell->to[0]) < buy_count + Cnt(buy->to[1]))
        {
            ans -= Cost(sell->to[0]);
            sell_count += Cnt(sell->to[0]);
            sell = sell->to[1];
            buy = buy->to[1];
            cost = cost * 2 + 1;
        }
        else
        {
            ans += Cost(buy->to[1]);
            buy_count += Cnt(buy->to[1]);
            sell = sell->to[0];
            buy = buy->to[0];
            cost = cost * 2;
        }
    }
    ans += (sell_count - buy_count) * cost;
    return ans;
}

struct query
{
    int type;
    unsigned cost;
    ll cnt;
};

query nextQuery()
{
    string type;
    cin >> type;
    query res;
    if (type[0] == 'e')
        exit(0);
    if (type[0] == 's')
        res.type = 0;
    else
        res.type = 1;
    cin >> res.cnt >> res.cost;
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);

    node * sell = new node();
    node * buy = new node();

    while(1)
    {
        query Q = nextQuery();
        if (Q.type == 0)
        {
            add(sell, Q.cost, Q.cnt);
            add(buy, Q.cost, 0);
        }
        else
        {
            add(buy, Q.cost, Q.cnt);
            add(sell, Q.cost, 0);
        }
        cout << GET(sell, buy) << endl;
    }
    return 0;
}
