eolymp
bolt
Try our new interface for solving problems
Problems

Segments

Segments

Time limit 1 second
Memory limit 64 MiB

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 data

The first line contains an integer n (1n10^5). Each of the next n lines contains numbers a_i and b_i - the end points of a corresponding segment (-10^9a_i, b_i10^9).

Output data

Print the number of pairs of intersecting segments.

Examples

Input example #1
3
0 1
1 2
2 3
Output example #1
2
Input example #2
4
0 6
2 3
1 4
5 7
Output example #2
4
Source XX комплексная олимпиада "Турнир Чемпионов", Командный тур, Винница, 30 апреля 2013 г.