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 MaxN = 100003;
const int OP_LEN = 4;
int n, x;
char op[OP_LEN];
struct node {
  int x, size;
  node *fa, *lc, *rc;
  long long sum[5];
  node() {}
  node(int X) : x(X), size(1), fa(NULL), lc(NULL), rc(NULL) {
    memset(sum, 0, sizeof sum);
    sum[0] = X;
  }
} T[MaxN];
int T_tot;
node* root;
inline node* newnode() { return T + (T_tot++); }
inline void update(node* x) {
  register int p = 0;
  x->size = 0;
  for (register int i = 0; i < 5; ++i) x->sum[i] = 0;
  if (x->lc != NULL) {
    for (register int i = 0; i < 5; ++i) x->sum[i] += x->lc->sum[i];
    p = x->lc->size % 5;
    x->size += x->lc->size;
  }
  x->sum[p] += x->x;
  x->size++;
  p = (p + 1) % 5;
  if (x->rc != NULL) {
    for (register int i = 0; i < 5; ++i) x->sum[(i + p) % 5] += x->rc->sum[i];
    x->size += x->rc->size;
  }
}
inline void left_rotate(node* x) {
  node* r = x->rc;
  x->rc = r->lc;
  if (r->lc != NULL) r->lc->fa = x;
  r->fa = x->fa;
  if (x->fa != NULL) {
    if (x == x->fa->lc)
      x->fa->lc = r;
    else
      x->fa->rc = r;
  } else {
    root = r;
  }
  r->lc = x;
  x->fa = r;
  update(x);
  update(x->fa);
}
inline void right_rotate(node* x) {
  node* l = x->lc;
  x->lc = l->rc;
  if (l->rc != NULL) l->rc->fa = x;
  l->fa = x->fa;
  if (x->fa != NULL) {
    if (x == x->fa->lc)
      x->fa->lc = l;
    else
      x->fa->rc = l;
  } else {
    root = l;
  }
  l->rc = x;
  x->fa = l;
  update(x);
  update(x->fa);
}
inline void splay(node* x) {
  while (x->fa != NULL) {
    if (x->fa->fa == NULL) {
      if (x == x->fa->lc)
        right_rotate(x->fa);
      else
        left_rotate(x->fa);
    } else if (x == x->fa->lc && x->fa == x->fa->fa->lc) {
      right_rotate(x->fa->fa);
      right_rotate(x->fa);
    } else if (x == x->fa->rc && x->fa == x->fa->fa->rc) {
      left_rotate(x->fa->fa);
      left_rotate(x->fa);
    } else if (x == x->fa->lc && x->fa == x->fa->fa->rc) {
      right_rotate(x->fa);
      left_rotate(x->fa);
    } else {
      left_rotate(x->fa);
      right_rotate(x->fa);
    }
  }
}
void dfs(const node* root) {
  printf("T[%d]:x:%d fa:%d lc:%d rc:%d\n", root - T, root->x,
         (root->fa == NULL ? -1 : root->fa - T),
         (root->lc == NULL ? -1 : root->lc - T),
         (root->rc == NULL ? -1 : root->rc - T));
  printf("sum:");
  for (register int i = 0; i < 5; ++i) printf("%I64d ", root->sum[i]);
  putchar('\n');
  if (root->lc != NULL) dfs(root->lc);
  if (root->rc != NULL) dfs(root->rc);
}
node* insert_recursive(node* p, const int& key) {
  if (key < p->x) {
    if (p->lc == NULL) {
      p->lc = newnode();
      p->lc->fa = p;
      p->lc->x = key;
      update(p->lc);
      update(p);
      return p->lc;
    } else {
      node* ret = insert_recursive(p->lc, key);
      if (ret != NULL) update(p);
      return ret;
    }
  } else if (key > p->x) {
    if (p->rc == NULL) {
      p->rc = newnode();
      p->rc->fa = p;
      p->rc->x = key;
      update(p->rc);
      update(p);
      return p->rc;
    } else {
      node* ret = insert_recursive(p->rc, key);
      if (ret != NULL) update(p);
      return ret;
    }
  } else {
    return NULL;
  }
}
inline void add(const int& key) {
  if (root == NULL) {
    root = newnode();
    root->x = key;
    update(root);
    return;
  }
  node* p = insert_recursive(root, key);
  if (p == NULL) return;
  splay(p);
  root = p;
}
inline node* find(const int& key) {
  node* p = root;
  while (p != NULL) {
    if (key == p->x) return p;
    if (key < p->x)
      p = p->lc;
    else
      p = p->rc;
  }
  return p;
}
inline void del(const int& key) {
  node* p = find(key);
  if (p == NULL) return;
  splay(p);
  root = p;
  if (root->size == 1) {
    root = NULL;
    return;
  }
  if (p->lc == NULL) {
    p->rc->fa = NULL;
    root = p->rc;
  } else if (p->rc == NULL) {
    p->lc->fa = NULL;
    root = p->lc;
  } else {
    node* t = p->lc;
    p->lc->fa = NULL;
    while (t->rc != NULL) t = t->rc;
    splay(t);
    p->rc->fa = t;
    t->rc = p->rc;
    update(t);
    root = t;
  }
}
int main() {
  scanf("%d", &n);
  for (int I = 1; I <= n; ++I) {
    scanf("%s", op);
    if (!strncmp(op, "add", 3)) {
      scanf("%d", &x);
      add(x);
    } else if (!strncmp(op, "del", 3)) {
      scanf("%d", &x);
      del(x);
    } else if (!strncmp(op, "sum", 3)) {
      if (root == NULL)
        puts("0");
      else
        printf("%I64d\n", root->sum[2]);
    }
  }
  return 0;
}