Under construction

Still being built. Things may change

Garden

Time limit3sMemory limit128 MB

Summary
Count the number of axis-aligned squares whose four corners are all points from a given set.
Level

Medium4 of 10

Topics
Hash map, Geometry, Brute force
Solved
No attempts yet

Problem

Byteen wants to plant a garden next to her house. The garden must be an axis-aligned square, that is, a square whose sides are parallel to the North-South and East-West directions. Each of the square's four corners must coincide with one of the nn apple-trees growing nearby.

Byteen inspects every possible location before choosing, and checking one location takes exactly one second. Determine how many valid garden locations there are: the number of axis-aligned squares whose four corners are all apple-trees.

Input

The first line contains the number of apple-trees nn (1≤n≤100 0001 \le n \le 100\,000). Each of the next nn lines contains two space-separated integers xix_i and yiy_i (−106≤xi,yi≤106-10^6 \le x_i, y_i \le 10^6), the coordinates of the ii-th apple-tree. No two trees share the same coordinates.

Output

Print a single integer: the number of axis-aligned squares (sides parallel to the coordinate axes) whose four corners are all apple-trees.

Examples4

  1. Example 1

    Input
    6
    0 0
    0 1
    1 0
    1 1
    3 0
    3 1
    
    Expected output
    1
    
  2. Example 2

    Input
    4
    0 0
    0 1
    1 0
    1 1
    
    Expected output
    1
    
  3. Example 3

    Input
    4
    0 0
    0 1
    2 0
    2 1
    
    Expected output
    0
    
  4. Example 4

    Input
    9
    0 0
    0 1
    0 2
    1 0
    1 1
    1 2
    2 0
    2 1
    2 2
    
    Expected output
    5