#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}



//おちこんだりもしたけれど、私はげんきです。
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int N;
	cin>>N;
	ll cen[4];
	rep(i,4) cen[i]=0;
	vector<ll> A(N),B(N),C(N),D(N); 
	rep(i,N){
		cin>>A[i]>>B[i];
		A[i]*=N;
		B[i]*=N;
		cen[0]+=A[i];
		cen[1]+=B[i];
	}
	rep(i,N){
		cin>>C[i]>>D[i];
		C[i]*=N;
		D[i]*=N;
		cen[2]+=C[i];
		cen[3]+=D[i];
	}
	rep(i,4) cen[i]/=N;
	rep(i,N){
		A[i]-=cen[0];
		B[i]-=cen[1];
		C[i]-=cen[2];
		D[i]-=cen[3];
	}
	if(A[0]*A[0]+B[0]*B[0]==0){
		swap(A[0],A[1]);
		swap(B[0],B[1]);
	}
	set<pair<int,int>> s;
	ll L=A[0]*A[0]+B[0]*B[0];
	rep(i,N) s.insert({C[i]*L,D[i]*L});
	bool T=false;
	vector<vector<ll>> q=
	{
		{A[0],B[0]},
		{B[0]*-1,A[0]}
	};
	//rep(i,N) cout<<A[i]<<" "<<B[i]<<" "<<C[i]<<" "<<D[i]<<endl;
	rep(i,N){
		if(L!=C[i]*C[i]+D[i]*D[i]) continue;
		bool U=true;
		vector<vector<ll>> p(2,vector<ll>(2));
		vector<vector<ll>> r=
		{
			{C[i],D[i]*-1},
			{D[i],C[i]}
		};
		rep(a,2) rep(b,2) rep(c,2){
			p[a][b]+=q[a][c]*r[c][b];
		}
		/*rep(i,2){
			rep(j,2) cout<<p[i][j]<<" ";
			cout<<endl;
		}*/
		rep(j,N){
			ll X=0,Y=0;
			X=A[j]*p[0][0]+B[j]*p[0][1];
			Y=A[j]*p[1][0]+B[j]*p[1][1];
			if( !s.count({X,Y}) ){
				U=false;
				break;
			}
		}
		T|=U;
	}
	yneos(T);
}


#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a,const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b) {if(b<a){a=b; return 1;} return 0;}
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int h,w; cin >> h >> w;
  int a[h][w];
  int mina = INF;
  REP(i,h) REP(j,w){
    cin >> a[i][j];
    chmin(mina,a[i][j]);
  }

  int ans = 0;
  REP(i,h) REP(j,w){
    ans += a[i][j] - mina;
  }
  COUT(ans);


  return 0;
}