Segments
Time limit1sMemory limit128 MB
Given n disjoint vertical segments, find the maximum possible number of pairs that can see each other via an unobstructed horizontal segment.
- Level
Hard8 of 10
- Topics
- Geometry, Combinatorics, Greedy
- Solved
- No attempts yet
Problem
Consider a set of vertical segments in the plane (each segment includes its two endpoints). No two segments of have a point in common.
Two segments see each other if there is a horizontal segment that joins them and has no point in common with any other segment of .
The figure below shows an example set of segments. The pairs of segments that see each other are 1-2, 1-3, 2-3, 1-5, and 4-5. Segments 1 and 4 do not see each other.

Among all sets of exactly pairwise disjoint vertical segments, we look for the largest possible number of pairs of segments that see each other. Given , compute this maximum number of visible pairs.
Input
The only line of input contains one integer ().
Output
Print one integer: the maximum possible number of pairs of segments that can see each other, taken over all sets of pairwise disjoint vertical segments.
Hint
