#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

struct UnionFind {
	vector<int> d;
	UnionFind(int n=0): d(n,-1) {}
	int find(int x) {
		if (d[x] < 0) return x;
		return d[x] = find(d[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		if (d[x] > d[y]) swap(x,y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) { return find(x) == find(y);}
	int size(int x) { return -d[find(x)];}
};

int main(){
	int n, q;
	cin>>n>>q;
	vector<int> c(n);
	rep(i, n){cin>>c[i]; c[i]--;};

	UnionFind uf(n);
	vector<map<int, int>> mas(n);
	rep(i, n) mas[i][c[i]]=1;
	rep(_, q){
		int t;
		cin>>t;
		if(t==1){
			int a, b;
			cin>>a>>b; a--; b--;

			int aa=uf.find(a), bb=uf.find(b);
			if(aa!=bb){
				uf.unite(a, b);
				int c=uf.find(a), d;
				if(c==aa) d=bb;
				else d=aa;
				for(auto p : mas[d]) mas[c][p.first]+=p.second;
			}
		}
		else{
			int x, y;
			cin>>x>>y; x--; y--;

			int a=uf.find(x);
			cout<<mas[a][y]<<endl;
		}
	}
	return 0;
}

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

int main() {
    int64_t N;
    cin >> N;
    vector<vector<int64_t>> C(N, vector<int64_t>(N));
    for (int64_t i = 0; i < N; i++) {
        for (int64_t j = 0; j < N; j++) {
            cin >> C[i][j];
        }
    }

    vector<int64_t> diff(N - 1);
    for (int64_t i = 0; i < N - 1; i++) {
        set<int64_t> curr_diff;
        for (int64_t j = 0; j < N; j++) {
            curr_diff.insert(C[i + 1][j] - C[i][j]);
        }

        if (curr_diff.size() > 1) {
            cout << "No" << endl;
            return 0;
        }
        diff[i] = *curr_diff.begin();
    }

    vector<int64_t> A(N, 0);
    for (int64_t i = 0; i < N - 1; i++) {
        A[i + 1] = A[i] + diff[i];
    }

    const int64_t min_A = *min_element(A.begin(), A.end());
    if (min_A < 0) {
        for (int64_t i = 0; i < N; i++) {
            A[i] -= min_A;
        }
    }

    vector<int64_t> B(N);
    for (int64_t i = 0; i < N; i++) {
        B[i] = C[0][i] - A[0];
    }

    const int64_t min_B = *min_element(B.begin(), B.end());
    if (min_B < 0) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    for (int64_t i = 0; i < N; i++) {
        cout << A[i] << " \n"[i == N - 1];
    }
    for (int64_t i = 0; i < N; i++) {
        cout << B[i] << " \n"[i == N - 1];
    }
}