require 'set'

q = gets.to_i

c = 0
p = 0
m = nil
l = SortedSet.new
r = SortedSet.new
ls = 0
rs = 0

q.times do |i|
  case query = gets.split.map(&:to_i)
  when [2]
    if c.odd?
      puts "#{m.first} #{p + rs - ls}"
    else
      puts "#{l.to_a.last.first} #{p + rs - ls}"
    end
  else
    c += 1
    _, a, b = query
    p += b
    if c == 1
      m = [a, i]
      next
    elsif c == 2
      if m.first < a
        l << m
        ls += m.first
        r << [a, i]
        rs += a
      else
        l << [a, i]
        ls += a
        r << m
        rs += m.first
      end
      next
    end
    lmax = l.to_a.last.first
    rmin = r.to_a.first.first
    if lmax > a
      l << [a, i]
      ls += a
      if c.odd?
        l.delete_if {|(v, _)| v == lmax }
        ls -= lmax
        m = [lmax, i]
      else
        r << m
        rs += m.first
      end
    elsif rmin < a
      r << [a, i]
      rs += a
      if c.odd?
        r.delete_if {|(v, _)| v == rmin }
        rs -= rmin
        m = [rmin, i]
      else
        l << m
        ls += m.first
      end
    else
      if c.odd?
        m = [a, i]
      else
        if l.size < r.size
          l << [a, i]
          ls += a
        else
          r << [a, i]
          rs += a
        end
      end
    end
  end
end
