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;
class IO {
  static const int bufSize = 1 << 18;
  char inBuf[bufSize], outBuf[bufSize];
  char *ip1 = inBuf, *ip2 = inBuf;
  int goodReadBit = 0, op1 = -1, op2 = bufSize - 1;
  template <typename T>
  __inline__ __attribute__((always_inline)) void __RI(T& x) {
    int ch = gc(), neg = 1;
    x = 0;
    for (; !(isdigit(ch) || ch == '-' || ch == EOF); ch = gc())
      ;
    if (ch == EOF) {
      goodReadBit = 0;
      return;
    }
    if (ch == '-') neg = -1, ch = gc();
    for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - 48) * neg;
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) void __RC(T& x) {
    unsigned char ch;
    while (isspace(ch = gc()))
      ;
    x = ch;
  }
  __inline__ __attribute__((always_inline)) void __RS(string& x) {
    char ch;
    x.clear();
    for (ch = gc(); isspace(ch); ch = gc())
      ;
    if (ch == EOF) {
      goodReadBit = 0;
      return;
    }
    for (; !isspace(ch); ch = gc()) x.push_back(ch);
  }

 public:
  __inline__ __attribute__((always_inline)) int gc() {
    return ip1 == ip2 && (ip2 = (ip1 = inBuf) + fread(inBuf, 1, bufSize, stdin),
                          ip1 == ip2)
               ? EOF
               : *ip1++;
  }
  __inline__ __attribute__((always_inline)) IO& R(char& x) {
    __RC(x);
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& R(unsigned char& x) {
    __RC(x);
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& R(string& x) {
    __RS(x);
    return (*this);
  }
  template <typename T1, typename T2>
  __inline__ __attribute__((always_inline)) IO& R(pair<T1, T2>& x) {
    R(x.first), R(x.second);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& R(vector<T>& x) {
    for (auto& i : x) R(i);
    return (*this);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) IO& RA(T* a, int n) {
    for (int i = 0; i < n; ++i) R(a[i]);
    return (*this);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) IO& R(T& x, Args&... args) {
    R(x), R(args...);
    return (*this);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) IO& RA(T* a, int n, Args... args) {
    for (int i = 0; i < n; ++i) RA(a[i], args...);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& R(T& x) {
    static_assert(is_integral<T>::value, "Unsupported types");
    if (is_integral<T>::value) __RI(x);
    return (*this);
  }

 private:
  char space = ' ';
  template <typename T>
  __inline__ __attribute__((always_inline)) void __WI(T x) {
    static char buf[64];
    static int len = -1;
    if (x >= 0) {
      do {
        buf[++len] = x % 10 + 48, x /= 10;
      } while (x);
    } else {
      pc('-');
      do {
        buf[++len] = -(x % 10) + 48, x /= 10;
      } while (x);
    }
    while (len >= 0) {
      pc(buf[len]), --len;
    }
  }

 public:
  __inline__ __attribute__((always_inline)) void pc(const char& x) {
    if (op1 == op2) flush();
    outBuf[++op1] = x;
  }
  __inline__ __attribute__((always_inline)) void flush() {
    fwrite(outBuf, 1, op1 + 1, stdout), op1 = -1;
  }
  __inline__ __attribute__((always_inline)) IO& W(const char& x) {
    pc(x);
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& W(const char* x) {
    while (*x != '\0') pc(*(x++));
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& W(const string& x) {
    W(x.c_str());
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& W(const vector<T>& x) {
    for (auto& i : x) WS(i);
    WL();
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& WL() {
    W('\n');
    return (*this);
  }
  template <typename T1, typename T2>
  __inline__ __attribute__((always_inline)) IO& W(pair<T1, T2>& x) {
    WS(x.first), W(x.second);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& WL(const T& x) {
    W(x), W('\n');
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& WS() {
    W(' ');
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& WS(const T& x) {
    W(x), W(space);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& WA(T* a, int n) {
    for (int i = 0; i < n; i++) WS(a[i]);
    WL();
    return (*this);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) IO& W(const T& x,
                                                  const Args&... args) {
    W(x), W(space), W(args...);
    return (*this);
  }
  template <typename... Args>
  __inline__ __attribute__((always_inline)) IO& WL(const Args&... args) {
    W(args...), W('\n');
    return (*this);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) IO& WA(T* a, int n, Args... args) {
    for (int i = 0; i < n; i++) WA(a[i], args...);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& W(const T& x) {
    static_assert(is_integral<T>::value, "Unsupported types");
    if (is_integral<T>::value) __WI(x);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& operator>>(T& x) {
    R(x);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& operator<<(const T& x) {
    W(x);
    return (*this);
  }
  IO() {}
} io;
void EXIT(int code) { io.flush(), exit(code); }
const int8_t INFC = 0x3f;
const int16_t INFS = 0x3f3f;
const int32_t INF = 0x3f3f3f3f;
const int64_t INFL = 0x3f3f3f3f3f3f3f3fLL;
vector<pair<string, int> > ops;
map<int, int> fmap, rmap;
struct SegmentTree {
  struct Node {
    int64_t sum[5];
    int cnt = 0;
  };
  static const int MAXN = 1 << 20;
  Node data[MAXN];
  int N;
  void init(int n) {
    N = 1;
    while (N < n) N <<= 1;
  }
  void add(int x) {
    int k = x + N - 1;
    data[k].cnt = 1;
    data[k].sum[0] = rmap[x];
    while (k) {
      k = (k - 1) >> 1;
      data[k].cnt = data[(k << 1) + 1].cnt + data[(k << 1) + 2].cnt;
      for (int i = 0; i < 5; i++)
        data[k].sum[i] =
            data[(k << 1) + 1].sum[i] +
            data[(k << 1) + 2].sum[(i - data[(k << 1) + 1].cnt % 5 + 5) % 5];
    }
  }
  void del(int x) {
    int k = x + N - 1;
    data[k].cnt = 0;
    data[k].sum[0] = 0;
    while (k) {
      k = (k - 1) / 2;
      data[k].cnt = data[(k << 1) + 1].cnt + data[(k << 1) + 2].cnt;
      for (int i = 0; i < 5; i++)
        data[k].sum[i] =
            data[(k << 1) + 1].sum[i] +
            data[(k << 1) + 2].sum[(i - data[(k << 1) + 1].cnt % 5 + 5) % 5];
    }
  }
} segmentTree;
int main() {
  int q;
  io >> q;
  ops.resize(q);
  for (auto& [k, v] : ops) {
    io >> k;
    if (k[0] != 's') io >> v, fmap[v] = 1;
  }
  segmentTree.init(fmap.size());
  int key = 0;
  for (auto& [k, v] : fmap) key++, v = key, rmap[key] = k;
  for (auto& [k, v] : ops)
    if (k[0] != 's') v = fmap[v];
  for (auto [k, v] : ops) {
    if (k[0] == 's')
      io.WL(segmentTree.data[0].sum[2]);
    else if (k[0] == 'a')
      segmentTree.add(v);
    else if (k[0] == 'd')
      segmentTree.del(v);
  }
  EXIT(0);
}