def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
def debug(k,v) puts "#{k}: #{v}" end
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a==-1 ? b : (a<=b ? a : b) end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

n = gi #15
xyps = Array.new(n){gsmi}
ans = Array.new(n+1){-1}

xss = Array.new(2**n) do |num|
  i = 0
  xls = [0]
  for j in (0...n)
    if (num>>j)&1==1
      i+=1
      xls << xyps[j][0]
    end
    break if num>>j==0
  end
  xyps.map do |x,y,p|
    min = 10000
    xls.each do |xl|
      min = min(min, (xl-x).abs)
    end
    min * p
  end
end

yss = Array.new(2**n) do |num|
  i = 0
  yls = [0]
  for j in (0...n)
    if (num>>j)&1==1
      i+=1
      yls << xyps[j][1]
    end
    break if num>>j==0
  end
  xyps.map do |x,y,p|
    min = 10000
    yls.each do |y1|
      min = min(min, (y1-y).abs)
    end
    min * p
  end
end

(3**n).times do |num|
  i = 0
  xls = [] # 2
  yls = []
  for j in (0...n)
    if (num/(3**j))%3==1
      xls << j
      i+=1
    elsif (num/(3**j))%3==2
      yls << j
      i+=1
    end
    break if (num/(3**j))==0
  end
  xi = xls.sum{|xl| 2**xl }
  yi = yls.sum{|yl| 2**yl }
  sum = n.times.to_a.sum do |j|
    min(xss[xi][j], yss[yi][j])
  end
  #p [num,i,xss[xi],yss[yi],sum]
  ans[i] = min(ans[i], sum)
end
puts ans
