14350 - 2024_DS_Summer_Exam1_pC   

Description

Given rectangle Ri, i = 1, 2, ..., n in the Euclidean plane. The lower left point and upper right point of Ri is (0, 0) and (ui, ri) repectively.

Find the number of pairs (i, j) such that Ri can be contained in Rj after rotating 90o or 0o. Formally speaking, find the number of pairs (ij) that satisfy at least one of the following conditions:

  • ui  uj and ri  rj
  • ui  rj and ri ≤ uj

For example, the following two rectangles satisfy the condition, since the blue rectangle can be contained in the red rectangle by rotating 90o (see picture on right hand side).

      

Input

The first line contains an integer n. For the next n line, each line contains two integers ui, ri, i = 1, 2, ..., n.

Constrain

  • 1  n  105
  • 1  ui, ri  109, i = 1, 2, ..., n
  • No two rectangles are identical after rotating 90o or 0o.

Output

Output one integer: the number of pairs satisfying the condition above.

Sample Input  Download

Sample Output  Download

Tags




Discuss