Segments
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
n segments [a_i, b_i] are given on a coordinate line. Find the number of pairs (i, j) such that i < j and segments [a_i, b_i] and [a_j, b_j] have at least one common point.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5). Each of the next n lines contains numbers a_i and b_i - the end points of a corresponding segment (-10^9 ≤ a_i, b_i ≤ 10^9).
Output
Print the number of pairs of intersecting segments.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 75
Acceptance rate 47%