#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<ll> x(n),y(n),p(n);
    rep(i,n){
        cin>>x[i]>>y[i]>>p[i];
    }
    vector<ll> ans(n+1,inf);
    vector<vector<ll>> dp1(n,vector<ll>(1<<n,inf)),dp2(n,vector<ll>(1<<n,inf));
    rep(i,n){
        rep(S,1<<n){
            dp1[i][S]=abs(y[i]);
            rep(j,n){
                if(S & 1<<j){
                    chmin(dp1[i][S],abs(y[j]-y[i]));
                }
            }
        }
    }
    rep(i,n){
        rep(S,1<<n){
            dp2[i][S]=abs(x[i]);
            rep(j,n){
                if(S & 1<<j){
                    chmin(dp2[i][S],abs(x[j]-x[i]));
                }
            }
        }
    }
    auto dfs=[&](auto &dfs,int d,vector<int> &state)->void{
        if(d==n){
            ll now=0,k=0,mask1=0,mask2=0;
            rep(i,n){
                if(state[i]==1){
                    k++;
                    mask1|=(1<<i);
                }else if(state[i]==2){
                    k++;
                    mask2|=(1<<i);
                }
            }
            rep(i,n){
                now+=p[i]*min(dp1[i][mask1],dp2[i][mask2]);
            }
            chmin(ans[k],now);
            return ;
        }  
        state[d]=0;//何もおかない
        dfs(dfs,d+1,state);
        state[d]=1;//x軸並行
        dfs(dfs,d+1,state);
        state[d]=2;//y軸並行
        dfs(dfs,d+1,state);
    };
    vector<int> state(n);
    dfs(dfs,0,state);
    cout<<ans<<endl;
}

Measured memory_bytes: 11172