#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807ll
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

ll n;
ll dp[17][(1<<17)];
ll x[17],y[17],z[17];
ll dps(ll cur,ll mask)
{
    if(mask==((1<<n)-1))
    {
        return abs(x[0]-x[cur])+abs(y[0]-y[cur])+max(0ll,z[0]-z[cur]);
    }
    if(dp[cur][mask]!=-1)
        return dp[cur][mask];
    ll ans=hell;
    rep(i,0,n)
    {
        if(((1<<i)&mask)==0)
        {
            ll c=abs(x[i]-x[cur])+abs(y[i]-y[cur])+max(0ll,z[i]-z[cur]);
            ans=min(ans,c+dps(i,mask|(1<<i)));
        }
    }
    return dp[cur][mask]=ans;
}
void solve()
{
    cin>>n;
    rep(i,0,n)
    {
        cin>>x[i]>>y[i]>>z[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<dps(0,1);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int maxn = 1e5+5;
int l[maxn], r[maxn];
int p[maxn];
bool ok[205][205];
void build(int L,int R) {
    int sz = (R - L + 1) / 2;
    for (int i = L, j = i + sz ; j <= R ; i++,j++) {
        if (p[i] && p[j] && p[i] + p[j]) return;
        if (p[i] > 0)return;
        if (p[j] < 0) return;
    }
    ok[L][R] = 1;
}
void go() { 
    int n;
    cin >> n;
    f1(n) {
        cin >> l[i] >> r[i];
        if (~l[i] && ~r[i] && l[i] > r[i]) {
            cout << "No\n";
            exit(0);
        }
        if (~l[i]) {
            if (p[l[i]]) {
                cout << "No\n";
                exit(0);
            }
            p[l[i]] = -i;
        }
        if (~r[i]) {
            if (p[r[i]]) {
                cout << "No\n";
                exit(0);
            }
            p[r[i]] = i;
        }
    }
    n *= 2;
    for (int i = 1 ; i <= n ; i += 2) {
        for (int j = i + 1 ; j <= n ; j++) {
            build(i,j);
            //cout << i <<' '<<j<<' '<<ok[i][j] << '\n';
        }
    }
    int dp[n+5] = {};
    dp[0] = 1;
    for (int i = 2 ; i <= n ; i+= 2) {
        for (int j = 1 ; j <= i ; j += 2) {
            if (ok[j][i] && dp[j-1]) dp[i]= 1;
        }
    }
    if (dp[n]) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}