#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int n, x, now;   long long ans;   char a[3];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       if (a[0] ==  a ) {         cin >> x;         v.insert(lower_bound(v.begin(), v.end(), x), x);       }       if (a[0] ==  d ) {         cin >> x;         v.erase(lower_bound(v.begin(), v.end(), x));       }       if (a[0] ==  s ) {         ans = 0;         for (int i = 2; i < v.size(); i += 5) ans += v[i];         cout << ans << endl;       }     }     return 0;   }   