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;
struct BNode {
  int _arr[316];
  long long _sum[5];
  int _cnt;
  BNode *_prev, *_next;
  BNode() : _cnt(0), _prev(0), _next(0) { update(); }
  void update() {
    memset(_sum, 0, sizeof(_sum));
    for (int i = 0; i < _cnt; ++i) _sum[i % 5] += _arr[i];
  }
  void insert(int p, const int &x) {
    for (int i = _cnt++; i > p; --i) _arr[i] = _arr[i - 1];
    _arr[p] = x;
    update();
  }
  void insert2(int p, const int &x) {
    for (int i = 0; i < p; ++i) _arr[i] = _arr[i + 1];
    _arr[p] = x;
    update();
  }
  void erase(int p) {
    --_cnt;
    for (int i = p; i < _cnt; ++i) _arr[i] = _arr[i + 1];
    update();
  }
};
struct Rope {
  BNode *_head, *_tail;
  Rope() {
    _head = new BNode;
    _tail = new BNode;
    _head->_next = _tail;
    _tail->_prev = _head;
    _head->_cnt = _tail->_cnt = 316;
  }
  ~Rope() {
    delete _head;
    delete _tail;
  }
  void clear() {}
  bool empty() const { return _head->_next == _tail; }
  void insert(const int &x) {
    if (empty()) {
      BNode *nd = new BNode;
      nd->insert(0, x);
      nd->_next = _tail;
      nd->_prev = _head;
      _tail->_prev = nd;
      _head->_next = nd;
      return;
    }
    BNode *it;
    for (it = _head->_next; it != _tail; it = it->_next)
      if (x <= it->_arr[it->_cnt - 1]) break;
    if (it == _tail) it = it->_prev;
    int p = lower_bound(it->_arr, it->_arr + it->_cnt, x) - it->_arr;
    if (it->_cnt < 316) {
      it->insert(p, x);
    } else {
      if (it->_prev->_cnt < 316) {
        if (p == 0)
          it->_prev->insert(it->_prev->_cnt, x);
        else {
          it->_prev->insert(it->_prev->_cnt, it->_arr[0]);
          it->insert2(p - 1, x);
        }
      } else if (it->_next->_cnt < 316) {
        if (p == 316)
          it->_next->insert(0, x);
        else {
          it->_next->insert(0, it->_arr[it->_cnt - 1]);
          --it->_cnt;
          it->insert(p, x);
        }
      } else {
        BNode *nd = new BNode;
        if (p < 316) {
          nd->insert(0, it->_arr[316 - 1]);
          --it->_cnt;
          it->insert(p, x);
        } else
          nd->insert(0, x);
        nd->_next = it->_next;
        nd->_prev = it;
        it->_next = nd;
        nd->_next->_prev = nd;
      }
    }
  }
  void erase(const int &x) {
    BNode *it;
    for (it = _head->_next; it != _tail; it = it->_next)
      if (x <= it->_arr[it->_cnt - 1]) break;
    if (it == _tail) return;
    int p = lower_bound(it->_arr, it->_arr + it->_cnt, x) - it->_arr;
    if (p == it->_cnt || it->_arr[p] != x) return;
    for (int i = p; i < it->_cnt - 1; ++i) it->_arr[i] = it->_arr[i + 1];
    --it->_cnt;
    if (it->_cnt + it->_prev->_cnt <= 316) {
      copy(it->_arr, it->_arr + it->_cnt, it->_prev->_arr + it->_prev->_cnt);
      it = it->_prev;
      it->_cnt += it->_next->_cnt;
      BNode *t = it->_next;
      it->_next = it->_next->_next;
      it->_next->_prev = it;
      delete t;
    } else if (it->_cnt + it->_next->_cnt <= 316) {
      copy(it->_next->_arr, it->_next->_arr + it->_next->_cnt,
           it->_arr + it->_cnt);
      it->_cnt += it->_next->_cnt;
      BNode *t = it->_next;
      it->_next = it->_next->_next;
      it->_next->_prev = it;
      delete t;
    }
    it->update();
  }
  long long query() {
    BNode *it;
    long long ans = 0;
    int cnt = 0;
    for (it = _head->_next; it != _tail; it = it->_next) {
      ans += it->_sum[((2 - cnt) % 5 + 5) % 5];
      cnt += it->_cnt;
    }
    return ans;
  }
} rope;
int main() {
  int n, x;
  char opt[15];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", opt);
    if (opt[0] == 'a') {
      scanf("%d", &x);
      rope.insert(x);
    } else if (opt[0] == 'd') {
      scanf("%d", &x);
      rope.erase(x);
    } else {
      printf("%I64d\n", rope.query());
    }
  }
  return 0;
}