
#include <bits/stdc++.h>
#define MAX 10000
using namespace std;

typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef double ld;

 const int N=1e5+5;

ll a[N];
list<ll>diff;

/*
void prints(vector<pair<ll,ll>>v,ll n){

  cout<<"after sorting the elements"<<endl;
   for(int i=0;i<n;i++)
  cout<<v[i].first<<" "<<v[i].second<<endl;
 
 return ;
}

*/

int main()
 {
   
    IOS;
     ll t,cnt=0; 
     cin>>t;  
     vector<pair<ll,ll>>v(t);
    
    for(int i=0;i<t;i++){
      cin>>v[i].first>>v[i].second;
     }

       sort(v.begin(),v.end());

     for(int i=0;i<t-1;i++)
     {
        ll f1 = v[i].first;
         ll g1 = v[i].second;
      for(int j=i+1;j<t;j++)
      { 
         ll f2 = v[j].first;
         ll g2 = v[j].second;
             
          //   cout<<"("<<f1<<"."<<g1<<")"<<" "<<"("<<f2<<"."<<g2<<")"<<endl;

          
           double upper ,lower;
            upper =  (g2-g1);
         
           lower = (f2-f1);
          

           double dist = double(upper/lower);

       //     cout<<upper<<" ? "<<lower<<"  ? "<<dist<<endl;

          if( dist >= -1 && dist <= 1) 
              cnt++;

      }

     }

     cout<<cnt<<endl;

  return 0;
 }

#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;

int main() {
	long long N; cin >> N;
	vector<long long> X(N), C(N);
	for (int i = 0; i < N; i++) cin >> X[i] >> C[i];

	priority_queue<long long> Que[200020];
	for (int i = 0; i < N; i++) {
		Que[C[i] - 1].push(X[i]);
	}

	long long min_dp = 0;
	long long max_dp = 0;
	long long min_dp_num = 0;
	long long max_dp_num = 0;

	for (int i = 0; i < N; i++) {
		if (Que[i].empty()) continue;
		long long min_ = 1LL << 60;
		long long max_ = 0 - (1LL << 60);
		while (!Que[i].empty()) {
			long long a = Que[i].top();
			Que[i].pop();
			min_ = min(min_, a);
			max_ = max(max_, a);
		}
		long long p;
		if (max_ < min_dp_num) p = min_dp + (min_dp_num - min_);
		else p = min_dp + (max_ - min_dp_num) + (max_ - min_);
		long long q;
		if (max_ < max_dp_num) q = max_dp + (max_dp_num - min_);
		else q = max_dp + (max_ - max_dp_num) + (max_ - min_);
		long long r;
		if (min_ > min_dp_num) r = min_dp + (max_ - min_dp_num);
		else r = min_dp + (min_dp_num - min_) + (max_ - min_);
		long long s;
		if (min_ > max_dp_num) s = max_dp + (max_ - max_dp_num);
		else s = max_dp + (max_dp_num - min_) + (max_ - min_);

		min_dp = min(p, q);
		max_dp = min(r, s);
		min_dp_num = min_;
		max_dp_num = max_;
	}
	min_dp = min_dp + abs(min_dp_num);
	max_dp = max_dp + abs(max_dp_num);

	cout << min(min_dp, max_dp) << endl;
}