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;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
char s[10];
int n, m, x;
int d[100010];
map<int, int> mp;
struct opr {
  int op, x;
} q[100010];
struct segtree {
  long long sum[5];
  int l, r, tag, tot;
} t[100010 * 8];
long long swp[5];
inline void gao(int k, int tt) {
  int t2 = 0;
  t[k].tot += tt;
  for (int i = 0; i < 5; i++) {
    t2 = i + tt;
    if (t2 >= 5) t2 -= 5;
    if (t2 < 0) t2 += 5;
    swp[t2] = t[k].sum[i];
  }
  for (int i = 0; i < 5; i++) t[k].sum[i] = swp[i];
}
inline void pushdown(int k) {
  int tt = t[k].tag;
  t[k].tag = 0;
  t[k << 1].tag += tt;
  t[k << 1 | 1].tag += tt;
  if (t[k << 1].tag >= 5) t[k << 1].tag -= 5;
  if (t[k << 1].tag < 0) t[k << 1].tag += 5;
  if (t[k << 1 | 1].tag >= 5) t[k << 1 | 1].tag -= 5;
  if (t[k << 1 | 1].tag < 0) t[k << 1 | 1].tag += 5;
  gao(k << 1, tt);
  gao(k << 1 | 1, tt);
}
inline void update(int k) {
  for (int i = 0; i < 5; i++)
    t[k].sum[i] = t[k << 1].sum[i] + t[k << 1 | 1].sum[i];
}
inline void buildtree(int now, int l, int r) {
  t[now].l = l;
  t[now].r = r;
  if (l == r) return;
  int mid = (l + r) >> 1;
  buildtree(now << 1, l, mid);
  buildtree(now << 1 | 1, mid + 1, r);
}
inline void rotate(int now, int x, int y, int d) {
  pushdown(now);
  int l = t[now].l, r = t[now].r;
  if (l == x && r == y) {
    t[now].tag += d;
    gao(now, d);
    return;
  }
  int mid = (l + r) >> 1;
  if (y <= mid)
    rotate(now << 1, x, y, d);
  else if (x > mid)
    rotate(now << 1 | 1, x, y, d);
  else
    rotate(now << 1, x, mid, d), rotate(now << 1 | 1, mid + 1, y, d);
  update(now);
}
inline void insert(int now, int x, int z) {
  pushdown(now);
  int l = t[now].l, r = t[now].r;
  if (l == x && r == x) {
    if (z == 1)
      t[now].sum[t[now].tot % 5] += d[x];
    else if (z == -1)
      t[now].sum[t[now].tot % 5] -= d[x];
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    insert(now << 1, x, z);
  else
    insert(now << 1 | 1, x, z);
  update(now);
}
inline void bianli(int k) {
  int l = t[k].l, r = t[k].r;
  printf("%d %d %d |%lld|%lld|%lld|%lld|%lld| %d %d\n", k, l, r, t[k].sum[0],
         t[k].sum[1], t[k].sum[2], t[k].sum[3], t[k].sum[4], t[k].tag,
         t[k].tot);
  if (l == r) return;
  bianli(k << 1);
  bianli(k << 1 | 1);
}
int main() {
  m = read();
  for (int i = 1; i <= m; i++) {
    scanf("%s", s + 1);
    if (s[1] == 'a') {
      x = read();
      q[i].op = 1;
      q[i].x = x;
      d[++n] = x;
    } else if (s[1] == 'd') {
      x = read();
      q[i].op = 2;
      q[i].x = x;
    } else
      q[i].op = 3;
  }
  if (!n) {
    for (int i = 1; i <= m; i++) puts("0");
    return 0;
  }
  sort(d + 1, d + n + 1);
  for (int i = 1; i <= n; i++) mp[d[i]] = i;
  for (int i = 1; i <= m; i++)
    if (q[i].x) q[i].x = mp[q[i].x];
  buildtree(1, 1, n);
  for (int i = 1; i <= m; i++) {
    if (q[i].op == 1) {
      rotate(1, q[i].x, n, 1);
      insert(1, q[i].x, 1);
    } else if (q[i].op == 2) {
      rotate(1, q[i].x, n, -1);
      insert(1, q[i].x, -1);
    } else if (q[i].op == 3) {
      printf("%lld\n", t[1].sum[3]);
    }
  }
}