#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

int main(){
    int n; cin >> n;
    VI a(n), b(n), c(n), d(n);
    REP(i,n) cin >> a[i] >> b[i], a[i]*=n, b[i]*=n;
    REP(i,n) cin >> c[i] >> d[i], c[i]*=n, d[i]*=n;
    if(n==1){
        cout << "Yes" << endl;
        return 0;
    }
    double csx=0, csy=0, ctx=0, cty=0;
    REP(i,n){
        csx+=a[i];
        csy+=b[i];
        ctx+=c[i];
        cty+=d[i];
    }
    csx/=n, csy/=n, ctx/=n, cty/=n;
    REP(i,n){
        a[i]-=csx;
        b[i]-=csy;
        c[i]-=ctx;
        d[i]-=cty;
    }
    if(a[0]==0&&b[0]==0){
        swap(a[0],a[1]);
        swap(b[0],b[1]);
    }
    REP(i,n){
        if(c[i]==0&&d[i]==0)
            continue;
        double ang=atan2(d[i],c[i])-atan2(b[0],a[0]);
        bool ok=1;
        REP(j,n){
            double x=a[j]*cos(ang)-b[j]*sin(ang);
            double y=a[j]*sin(ang)+b[j]*cos(ang);
            bool f=0;
            REP(k,n){
                if(abs(x-c[k])<=1e-6&&abs(y-d[k])<=1e-6)
                    f=1;
            }
            if(!f){
                ok=0;
                break;
            }
        }
        if(ok){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
typedef long long int_;
inline int readint(){
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0'||c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c&&c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}

const int MaxN = 200005;
const int Mod = 998244353;
vector<int> v[MaxN];
map<int,int> mp;
int c[MaxN]; // BIT

int main(){
	int n = readint();
	for(int i=1,t=0; i<=n; ++i){
		int &x = mp[readint()+i];
		if(!x) x = ++ t; // new id
		v[x].push_back(i);
	}
	for(int i=1; i<=n; ++i){
		int len = v[i].size();
		rep(j,0,len-1-j)
			swap(v[i][j],v[i][len-1-j]);
	}
	int_ ans = 0;
	for(int i=1; i<=n; ++i){
		int &x = mp[readint()+i];
		if(!x || v[x].empty()){
			puts("-1"); return 0;
		}
		int id = n+1-v[x].back();
		v[x].pop_back(); // match
		for(int j=id; j; j-=(j&-j))
			ans += c[j]; // inversion
		for(int j=id; j<=n; j+=(j&-j))
			++ c[j]; // count
	}
	printf("%lld\n",ans);
	return 0;
}
