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

typedef long long ll;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define repc(i, l, n, d) for (int64_t i = l; i < n; i+=d)
#define repc2(i, l, n, d) for (int64_t i = l; i <= n; i+=d)
#define repe(a, b) for (auto&(a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define mp(a, b) make_pair((a), (b))
#define Push_back(a, b) push_back( mp( (a), (b) ) )
#define ctoi(c) (c)-'0'

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

const int inf = 0x3fffffff;
const int64_t INF = 0x3fffffffffffffff;
const int64_t MOD = 1e9+7;

int main() {
    int64_t n;
    cin >> n;
    std::vector<int64_t> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
    }
    int64_t ans = 0;
    rep(i, n-1) {
        repb(j, i+1, n) {
            // if ( x[i] <= x[j] ) {
                if ( y[i]-abs(x[j]-x[i]) <= y[j]
                    && y[j] <= y[i]+abs(x[j]-x[i]) ) {
                    ++ans;
                }
            // } else {

            // }
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod = 1000000007;
// const int mod = 998244353;



int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n), z(n);
  rep(i, n) cin >> x[i] >> y[i] >> z[i];
  int n2 = 1<<n;
  vvi dp(n2, vi(n, INF));
  vvi dist(n, vi(n));
  rep(i, n) rep(j, n) {
    int now = abs(x[j] - x[i]);
    now += abs(y[j] - y[i]);
    now += max(0, z[j] - z[i]);
    dist[i][j] = now;
  }
  rep(i, n) {
    if (i == 0) continue;
    dp[1<<i][i] = dist[0][i];
  }
  rep(i, n2) rep(j, n) {
    if (~i>>j&1) continue;
    rep(k, n) {
      if (i>>k&1) continue;
      chmin(dp[i|1<<k][k], dp[i][j] + dist[j][k]);
    }
  }
  cout << dp[n2-1][0] << endl;
}