Problem:
Score: 500 points

Problem Statement

New AtCoder City has an infinite grid of streets, as follows:

At the center of the city stands a clock tower. Let (0, 0) be the coordinates of this point.

A straight street, which we will call East-West Main Street, runs east-west and passes the clock tower. It corresponds to the x-axis in the two-dimensional coordinate plane.

There are also other infinitely many streets parallel to East-West Main Street, with a distance of 1 between them. They correspond to the lines \ldots, y = -2, y = -1, y = 1, y = 2, \ldots in the two-dimensional coordinate plane.

A straight street, which we will call North-South Main Street, runs north-south and passes the clock tower. It corresponds to the y-axis in the two-dimensional coordinate plane.

There are also other infinitely many streets parallel to North-South Main Street, with a distance of 1 between them. They correspond to the lines \ldots, x = -2, x = -1, x = 1, x = 2, \ldots in the two-dimensional coordinate plane.

There are N residential areas in New AtCoder City. The i-th area is located at the intersection with the coordinates (X_i, Y_i) and has a population of P_i. Each citizen in the city lives in one of these areas.

The city currently has only two railroads, stretching infinitely, one along East-West Main Street and the other along North-South Main Street.

M-kun, the mayor, thinks that they are not enough for the commuters, so he decides to choose K streets and build a railroad stretching infinitely along each of those streets.

Let the walking distance of each citizen be the distance from his/her residential area to the nearest railroad.

M-kun wants to build railroads so that the sum of the walking distances of all citizens, S, is minimized.

For each K = 0, 1, 2, \dots, N, what is the minimum possible value of S after building railroads?

Constraints

1 \leq N \leq 15

-10 \ 000 \leq X_i \leq 10 \ 000

-10 \ 000 \leq Y_i \leq 10 \ 000

1 \leq P_i \leq 1 \ 000 \ 000

The locations of the N residential areas, (X_i, Y_i), are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 Y_1 P_1
X_2 Y_2 P_2
: : :
X_N Y_N P_N

Output

Print the answer in N+1 lines.

The i-th line (i = 1, \ldots, N+1) should contain the minimum possible value of S after building railroads for the case K = i-1.

Sample Input 1

3
1 2 300
3 3 600
1 4 800

Sample Output 1

2900
900
0
0

When K = 0, the residents of Area 1, 2, and 3 have to walk the distances of 1, 3, and 1, respectively, to reach a railroad.

Thus, the sum of the walking distances of all citizens, S, is 1 \times 300 + 3 \times 600 + 1 \times 800 = 2900.

When K = 1, if we build a railroad along the street corresponding to the line y = 4 in the coordinate plane, the walking distances of the citizens of Area 1, 2, and 3 become 1, 1, and 0, respectively.

Then, S = 1 \times 300 + 1 \times 600 + 0 \times 800 = 900.

We have many other options for where we build the railroad, but none of them makes S less than 900.

When K = 2, if we build a railroad along the street corresponding to the lines x = 1 and x = 3 in the coordinate plane, all citizens can reach a railroad with the walking distance of 0, so S = 0. We can also have S = 0 when K = 3.

The figure below shows the optimal way to build railroads for the cases K = 0, 1, 2.

The street painted blue represents the roads along which we build railroads.

Sample Input 2

5
3 5 400
5 3 700
5 5 1000
5 7 700
7 5 400

Sample Output 2

13800
1600
0
0
0
0

The figure below shows the optimal way to build railroads for the cases K = 1, 2.

Sample Input 3

6
2 5 1000
5 2 1100
5 5 1700
-2 -5 900
-5 -2 600
-5 -5 2200

Sample Output 3

26700
13900
3200
1200
0
0
0

The figure below shows the optimal way to build railroads for the case K = 3.

Sample Input 4

8
2 2 286017
3 1 262355
2 -2 213815
1 -3 224435
-2 -2 136860
-3 -1 239338
-2 2 217647
-1 3 141903

Sample Output 4

2576709
1569381
868031
605676
366338
141903
0
0
0

The figure below shows the optimal way to build railroads for the case K = 4.

Solution in C# (Mono-csc 3.5.0) (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
  class Program
  {
    static void Main(string[] args)
    {
      MSOLUTIONS2020.E();
    }

    class MSOLUTIONS2020
    {
      public static void A()
      {
        var X = Read.Int();
        Console.WriteLine((2199 - X) / 200);
      }
      public static void B()
      {
        var A = Read.Int();
        var B = Read.Int();
        var C = Read.Int();
        var K = Read.Int();
        int count = 0;
        while (B <= A)
        {
          B *= 2;
          count++;
        }
        while (C <= B)
        {
          C *= 2;
          count++;
        }
        Console.WriteLine(count <= K ? "Yes" : "No");
      }
      public static void C()
      {
        var N = Read.Int();
        var K = Read.Int();
        var A = Read.LongN();
        var sb = new System.Text.StringBuilder();
        for(int i = K; i < N; ++i)
        {
          sb.AppendLine(A[i - K] < A[i] ? "Yes" : "No");
        }
        Console.Write(sb.ToString());
      }
      public static void D()
      {
        var N = Read.Int();
        var A = Read.LongN();
        long money = 1000;
        long min = A[0];
        long max = A[0];
        for(int i = 1; i < N; ++i)
        {
          if(A[i] > max) { max = A[i]; }
          else
          {
            money += money / min * (max - min);
            max = A[i];
            min = A[i];
          }
        }
        money += money / min * (max - min);
        Console.WriteLine(money);
      }
      public static void E()
      {
        var N = Read.Int();
        var XYP = Enumerable.Range(0, N).Select(i => Read.LongN()).ToArray();
        var minCost = Enumerable.Range(0, N + 1).Select(i => (long)1e18).ToArray();

        long[,] XCost = new long[N, 1 << N];
        long[,] YCost = new long[N, 1 << N];
        for(int i = 0; i < (1 << N); ++i)
        {
          for(int j = 0; j < N; ++j)
          {
            var X = XYP[j][0];
            var Y = XYP[j][1];
            var P = XYP[j][2];
            {
              long minX = Math.Abs(X);
              long minY = Math.Abs(Y);
              for (int k = 0; k < N; ++k)
              {
                if ((i & (1 << k)) > 0)
                {
                  minX = Math.Min(minX, Math.Abs(X - XYP[k][0]));
                  minY = Math.Min(minY, Math.Abs(Y - XYP[k][1]));
                }
              }
              XCost[j, i] = minX * P;
              YCost[j, i] = minY * P;
            }
          }
        }
        E_DFS(N, 0, 0, 0, 0, XCost, YCost, minCost);
        Console.WriteLine(String.Join(Environment.NewLine, minCost));

        //long p3 = 1;
        //for(int i = 0; i < N; ++i) { p3 *= 3; }
        //for(int i = 0; i < p3; ++i)
        //{
        //  int xp = 0, yp = 0, c = N;
        //  int ii = i;
        //  for(int j = 0; j < N; ++j)
        //  {
        //    switch (ii % 3)
        //    {
        //      case 0: c--; break;
        //      case 1: xp += 1 << j; break;
        //      case 2: yp += 1 << j; break;
        //    }
        //    ii /= 3;
        //  }
        //  long cost = 0;
        //  for(int j = 0; j < N; ++j)
        //  {
        //    cost += Math.Min(XCost[j, xp], YCost[j, yp]);
        //  }
        //  minCost[c] = Math.Min(minCost[c], cost);
        //}
        //Console.WriteLine(String.Join(Environment.NewLine, minCost));
      }
      static void E_DFS(int N, int step, int c, int xp, int yp, long[,] XCost, long[,] YCost, long[] minCost)
      {
        if (N == step)
        {
          long cost = 0;
          for(int i = 0; i < N; ++i)
          {
            cost += Math.Min(XCost[i, xp], YCost[i, yp]);
          }
          minCost[c] = Math.Min(minCost[c], cost);
          return;
        }
        E_DFS(N, step + 1, c, xp, yp, XCost, YCost, minCost);
        E_DFS(N, step + 1, c + 1, xp + (1 << step), yp, XCost, YCost, minCost);
        E_DFS(N, step + 1, c + 1, xp, yp + (1 << step), XCost, YCost, minCost);
      }
      public static void F()
      {
        var N = Read.Int();
        var listU = new List<Tuple<int, int>>();
        var listD = new List<Tuple<int, int>>();
        var listL = new List<Tuple<int, int>>();
        var listR = new List<Tuple<int, int>>();
        for(int i = 0; i < N; ++i)
        {
          var X = Read.Int();
          var Y = Read.Int();
          var U = Read.Str();
          var t = new Tuple<int, int>(X, Y);
          if (U == "U") { listU.Add(t); }
          if (U == "D") { listD.Add(t); }
          if (U == "L") { listL.Add(t); }
          if (U == "R") { listR.Add(t); }
        }
        long min = (long)1e18;
        {
          var dictL = new Dictionary<int, List<int>>();
          var dictR = new Dictionary<int, List<int>>();
          foreach (var t in listL)
          {
            if (!dictL.ContainsKey(t.Item2)) { dictL.Add(t.Item2, new List<int>()); }
            dictL[t.Item2].Add(t.Item1);
          }
          foreach (var t in listR)
          {
            if (!dictR.ContainsKey(t.Item2)) { dictR.Add(t.Item2, new List<int>()); }
            dictR[t.Item2].Add(t.Item1);
          }
          min = Math.Min(min, F_LR(dictL, dictR));
        }
        {
          var dictL = new Dictionary<int, List<int>>();
          var dictR = new Dictionary<int, List<int>>();
          foreach (var t in listD)
          {
            if (!dictL.ContainsKey(t.Item1)) { dictL.Add(t.Item1, new List<int>()); }
            dictL[t.Item1].Add(t.Item2);
          }
          foreach (var t in listU)
          {
            if (!dictR.ContainsKey(t.Item1)) { dictR.Add(t.Item1, new List<int>()); }
            dictR[t.Item1].Add(t.Item2);
          }
          min = Math.Min(min, F_LR(dictL, dictR));
        }
        {
          var dict1 = new Dictionary<int, List<int>>();
          var dict2 = new Dictionary<int, List<int>>();
          foreach (var t in listR)
          {
            var key = t.Item2 - t.Item1;
            var value = t.Item1;
            var d = dict1;
            if (!d.ContainsKey(key)) { d.Add(key, new List<int>()); }
            d[key].Add(value);
          }
          foreach (var t in listD)
          {
            var key = t.Item2 - t.Item1;
            var value = t.Item1;
            var d = dict2;
            if (!d.ContainsKey(key)) { d.Add(key, new List<int>()); }
            d[key].Add(value);
          }
          min = Math.Min(min, F_RD(dict1, dict2));
        }
        {
          var dict1 = new Dictionary<int, List<int>>();
          var dict2 = new Dictionary<int, List<int>>();
          foreach (var t in listD)
          {
            var key = t.Item2 + t.Item1;
            var value = t.Item1;
            var d = dict1;
            if (!d.ContainsKey(key)) { d.Add(key, new List<int>()); }
            d[key].Add(value);
          }
          foreach (var t in listL)
          {
            var key = t.Item2 + t.Item1;
            var value = t.Item1;
            var d = dict2;
            if (!d.ContainsKey(key)) { d.Add(key, new List<int>()); }
            d[key].Add(value);
          }
          min = Math.Min(min, F_RD(dict1, dict2));
        }
        {
          var dict1 = new Dictionary<int, List<int>>();
          var dict2 = new Dictionary<int, List<int>>();
          foreach (var t in listL)
          {
            var key = t.Item2 - t.Item1;
            var value = -t.Item1;
            var d = dict1;
            if (!d.ContainsKey(key)) { d.Add(key, new List<int>()); }
            d[key].Add(value);
          }
          foreach (var t in listU)
          {
            var key = t.Item2 - t.Item1;
            var value = -t.Item1;
            var d = dict2;
            if (!d.ContainsKey(key)) { d.Add(key, new List<int>()); }
            d[key].Add(value);
          }
          min = Math.Min(min, F_RD(dict1, dict2));
        }
        {
          var dict1 = new Dictionary<int, List<int>>();
          var dict2 = new Dictionary<int, List<int>>();
          foreach (var t in listU)
          {
            var key = t.Item2 + t.Item1;
            var value = -t.Item1;
            var d = dict1;
            if (!d.ContainsKey(key)) { d.Add(key, new List<int>()); }
            d[key].Add(value);
          }
          foreach (var t in listR)
          {
            var key = t.Item2 + t.Item1;
            var value = -t.Item1;
            var d = dict2;
            if (!d.ContainsKey(key)) { d.Add(key, new List<int>()); }
            d[key].Add(value);
          }
          min = Math.Min(min, F_RD(dict1, dict2));
        }
        Console.WriteLine(min == (long)1e18 ? "SAFE" : min.ToString());
      }
      static long F_LR(Dictionary<int, List<int>> L, Dictionary<int, List<int>> R)
      {
        long min = (long)1e18;
        foreach(var kvp in L)
        {
          if (!R.ContainsKey(kvp.Key)){ continue; }
          var Ls = kvp.Value.OrderBy(x => x).ToArray();
          foreach(var v in R[kvp.Key])
          {
            var idx = Bound.Upperbound(Ls, v);
            if (idx < Ls.Length)
            {
              min = Math.Min(min, (Ls[idx] - v) * 5);
            }
          }
        }
        return min;
      }
      static long F_RD(Dictionary<int, List<int>> R, Dictionary<int, List<int>> D)
      {
        long min = (long)1e18;
        foreach (var kvp in R)
        {
          if (!D.ContainsKey(kvp.Key)) { continue; }
          var Ds = D[kvp.Key].OrderBy(x => x).ToArray();
          foreach (var v in kvp.Value)
          {
            var idx = Bound.Upperbound(Ds, v);
            if (idx < Ds.Length)
            {
              min = Math.Min(min, (Ds[idx] - v) * 10);
            }
          }
        }
        return min;
      }
    }






    class Util
    {
      public static T[,] Gen<T>(int r, int c, T v)
      {
        var matrix = new T[r, c];
        for (int i = 0; i < r; ++i)
        {
          for (int j = 0; j < c; ++j)
          {
            matrix[i, j] = v;
          }
        }
        return matrix;
      }
      public static long[] ASum(long[] array)
      {
        var res = new long[array.Length + 1];
        for (int i = 0; i < array.Length; ++i)
        {
          res[i + 1] = res[i] + array[i];
        }
        return res;
      }
      public static long[,] ASum(long[,] matrix)
      {
        var N = matrix.GetLength(0);
        var M = matrix.GetLength(1);
        var res = new long[N + 1, M + 1];
        for(int i = 0; i < N; ++i)
        {
          for(int j = 0; j < M; ++j)
          {
            res[i + 1, j + 1] = res[i, j + 1] + res[i + 1, j] - res[i, j] + matrix[i, j];
          }
        }
        return res;
      }
      public static MyDict<T, long> Frequency2<T>(T[] array)
      {
        var dict = new MyDict<T, long>();
        foreach (var a in array)
        {
          dict[a]++;
        }
        return dict;
      }
      public class MyDict<T1, T2> : Dictionary<T1, T2>
      {
        public new T2 this[T1 key]
        {
          get { if (!base.ContainsKey(key)) { base.Add(key, default(T2)); } return base[key]; }
          set { base[key] = value; }
        }
      }

      public static void WarshallFloyd(long[,] dist)
      {
        var N = dist.GetLength(0);
        for (int k = 0; k < N; ++k)
        {
          for (int i = 0; i < N; ++i)
          {
            for (int j = 0; j < N; ++j)
            {
              dist[i, j] = Math.Min(dist[i, j], dist[i, k] + dist[k, j]);
            }
          }
        }
      }
      public static long[,] DistFromAdj(int N, Dictionary<int, Dictionary<int, long>> adj)
      {
        var dist = new long[N, N];
        for (int i = 0; i < N; ++i)
        {
          for (int j = 0; j < N; ++j)
          {
            dist[i, j] = adj.ContainsKey(i + 1) && adj[i + 1].ContainsKey(j + 1) ? adj[i + 1][j + 1] : (long)1e18;
          }
        }
        return dist;
      }

    }
    class Bound
    {
      public static int Lowerbound<T1, T2>(SortedList<T1, T2> list, T1 x) where T1 : IComparable<T1>
      {
        return Lowerbound(list.Keys, x);
      }
      public static int Upperbound<T1, T2>(SortedList<T1, T2> list, T1 x) where T1 : IComparable<T1>
      {
        return Upperbound(list.Keys, x);
      }
      public static int Lowerbound<T>(IList<T> list, T x) where T : IComparable<T>
      {
        int min = 0;
        int max = list.Count;
        while (min < max)
        {
          var mid = (min + max) / 2;
          if (list[mid].CompareTo(x) >= 0)
          {
            max = mid;
          }
          else
          {
            min = mid + 1;
          }
        }
        return max;
      }
      public static int Upperbound<T>(IList<T> list, T x) where T : IComparable<T>
      {
        int min = 0;
        int max = list.Count;
        while (min < max)
        {
          var mid = (min + max) / 2;
          if (list[mid].CompareTo(x) > 0)
          {
            max = mid;
          }
          else
          {
            min = mid + 1;
          }
        }
        return max;
      }

    }

    struct MOD
    {
      public static long P = 1000000007;
      public readonly long V;

      public MOD(long a) { this.V = a % P; }
      public static implicit operator MOD(long a) { return new MOD(a); }
      public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); }
      public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); }
      public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); }
      public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); }
      public MOD Inverse()
      {
        long a = V, p = P; long b = p, c = 1, d = 0, e = 0, f = 0;
        while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; }
        c %= p;
        return c + (c < 0 ? p : 0);
      }
      public MOD Power(long n)
      {
        long a = V, p = P; long res = 1; long mult = a;
        for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; }
        return res;
      }
      public override string ToString() { return V.ToString(); }
    }


    static class Read
{
static Queue<string> queue = new Queue<string>();
static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
public static ulong[] ULongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToUInt64(s)).ToArray(); }
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; }
public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false)
{
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); }
for (int i = 0; i < M; ++i) { var ab = Read.IntN(); if (!dict[ab[0]].Contains(ab[1])) { dict[ab[0]].Add(ab[1]); } if (!isDirectional && !dict[ab[1]].Contains(ab[0])) { dict[ab[1]].Add(ab[0]); } }
return dict;
}
public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M, bool isDirectional = false)
{
Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); }
for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); if (!isDirectional) { dict[ab[1]].Add(ab[0], ab[2]); } }
return dict;
}
}
    }
}