
module Set_ii = Set.Make(struct
  type t = int * int
  let compare (a, b) (d, e) =
    if a <> d then a-d else b-e
end)
module S = Set_ii

type state = { tl: Set_ii.t; tr: Set_ii.t; sl: int; sr: int; b: int }

let update {tl; tr; sl; sr; b=tb} n a b =
  let (vl, _ as el), (vr, _ as er) = S.max_elt tl, S.min_elt tr in
  let tl, ((vm, _) as m), tr, sl, sr =
    if a <= vl then
      let tl' = S.remove el tl in
      (S.add (a, n) tl', el, tr, sl-vl+a, sr)
    else if a <= vr then
      (tl, (a, n), tr, sl, sr)
    else
      let tr' = S.remove er tr in
      (tl, er, S.add (a, n) tr', sl, sr-vr+a)
  in
  if S.cardinal tl > S.cardinal tr then
    {tl; tr = S.add m tr; sl = sl; sr = sr+vm; b = tb+b}
  else
    {tl = S.add m tl; tr; sl = sl+vm; sr; b = tb+b}

let calc {tl; tr; sl; sr; b} =
  let x, _ = S.max_elt tl in
  let _, _ = S.min_elt tr in
  let sum = (S.cardinal tl - S.cardinal tr) * x - sl + sr + b in
  (x, sum)

let rec loop n st =
  if n = 0 then ()
  else Scanf.scanf " %d" @@ function
  | 1 -> Scanf.scanf " %d %d" (update st n) |> loop (n-1)
  | _ -> begin
      let x, fx = calc st in Printf.printf "%d %d\n" x fx;
      loop (n-1) st
    end

let inf = 1000000000000
let _ = Scanf.scanf "%d" @@ fun q -> loop q {
  tl = S.singleton (-inf, -inf) ; tr = S.singleton (inf, inf);
  sl = 0; sr = 0; b = 0
}
