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 <stdio.h>
#include <sys/time.h>

#define N	800000

unsigned int X;

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	X = tv.tv_sec ^ tv.tv_usec;
	if (X % 2 == 0)
		X++;
}

int rand_() {
	return (X *= 3) >> 1;
}

int xx[N], yy[N];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (xx[ii[j]] == xx[i_])
				j++;
			else if (xx[ii[j]] < xx[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

long long zz[N * 2];
int pq[N * 2], iq[2][1 + N * 2], cnt[2], mode;

int lt(int i, int j) { return mode == 0 ? zz[i] > zz[j] : zz[i] < zz[j]; }

int p2(int p) {
	return (p *= 2) > cnt[mode] ? 0 : (p < cnt[mode] && lt(iq[mode][p + 1], iq[mode][p]) ? p + 1 : p);
}

void pq_up(int i) {
	int p, q, j;

	for (p = pq[i]; (q = p / 2) && lt(i, j = iq[mode][q]); p = q)
		iq[mode][pq[j] = p] = j;
	iq[mode][pq[i] = p] = i;
}

void pq_dn(int i) {
	int p, q, j;

	for (p = pq[i]; (q = p2(p)) && lt(j = iq[mode][q], i); p = q)
		iq[mode][pq[j] = p] = j;
	iq[mode][pq[i] = p] = i;
}

void pq_add(int mode_, int i) {
	mode = mode_;
	pq[i] = ++cnt[mode], pq_up(i);
}

int pq_first(int mode_) {
	mode = mode_;
	return iq[mode][1];
}

void pq_remove_first(int mode_) {
	int i, j;

	mode = mode_, i = iq[mode][1], j = iq[mode][cnt[mode]--];
	if (j != i)
		pq[j] = 1, pq_dn(j);
	pq[i] = 0;
}

int main() {
	static int ii[N];
	int n, i;
	long long x, ans;

	srand_();
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		int u, v;

		scanf("%d%d", &xx[i], &yy[i]);
		u = xx[i] + yy[i], v = xx[i] - yy[i], xx[i] = u, yy[i] = v;
		ii[i] = i;
	}
	sort(ii, 0, n);
	ans = 0, x = 0;
	for (i = 0; i < n; i++) {
		int y, l, r;

		zz[i << 1 | 0] = zz[i << 1 | 1] = yy[ii[i]];
		if (i == 0)
			pq_add(0, i << 1 | 0), pq_add(1, i << 1 | 1);
		else {
			x += xx[ii[i]] - xx[ii[i - 1]], y = yy[ii[i]], l = pq_first(0), r = pq_first(1);
			if (y < zz[l] - x) {
				ans += zz[l] - x - y;
				pq_remove_first(0);
				zz[i << 1 | 0] += x, pq_add(0, i << 1 | 0);
				zz[i << 1 | 1] += x, pq_add(0, i << 1 | 1);
				zz[l] -= x * 2, pq_add(1, l);
			} else if (y > zz[r] + x) {
				ans += y - zz[r] - x;
				pq_remove_first(1);
				zz[i << 1 | 0] -= x, pq_add(1, i << 1 | 0);
				zz[i << 1 | 1] -= x, pq_add(1, i << 1 | 1);
				zz[r] += x * 2, pq_add(0, r);
			} else {
				zz[i << 1 | 0] += x, pq_add(0, i << 1 | 0);
				zz[i << 1 | 1] -= x, pq_add(1, i << 1 | 1);
			}
		}
	}
	ans /= 2;
	printf("%lld\n", ans);
	return 0;
}