#include <iostream>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>

using ll = long long;
#define fast_io                                                                                                                \
    ios::sync_with_stdio(false);                                                                                               \
    cin.tie(0)

using namespace std;
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };

void solve(ll t) {
	ll n;
	cin >> n;
	vector<vector<ll>> c(n, vector<ll>(n));

	ll num = INT_MAX;
	ll x, y;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> c[i][j];
			if (c[i][j] < num) {
				num = c[i][j];
				x = i;
				y = j;
			}
		}
	}

	vector<vector<ll>> c1(c);

	vector<ll> a(n), b(n);
	vector<ll> tmp = c[x];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			c[i][j] -= tmp[j];
		}
	}

	//for (int i = 0; i < n; i++) {
	//	for (int j = 0; j < n; j++) {
	//		cout<<c[i][j]<<" ";
	//	}
	//	cout << endl;
	//}

	for (ll i = 0; i < n; i++) {
		int flag = 1;
		for (ll j = 0; j < n; j++) {
			if (c[i][j] != c[i][0]) {
				flag = 0;
				break;
			}
		}

		if (flag == 1) {
			a[i] = c[i][0];
		}
		else {
			cout << "No" << endl;
			return;
		}
	}
	
	c = c1;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			c[i][j] -= a[i];
		}
	}

	for (ll j = 0; j < n; j++) {
		ll flag = 1;
		for (ll i = 0; i< n; i++) {
			if (c[i][j] != c[0][j] || c[i][j] < 0) {
				flag = 0;
				break;
			}
		}

		if (flag == 1) {
			b[j] = c[0][j];
		}
		else {
			cout << "No" << endl;
			return;
		}
	}

	cout << "Yes" << endl;
	cout << a[0];
	for (ll i = 1; i < n; i++) {
		cout << " " << a[i] ;
	}
	cout << endl;

	cout << b[0];
	for (ll i = 1; i < n; i++) {
		cout << " " << b[i] ;
	}
	cout << endl;

}

int main(void)
{
	ll t = 0; 
	//cin >> t; for (ll i = 1; i <= t; i++) {solve(i);}
	solve(t);
	return 0;
}
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
#define SZ(x) ((int)(x).size())

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T> 
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

/*



*/

ll n,m,x,y;
vector<ll>a,b,t,k;

struct edge{
	int to,cost,mult;
};

vector<edge> g[100010];
vector<ll>dist;

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > pq;
	dist.resize(n,INF);
	dist[s]=0;
	pq.push({0,s});

	while(!pq.empty()){
		P p = pq.top();pq.pop();
		int v = p.second;
		if(dist[v]<p.first)continue;
		for(auto e:g[v]){
			ll time = (dist[v]+e.mult-1)/e.mult*e.mult+e.cost;
			if(dist[e.to]>time){
				dist[e.to]=time;
				pq.push({dist[e.to],e.to});
			}
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	cin >> n >> m >> x >> y;
	x--;y--;
	a.resize(m);
	b.resize(m);
	t.resize(m);
	k.resize(m);
	rep(i,m){
		cin>>a[i]>>b[i]>>t[i]>>k[i];
		a[i]--;b[i]--;
	}
	rep(i,m){
		g[a[i]].push_back({b[i],t[i],k[i]});
		g[b[i]].push_back({a[i],t[i],k[i]});
	}
	dijkstra(x);
	if(dist[y]==INF)cout<<-1<<endl;
	else cout << dist[y] << endl;
	//debug(dist);
	return 0;
}