SP25001 CS345A1 - Red Blue Line Segments

Description

There are n vertical line segments colored red and there are n horizontal line segments colored blue. We wish to find the number of red-blue pairs of intersecting segments. ![Red Blue segments in a unit square](http://home.iitk.ac.in/~sshekh/spoj/red_blue.png "Red Blue segments in a unit square") These line segments are inside a unit square. Each blue segment is created by generating 3 random numbers (x\_1, x\_2, y) in the interval \[0, 1\]. These 3 numbers represent the segment joining (x\_1, y) and (x\_2, y). Red segments are generated similarly.

Input Format

First line contains the number of segments n (n

Output Format

Print a single line containing the number of intersections. _Note: Toucing line segments also count as intersecting. For ex - blue segment joining (0.1, 0.2) and (0.3, 0.2) intersects with red segment joining (0.3, 0.4) and (0.3, 0.2)._