#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

int n;
int link[1048576];
__int64 ans;
int *tree[21];

void push(int a, int b, int c) {
	
	while (a>0) {
		tree[a][b]++;
		if (c>=(1<<(a-1))) {
			a--;
			b=b*2+1;
			c-=(1<<a);
		} else {
			a--;
			b*=2;
		}
	}
	tree[a][b]++;
}

int pop(int a, int b, int c) {
	int ret=0;

	while (a>0) {
		if (c>=(1<<(a-1))) {
			ret+=tree[a-1][b*2];
			a--;
			b=b*2+1;
			c-=(1<<a);
		} else {
			a--;
			b*=2;
		}
	}
	return ret+tree[a][b];
}

int main(void) {
	int i, t1, t2;

	for (i=0; i<21; i++) {
		tree[i]=malloc(sizeof(int)*(1<<(20-i)));
		memset(tree[i], 0, sizeof(int)*(1<<(20-i)));
	}
	scanf("%d", &n);
	for (i=0; i<n; i++) {
		scanf("%d %d", &t1, &t2);
		link[t1]=t2;
		link[t2]=t1;
	}

	for (i=0; i<n*2; i++) if (link[i]>i) {
		ans+=pop(20, 0, link[i])-pop(20, 0, i);
		push(20, 0, link[i]);
	}

	printf("%Ld\n", ans);
	
	return 0;
}
