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 Maxk = 1005;
string mul(string a, string b) {
  int res[Maxk];
  memset(res, 0, sizeof(res));
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  for (int i = 0; i < a.length(); i++) {
    for (int j = 0; j < b.length(); j++) {
      res[i + j] += (a[i] - '0') * (b[j] - '0');
    }
  }
  for (int i = 0; i < Maxk; i++) {
    if (res[i] >= 10) {
      res[i + 1] += (res[i] / 10);
      res[i] %= 10;
    }
  }
  string ret;
  bool flag = false;
  for (int i = Maxk - 1; i >= 0; i--) {
    if (flag || res[i]) {
      flag = true;
      ret = ret + (char)(res[i] + '0');
    }
  }
  if (ret == "") ret = "0";
  return ret;
}
string add(string a, string b) {
  if (a.length() < b.length()) swap(a, b);
  while (a.length() != b.length()) {
    b = '0' + b;
  }
  for (int i = a.length() - 1; i >= 0; i--) {
    a[i] += (b[i] - '0');
    if (a[i] > '9' && i) {
      a[i] -= 10;
      a[i - 1]++;
    }
  }
  if (a[0] > '9') {
    a[0] -= 10;
    a = '1' + a;
  }
  return a;
}
const int Maxn = 100005;
int tot;
struct node {
  long long val, fix;
  long long sum[5];
  int siz;
  node *l, *r;
  node() {
    l = NULL, r = NULL;
    memset(sum, 0, sizeof(sum));
    val = 0, fix = 0;
  }
  int lsize() { return (l) ? l->siz : 0; }
  int rsize() { return (r) ? r->siz : 0; }
};
node* root;
void Update(node* p) {
  if (!p) return;
  p->siz = p->lsize() + p->rsize() + 1;
  for (int i = 0; i < 5; i++) p->sum[i] = 0;
  int tmp = 0;
  if (p->l) {
    for (int i = 0; i < 5; i++) p->sum[i] += p->l->sum[i];
    tmp = p->lsize() % 5;
  }
  p->sum[tmp] += p->val;
  tmp++;
  tmp %= 5;
  if (p->r) {
    for (int i = 0; i < 5; i++) p->sum[(i + tmp) % 5] += p->r->sum[i];
  }
}
node Node[Maxn];
void treap_merge(node* l, node* r, node*& res) {
  if (!l || !r) {
    if (l)
      res = l;
    else
      res = r;
  } else if (l->fix > r->fix) {
    treap_merge(l, r->l, r->l);
    res = r;
  } else {
    treap_merge(l->r, r, l->r);
    res = l;
  }
  Update(res);
  return;
}
void treap_split(node* p, node*& l, node*& r, int k) {
  if (!p) {
    l = NULL, r = NULL;
    return;
  } else if (p->val > k) {
    treap_split(p->l, l, p->l, k);
    r = p;
  } else {
    treap_split(p->r, p->r, r, k);
    l = p;
  }
  Update(p);
}
void treap_ins(int val) {
  node *l, *r, *k;
  treap_split(root, l, r, val);
  k = &Node[tot++];
  k->fix = rand();
  k->val = val;
  Update(k);
  treap_merge(l, k, root);
  treap_merge(root, r, root);
}
void treap_del(node*& p, int val) {
  if (p->val == val) {
    treap_merge(p->l, p->r, p);
  } else if (p->val < val) {
    treap_del(p->r, val);
  } else {
    treap_del(p->l, val);
  }
  Update(p);
}
char op[5];
int main() {
  srand(20160116);
  root = NULL;
  int n;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", op);
    if (op[0] == 'a') {
      int x;
      scanf("%d\n", &x);
      treap_ins(x);
    } else if (op[0] == 'd') {
      int x;
      scanf("%d\n", &x);
      treap_del(root, x);
    } else {
      if (!root)
        printf("0\n");
      else
        printf("%I64d\n", root->sum[2]);
    }
  }
  return 0;
}