Problem 865
Valid Square
Medium · 20 pts · Math, Geometry
Problem
Four points are given in no particular order. Decide whether they are the corners of a square with positive side length (the square may be rotated). Compute the six squared distances between pairs of points. For a square, the four smallest are equal and positive (the sides) and the two largest are equal and twice as large (the diagonals). Using squared distances keeps everything in integers.
Input
Four lines, each with the coordinates x y of one point.
Output
Print YES if the points form a square, otherwise NO.
Constraints
-10^4 <= x, y <= 10^4
Example input
0 0 1 1 1 0 0 1
Example output
YES
Explanation
The points (0,0), (1,1), (1,0) and (0,1) have four sides of squared length 1 and two diagonals of squared length 2, so they form a square and the answer is YES.