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>
const double PI = acos(-1.0);
using namespace std;
long long bigmod(long long b, long long p, long long m) {
  if (p == 0) return 1;
  long long my = bigmod(b, p / 2, m);
  my *= my;
  my %= m;
  if (p & 1) my *= b, my %= m;
  return my;
}
int setb(int n, int pos) { return n = n | (1 << pos); }
int resb(int n, int pos) { return n = n & ~(1 << pos); }
bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }
struct query {
  int t, x;
  query() {}
  query(int tt, int xx) {
    t = tt;
    x = xx;
  }
};
query q[100005];
map<int, int> mp;
vector<int> v;
int n;
struct info {
  long long t, a[5];
  void Print1() {
    printf("%lld:", t);
    for (int i = 0; i < 5; i++) printf(" %lld", a[i]);
    printf("\n");
  }
};
info tree[400005];
info Merge(info A, info B) {
  info ret;
  ret.t = A.t + B.t;
  for (int i = 0; i < 5; i++) {
    int baki = A.t % 5;
    int id = 5 - baki;
    id = (id + i) % 5;
    ret.a[i] = A.a[i] + B.a[id];
  }
  return ret;
}
void U(int ind, int b, int e, int i, int x) {
  if (b == e) {
    if (x)
      tree[ind].t = 1;
    else
      tree[ind].t = 0;
    for (int i = 0; i < 5; i++) tree[ind].a[i] = 0;
    if (x) tree[ind].a[0] = v[b - 1];
    return;
  }
  int mid = (b + e) / 2, l = 2 * ind, r = l + 1;
  if (i <= mid)
    U(l, b, mid, i, x);
  else
    U(r, mid + 1, e, i, x);
  tree[ind] = Merge(tree[l], tree[r]);
}
int main() {
  int x, t, i, j;
  char ins[10];
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", ins);
    if (ins[0] == 'a') {
      t = 1;
      scanf("%d", &x);
      if (mp.find(x) == mp.end()) {
        mp[x] = 1;
        v.push_back(x);
      }
    } else if (ins[0] == 'd') {
      t = 2;
      scanf("%d", &x);
    } else {
      t = 3;
      x = 0;
    }
    q[i] = query(t, x);
  }
  sort(v.begin(), v.end());
  for (i = 0; i < v.size(); i++) mp[v[i]] = i + 1;
  int N = v.size();
  for (i = 1; i <= n; i++) {
    int t = q[i].t;
    int x = q[i].x;
    x = mp[x];
    if (t == 1) U(1, 1, N, x, 1);
    if (t == 2) U(1, 1, N, x, 0);
    if (t == 3) {
      info my = tree[1];
      long long ret = my.a[2];
      printf("%lld", ret);
      printf("\n");
    }
  }
  return 0;
}