# John`s Inversions

John has recently come across the definition of an inversion.

An inversion in a sequence of numbers `s[k]`

is any pair `s[i]`

, `s[j]`

such that i < j and `s[i]`

> `s[j]`

.

John believes that inversions are a perfect tool for estimation of how well a sequence of numbers is sorted. The smaller the number of inversions in the sequence, the better it is sorted. For example, the sequences sorted in the ascending order have zero inversions in them.

Peter gave John a stack of n cards. Each card has two numbers written on it - one in red and one in blue color. John is anxious to apply his knowledge of inversions to that stack.

He places the cards in front of him in arbitrary order and calculates the total number of nice inversions in front of him. John considers an inversion to be nice if it consists of the numbers of the same color. In our case nice inversion can be formed by either two blue or two red numbers. If the number of nice inversions is too big by John's standards, he rearranges the cards and repeats the process.

Your task is to help John find out the minimal possible number of nice inversions he can get while following his algorithm.

## Input

The first line contains one integer number n (1 ≤ n ≤ 100000) - the number of cards in the deck. The following n lines describe one card each. The i-th line contains two integer numbers `r[i]`

and `b[i]`

(1 ≤ `r[i]`

, `b[i]`

≤ `10^9`

) - the numbers written on i-th card in red and blue colors respectively.

## Output

Print the minimal possible number of nice inversions.