local mmi, mma = math.min, math.max
local mab = math.abs
local mfl, mce = math.floor, math.ceil
local bls, brs = bit.lshift, bit.rshift
local bxor = bit.bxor

local n = io.read("*n")
local x, y, p = {}, {}, {}
local flag = {}
for i = 1, n do
  x[i], y[i], p[i] = io.read("*n", "*n", "*n")
end

local function grayCode(x)
  return bxor(x, brs(x, 1))
end

local function getmincosts(ik, pos, val, idx_pos, idx_val)
  local retary = {}
  for i = 1, ik + 1 do retary[i] = 0 end
  for i = 1, #pos do flag[i] = false end
  local targetpos = {}
  for linecnt = 0, ik do
    if #pos <= linecnt then
      break
    end
    if 0 < linecnt then
      flag[idx_val[linecnt]] = true
      table.insert(targetpos, pos[idx_val[linecnt]])
    end
    local retval = 0
    for i = 1, #idx_pos do
      local idx_i = idx_pos[i]
      if not flag[idx_i] then
        local p = pos[idx_i]
        local cand = mab(p)
        for j = 1, #targetpos do
          cand = mmi(cand, mab(targetpos[j] - p))
        end
        retval = retval + cand * val[idx_i]
      end
    end
    retary[linecnt + 1] = retval
  end
  return retary
end

local retik = {}

local xs, ys = {}, {}
local function add_func(idx)
  local xv = x[idx]
  local yv = y[idx]
  xs[xv] = xs[xv] - p[idx]
  if xs[xv] == 0 then xs[xv] = nil end
  if not ys[yv] then
    ys[yv] = p[idx]
  else
    ys[yv] = ys[yv] + p[idx]
  end
end
local function rm_func(idx)
  local xv = x[idx]
  local yv = y[idx]
  ys[yv] = ys[yv] - p[idx]
  if ys[yv] == 0 then ys[yv] = nil end
  if not xs[xv] then
    xs[xv] = p[idx]
  else
    xs[xv] = xs[xv] + p[idx]
  end
end
local function work_func()
  local cand = 0
  local xpos, xval, xidx_pos, xidx_val = {}, {}, {}, {}
  for k, v in pairs(xs) do
    table.insert(xpos, k)
    table.insert(xval, v)
  end
  for i = 1, #xpos do xidx_pos[i], xidx_val[i] = i, i end
  table.sort(xidx_pos, function(a, b) return xpos[a] < xpos[b] end)
  table.sort(xidx_val, function(a, b) return xval[a] > xval[b] end)

  local ypos, yval, yidx_pos, yidx_val = {}, {}, {}, {}
  for k, v in pairs(ys) do
    table.insert(ypos, k)
    table.insert(yval, v)
  end
  for i = 1, #ypos do yidx_pos[i], yidx_val[i] = i, i end
  table.sort(yidx_pos, function(a, b) return ypos[a] < ypos[b] end)
  table.sort(yidx_val, function(a, b) return yval[a] > yval[b] end)

  local xcosts = getmincosts(n - 1, xpos, xval, xidx_pos, xidx_val)
  local ycosts = getmincosts(n - 1, ypos, yval, yidx_pos, yidx_val)
  for ik = 0, n - 1 do
    cand = xcosts[0 + 1] + ycosts[ik + 1]
    for i = 1, ik do
      cand = mmi(cand, xcosts[i + 1] + ycosts[ik - i + 1])
    end
    if not retik[ik + 1] then
      retik[ik + 1] = cand
    elseif cand < retik[ik + 1] then
      retik[ik + 1] = cand
    end
  end
end

local function grayWalk(size, add_func, rm_func, work_func)
  local prv = 0
  local total = bls(1, size) - 1
  local bpos = {}
  for i = 1, size do
    bpos[bls(1, i - 1)] = i
  end
  work_func()
  for i = 1, total do
    local v = grayCode(i)
    if prv < v then
      prv, v = v, v - prv
      add_func(bpos[v])
    else
      prv, v = v, prv - v
      rm_func(bpos[v])
    end
    work_func()
  end
end

for j = 1, n do
  local xj = x[j]
  if not xs[xj] then
    xs[xj] = p[j]
  else
    xs[xj] = xs[xj] + p[j]
  end
end
for ik = 0, n do
  retik[ik + 1] = false
end

grayWalk(n, add_func, rm_func, work_func)
retik[n + 1] = 0
print(table.concat(retik, "\n"))
-- print(os.clock())
