11210 - Interval Overlap: function   

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.

This problem involves three parts:

  1. 11210.c: the source file containing the main function which calls isIntersec().
  2. 11210.h: the header file which defines isIntersec() and its prototype.
  3. Your answer as a C source file, in which you should implement the isIntersec() function, and the function only.

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

Partial Judge Code

11210.c

Partial Judge Header

11210.h

Tags




Discuss