
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 n memo {tl; tr; sl; sr; b} =
  match memo with
  | Some (x, sum) -> (x, sum)
  | None -> begin
    let x, _ = S.max_elt tl in
    let _, _ = S.min_elt tr in
    let sum = (n mod 2) * x - sl + sr + b in
    (x, sum)
  end

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

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