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 = 100100;
int lt[maxn], rt[maxn], fa[maxn], siz[maxn], val[maxn], laz[maxn];
long long int s[maxn][5];
int N, root, cnt;
int New(int x) {
  int p = ++cnt;
  lt[p] = rt[p] = fa[p] = 0;
  siz[p] = 1;
  s[p][1] = x;
  val[p] = x;
  return p;
}
int mod(int x) { return (x % 5 + 5) % 5; }
bool isrs(int p) { return p == rt[fa[p]]; }
void update(int p) {
  siz[p] = siz[lt[p]] + siz[rt[p]] + 1;
  for (int i = 0; i <= 4; i++) {
    s[p][i] = s[lt[p]][i] + s[rt[p]][mod(i - siz[lt[p]] - 1)];
    if (i == mod(siz[lt[p]] + 1)) s[p][i] += val[p];
  }
}
void print(int p, int dp) {
  if (!dp) printf("!!!!!!!!!\n");
  if (!p) {
    for (int i = 0; i < dp; i++) printf("\t");
    printf("#\n");
    return;
  }
  print(lt[p], dp + 1);
  for (int i = 0; i < dp; i++) printf("\t");
  printf("%d %d %d %d\n", p, siz[p], val[p], s[p][3]);
  print(rt[p], dp + 1);
}
void rotate(int p) {
  int f = fa[p], ff = fa[f];
  bool b = isrs(p);
  if (ff) {
    if (isrs(f))
      rt[ff] = p;
    else
      lt[ff] = p;
  }
  fa[p] = ff;
  if (b) {
    int l = lt[p];
    rt[f] = l;
    if (l) fa[l] = f;
    lt[p] = f;
    fa[f] = p;
  } else {
    int r = rt[p];
    lt[f] = r;
    if (r) fa[r] = f;
    rt[p] = f;
    fa[f] = p;
  }
  update(f);
}
void splay(int p, int tf) {
  while (fa[p] != tf && fa[fa[p]] != tf) {
    if (isrs(p) == isrs(fa[p]))
      rotate(fa[p]);
    else
      rotate(p);
    rotate(p);
  }
  if (fa[p] != tf) rotate(p);
  update(p);
  if (!tf) root = p;
}
void opr_add(int x) {
  if (!root)
    root = New(x);
  else {
    int p = root, xx = New(x);
    while (1) {
      if (val[xx] > val[p]) {
        if (rt[p])
          p = rt[p];
        else {
          rt[p] = xx;
          fa[xx] = p;
          break;
        }
      } else {
        if (lt[p])
          p = lt[p];
        else {
          lt[p] = xx;
          fa[xx] = p;
          break;
        }
      }
    }
    splay(xx, 0);
  }
}
void opr_del(int x) {
  int p = root;
  while (1) {
    if (x > val[p])
      p = rt[p];
    else if (x < val[p])
      p = lt[p];
    else
      break;
  }
  splay(p, 0);
  int l = lt[p], r = rt[p];
  if (!l) {
    root = r;
    fa[r] = 0;
    rt[p] = 0;
  } else if (!r) {
    root = l;
    fa[l] = 0;
    lt[p] = 0;
  } else {
    while (rt[l]) l = rt[l];
    while (lt[r]) r = lt[r];
    splay(l, 0);
    splay(r, l);
    fa[p] = 0;
    lt[r] = 0;
    update(r);
    update(l);
  }
}
long long int opr_sum() { return s[root][3]; }
int main() {
  int i, j, k;
  char o[10];
  scanf("%d", &N);
  for (i = 1; i <= N; i++) {
    scanf("%s", o);
    if (o[0] == 'a') {
      scanf("%d", &j);
      opr_add(j);
    } else if (o[0] == 's') {
      printf("%I64d\n", opr_sum());
    } else {
      scanf("%d", &j);
      opr_del(j);
    }
  }
}