// In The Name Of God :
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std ;
using namespace __gnu_pbds;
#define time fhnstkgnxdkj
#define X first 
#define Y second
#define int long long 
typedef long long ll ;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef pair < int , int > pii ; 
typedef pair < pii , int > pii_i ;
typedef pair < pii , pii > pii_ii ;
#define ordered_set(TYPE) tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update>
//#define "%I64d" "%I64d"
const int maxL = 21 ;
const int inf = 1e9+100 ;
typedef long long ll ;
ll mod = 1e9 + 7 ;
//const int inf = 1e13 ;
typedef long double ld ;
const int maxn = 1e5 +10 ;
int n ;
set < int > st [ maxn ] ; 
int get_sum [ maxn ] [ 5 ]; 
const int baze = 333 ; 
int size ;


void relax ( )
{
  vector < int > hlp ;
  for ( int i = 0 ; i < size ; i ++ )
    for ( auto it = st [ i ] . begin ( ) ; it != st [ i ] . end ( ) ; ++it )
      hlp . push_back ( *it ) ;
  int pos = 0;
  for ( int i =0  ; i < (long)hlp  .size ( ) ; i ++)
    {
      if ( (i+1)%baze == 0 )
	pos ++ ;    
      st [ pos ] . insert ( hlp [ i ] ) ;
    }
  size = pos + 1 ;
  if ( st [ pos ] . size ( ) == 0 )
    size -- ;
  for ( int i= 0 ; i < size ; i ++)
    {
      get_sum [ i ] [ 0 ] = get_sum [ i ] [ 1 ] = get_sum [ i ] [ 2 ] = get_sum [ i ] [ 3 ] = get_sum [ i ] [ 4 ] = 0 ;
      int cnt = 0 ;
      for ( auto it = st [ i ] . begin ( ) ; it != st [ i ] . end ( ) ; ++it )
	{
	  get_sum [ i ] [ cnt ] += *it ;
	  cnt ++ ;
	  cnt %= 5 ;
	}
    } 
}

void print  ()
{
  cout << "\n*******************************\n" ;
  cout << size << endl ;
  for ( int i = 0 ; i< size ; i ++ )
    {
      for ( auto it = st [ i ] . begin ( ) ; it != st [ i ] . end ( ) ; ++it )
	cout << *it << ' ' ;
      cout << endl ;
    } 
  for ( int i = 0 ; i< size ; i ++ )
    for (int j = 0 ; j < 5 ;  j ++ )
      cout << get_sum [ i ][ j ] << (j==4?'\n':' ') ;
}
   

int32_t main ( )
{
  fast ;
  cin >> n ;
  string s ;
  int x ;
  for ( int i = 0 ; i < n ; i ++ )
    {
      if ( (n+1) % 1000 )
	relax ( ) ;
      cin >> s;
      if ( s == "add" )
	{
	  cin >> x ;
	  bool flag = 0 ;
	  for ( int i = 0 ; i < size ; i ++ )
	    if ( st[i].size() && ( *st[i].rbegin() > x) )
	      {
		st [ i ] . insert ( x ) ;
		get_sum [ i ] [ 0 ] = get_sum [ i ] [ 1 ] = get_sum [ i ] [ 2 ] = get_sum [ i ] [ 3 ] = get_sum [ i ] [ 4 ] = 0 ;
		int cnt = 0;
		for ( auto it = st [ i ] . begin ( ) ; it != st [ i ] . end ( ) ; ++it )
		  {
		    get_sum [ i ] [ cnt ] += *it ;
		    cnt ++ ;
		    cnt %= 5 ;
		  }
		flag = 1 ;
		break ;
	      }
	  if ( !flag )
	    st [ size ] . insert ( x ) ,
	      get_sum [size][0] = get_sum [ size ] [ 1 ] = get_sum [ size ] [ 2 ] = get_sum [ size ] [ 3 ] = get_sum [ size ] [ 4 ] = 0 ,
	      get_sum [ size ] [ 0 ] = x , size++ ;
	}
      else if ( s == "del" )
	{
	  cin >> x ;
	  for ( int i = 0 ; i < size ; i ++ )
	    if ( (st[i].size()) && (*st[i].rbegin()>= x) )
	      {
		st [ i ] . erase ( x ) ;
		get_sum [ i ] [ 0 ] = get_sum [ i ] [ 1 ] = get_sum [ i ] [ 2 ] = get_sum [ i ] [ 3 ] = get_sum [ i ] [ 4 ] = 0 ;
		int cnt = 0;
		for ( auto it = st [ i ] . begin ( ) ; it != st [ i ] . end ( ) ; ++it )
		  get_sum [ i ] [ cnt ] += *it , cnt = (cnt+1)%5 ;
		break ;
	      }
	  while ( size && (!st[size-1].size()) )
	    size -- ;
	}
      else
	{
	  int pos = 2 , ans = 0;;
	  for ( int i = 0 ; i < size ; i ++)
	    ans += get_sum [ i ] [ pos ] ,
	      pos = (5-pos+st [ i ] . size ( ))%5 , pos = 5 - pos , pos %= 5 ; 
	  cout << ans << endl ;
	}
    } 
} 
