rt,RE20pts
#include <bits/stdc++.h>
using u64 = long long;
using namespace std;
const int N = 1e5 + 10;
set<u64> s;
u64 cost[N];
u64 t, w, c, wst = 0, ans = 0;
int main()
{
while(true)
{
scanf("%lld", &t);
if(t == 1)
{
scanf("%lld%lld", &w, &c);
if(s.count(c)) continue;
s.insert(c);
cost[c] = w;
}
if(t == 2) if(s.size() != 0) s.erase(--s.end());
if(t == 3) if(s.size() != 0) s.erase(s.begin());
if(t == -1) break;
}
set<u64>::iterator it;
for(it = s.begin(); it != s.end(); it++)
{
ans += cost[*it];
wst += *it;
}
printf("%lld %lld", ans, wst);
return 0;
}