Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

E. Infinite Inversions

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputThere 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* < *j* and *p*_{i} > *p*_{j}.

Input

The first line contains a single integer *n* (1 ≤ *n* ≤ 10^{5}) — the number of swap operations applied to the sequence.

Each of the next *n* lines contains two integers *a*_{i} and *b*_{i} (1 ≤ *a*_{i}, *b*_{i} ≤ 10^{9}, *a*_{i} ≠ *b*_{i}) — the arguments of the swap operation.

Output

Print a single integer — the number of inversions in the resulting sequence.

Examples

Input

2

4 2

1 4

Output

4

Input

3

1 6

3 4

2 5

Output

15

Note

In the first sample the sequence is being modified as follows: . It has 4 inversions formed by index pairs (1, 4), (2, 3), (2, 4) and (3, 4).

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/26/2017 20:02:31 (c2).

Desktop version, switch to mobile version.
User lists

Name |
---|