This page is still under construction.

Parts of this page are still being built. What you see may change.

Segments

Time limit1sMemory limit128 MB

Summary
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 SS of nn vertical segments in the plane (each segment includes its two endpoints). No two segments of SS 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 SS.

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 nn pairwise disjoint vertical segments, we look for the largest possible number of pairs of segments that see each other. Given nn, compute this maximum number of visible pairs.

Input

The only line of input contains one integer nn (1≤n≤20 0001 \le n \le 20\,000).

Output

Print one integer: the maximum possible number of pairs of segments that can see each other, taken over all sets of nn pairwise disjoint vertical segments.

Hint

Examples4

  1. Example 1

    Input
    1
    
    Expected output
    0
    
  2. Example 2

    Input
    2
    
    Expected output
    1
    
  3. Example 3

    Input
    3
    
    Expected output
    3
    
  4. Example 4

    Input
    4
    
    Expected output
    6