//#pragma GCC optimize ("O2")
//#pragma GCC optimize ("Ofast")
// IN THE NAME OF GOD
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;

template <typename Head>
inline void dout(Head in) {
  cerr << in << '\n';
} 

int main() {
  ios::sync_with_stdio(false), cin.tie(NULL);
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int> (n));
  vector<int> tmp(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    bool ok = true;
    tmp = a[i];
    for (int j = 0; j < n; j++) {
      int cnt = 0;
      for (int k = 0; k < n; k++) {
        cnt += tmp[j] <= a[k][j];
      }
      ok &= cnt == n;
    }
    if (ok) {
      break;
    }
  }
//  cout << "tmp: ";
//  for (int i = 0; i < n; i++) {
//    cout << tmp[i] << ' ';
//  }
  bool exist = true;
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    int ith = a[i][0] - tmp[0];
    bool ok = true;
    for (int j = 1; j < n; j++) {
      if (a[i][j] - tmp[j] != ith) {
        ok = false;
      }
    }
    if (ok) {
      ans[i] = ith;
    }
    else {
      exist = false;
      break;
    }
  }
  if (exist) {
    cout << "Yes\n";
    for (int i = 0; i < n; i++) {
      cout << ans[i] << ' ';
    }
    cout << '\n';
    for (int i = 0; i < n; i++) {
      cout << tmp[i] << ' ';
    }
  }
  else {
    cout << "No";
  } 
  return 0;
}
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 200005;

int A[N], B[N];
map<int, vi > idx;
map<int, vi >::iterator it;

class BinaryIndexTree {
  vector<int > BIT;
  int sz;

public:

  BinaryIndexTree(int _sz) {
    sz = _sz;
    BIT.resize(_sz+1, 0);
  }

  void update(int idx, int val) {
    for(int i = idx; i < sz; i += i & -i) {
      BIT[i] += val;
    }
  }

  int query(int idx) {
    int res = 0;
    for(int i = idx; i; i -= i & -i) {
      res += BIT[i];
    }
    return res;
  }

};

BinaryIndexTree bit(N);

int main() {
  int n;
  S(n);
  rep(i,0,n) {
    S(A[i]);
    A[i] += i;
    idx[A[i]].pb(i + 1);
  }

  for(it = idx.begin(); it != idx.end(); it++) {
    reverse(all(it->SS));
  }
  LL ans = 0;
  rep(i,0,n) {
    S(B[i]);
    B[i] += i;
    if(idx.find(B[i]) == idx.end() || idx[B[i]].size() == 0) {
      P(-1);
      return 0;
    }
    int num = idx[B[i]].back();
    idx[B[i]].pop_back();
    ans += i - bit.query(num);
    bit.update(num, 1);
  }
  cout << ans << "\n";
  return 0;
}
