#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0; i<(ll)n; i++)
#define INF 1e9
typedef long long ll;

const ll MAXN=17;
ll n;
ll d[MAXN][MAXN];
ll dp[1<<MAXN][MAXN];

ll rec(ll S, ll v) {
    if(dp[S][v] >= 0) return dp[S][v];
    if(S==(1<<n)-1 && v==0) return dp[S][v]=0;
    ll tmp=INF;
    REP(u,n) if(!(S>>u & 1)) tmp=min(tmp, rec(S|1<<u,u)+d[v][u]);
    return dp[S][v]=tmp;
}

int main() {
    
    cin >> n ;
    ll m = n*n;
    vector<ll> x(n);
    vector<ll> y(n);
    vector<ll> z(n);

    for(ll i = 0; i < n; i++) {
        cin >> x.at(i) >> y.at(i) >> z.at(i);
        x.at(i)--;
        y.at(i)--;
        z.at(i)--;
    }
    REP(i,n) REP(j,n) d[i][j]=d[j][i]=INF;
    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j < n; j++) {
            if(i != j) {
                ll a, b, c;
                a = i;
                b = j;
                d[a][b]=abs(x.at(i) - x.at(j)) + abs(y.at(i) - y.at(j)) + max((ll)0, z.at(j) - z.at(i));
            }
        }
    }
    fill((ll *)dp, (ll *)(dp+(1<<MAXN)), -1);
    cout << rec(0,0) << endl;
    return 0;
}
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int INF = 1e9 + 239;
const int N = 501;

int a[N][N];
int b[N];
int c[N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    int mn = INF;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            mn = min(mn, a[i][j]);
        }
    }
    int any = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i][j] == mn && !any) {
                any = 1;
                for (int nj = 0; nj < n; nj++) {
                    b[nj] = 0;
                    c[nj] = a[i][nj];
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        b[i] = a[i][0] - c[0];
    }
    int ok = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            ok &= (a[i][j] == b[i] + c[j]);
        }
        ok &= (b[i] >= 0);
        ok &= (c[i] >= 0);
    }
    if (ok) {
        cout << "Yes\n";
        for (int i = 0; i < n; i++) {
            cout << b[i] << ' ';
        }
        cout << '\n';
        for (int i = 0; i < n; i++) {
            cout << c[i] << ' ';
        }
        cout << '\n';
    } else {
        cout << "No\n";
    }
}
