require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
x = []
y = []
q = []
n.times do
  a,b,c = gets.chomp.split.map(&:to_i)
  x.push a
  y.push b
  q.push c
end

@tate = Array.new(n+1){Array.new}
@yoko = Array.new(n+1){Array.new}

2.times do |set_count|
  is_yoko = set_count == 0
  [false, true].repeated_permutation(n) do |bits|
    candidates = []
    n.times do |i|
      if bits[i]
        candidates.push is_yoko ? y[i] : x[i]
      end
    end

    ar = Array.new(n)
    n.times do |i|
      if bits[i]
        ar[i] = 0
      else
        if candidates.empty?
          min = INF
        else
          if is_yoko
            ate = y[i]
          else
            ate = x[i]
          end
          index = candidates.bsearch_index{|x| x >= ate}
          if index.nil?
            min = (candidates.last - ate).abs
          elsif index == 0
            min = (candidates.first - ate).abs
          else
            min = [(candidates[index] - ate).abs, (candidates[index-1] - ate).abs].min
          end
        end

        # min = INF
        # candidates.each do |can|
        #   if is_yoko
        #     min = [min, (can - y[i]).abs].min
        #   else
        #     min = [min, (can - x[i]).abs].min
        #   end
        # end

        if is_yoko
          ar[i] = [min, x[i].abs].min * q[i]
        else
          ar[i] = [min, y[i].abs].min * q[i]
        end
      end
    end
    bit_count = bits.count{|e| e}
    if is_yoko
      @yoko[bit_count].push ar
    else
      @tate[bit_count].push ar
    end
  end
end

@yoko.each_with_index do |yoko, i|
  # p ['yoko', i, yoko]
end
@tate.each_with_index do |yoko, i|
  # p ['tate', i, yoko]
end

# メインループ
n.times do |k|
# [1].each do |k|
  ans = INF
  (k+1).times do |i|
    yoko_num = i
    tate_num = k - i

    @yoko[yoko_num].each do |yoko|
      @tate[tate_num].each do |tate|
        cost = 0
        n.times do |j|
          cost += [yoko[j], tate[j]].min
        end
        ans = [ans, cost].min
      end
    end
    # p [k, cost]
  end
  puts ans
end
puts 0
