#include "bits/stdc++.h"
#define int long long
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 998244353;
template <typename T>
struct BIT {
	int n;          // 配列の要素数(数列の要素数+1)
	vector<T> bit;  // データの格納先
	BIT(int n_) : n(n_ + 1), bit(n, 0) {}
	void add(int i, T x) {
		for (int idx = i; idx < n; idx += (idx & -idx)) {
			bit[idx] += x;
		}
	}
	T sum(int i) {
		T s(0);
		for (int idx = i; idx > 0; idx -= (idx & -idx)) {
			s += bit[idx];
		}
		return s;
	}
};
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N; cin >> N;
	vector<int>A(N), B(N);
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < N; i++)cin >> B[i];
	map<int, vector<int>>mp;
	for (int i = N - 1; i >= 0; i--)mp[i + A[i]].push_back(i);
	vector<int>c(N);
	BIT<int>bit(N + 100);
	for (int i = 0; i < N; i++) {
		if (mp[i + B[i]].empty()) {
			cout << -1 << endl; return 0;
		}
		int idx = mp[i + B[i]].back();
		mp[i + B[i]].pop_back();
		c[i] = idx + 1;
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {

		ans += i - bit.sum(c[i]);
		bit.add(c[i], 1);
	}
	cout << ans << endl;
	return 0;

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(){
    ll n;cin >>n;
    vector<vector<ll>> c(n,vector<ll>(n));
    rep(i,n)rep(j,n)cin >>c[i][j];
    
    bool y_n=true;
    vector<ll> dc(n-1);
    rep(i,n-1)dc[i]=c[0][i+1]-c[0][i];
    rep(i,n-1)rep(j,n-1)if(dc[j]!=c[i+1][j+1]-c[i+1][j])y_n=false;
    if(!y_n){
        cout <<"No";
        return 0;
    }
    
    vector<ll> cn0(n);
    rep(i,n) cn0[i]=c[i][0];
    vector<ll> a=cn0;
    sort(all(a));
    rep(i,n){
        cn0[i]-=a[0];
        if(cn0[i]<0)y_n=false;
    }
    if(!y_n){
        cout <<"No";
        return 0;
    }
    cout <<"Yes" <<endl;

    ll num;
    rep(i,n)if(c[i][0]==a[0])num=i;
    rep(i,n){
        cout <<cn0[i];
        if(i!=n-1)cout <<" ";
    }
    cout <<endl;
    rep(i,n){
        cout <<c[num][i];
        if(i!=n-1)cout <<" ";
    }
}