#include<bits/stdc++.h>
using namespace std;

struct {
        int x, y, z;
}city[18], a, b;
int drum[18][18], total_cost = INT_MAX, cities, t, cost[(1 << 18)][18];

int distance(int i, int  j) {
        a = city[i];
        b = city[j];
        return abs(b.x - a.x) + abs(b.y - a.y) + max(0, b.z - a.z);
}

int main() {
        cin >> cities;
        for (int i = 1; i <= cities; i++)
                cin >> city[i].x >> city[i].y >> city[i].z;
        for (int i = 1; i <= cities; i++)
                for (int j = 1; j <= cities; j++)
                        drum[i][j] = distance(i, j);
        int maxim = (1 << cities);
        for (int i = 1; i <= maxim; i++)
            for (int j = 1; j <= cities; j++)
                cost[i][j] = 1000000000;
        cost[1][1] = 0;
        for (int i = 1; i < maxim; i++)
                for (int j = 1; j < cities; j++)
                        if (i & (1 << j))
                                for (int x = 1, exc = (i - (1 << j)); x <= cities; x++)
                                        cost[i][j + 1] = min(cost[i][j + 1], cost[exc][x] + drum [x][j + 1]);

        for (int i = 2; i <= cities; i++)
                total_cost = min(total_cost, cost[maxim - 1][i] + drum[i][1]);
        cout << total_cost;
}

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

vector<int> x,y,z;

int dist(int a,int b){
  return abs(x[b]-x[a])+abs(y[b]-y[a])+max(0,z[b]-z[a]);
}

void infout(int a){
  if(a == 1e9) cout << "INF";
  else cout << a;
  cout << ",";
}

void chmin(int& a, int b){
  a = min(a,b);
}

int main(){
  
  int n;
  cin >> n;
  x.resize(n);
  y.resize(n);
  z.resize(n);
  rep(i,n) cin >> x[i] >> y[i] >> z[i];
  vector<vector<int>> dp(1<<n,vector<int>(n,1e9));
  rep(i,n){
    if(i == 0) continue;
    dp[1<<i][i] = dist(0,i);
  }
  rep(i,1<<n){
    //from where?
    rep(from,n){
      //to where?
      rep(to,n){
        chmin(dp[i|1<<to][to],dp[i][from]+dist(from,to));
      }
    }
  }
  cout << dp[(1<<n)-1][0] << endl;
}