#include<bits/stdc++.h>
using namespace std;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
priority_queue<pair<int,int> > q1;
inline int read(){
int x=0,m=1;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') m=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+ch-48;
ch=getchar();
}
return x*m;
}
inline void write(int x){
if(x < 0){
putchar('-');
write(-x);
return;
}
if(x>=10) write(x/10);
putchar(x%10+'0');
}
inline void writesp(int x){
write(x);
putchar(' ');
}
inline void writeln(int x){
write(x);
putchar('\n');
}
int w,c,n;
map<int,int> Map;
signed main(){
cin>>n;
while (n!=-1){
if (n==1){
cin>>w>>c;
if (Map[c]==0){
Map[c]=1;
q.push(make_pair(c,w));
q1.push(make_pair(c,w));
}
}
if (n==2){
while (!q1.empty()&&Map[q1.top().first]==0) q1.pop();
if (!q1.empty()){
Map[q1.top().first]=0;
q1.pop(); }
}
if (n==3){
while (!q.empty()&&Map[q.top().first]==0) q.pop();
if (!q.empty()){
Map[q.top().first]=0;
q.pop(); }
}
cin>>n;
}
int sum=0,sum1=0;
while (!q1.empty()){
if (Map[q1.top().first]==1){
sum1+=q1.top().first;
sum+=q1.top().second;
}
q1.pop();
}
cout<<sum<<" "<<sum1;
}