Problem: Annie has gotten bored of winning every coding contest and farming unlimited rating. Today, she is going to farm potatoes instead.

Annie's garden is an infinite 2D plane. She has n potatoes to plant, and the i-th potato must be planted at (x_i,y_i). Starting at the point (0, 0), Annie begins walking, in one step she can travel one unit right or up (increasing her x or y coordinate by 1 respectively). At any point (X,Y) during her walk she can plant some potatoes at arbitrary points using her potato gun, consuming max(|X-x|,|Y-y|) units of energy in order to plant a potato at (x,y). Find the minimum total energy required to plant every potato.

Note that Annie may plant any number of potatoes from any point.

Input

The first line contains the integer n (1 ≤ n ≤ 800 000).

The next n lines contain two integers x_i and y_i (0 ≤ x_i,y_i ≤ 10^9), representing the location of the i-th potato. It is possible that some potatoes should be planted in the same location.

Output

Print the minimum total energy to plant all potatoes.

Examples

Input


2
1 1
2 2


Output


0


Input


2
1 1
2 0


Output


1


Input


3
5 5
7 7
4 9


Output


2


Input


10
5 1
4 0
9 6
0 2
10 1
9 10
3 10
0 10
8 9
1 5


Output


19


Input


10
1 1
2 2
2 0
4 2
4 0
2 0
0 2
4 0
4 2
5 1


Output


6

Note

In example 1, Annie can travel to each spot directly and plant a potato with no energy required.

In example 2, moving to (1,0), Annie plants the second potato using 1 energy. Next, she travels to (1,1) and plants the first potato with 0 energy.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define endl '\n'

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define lb lower_bound
#define ub upper_bound
#define pb push_back

using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

template<typename T>
struct slope_trick {
	T offset_l, offset_r, zero_height;
	multiset<T> L;
	multiset<T> R;

	slope_trick() {
		offset_l = 0;
		offset_r = 0;
		zero_height = 0;
	}

	T zero_start() {
		if(L.empty()) {
			return numeric_limits<T>::min();
		} else {
			return *L.rbegin() + offset_l;
		}
	}

	T zero_end() {
		if(R.empty()) {
			return numeric_limits<T>::max();
		} else {
			return *R.begin() + offset_r;
		} 
	}

	inline size_t size() {
		return L.size() + R.size();
	}

	/* Add the function f(x) = height + |x - center| to the current slope trick. */
	void add_simple(const T &center, const T &height = 0) {
		T s = zero_start(), e = zero_end();
		zero_height += height;
		if(s <= center && center <= e) {
			L.insert(center - offset_l);
			R.insert(center - offset_r);
		} else if(center < s) {
			L.insert(center - offset_l);
			L.insert(center - offset_l);
			L.erase(prev(L.end()));
			R.insert(s - offset_r);					
			zero_height += abs(center - s);	
		} else {
			R.insert(center - offset_r);
			R.insert(center - offset_r);
			R.erase(R.begin());	
			L.insert(e - offset_l);
			zero_height += abs(center - e);	
		}
	}

	/* Update the current slope trick to its prefix minimum - i.e. f'(x) = min f(x') for all x' <= x.  */ 
	void prefix_min() {
		R.clear();
	}

	/* Update the current slope trick to its prefix minimum - i.e. f'(x) = min f(x') for all x' >= x.  */ 
	void suffix_min() {
		L.clear();
	}

	/* Update the current slope trick to the local minimum - i.e. f'(x) = min f(x') for all x - strip_width <= x' <= x + strip_width.  */ 
	void local_min(const T &strip_width) {
		if(!L.empty()) {
			offset_l -= strip_width;
		}

		if(!R.empty()) {
			offset_r += strip_width;
		}
	}

	void add(const slope_trick &other) {
		// TODO: Add arbitrary slope trick.
	}

	void add_with_destroy(slope_trick &other) {
		// TODO: Add using small to large.
	}
};

int n;
vector<pair<int, int>> P;

void read() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		P.pb({x + y, x - y});
	}
}

void solve() {
	slope_trick<int64_t> dp;
	sort(ALL(P));	

	int last_x = 0;
	for(int i = 0; i < SZ(P); ) {
		int delta = P[i].first - last_x;
		last_x = P[i].first;
		dp.local_min(delta);
		while(i < SZ(P) && P[i].first == last_x) {
			dp.add_simple(P[i].second);
			i++;
		}
	}

	assert(dp.zero_height % 2 == 0);
	cout << dp.zero_height / 2 << endl;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int T = 1;
	//cin >> T;
	for(int test = 1; test <= T; test++) {
		read();
		//cout << "Case #" << test << ": ";
		solve();
	}

	return 0;
}