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")
  flag[i] = false
end

local function grayCode(x)
  return bxor(x, brs(x, 1))
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

local function findright(idxes, ofst)
  for i = ofst, #idxes do
    if flag[idxes[i]] then
      return i
    end
  end
  return false
end

local function getmincost(t, linecnt)
  local pos, val, idx = {}, {}, {}
  for k, v in pairs(t) do
    table.insert(pos, k)
    table.insert(val, v)
  end
  if #pos <= linecnt then
    return 0
  end
  for i = 1, #pos do idx[i] = i end
  table.sort(idx, function(a, b) return val[a] > val[b] end)
  for i = 1, linecnt do
    flag[idx[i]] = true
  end
  for i = linecnt + 1, #pos do
    flag[idx[i]] = false
  end
  local retval = 0
  table.sort(idx, function(a, b) return pos[a] < pos[b] end)
  local leftpos = false
  local rightpos = findright(idx, 1)
  for i = 1, #idx do
    local idx_i = idx[i]
    if flag[idx_i] then
      leftpos = rightpos
      if rightpos then
        rightpos = findright(idx, rightpos + 1)
      end
    else
      local cand = mab(pos[idx_i])
      if leftpos then
        cand = mmi(cand, mab(pos[idx_i] - pos[idx[leftpos]]))
      end
      if rightpos then
        cand = mmi(cand, mab(pos[idx_i] - pos[idx[rightpos]]))
      end
      retval = retval + cand * val[idx_i]
    end
  end
  return retval
end

local ret = false
local g_ik = 0
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
  for xline = 0, g_ik do
    local yline = g_ik - xline
    local xcost = getmincost(xs, xline)
    local ycost = getmincost(ys, yline)
    local z = xcost + ycost
    if xline == 0 then
      cand = z
    elseif z < cand then
      cand = z
    end
  end
  if not ret then
    ret = cand
  elseif cand < ret then
    ret = cand
  end
end

for ik = 0, n do
  g_ik = ik
  ret = false
  xs, ys = {}, {}
  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
  grayWalk(n, add_func, rm_func, work_func)
  print(ret)
end
