There is an infinite sequence consisting of all positive integers in the increasing order: *p* = {1, 2, 3, ...}. We performed *n* swap operations with this sequence. A *swap*(*a*, *b*) is an operation of swapping the elements of the sequence on positions *a* and *b*. Your task is to find the number of inversions in the resulting sequence, i.e. the number of such index pairs (*i*, *j*), that *i* &lt; *j* and *p*<sub class="lower-index">*i*</sub> &gt; *p*<sub class="lower-index">*j*</sub>.
The first line contains a single integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) — the number of swap operations applied to the sequence.

Each of the next *n* lines contains two integers *a*<sub class="lower-index">*i*</sub> and *b*<sub class="lower-index">*i*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub>, *b*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>, *a*<sub class="lower-index">*i*</sub> ≠ *b*<sub class="lower-index">*i*</sub>) — the arguments of the swap operation.
n = int(input())
a = list(range(1, n * 2 + 1))
b = [0] * (n * 2 + 1)
cnt = 0

def merge(l, mid, r):
    i = l
    j = mid + 1
    k = l
    while i <= mid and j <= r:
        if a[i] <= a[j]:
            b[k] = a[i]
            i += 1
        else:
            b[k] = a[j]
            j += 1
            global cnt
            cnt += mid - i + 1
        k += 1
    while i <= mid:
        b[k] = a[i]
        i += 1
        k += 1
    while j <= r:
        b[k] = a[j]
        j += 1
        k += 1
    for k in range(l, r + 1):
        a[k] = b[k]


def merge_sort(l, r):
    if l < r:
        mid = (l + r) // 2
        merge_sort(l, mid)
        merge_sort(mid + 1, r)
        merge(l, mid, r)


for i in range(n):
    x, y = map(int, input().split())
    a[x - 1], a[y - 1] = a[y - 1], a[x - 1]

merge_sort(0, n * 2 +1)
print(cnt)

		 		  	 		 	 				  		 		  	  	