#include <bits/stdc++.h>
using namespace std;
string a;
int L[407], F[407];
int Left[100007], Right[100007], war[100007];
int sum[407][7];
int amount[407];
void przesun2(int a) {
  for (int i = a + 1; i <= 400; i++) {
    if (amount[i] < 300) {
      if (amount[i] == 1) {
        amount[i] == 0;
        sum[i][1] = 0;
        return;
      } else {
        amount[i]--;
        sum[i][1] = sum[i][2];
        sum[i][2] = sum[i][3];
        sum[i][3] = sum[i][4];
        sum[i][4] = sum[i][0];
        sum[i][0] = sum[i][1] - war[F[i]];
        F[i] = Right[F[i]];
        return;
      }
    } else {
      if (amount[i + 1] > 0) {
        sum[i][1] = sum[i][2];
        sum[i][2] = sum[i][3];
        sum[i][3] = sum[i][4];
        sum[i][4] = sum[i][0];
        sum[i][0] = sum[i][1] - war[F[i]] + war[F[i + 1]];
        F[i] = Right[F[i]];
        L[i] = F[i + 1];
      } else {
        amount[i]--;
        sum[i][1] = sum[i][2];
        sum[i][2] = sum[i][3];
        sum[i][3] = sum[i][4];
        sum[i][4] = sum[i][0];
        sum[i][0] = sum[i][1] - war[F[i]];
        F[i] = Right[F[i]];
        return;
      }
    }
  }
}
void licz(int a) {
  int b = F[a];
  sum[a][0] = 0;
  sum[a][1] = 0;
  sum[a][2] = 0;
  sum[a][3] = 0;
  sum[a][4] = 0;
  for (int i = 1; i <= 10; i++) {
    if (b == 0) return;
    sum[a][i % 5] += war[b];
    b = Right[b];
  }
  return;
}
void zabierz(int x) {
  for (int i = 1; i <= 400; i++) {
    if (L[i] >= x) {
      int b = F[i];
      for (int a = 1; a <= 300; a++) {
        if (war[b] == x) {
          if (a == 1) {
            F[i] = Right[F[i]];
          }
          if (amount[i + 1] > 0) {
            L[i] = F[i + 1];
          }
          Left[Right[b]] = Left[b];
          Right[Left[b]] = Right[b];
          przesun2(i);
          licz(i);
        }
        b = Right[b];
      }
      return;
    }
  }
  return;
}
long long sumuj() {
  long long odp = 0;
  for (int i = 1; i <= 400; i++) {
    odp += sum[i][3];
  }
  return odp;
}
void przesun(int a) {
  int b = L[a];
  for (int i = a + 1; i <= 400; i++) {
    if (amount[i] < 300) {
      amount[i]++;
      F[i] = b;
      sum[i][0] = sum[i][4] + war[b];
      sum[i][1] = sum[i][0];
      sum[i][2] = sum[i][1];
      sum[i][3] = sum[i][2];
      sum[i][4] = sum[i][3];
      return;
    }
    sum[i][0] = sum[i][4] + war[b] - war[L[i]];
    sum[i][1] = sum[i][0];
    sum[i][2] = sum[i][1];
    sum[i][3] = sum[i][2];
    sum[i][4] = sum[i][3];
    F[i] = b;
    L[i] = Left[L[i]];
    b = Right[L[i]];
  }
}
void dodaj(int c, int x) {
  for (int i = 1; i < 400; i++) {
    if (amount[i] == 0) {
      L[i] = c;
      F[i] = c;
      sum[i][1] = x;
      amount[i]++;
      if (i > 1) {
        Right[L[i - 1]] = c;
        Left[c] = L[i - 1];
      }
      return;
    } else {
      if (x < war[L[i]]) {
        amount[i]++;
        int cur = F[i];
        for (int a = 1; a <= 300; a++) {
          if (war[cur] > x) {
            if (a == 1) {
              F[i] = c;
            }
            Right[Left[cur]] = c;
            Right[c] = cur;
            Left[c] = Left[cur];
            Left[cur] = c;
            if (amount[i] > 300) {
              amount[i]--;
              przesun(i);
              L[i] = Left[L[i]];
            }
            licz(i);
            return;
          }
          cur = Right[cur];
        }
        return;
      } else {
        if (amount[i] < 300) {
          Left[c] = L[i];
          Right[L[i]] = c;
          L[i] = c;
          amount[i]++;
          sum[i][amount[i] % 5] += x;
          return;
        }
      }
    }
  }
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie();
  int n, x;
  int licznik = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    war[0] = 0;
    cin >> a;
    if (a == "add") {
      cin >> x;
      licznik++;
      war[licznik] = x;
      dodaj(licznik, x);
    } else if (a == "del") {
      cin >> x;
      zabierz(x);
    } else {
      cout << sumuj();
    }
  }
  return 0;
}
