#include <bits/stdc++.h>
//#include <atcoder/modint>
//#include <atcoder/math>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c = a % i_7;
    if(c >= 0) return c;
    return c + i_7;
}
long long po(long a, long b){
    if(b == 0) return 1;
    
    long long z = po(a , b / 2);
    z = mod(z * z);
    if(b % 2 != 0) z = mod(a * z);
    return z;
}

bool prime_(int n){
    if(n == 1){
        return false;
    }else if(n == 2){
        return true;
    }else{
        for(int i = 2; i <= std::sqrt(n); i++) if(n % i == 0) return false;
        return true;
    }
}

long long gcd_(long long a, long long b){
    if(a < b) std::swap(a,b);
    if(a % b == 0) return b;
    else return gcd_(b, a % b);
}

long long lcm_(long long x, long long y){
    return (x / gcd_(x,y)) * y;
}

using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//using mint = modint998244353;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  //using namespace std;
  
  int n;
  cin>>n;
  long long x[n];
  int c[n];
  REP(i, n){
    cin>>x[i]>>c[i];
    c[i]--;
  }
  
  vector<long long> balls[n];
  REP(i, n) balls[c[i]].push_back(x[i]);
  vector<int> colors;
  REP(i, n){
    if(balls[i].empty()) continue;
    colors.push_back(i);
    sort(ALL(balls[i]));
  }
  //sort(ALL(colors));
  int num = colors.size();
  vector<vector<long long>> dp(num, vector<long long>(2, INF));
  REP(i, num){
    int color = colors[i];
    int cnt = balls[color].size();
    long long width = balls[color][cnt - 1] - balls[color][0];
    if(i == 0){
      dp[i][0] = abs(balls[color][0]) + width;
      dp[i][1] = abs(balls[color].back()) + width;
      continue;
    }
    dp[i][0] = min(dp[i][0], abs(balls[color][0] - balls[colors[i - 1]][0]) + width + dp[i - 1][1]);
    dp[i][0] = min(dp[i][0], abs(balls[color][0] - balls[colors[i - 1]].back()) + width + dp[i - 1][0]);
    dp[i][1] = min(dp[i][1], abs(balls[color].back() - balls[colors[i - 1]][0]) + width + dp[i - 1][1]);
    dp[i][1] = min(dp[i][1], abs(balls[color].back() - balls[colors[i - 1]].back()) + width + dp[i - 1][0]);
  }
  long long ans = min(dp[num - 1][0] + abs(balls[colors[num - 1]].back()), dp[num - 1][1] + abs(balls[colors[num - 1]][0]));
  cout << ans << endl;

  return 0;
}
#include <algorithm>
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cmath>
#include <climits>
#include <queue>
#include <bitset>
#include <set>
#include <assert.h>
#include <map>
using namespace std;
typedef vector<vector<long> > dim2veclo;
typedef vector<vector<int> > dim2vecin;
typedef vector<vector<double> > dim2vecdo;
typedef vector<vector<long long> > dim2vecll;
typedef vector<int> vecin;
typedef vector<long> veclo;
typedef vector<double> vecdo;
typedef vector<long long> vecll;
typedef vector<bool> vecbo;
typedef vector<vector<bool> > dim2vecbo;
typedef long long ll;
typedef vector < pair<ll, ll> > vecpa;
typedef vector<string> vecst;
typedef pair<ll, ll> pail;
typedef pair<int, int> pain;
typedef vector<vecpa > dim2vecpa;


#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };

const ll MOD = 1000000007;

int dist(double x1, double y1, double x2, double y2) {
    return (int)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int angG(double X, double Y, double x2, double y2, double x3, double y3) {
    double gaiseki = (x2 - X) * (y3 - Y) - (y2 - Y) * (x3 - X);
    return (int)(asin(gaiseki / (dist(X, Y, x2, y2) * dist(X, Y, x3, y3))) * 100000);
}

int angN(double X, double Y, double x2, double y2, double x3, double y3) {
    double naiseki = (x2 - X) * (x3 - X) + (y2 - Y) * (y3 - Y);
    return (int)(acos(naiseki / (dist(X, Y, x2, y2) * dist(X, Y, x3, y3))) * 100000);
}



int main() {
    int n; cin >> n;
    vecdo a = vecdo(n);
    vecdo b = vecdo(n);
    vecdo c = vecdo(n);
    vecdo d = vecdo(n);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, n) cin >> c[i] >> d[i];
    if (n == 1) {
        cout << "Yes";
        return 0;
    }
    if (n == 2) {
        if (dist(a[0], b[0], a[1], b[1]) == dist(c[0], d[0], c[1], d[1])) {
            cout << "Yes";
        }
        else cout << "No";
        return 0;
    }

    ll length = dist(a[0], b[0], a[1], b[1]);

    bool res = false;
    
    vector<pair<int, pair<int, int>>> ans = vector<pair<int, pair<int, int>>>(n - 2);
    for (int i = 2; i < n; i++) {
        ans.push_back(make_pair(dist(a[0], b[0], a[i], b[i]), make_pair(angN(a[0], b[0], a[1], b[1], a[i], b[i]), angG(a[0], b[0], a[1], b[1], a[i], b[i]))));
    }
    sort(ans.begin(), ans.end());

    rep(i, n) rep(j, n) {
        if (i == j) continue;
        if (length != dist(c[i], d[i], c[j], d[j])) continue;
        bool flag = true;
        rep(k, n) {
            if (i == k) continue;
            if (j == k) continue;
            pair<int, pair<int, int>> isOK = make_pair(dist(c[i], d[i], c[k], d[k]), make_pair(angN(c[i], d[i], c[j], d[j], c[k], d[k]), angG(c[i], d[i], c[j], d[j], c[k], d[k])));
            if (!binary_search(ans.begin(), ans.end(), isOK)) {
                flag = false;
                break;
            }
        }
        if (flag) {
            res = true;
            break;
        }
    }
    if (res) cout << "Yes";
    else cout << "No";



    return 0;
}