#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif

using namespace std;
using Graph = vector<vector<int>>;
using vst= vector<string>;
using vin= vector<int>;
using ll=long long;
using ull=unsigned long long;
using vll= vector<ll>;
using P=pair<int ,int>;
using pqi=priority_queue<int, vector<int>, greater<int>>;
using pqp=priority_queue<P, vector<P>, greater<P>>;

//const long double pi=acos(-1);
#define ft first
#define sd second
#define fn front
#define pb push_back
#define eb emplace_back
#define it insert
#define vvi vector<vector<int>>
#define si(v) int((v).size())
#define pq priority_queue
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define gsot(x) sort(x.begin(), x.end(), greater<ll>());
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))
#define cps CLOCKS_PER_SEC
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define cset(x) cout<<fixed<<setprecision(x)


//const int INF=1001001001;
//const ll INF=1e18;
//998244353  1000000007


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vin a(n),b(n),c(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n) cin>>c[i];
    vin cnt(100008,0),d(n);
    rep(i,n){
        cnt[a[i]]++;
    }
    rep(i,n){
        d[c[i]-1]++;
    }
    ll ans=0;
    rep(i,n){
        ans+=(d[i]*cnt[b[i]]);
    }
    cout<<ans<<endl;
}



















#include <bits/stdc++.h>
/* #include <atcoder/lazysegtree> */
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vint = vector<int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (long long i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (long long i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}
template <typename... T>
void In(T&&... args) {
    (std::cin >> ... >> args);
}
template <typename T, typename ...Tail>
void Out(T head, Tail... tail) {
    std::cout << head;
    if constexpr(sizeof...(tail) > 0) {
        std::cout << ' ';
        Out(tail...);
    } else {
        std::cout << '\n';
    }
}
template <typename T>
T& chmin(T& val, T val2) {
    return val = min(val, val2);
}
template <typename T>
T& chmax(T& val, T val2) {
    return val = max(val, val2);
}

void solve() {
    int n; In(n);
    vector<vll> c(n, vll(n,0));
    REP(i,n) {
        REP(j,n) {
            cin >> c[i][j];
        }
    }
    bool flag = true;
    vll asub(n-1,0), bsub(n-1,0);
    REP(j,n) {
        vll tmp;
        REP(i,n-1) {
            tmp.push_back(c[i+1][j] - c[i][j]);
        }
        if (j == 0) {
            asub = tmp;
        } else {
            if (asub != tmp) {
                flag = false;
                break;
            }
        }
    }
    REP(i,n) {
        vll tmp;
        REP(j,n-1) {
            tmp.push_back(c[i][j+1] - c[i][j]);
        }
        if (i == 0) {
            bsub = tmp;
        } else {
            if (bsub != tmp) {
                flag = false;
                break;
            }
        }
    }
    if (!flag) {
        Out("No");
        return;
    }
    vll a,b;
    a.push_back(0);
    b.push_back(c[0][0]);
    REP(i,n-1) {
        a.push_back((*a.rbegin()) + asub[i]);
        b.push_back((*b.rbegin()) + bsub[i]);
    }
    ll amin = LLONG_MAX, bmin = LLONG_MAX;
    REP(i,n) {
        chmin(amin,a[i]);
        chmin(bmin,b[i]);
    }
    if (amin < 0) {
        bmin += amin;
        if (bmin < 0) {
            Out("No");
            return;
        }
        REP(i,n) {
            a[i] -= amin;
            b[i] += amin;
        }
    } else if (bmin < 0) {
        amin += bmin;
        if (amin < 0) {
            Out("No");
            return;
        }
        REP(i,n) {
            a[i] += bmin;
            b[i] -= bmin;
        }
    }
    Out("Yes");
    Out(a);
    Out(b);
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}

