Problem: In one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five consecutive elements and find the median of each five. A median is called the middle element of a sorted array (it's the third largest element for a group of five). To increase the algorithm's performance speed on a modern video card, you should be able to find a sum of medians in each five of the array.

A sum of medians of a sorted k-element set S = {a1, a2, ..., ak}, where a1 < a2 < a3 < ... < ak, will be understood by as 

<image>

The <image> operator stands for taking the remainder, that is <image> stands for the remainder of dividing x by y.

To organize exercise testing quickly calculating the sum of medians for a changing set was needed.

Input

The first line contains number n (1 ≤ n ≤ 105), the number of operations performed.

Then each of n lines contains the description of one of the three operations: 

  * add x — add the element x to the set; 
  * del x — delete the element x from the set; 
  * sum — find the sum of medians of the set. 



For any add x operation it is true that the element x is not included in the set directly before the operation.

For any del x operation it is true that the element x is included in the set directly before the operation.

All the numbers in the input are positive integers, not exceeding 109.

Output

For each operation sum print on the single line the sum of medians of the current set. If the set is empty, print 0.

Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams (also you may use the %I64d specificator).

Examples

Input

6
add 4
add 5
add 1
add 2
add 3
sum


Output

3


Input

14
add 1
add 7
add 2
add 5
sum
add 6
add 8
add 9
add 3
add 4
add 10
sum
del 1
sum


Output

5
11
13

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXQ = 1e5 + 5;
inline int rnd(void) { return (rand() << 15) | rand(); }
struct Treap {
  struct Node {
    int val, siz, fix;
    Node *son[2];
    long long sum[5];
    Node(int val_) : val(val_), siz(1), fix(rnd()), son(), sum() {
      sum[1] = val;
    }
  } * emp, *root;
  Treap(void) : emp(new Node(0)), root(emp) { emp->siz = 0; }
  inline Node *new_Node(int val = 0) {
    Node *res = new Node(val);
    res->son[0] = res->son[1] = emp;
    return res;
  }
  inline void del_Node(Node *&u, Node *to) {
    delete u;
    u = to;
  }
  inline void push_up(Node *u) {
    Node *l = u->son[0], *r = u->son[1];
    u->siz = l->siz + r->siz + 1;
    for (int i = 0; i < 5; ++i) u->sum[i] = l->sum[i];
    for (int i = 0; i < 5; ++i) u->sum[(l->siz + 1 + i) % 5] += r->sum[i];
    u->sum[(l->siz + 1) % 5] += u->val;
  }
  inline void rotate(Node *&u, int k) {
    Node *v = u->son[k];
    u->son[k] = v->son[k ^ 1];
    v->son[k ^ 1] = u;
    push_up(u);
    push_up(v);
    u = v;
  }
  void insert(Node *&u, int val) {
    if (!u->val) {
      u = new_Node(val);
      return;
    }
    int k = val > u->val;
    insert(u->son[k], val);
    if (u->son[k]->fix < u->fix)
      rotate(u, k);
    else
      push_up(u);
  }
  inline void insert(int val) { insert(root, val); }
  void erase(Node *&u, int val) {
    if (u->val == val) {
      if (!u->son[0]->val) {
        del_Node(u, u->son[1]);
        return;
      }
      if (!u->son[1]->val) {
        del_Node(u, u->son[0]);
        return;
      }
      rotate(u, u->son[1]->fix < u->son[0]->fix);
    }
    erase(u->son[val > u->val], val);
    push_up(u);
  }
  inline void erase(int val) { erase(root, val); }
  inline long long query(void) { return root->sum[3]; }
} tree;
int main(void) {
  srand((unsigned long long)new char);
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    static char s[10];
    scanf("%s", s + 1);
    if (s[1] == 's')
      printf("%lld\n", tree.query());
    else {
      int x;
      scanf("%d", &x);
      if (s[1] == 'a')
        tree.insert(x);
      else
        tree.erase(x);
    }
  }
  return 0;
}