11179 - Interval Overlap   

Description

In this problem, we define an interval [a..b] as a continuous one-dimensional area form number a to b.

you are asked to calculate the number of interval pairs that overlap each other among a set of given intervals.  All intervals are located in a number line, and all their endpoints are integers.

Input

The first line contains one number N, where 2 <= N <= 256, standing for the number of given intervals.

Each of the following N lines describes an interval and has 2 integers separated by space, representing

  1. the coordinate of the left vertex
  2. the coordinate of the right vertex

For each interval, you may assume the coordinate of the left vertex is smaller than the one of the right vertex.

Notice that each of the 2 numbers is representable by an int type in C language.

Output

The output should contain only one number, representing the number of interval pairs that intersect to each other.

Notice that if the overlapping part is of zero length, then the pair should NOT count.

Sample Input  Download

Sample Output  Download

Tags

I2P CS 2016 Lee Mid1



Discuss