import java.util.Scanner;
import java.util.TreeSet;


public class SumOfMedians {
    
    TreeSet<Integer> data = new TreeSet<Integer>();
    
    public int sum(){
        int s = 0;
        int counter = 1;
            for(int i : data) if( counter++%5==3 ) s+=i;
        
        return s;
    }
    
    
    public void run(){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        for(int i = 1 ; i<=n; i++){
            String op = sc.next();
            
            if( op.equals("sum")) System.out.println(sum());
            else if(op.equals("add")) data.add(sc.nextInt());
            else data.remove(sc.nextInt());
        }
        
        
    }
    
    
    public static void main(String args[]){
        new SumOfMedians().run();
    }
    
}
