class MaxHeap
  def initialize(&block)
    @array = []
    @score = block
  end

  def insert(key)
    @array.push(key)

    # sifting up
    index = @array.size - 1
    until index == 0
      pindex = (index - 1) / 2
      if (@score.(@array[index]) <=> @score.(@array[pindex])) <= 0
        break
      else
        @array[pindex], @array[index] = @array[index], @array[pindex]
        index = pindex
      end
    end
  end

  alias push insert

  def peek
    if @array.empty?
      fail 'empty'
    end

    @array[0]
  end

  def size
    @array.size
  end

  def empty?
    @array.empty?
  end

  def pop
    if @array.empty?
      fail 'empty'
    end

    top = @array[0]
    last = @array.pop
    if @array.empty?
      return top
    end

    @array[0] = last
    i = 0
    # sifting down
    while true
      break unless i*2 + 1 < @array.size

      if i*2 + 2 < @array.size &&
         (@score.(@array[i*2 + 1]) <=> @score.(@array[i*2 + 2])) <= 0
        if (@score.(@array[i*2 + 2]) <=> @score.(@array[i])) <= 0
          break
        else
          @array[i], @array[i*2 + 2] = @array[i*2 + 2], @array[i]
          i = i*2 + 2
        end
      else
        fail "logic error" unless i*2 + 1 < @array.size
        if (@score.(@array[i*2 + 1]) <=> @score.(@array[i])) <= 0
          break
        else
          @array[i], @array[i*2 + 1] = @array[i*2 + 1], @array[i]
          i = i*2 + 1
        end
      end
    end

    return top
  end
end

q = gets.to_i
queries = q.times.map { gets.split.map(&:to_i) }

ql = MaxHeap.new { |v| v }
qr = MaxHeap.new { |v| -v }
minimum = 0

queries.each do |type, a, b|
  case type
  when 1
    left = ql.size == 0 ? -Float::INFINITY : ql.peek
    right = qr.size == 0 ? Float::INFINITY : qr.peek

    if ql.size < qr.size
      ql.push(a)
      ql.push(a)
    elsif ql.size > qr.size
      qr.push(a)
      qr.push(a)
    else
      ql.push(a)
      qr.push(a)
    end

    if a.between?(left, right)
    else
      minimum += [left - a, right - a].map(&:abs).min
    end

    minimum += b
  when 2
    x = ql.peek
    puts "#{x} #{minimum}"
  end
end
