
module Map_int = Map.Make(struct
  type t = int
  let compare = (-)
end)
module M = Map_int

let add1 k m =
  let v = 1 + (try M.find k m with _ -> 0) in
  M.add k v m

let sub1 k m =
  let v = try M.find k m - 1 with _ -> 0 in
  if v = 0 then M.remove k m else M.add k v m

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: int Map_int.t; tr: int Map_int.t; sl: int; sr: int; b: int }

let update {tl; tr; sl; sr; b=tb} n a b =
  let (kl, vl), (kr, vr) = M.max_binding tl, M.min_binding tr in
  let tl, km, tr, sl, sr =
    if a <= kl then
      let tl' = sub1 kl tl in
      (add1 a tl', kl, tr, sl-kl+a, sr)
    else if a <= kr then
      (tl, a, tr, sl, sr)
    else
      let tr' = sub1 kr tr in
      (tl, kr, add1 a tr', sl, sr-kr+a)
  in
  if n mod 2 = 1 then
    {tl; tr = add1 km tr; sl = sl; sr = sr+km; b = tb+b}
  else
    {tl = add1 km tl; tr; sl = sl+km; sr; b = tb+b}

let calc n {tl; tr; sl; sr; b} =
  let x, _ = M.max_binding tl in
  let _, _ = M.min_binding tr in
  let sum = (n mod 2) * x - sl + sr + b in
  (x, sum)

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

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