#include <iostream>
#include <set>
#include <map>
using namespace std;
long long n, sum1, sum2;
set<pair<int, int> > s;
int main() {
ios :: sync_with_stdio(0), cin.tie(0);
int op, x, y;
while (cin >> op) {
if (op == -1) break;
if (op == 1) {
cin >> x >> y;
if ((*s.lower_bound({y, x})).first != y) {
s.insert(make_pair(y, x));
}
} else if (op == 2) {
if (!s.empty()) {
s.erase(prev(s.end()));
}
} else {
if (!s.empty()) {
s.erase(s.begin());
}
}
}
for ( auto i : s ) {
sum1 += i.first, sum2 += i.second;
}
cout << sum2 << " " << sum1;
return 0;
}