#include <bits/stdc++.h>
struct cavlnode {
  struct cavlnode *left, *right;
  int val;
  int a[5];
  int height;
  int size;
  cavlnode(int val) : left(NULL), right(NULL), val(val), height(1), size(1) {
    for (int i = 0; i < 5; i++) {
      a[i] = 0;
    }
    a[0] = val;
  }
  static int getheight(struct cavlnode* node) {
    return node ? node->height : 0;
  }
  static int getsize(struct cavlnode* node) { return node ? node->size : 0; }
  static int getbal(struct cavlnode* node) {
    return node ? (getheight(node->left) - getheight(node->right)) : 0;
  }
  static int geta(struct cavlnode* node, int index) {
    return node ? node->a[index % 5] : 0;
  }
  static void recalc(struct cavlnode* node) {
    if (node) {
      node->height =
          std::max(getheight(node->left), getheight(node->right)) + 1;
      node->size = getsize(node->left) + getsize(node->right) + 1;
      for (int i = 0; i < 5; i++) {
        node->a[i] = geta(node->left, i);
      }
      for (int i = 0; i < 5; i++) {
        node->a[(i + 1 + getsize(node->left)) % 5] += geta(node->right, i);
      }
      node->a[getsize(node->left) % 5] += node->val;
    }
  }
  static struct cavlnode* rotateleft(struct cavlnode* node) {
    struct cavlnode *p = node, *q = node->right, *r = node->right->left;
    q->left = p;
    p->right = r;
    recalc(p);
    recalc(q);
    return q;
  }
  static struct cavlnode* rotateright(struct cavlnode* node) {
    struct cavlnode *p = node, *q = node->left, *r = node->left->right;
    q->right = p;
    p->left = r;
    recalc(p);
    recalc(q);
    return q;
  }
  static struct cavlnode* rebalance(struct cavlnode* node) {
    recalc(node);
    int bal = getbal(node);
    if (bal < -1) {
      if (getbal(node->right) > 0) {
        node->right = rotateright(node->right);
      }
      node = rotateleft(node);
    } else if (bal > 1) {
      if (getbal(node->left) < 0) {
        node->left = rotateleft(node->left);
      }
      node = rotateright(node);
    }
    return node;
  }
  static struct cavlnode* insert(struct cavlnode* node, int v) {
    if (node == NULL) {
      return new cavlnode(v);
    }
    if (v < node->val) {
      node->left = insert(node->left, v);
      return rebalance(node);
    } else if (v > node->val) {
      node->right = insert(node->right, v);
      return rebalance(node);
    } else {
      return node;
    }
  }
  static struct cavlnode* erase(struct cavlnode* node, int v) {
    if (node == NULL) {
      return node;
    }
    if (v < node->val) {
      node->left = erase(node->left, v);
      return rebalance(node);
    } else if (v > node->val) {
      node->right = erase(node->right, v);
      return rebalance(node);
    } else {
      if (node->left == NULL) {
        struct cavlnode* ret = node->right;
        delete node;
        return ret;
      } else if (node->right == NULL) {
        struct cavlnode* ret = node->left;
        delete node;
        return ret;
      }
      struct cavlnode* succ;
      for (succ = node->right; succ->left != NULL; succ = succ->left)
        ;
      node->val = succ->val;
      for (int i = 0; i < 5; i++) {
        node->a[i] = succ->a[i];
      }
      node = erase(node->right, succ->val);
      return rebalance(node);
    }
  }
  static int count(struct cavlnode* node, int v) {
    if (node == NULL) {
      return 0;
    }
    if (v < node->val) {
      return count(node->left, v);
    } else if (v > node->val) {
      return count(node->right, v);
    } else {
      return 1;
    }
  }
};
struct cavltree {
  struct cavlnode* root;
  cavltree() : root(NULL) {}
  void insert(int val) { root = cavlnode::insert(root, val); }
  void erase(int val) { root = cavlnode::erase(root, val); }
  bool count(int val) { return cavlnode::count(root, val); }
  int size() { return cavlnode::getsize(root); }
  int query() { return cavlnode::geta(root, 2); }
};
int main() {
  struct cavltree tree;
  int N;
  std::cin >> N;
  {
    std::string ign;
    std::getline(std::cin, ign);
  }
  for (int i = 0; i < N; i++) {
    std::string line;
    std::getline(std::cin, line);
    int val;
    if (sscanf(line.c_str(), "add %d", &val) >= 1) {
      tree.insert(val);
    } else if (sscanf(line.c_str(), "del %d", &val) >= 1) {
      tree.erase(val);
    } else if (sscanf(line.c_str(), "sum") >= 0) {
      std::cout << tree.query() << std::endl;
    } else {
      std::cerr << "Bad input" << std::endl;
    }
  }
  return 0;
}
