#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<climits>
#include<bitset>
#include<unordered_map>
#include<random>
#include<functional>


using namespace std;

#define max(A,B) ((A)>(B)?(A):(B))

#define min(A,B) ((A)<(B)?(A):(B))

int main(void) {
	string x;
	cin >> x;
	long long int m, mx = 0, res = 0;
	cin >> m;
	if (x.size() == 1) {
		if (x[0] - '0' <= m)cout << 1;
		else cout << 0;
		return 0;
	}

	for (int i = 0; i < x.size(); i++)mx = max(mx, x[i] - '0');
	long long int l = mx, r = m, now;
	res = l;
	while (l <= r) {
		int f = 0;
		long long int note = 0;
		now = (l + r) / 2;
		for (int i = 0; i <x.size(); i++) {
			if (note >= LLONG_MAX / now) {
				f = 1;
				break;
			}
			note *= now;
			note += x[i] - '0';
			if (note > m) {
				f = 1;
				break;
			}
			
		}
		if (f) {
			r = now - 1;
		}
		else {
			res = max(res, now);
			l = now + 1;
		}
	}
	cout << res - mx;
	return 0;
}
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 

#define int         long long
#define ll          long long
#define pb          push_back
#define vi          vector<ll>
#define mi          map<ll,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp          make_pair
#define F           first
#define S           second
#define rep(i, begin, end) for (int i=begin;i<end;i++)
#define repd(i, begin, end) for (int i=end-1;i>=begin;i--)
#define M           998244353
#define hell        1000000007
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update >
const int INF=1e18;
const int N=2e5+5;

int powm(int a,int b,int mod)
{
  int res=1;
  while(b)
  {
    if(b&1) 
    res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
  }
 
  return res;
}

int pow(int a,int b)
{
  int res=1;
  while(b)
  {
    if(b&1) 
    res=(res*a);
      a=(a*a);
      b>>=1;
  }
 
  return res;
}

signed main(void)
{ios
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout);
    #endif

    
    int tests=1;
    // cin>>tests;
    while(tests--)
    {
      int n;
      cin>>n;
      int a[n][n];
      rep(i,0,n) rep(j,0,n) cin>>a[i][j];
      vi r(n),c(n);
      rep(i,0,n)
      {
         r[i]=INF;
         rep(j,0,n)
         {
           r[i]=min(r[i],a[i][j]);
         }
      }

      rep(i,0,n)
      {
         c[i]=a[0][i]-r[0];
      }
      
      // rep(i,0,n) cout<<c[i]<<' ';
      rep(i,0,n)
      {
         rep(j,0,n)
         {
           if(a[i][j]!=r[i]+c[j])
           {
             cout<<"No"<<endl;
             return 0;
           }
         }
      }
      cout<<"Yes"<<endl;
      rep(i,0,n)
      {
         cout<<r[i]<<' ';
      }
      cout<<endl;
      rep(i,0,n) cout<<c[i]<<' ';
    }

                      
}
