import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	int q = read.to!int;

	auto xh = new RedBlackTree!(long, "a>b", true);
	auto yh = new RedBlackTree!(long, "a<b", true);
	long z;
	bool hasZ;
	long xsum, ysum;
	long bsum;
	
	foreach(_; 0 .. q){
		
		print!1("0 xh:", xh[], " xsum:", xsum, " z:", (hasZ? z: 999), " yh:", yh[], " ysum:", ysum, " bsum:", bsum);
		int t = read.to!int;
		if(t == 1){
			long a = read.to!long;
			long b = read.to!long;
			print!1("xh.length:", xh.length, " yh.length:", yh.length, " hasZ:", hasZ);
			print!1("1 xh:", xh[], " xsum:", xsum, " z:", (hasZ? z: 999), " yh:", yh[], " ysum:", ysum, " bsum:", bsum);
			if(hasZ){
				if(a < z){
					print!1("X odd");
					xh.insert(a), xsum += a;
					yh.insert(z), ysum += z;
					hasZ = 0;
				}
				else{
					print!1("Y odd");
					xh.insert(z), xsum += z;
					yh.insert(a), ysum += a;
					hasZ = 0;
				}
			}
			else{
				print!1("a:", a, " x:", xh.front, " y:", yh.front);
				if(! xh.empty && a < xh.front){
					print!1("X even");
					xh.insert(a), xsum += a;
					z = xh.front;
					xh.removeFront, xsum -= z;
					hasZ = 1;
				}
				else if(! yh.empty && a > yh.front){
					print!1("Y even");
					yh.insert(a), ysum += a;
					z = yh.front;
					yh.removeFront, ysum -= z;
					hasZ = 1;
				}
				else{
					print!1("Z even");
					z = a;
					hasZ = 1;
				}
			}
			bsum += b;
			print!1("2 xh:", xh[], " xsum:", xsum, " z:", (hasZ? z: 999), " yh:", yh[], " ysum:", ysum, " bsum:", bsum);
		}
		else{
			if(hasZ) writeln(z, " ", ysum - xsum + bsum);
			else writeln(xh.front, " ", ysum - xsum + bsum);
		}
		
		print!1("3 xh:", xh[], " xsum:", xsum, " z:", (hasZ? z: 999), " yh:", yh[], " ysum:", ysum, " bsum:", bsum);
	}
	
}

