This page is still under construction.

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

Count Squares

Time limit1sMemory limit128 MB

Summary
Given up to 2000 distinct integer points, count how many squares have all four vertices among them, including tilted squares.
Level

Medium6 of 10

Topics
Geometry, Hash map, Math
Solved
No attempts yet

Problem

You are given a set of points with integer coordinates (xi,yi)(x_i, y_i) for i=1…Ni = 1 \ldots N. Count the number of squares whose four vertices are all among these points. A square may be tilted; its sides need not be parallel to the axes.

Input

The input starts with the integer NN, followed by NN pairs of integers xix_i yiy_i. Values are separated by spaces or newlines.

Output

Output a single integer: the number of squares found.

Constraints

  • −104≤xi,yi≤104-10^4 \le x_i, y_i \le 10^4, 1≤N≤20001 \le N \le 2000.
  • All points in the input are distinct.

Examples2

  1. Example 1

    Input
    4 0 0 4 3 -3 4 1 7
    
    Expected output
    1
    
  2. Example 2

    Input
    9
    1 1  1 2  1 3  
    2 1  2 2  2 3  
    3 1  3 2  3 3
    
    Expected output
    6