This page is still under construction.

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

How many squares?

Time limit1sMemory limit256 MB

Summary
Count quadruples of the given infinite lines that form the four sides of a square.
Level

Medium6 of 10

Topics
Geometry, Hash map
Solved
No attempts yet

Problem

A quiz in a web advertisement asks how many squares a picture holds. To improve your odds of winning, you decide to write a program that counts the answer. To keep the task simple, assume the picture holds only infinite lines, not segments.

Count how many squares the lines in the picture form.

Four lines ℓ1\ell_1, ℓ2\ell_2, ℓ3\ell_3, ℓ4\ell_4 form a square when all three conditions below hold.

  • ℓ1\ell_1 and ℓ3\ell_3 are parallel.
  • ℓ2\ell_2 and ℓ4\ell_4 are perpendicular to ℓ1\ell_1 and ℓ3\ell_3, so ℓ2\ell_2 and ℓ4\ell_4 are parallel to each other.
  • The distance between ℓ1\ell_1 and ℓ3\ell_3 equals the distance between ℓ2\ell_2 and ℓ4\ell_4.

The order in which you pick the four lines does not matter, so a square made of the same four lines counts once.

Input

The first line contains the number of lines nn. (1≤n≤20001 \le n \le 2000)

Each of the next nn lines describes one line with four integers x1x_1, y1y_1, x2x_2, y2y_2. That line passes through the points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2). All four integers have absolute value at most 1000010000.

The two points describing a line are different, and the nn lines are all different from each other.

Output

Print the number of squares formed by the given lines as a single integer on one line.

Examples2

  1. Example 1

    Input
    10
    0 0 1 0
    0 1 1 1
    0 2 2 2
    0 0 0 4
    1 -1 1 0
    2 -2 2 2
    1 1 2 2
    1 1 0 2
    3 1 2 2
    1 3 0 2
    
    Expected output
    6
    
  2. Example 2

    Input
    4
    0 0 0 1
    1 0 1 5
    0 0 1 0
    0 1 5 1
    
    Expected output
    1