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 std::cin;
using std::cout;
using std::endl;
using std::string;
constexpr int MAXN = 1e5 + 5;
struct Node {
  int l, r;
  int fa;
  int siz;
  int ch[2];
  long long val;
  long long sum[6];
};
enum child { left = 0, right = 1 };
Node t[MAXN << 1 | 1];
int cnt;
int root;
int n;
inline int newNode(long long val = 0, int fa = 0) {
  ++cnt;
  t[cnt].val = val;
  t[cnt].sum[1] = val;
  t[cnt].fa = fa;
  t[cnt].siz = 1;
  return cnt;
}
inline void connect(int rt, int fa, int ch) {
  t[rt].fa = fa;
  t[fa].ch[ch] = rt;
}
inline int identify(int rt) { return t[t[rt].fa].ch[1] == rt; }
inline void pushUp(int rt) {
  t[rt].siz = t[t[rt].ch[0]].siz + t[t[rt].ch[1]].siz + 1;
  for (int i = 0; i < 5; ++i) {
    t[rt].sum[i] =
        t[t[rt].ch[0]].sum[i] +
        t[t[rt].ch[1]].sum[(i + 5 - ((t[t[rt].ch[0]].siz + 1) % 5)) % 5];
  }
  t[rt].sum[(t[t[rt].ch[0]].siz + 1) % 5] += t[rt].val;
}
inline void rotate(int x) {
  int y = t[x].fa;
  int z = t[y].fa;
  int chk = identify(x);
  connect(t[x].ch[chk ^ 1], y, chk);
  connect(y, x, chk ^ 1);
  t[x].fa = z;
  if (z) {
    t[z].ch[t[z].ch[1] == y] = x;
  }
  pushUp(y);
  pushUp(x);
}
inline void splay(int x, int to = root) {
  to = t[to].fa;
  while (t[x].fa != to) {
    int f = t[x].fa;
    if (t[f].fa == to) {
      rotate(x);
      break;
    } else if (identify(x) == identify(f)) {
      rotate(f);
      rotate(x);
    } else {
      rotate(x);
      rotate(x);
    }
  }
  if (!to) {
    root = x;
  }
}
inline int pre() {
  int rt = t[root].ch[0];
  while (t[rt].ch[1]) {
    rt = t[rt].ch[1];
  }
  return rt;
}
inline int nxt() {
  int rt = t[root].ch[1];
  while (t[rt].ch[0]) {
    rt = t[rt].ch[0];
  }
  return rt;
}
inline void insert(long long x) {
  if (!root) {
    root = newNode(x);
    return;
  }
  int rt = root;
  while (rt) {
    ++t[rt].siz;
    int nxt = t[rt].val < x;
    if (!t[rt].ch[nxt]) {
      t[rt].ch[nxt] = newNode(x, rt);
      pushUp(rt);
      splay(t[rt].ch[nxt]);
      return;
    } else {
      rt = t[rt].ch[nxt];
    }
  }
}
inline int rank(long long x) {
  int rt = root;
  int ans = 1;
  while (rt) {
    if (x < t[rt].val) {
      rt = t[rt].ch[0];
    } else {
      ans += t[t[rt].ch[0]].siz;
      if (t[rt].val == x) {
        splay(rt);
        return ans;
      }
      rt = t[rt].ch[1];
    }
  }
  return 0;
}
inline void del(long long k) {
  rank(k);
  if (!t[root].ch[0] && !t[root].ch[1]) {
    root = 0;
    return;
  }
  if (t[root].ch[0] && !t[root].ch[1]) {
    root = t[root].ch[0];
    t[root].fa = 0;
    return;
  }
  if (!t[root].ch[0] && t[root].ch[1]) {
    root = t[root].ch[1];
    t[root].fa = 0;
    return;
  }
  int x = pre();
  int rt = root;
  splay(x);
  connect(t[rt].ch[1], root, child::right);
  pushUp(root);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    string opt;
    long long x;
    cin >> opt;
    if (opt[0] == 'a') {
      cin >> x;
      insert(x);
    } else if (opt[0] == 'd') {
      cin >> x;
      del(x);
    } else if (opt[0] == 's') {
      cout << t[root].sum[3] << endl;
    }
  }
  return 0;
}