n = gets.to_i
m = 2**n
x, y, q = (1..n).map { gets.split.map &:to_i }.transpose
cost = [0] + (1...m).map { |i|
	[x.uniq.map { |lx| (0...n).sum { |j| q[j] * (lx - x[j]).abs * i[j] } }.min,
	 y.uniq.map { |ly| (0...n).sum { |j| q[j] * (ly - y[j]).abs * i[j] } }.min].min
}
dp = (0...m).map { |i|
	(0...n).sum { |j| q[j] * [x[j].abs, y[j].abs].min * i[j] }
}
puts dp[-1]
n.times {
	dp = (0...m).map { |bit|
		sub, x = bit, 10**18
		loop {
			y = dp[bit & ~sub] + cost[sub]
			x = y if x > y
			sub = (sub - 1) & bit
			break if sub == bit
		}
		x
	}
	puts dp[-1]
}
