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;
vector<pair<long long int, long long int> > consulta;
vector<long long int> valores;
vector<long long int> nuevo;
map<long long int, long long int> mapa;
long long int proceso() {
  sort((valores).begin(), (valores).end());
  long long int ant;
  if (valores.size() > 0) ant = valores[0], nuevo.push_back(ant);
  for (long long int x : valores) {
    if (x > ant) nuevo.push_back(x);
    ant = x;
  }
  long long int i = 0;
  for (long long int x : nuevo) {
    mapa[x] = i++;
  }
  return i;
}
struct st {
  long long int n;
  vector<long long int> arbol[5];
  vector<long long int> cant;
  void add(long long int p, long long int ini, long long int fin,
           long long int pos, long long int val) {
    if (ini > fin || pos > fin || pos < ini) return;
    if (ini == fin) {
      cant[p] = 1;
      for (long long int i = (long long int)(0); i < (long long int)(5); i++) {
        arbol[i][p] = (i == 2) ? val : 0;
      }
      return;
    }
    long long int mid = (ini + fin) / 2;
    add(p << 1, ini, mid, pos, val);
    add(p << 1 | 1, mid + 1, fin, pos, val);
    cant[p] = cant[p << 1] + cant[p << 1 | 1];
    for (long long int i = (long long int)(0); i < (long long int)(5); i++) {
      arbol[i][p] =
          arbol[i][p << 1] + arbol[(i + cant[p << 1]) % 5][p << 1 | 1];
    }
  }
  void delet(long long int p, long long int ini, long long int fin,
             long long int pos, long long int val) {
    if (ini > fin || pos > fin || pos < ini) return;
    if (ini == fin) {
      cant[p] = 0;
      for (long long int i = (long long int)(0); i < (long long int)(5); i++) {
        arbol[i][p] = 0;
      }
      return;
    }
    long long int mid = (ini + fin) / 2;
    delet(p << 1, ini, mid, pos, val);
    delet(p << 1 | 1, mid + 1, fin, pos, val);
    cant[p] = cant[p << 1] + cant[p << 1 | 1];
    for (long long int i = (long long int)(0); i < (long long int)(5); i++) {
      arbol[i][p] =
          arbol[i][p << 1] + arbol[(i + cant[p << 1]) % 5][p << 1 | 1];
    }
  }
  void solve() {
    for (long long int i = (long long int)(0);
         i < (long long int)(consulta.size()); i++) {
      if (consulta[i].first == 0) {
        if (n)
          printf("%lld\n", arbol[0][1]);
        else
          puts("0");
      } else if (consulta[i].first == 1) {
        add(1, 0, n - 1, mapa[consulta[i].second], consulta[i].second);
      } else if (consulta[i].first == 2) {
        delet(1, 0, n - 1, mapa[consulta[i].second], consulta[i].second);
      }
    }
  }
  void ini(long long int _n) {
    n = _n;
    for (long long int i = (long long int)(0); i < (long long int)(5); i++)
      arbol[i].assign(4 * n, 0);
    cant.assign(4 * n, 0);
  }
};
int main() {
  long long int q;
  scanf("%lld", &q);
  char s[30];
  long long int x;
  for (long long int i = (long long int)(0); i < (long long int)(q); i++) {
    scanf(" ");
    scanf("%s", s);
    if (s[0] == 'a') {
      scanf("%lld", &x);
      consulta.push_back(make_pair(1, x));
      valores.push_back(x);
    } else if (s[0] == 'd') {
      scanf("%lld", &x);
      consulta.push_back(make_pair(2, x));
      valores.push_back(x);
    } else if (s[0] == 's') {
      consulta.push_back(make_pair(0, x));
    }
  }
  long long int tam = proceso();
  st tree;
  tree.ini(tam);
  tree.solve();
  return 0;
}