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

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<double> VD;

int n;
int c[500][500];

int main() {
    //freopen("test.in","r",stdin);
    cin >> n;
    REP (i,n) REP (j,n) cin >> c[i][j];
    if (n==1) {
        cout << "Yes" << endl;
        cout << 0 << endl;
        cout << c[0][0] << endl;
        return 0;
    }
    int ok=1;
    vector<int> dx={0},dy={0};
    REP (i,n-1) {
        set<int> dif;
        REP (j,n) dif.insert(c[i+1][j]-c[i][j]);
        if (dif.size()!=1) { ok=0; break; }
        dy.PB(dy.back()+*dif.begin());
    }
    int m=*min_element(ALL(dy));
    for (int &x : dy) x-=m;
    REP (j,n-1) {
        set<int> dif;
        REP (i,n) dif.insert(c[i][j+1]-c[i][j]);
        if (dif.size()!=1) { ok=0; break; }
        dx.PB(dx.back()+*dif.begin());
    }
    m=*min_element(ALL(dx));
    for (int &x : dx) x-=m;
    int d=c[0][0]-(dy[0]+dx[0]);
    if (d<0) ok=0;
    else {
        for (int &x : dx) x+=d;
    }
    if (!ok) { cout << "No" << endl; return 0; }
    cout << "Yes" << endl;
    REP (i,n) {
        if (i!=0) cout << " ";
        cout << dy[i];
    }
    cout << endl;
    REP (i,n) {
        if (i!=0) cout << " ";
        cout << dx[i];
    }
    cout << endl;
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int score(vector<int> v){
  int res = 0;
  vector<int> cnt(10,0);
  rep(i,5){
    cnt[v[i]]++;
  }
  rep(i,10){
    if(i==0) continue;
    res += i*pow(10,cnt[i]);
  }
  //cerr << res << endl;
  return res;
}

int main(){
  int K; cin >> K;
  string S, T; cin >> S >> T;
  vector<int> cnt(10,K);
  cnt[0]=0;
  rep(i,4){
    cnt[S[i]-'0']--;
    cnt[T[i]-'0']--;
  }
  double ans = 0;
  for(int s=1;s<=9;s++){
    for(int t=1;t<=9;t++){
      vector<int> c=cnt;
      c[s]--;
      c[t]--;
      rep(i,10) if(c[i]<0)continue;
      double p;
      if(s==t){
        p = (double)cnt[s]*(cnt[s]-1)/(9*K-8)/(9*K-9);
      }
      else{
        p = (double)cnt[s]*cnt[t]/(9*K-8)/(9*K-9);
      }
      vector<int> ss, tt;
      rep(i,4){
        ss.pb(S[i]-'0');
        tt.pb(T[i]-'0');
      }
      ss.pb(s);
      tt.pb(t);
      if(score(ss)>score(tt)) ans+=p;
    }
  }
  cout << fixed << setprecision(20) << ans << endl;
  return 0;
}
