Given four different points in space. Find whether these points can form a square or not.
 
Example 1:
Input:
x1 = 20, y1 = 10, x2 = 10, y2 = 20, 
x3 = 20, y3 = 20, x4 = 10, y4 = 10 
Output:
Yes
Explanation:
The points (20,10), (10,20), (20,20),
(10,10) forms a square.
Example 2:
Input:
x1 = 2, y1 = 1, x2 = 10, y2 = 20, 
x3 = 5, y3 = 6, x4 = 10, y4 = 10 
Output:
No
Explanation:
The points (2,1), (10,20), (5,6),
(10,10) doesn't form a square.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function isSquare() which takes 8 Integers x1, y1, x2, y2, x3, y3, x4, and y4 as input and returns whether these points form a square.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
-10^{3} ≤ x1, y1, x2, y2, x3, y3, x4, y4 ≤ 10^{3}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
        # code here 

Solutions:
class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		a = [x1, y1, x2, y2, x3, y3, x4, y4]
		m = []
		for i in a:
			if i not in m:
				m.append(i)
		if len(m) == 2 or len(m) == 4:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		return 'Yes' if len(set([x1, y1, x2, y2, x3, y3, x4, y4])) == 2 else 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		if (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1) == (x4 - x2) * (x4 - x2) + (y4 - y2) * (y4 - y2) and (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1) != 0:
			return 'Yes'
		return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		ys = [y1, y2, y3, y4]
		top = max(ys)
		topc = [x for x in ys if x == top]
		if len(topc) != 2:
			return 'No'
		bottom = min(ys)
		bottomc = [x for x in ys if x == bottom]
		if len(bottomc) != 2:
			return 'No'
		ln = top - bottom
		xs = [x1, x2, x3, x4]
		right = max(xs)
		rightc = [x for x in xs if x == right]
		if len(rightc) != 2:
			return 'No'
		left = min(xs)
		leftc = [x for x in xs if x == left]
		if len(leftc) != 2:
			return 'No'
		if ln != right - left:
			return 'No'
		return 'Yes'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		x = set([x1, x2, x3, x4])
		y = set([y1, y2, y3, y4])
		x = list(x)
		y = list(y)
		if len(x) > 2 or len(y) > 2:
			return 'No'
		elif len(x) < 2 or len(y) < 2:
			return 'No'
		return 'Yes'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		v1 = x1 - x2
		v2 = x3 - x4
		v3 = y1 - y2
		v4 = y3 - y4
		if v1 == 0:
			return 'No'
		if abs(v1) == abs(v2) and abs(v3) == abs(v4):
			return 'Yes'
		return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		a1 = min(x1, x2, x3, x4)
		a2 = max(x1, x2, x3, x4)
		b1 = min(y1, y2, y3, y4)
		b2 = max(y1, y2, y3, y4)
		if a1 == a2:
			return 'No'
		if b1 == b2:
			return 'No'
		if x1 == a1 and x2 == a1 and (x3 == a2) and (x4 == a2):
			if y1 == b1 and y2 == b2 and (y3 == b2) and (y4 == b1):
				return 'Yes'
			if y1 == b2 and y2 == b1 and (y3 == b2) and (y4 == b1):
				return 'Yes'
			if y1 == b1 and y2 == b2 and (y3 == b1) and (y4 == b2):
				return 'Yes'
			if y1 == b2 and y2 == b1 and (y3 == b1) and (y4 == b2):
				return 'Yes'
			return 'No'
		if x1 == a1 and x2 == a2 and (x3 == a1) and (x4 == a2):
			if y1 == b1 and y2 == b2 and (y3 == b2) and (y4 == b1):
				return 'Yes'
			if y1 == b2 and y2 == b2 and (y3 == b1) and (y4 == b1):
				return 'Yes'
			if y1 == b1 and y2 == b1 and (y3 == b2) and (y4 == b2):
				return 'Yes'
			if y1 == b2 and y2 == b1 and (y3 == b1) and (y4 == b2):
				return 'Yes'
			return 'No'
		if x1 == a1 and x2 == a2 and (x3 == a2) and (x4 == a1):
			if y1 == b2 and y2 == b1 and (y3 == b2) and (y4 == b1):
				return 'Yes'
			if y1 == b2 and y2 == b2 and (y3 == b1) and (y4 == b1):
				return 'Yes'
			if y1 == b1 and y2 == b1 and (y3 == b2) and (y4 == b2):
				return 'Yes'
			if y1 == b1 and y2 == b2 and (y3 == b1) and (y4 == b2):
				return 'Yes'
			return 'No'
		if x1 == a2 and x2 == a1 and (x3 == a1) and (x4 == a2):
			if y1 == b2 and y2 == b1 and (y3 == b2) and (y4 == b1):
				return 'Yes'
			if y1 == b2 and y2 == b2 and (y3 == b1) and (y4 == b1):
				return 'Yes'
			if y1 == b1 and y2 == b1 and (y3 == b2) and (y4 == b2):
				return 'Yes'
			if y1 == b1 and y2 == b2 and (y3 == b1) and (y4 == b2):
				return 'Yes'
			return 'No'
		if x1 == a2 and x2 == a1 and (x3 == a2) and (x4 == a1):
			if y1 == b1 and y2 == b2 and (y3 == b2) and (y4 == b1):
				return 'Yes'
			if y1 == b2 and y2 == b2 and (y3 == b1) and (y4 == b1):
				return 'Yes'
			if y1 == b1 and y2 == b1 and (y3 == b2) and (y4 == b2):
				return 'Yes'
			if y1 == b2 and y2 == b1 and (y3 == b1) and (y4 == b2):
				return 'Yes'
			return 'No'
		if x1 == a2 and x2 == a2 and (x3 == a1) and (x4 == a1):
			if y1 == b1 and y2 == b2 and (y3 == b2) and (y4 == b1):
				return 'Yes'
			if y1 == b2 and y2 == b1 and (y3 == b2) and (y4 == b1):
				return 'Yes'
			if y1 == b1 and y2 == b2 and (y3 == b1) and (y4 == b2):
				return 'Yes'
			if y1 == b2 and y2 == b1 and (y3 == b1) and (y4 == b2):
				return 'Yes'
			return 'No'
		return 'No'


import math

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		d1 = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
		d2 = math.sqrt((x2 - x3) ** 2 + (y2 - y3) ** 2)
		d3 = math.sqrt((x3 - x4) ** 2 + (y3 - y4) ** 2)
		d4 = math.sqrt((x4 - x1) ** 2 + (y4 - y1) ** 2)
		d5 = math.sqrt((x1 - x3) ** 2 + (y1 - y3) ** 2)
		d6 = math.sqrt((x2 - x4) ** 2 + (y2 - y4) ** 2)
		a = set([d1, d2, d3, d4, d5, d6])
		if len(a) == 2:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		if x1 - x2 == x2 - x3:
			return 'No'
		a = (x1 - x2) ** 2 + (y1 - y2) ** 2
		b = (x3 - x2) ** 2 + (y3 - y2) ** 2
		if a == b & a != 0:
			c = (x3 - x4) ** 2 + (y3 - y4) ** 2
			d = (x1 - x4) ** 2 + (y1 - y4) ** 2
			if c == d == a:
				return 'Yes'
			return 'No'
		b = (x4 - x2) ** 2 + (y4 - y2) ** 2
		if a == b:
			c = (x3 - x4) ** 2 + (y3 - y4) ** 2
			d = (x1 - x3) ** 2 + (y1 - y3) ** 2
			if c == d == a:
				return 'Yes'
			return 'No'
		a = (x1 - x3) ** 2 + (y1 - y3) ** 2
		b = (x4 - x1) ** 2 + (y4 - y1) ** 2
		if a == b:
			c = (x3 - x2) ** 2 + (y3 - y2) ** 2
			d = (x4 - x2) ** 2 + (y2 - y4) ** 2
			if c == d == a:
				return 'Yes'
		return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		a = abs(x1 - x2)
		b = abs(x3 - x4)
		c = abs(y1 - y2)
		d = abs(y3 - y4)
		if x1 == x2 and x3 == x4 and (y1 == y2) and (y3 == y4):
			return 'No'
		if a == b and c == d:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def calc_distance(self, x1, y1, x2, y2):
		distance = (x2 - x1) ** 2 + (y2 - y1) ** 2
		return int(distance)

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		dist1 = self.calc_distance(x1, y1, x2, y2)
		dist2 = self.calc_distance(x1, y1, x3, y3)
		dist3 = self.calc_distance(x1, y1, x4, y4)
		dist4 = self.calc_distance(x2, y2, x3, y3)
		dist5 = self.calc_distance(x2, y2, x4, y4)
		dist6 = self.calc_distance(x3, y3, x4, y4)
		distances = [dist1, dist2, dist3, dist4, dist5, dist6]
		distances.sort()
		check = 0
		if distances[0] != 0 or distances[1] != 0 or distances[2] != 0 or (distances[3] != 0):
			if distances[0] == distances[1] and distances[0] == distances[2] and (distances[0] == distances[3]):
				if distances[0] * 2 == distances[4] and distances[0] * 2 == distances[5]:
					return 'Yes'
					check = 1
		if check == 0:
			return 'No'


import math

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		points = [(x1, y1), (x2, y2), (x3, y3), (x4, y4)]
		start = points[0]
		if x1 == x2 == x3 == x4 and y1 == y2 == y3 == y4:
			return 'No'
		distances = []
		for p in points[1:]:
			distances.append(math.sqrt((p[1] - start[1]) ** 2 + (p[0] - start[0]) ** 2))
		distances.sort()
		if distances[0] != distances[1]:
			return 'No'
		if distances[2] == math.sqrt(distances[0] ** 2 + distances[1] ** 2):
			return 'Yes'
		else:
			return 'No'


class Solution:

	def dist(self, n1, m1, n2, m2):
		return (n1 - n2) ** 2 + (m1 - m2) ** 2

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		if (x1 - x2) ** 2 + (y2 - y1) ** 2 == (x3 - x4) ** 2 + (y3 - y4) ** 2 and (not (x1 == x2 == x3 == x4 and y1 == y2 == y3 == y4)):
			return 'Yes'
		else:
			return 'No'


import math

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		x1_x2 = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
		x1_x3 = math.sqrt((x1 - x3) ** 2 + (y1 - y3) ** 2)
		x1_x4 = math.sqrt((x1 - x4) ** 2 + (y1 - y4) ** 2)
		x2_x3 = math.sqrt((x2 - x3) ** 2 + (y2 - y3) ** 2)
		x2_x4 = math.sqrt((x2 - x4) ** 2 + (y2 - y4) ** 2)
		x3_x4 = math.sqrt((x3 - x4) ** 2 + (y3 - y4) ** 2)
		dist = []
		dist.append(list([x1_x2, x1_x3, x1_x4]))
		dist.append(list([x1_x2, x2_x3, x2_x4]))
		dist.append(list([x1_x3, x2_x3, x3_x4]))
		dist.append(list([x1_x4, x2_x4, x3_x4]))
		for x in dist:
			mini = min(x)
			maxi = max(x)
			if maxi != math.sqrt(mini ** 2 + mini ** 2) or x.count(mini) != 2:
				return 'No'
		return 'Yes'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		sqlen12 = (x2 - x1) ** 2 + (y2 - y1) ** 2
		sqlen23 = (x2 - x3) ** 2 + (y2 - y3) ** 2
		sqlen13 = (x3 - x1) ** 2 + (y3 - y1) ** 2
		sqlen14 = (x4 - x1) ** 2 + (y4 - y1) ** 2
		sqlen24 = (x2 - x4) ** 2 + (y2 - y4) ** 2
		sqlen34 = (x3 - x4) ** 2 + (y3 - y4) ** 2
		lengths = [sqlen12, sqlen13, sqlen14, sqlen23, sqlen24, sqlen34]
		numoflength = {}
		for length in lengths:
			if length in numoflength:
				numoflength[length] += 1
			else:
				numoflength[length] = 1
		return 'Yes' if len(numoflength) == 2 else 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		if (x1 - x2) ** 2 + (y2 - y1) ** 2 == (x3 - x4) ** 2 + (y3 - y4) ** 2 and (not (x1 == x2 == x3 == x4 and y1 == y2 == y3 == y4)):
			return 'Yes'
		else:
			return 'No'


from math import sqrt

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		a = len(set([x1, y1, x2, y2, x3, y3, x4, y4]))
		if a == 2:
			return 'Yes'
		else:
			return 'No'


import math

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		t = abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))
		if t == 0:
			return 'No'
		p = abs(x2 * (y3 - y4) + x3 * (y4 - y2) + x4 * (y2 - y3))
		q = abs(x3 * (y4 - y1) + x4 * (y1 - y3) + x1 * (y3 - y4))
		r = abs(x4 * (y1 - y2) + x1 * (y2 - y4) + x2 * (y4 - y1))
		if t == p and t == q and (t == r):
			return 'Yes'
		return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		if x1 == x2 and x3 == x4 and (y1 == y2) and (y3 == y4):
			return 'No'
		elif abs(x1 - x2) == abs(x3 - x4) and abs(y1 - y2) == abs(y3 - y4):
			return 'Yes'
		else:
			return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		s1 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)
		s2 = (x1 - x4) * (x1 - x4) + (y1 - y4) * (y1 - y4)
		s3 = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2)
		s4 = (x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4)
		d1 = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)
		d2 = (x4 - x2) * (x4 - x2) + (y4 - y2) * (y4 - y2)
		x = [s1, s2, s3, s4, d1, d2]
		if len(set(x)) == 2:
			return 'Yes'
		return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		import math

		def distance(x1, y1, x2, y2):
			return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
		s = set()
		s.add(distance(x1, y1, x2, y2))
		s.add(distance(x1, y1, x3, y3))
		s.add(distance(x1, y1, x4, y4))
		s.add(distance(x2, y2, x3, y3))
		s.add(distance(x2, y2, x4, y4))
		s.add(distance(x3, y3, x4, y4))
		if len(s) == 2:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		countx = 0
		county = 0
		list = [[x1, y1], [x2, y2], [x3, y3], [x4, y4]]
		for i in range(len(list)):
			for j in range(i + 1, len(list)):
				if list[i][0] == list[j][0]:
					countx += 1
				if list[i][1] == list[j][1]:
					county += 1
		if countx == 2 and county == 2:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def f(self, x1, y1, x2, y2):
		d = x2 - x1
		e = y2 - y1
		return d * d + e * e

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		s = {}
		p = [[x1, y1], [x2, y2], [x3, y3], [x4, y4]]
		a = self.f(p[0][0], p[0][1], p[1][0], p[1][1])
		s[a] = 1
		a = self.f(p[1][0], p[1][1], p[2][0], p[2][1])
		s[a] = 1
		a = self.f(p[2][0], p[2][1], p[3][0], p[3][1])
		s[a] = 1
		a = self.f(p[3][0], p[3][1], p[0][0], p[0][1])
		s[a] = 1
		a = self.f(p[3][0], p[3][1], p[1][0], p[1][1])
		s[a] = 1
		a = self.f(p[0][0], p[0][1], p[2][0], p[2][1])
		s[a] = 1
		if len(s) != 2:
			return 'No'
		l = [0, 0]
		k = 0
		for i in s:
			l[k] = i
			k += 1
		if l[0] == l[1] * 2 or l[0] * 2 == l[1]:
			return 'Yes'
		return 'No'


import math

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		if x1 == x2 and x3 == x4 and (y1 == y2) and (y3 == y4):
			return 'No'
		elif math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) == math.sqrt((x4 - x3) ** 2 + (y4 - y3) ** 2) and math.sqrt((x3 - x2) ** 2 + (y3 - y2) ** 2) == math.sqrt((x4 - x1) ** 2 + (y4 - y1) ** 2):
			return 'Yes'
		else:
			return 'No'


class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

class Solution:

	def squaredist(self, p11, p22):
		dist = (p11.x - p22.x) ** 2 + (p11.y - p22.y) ** 2
		return dist

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		try:
			p1 = Point(x1, y1)
			p2 = Point(x2, y2)
			p3 = Point(x3, y3)
			p4 = Point(x4, y4)
			dist2 = self.squaredist(p1, p2)
			dist3 = self.squaredist(p1, p3)
			dist4 = self.squaredist(p1, p4)
			if dist2 == 0 or dist3 == 0 or dist4 == 0:
				return 'No'
			if dist2 == dist3 and dist4 == 2 * dist1 and (2 * self.squaredist(p4, p2) == self.squaredist(p3, p2)):
				return 'Yes'
			if dist2 == dist4 and dist3 == 2 * dist2 and (2 * self.squaredist(p2, p3) == self.squaredist(p2, p4)):
				return 'Yes'
			if dist3 == dist4 and dist2 == 2 * dist3 and (2 * self.squaredist(p3, p2) == self.squaredist(p3, p4)):
				return 'Yes'
			return 'No'
		except:
			return 'No'


import math

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		if len(set([x1, y1, x2, y2, x3, y3, x4, y4])) == 2:
			return 'Yes'
		else:
			return 'No'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(x1, y1, x2, y2, x3, y3, x4, y4) = map(int, input().split())
		ob = Solution()
		print(ob.isSquare(x1, y1, x2, y2, x3, y3, x4, y4))


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		if x1 == x2 == x3 == x4 == y1 == y2 == y3 == y4:
			return 'No'
		if abs(x1 - x2) == abs(x3 - x4) and abs(y1 - y2) == abs(y3 - y4):
			if x1 == x2 == x3 == x4 == y1 == y2 == y3 == y4:
				return 'No'
			else:
				return 'Yes'
		else:
			return 'No'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(x1, y1, x2, y2, x3, y3, x4, y4) = map(int, input().split())
		ob = Solution()
		print(ob.isSquare(x1, y1, x2, y2, x3, y3, x4, y4))


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		s1 = set()
		s2 = set()
		s1.add(x1)
		s1.add(x2)
		s1.add(x3)
		s1.add(x4)
		s2.add(y1)
		s2.add(y2)
		s2.add(y3)
		s2.add(y4)
		if len(s1) == 2 and len(s2) == 2:
			return 'Yes'
		return 'No'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(x1, y1, x2, y2, x3, y3, x4, y4) = map(int, input().split())
		ob = Solution()
		print(ob.isSquare(x1, y1, x2, y2, x3, y3, x4, y4))


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		prod1 = x1 * y1
		prod2 = x2 * y2
		prod3 = x3 * y3
		prod4 = x4 * y4
		if (prod1 == prod2) & (prod3 == prod4) & (prod1 == prod3):
			return 'No'
		if int(prod1 == prod2) == 1:
			if int(x3 == y3) * int(x4 == y4) == 1:
				return 'Yes'
		if int(prod1 == prod3) == 1:
			if int(x2 == y2) * int(x4 == y4) == 1:
				return 'Yes'
		if int(prod1 == prod4) == 1:
			if int(x2 == y2) * int(x3 == y3) == 1:
				return 'Yes'
		if int(prod2 == prod3) == 1:
			if int(x1 == y1) * int(x4 == y4) == 1:
				return 'Yes'
		if int(prod2 == prod4) == 1:
			if int(x1 == y1) * int(x3 == y3) == 1:
				return 'Yes'
		if int(prod3 == prod4) == 1:
			if int(x1 == y1) * int(x2 == y2) == 1:
				return 'Yes'
		else:
			return 'No'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(x1, y1, x2, y2, x3, y3, x4, y4) = map(int, input().split())
		ob = Solution()
		print(ob.isSquare(x1, y1, x2, y2, x3, y3, x4, y4))


import math

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):

		def dist(a, b, c, d):
			return (c - a) ** 2 + (d - b) ** 2
		if dist(x1, y1, x2, y2) == dist(x3, y3, x4, y4) != 0 and dist(x1, y1, x3, y3) == dist(x2, y2, x4, y4) != 0:
			return 'Yes'
		else:
			return 'No'


class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

class Solution:

	def distance(self, p, q):
		return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y)

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		p1 = Point(x1, y1)
		p2 = Point(x2, y2)
		p3 = Point(x3, y3)
		p4 = Point(x4, y4)
		d2 = self.distance(p1, p2)
		d3 = self.distance(p1, p3)
		d4 = self.distance(p1, p4)
		if d2 == 0 or d3 == 0 or d4 == 0:
			return 'No'
		if d2 == d4 and 2 * d2 == d3 and (2 * self.distance(p2, p3) == self.distance(p1, p3)):
			return 'Yes'
		if d3 == d2 and 2 * d3 == d4 and (2 * self.distance(p3, p4) == self.distance(p1, p4)):
			return 'Yes'
		if d3 == d4 and 2 * d4 == d2 and (2 * self.distance(p2, p4) == self.distance(p1, p2)):
			return 'Yes'
		return 'No'


from itertools import combinations

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		points = []
		points.append((x1, y1))
		points.append((x2, y2))
		points.append((x3, y3))
		points.append((x4, y4))
		h1 = 0
		h2 = 0
		for (p1, p2) in combinations(points, 2):
			h = self.HammingDistance(p1, p2)
			if h == 1:
				h1 += 1
			if h == 2:
				h2 += 1
		if h1 == 4 and h2 == 2:
			return 'Yes'
		return 'No'

	def HammingDistance(self, p1, p2):
		dist = 0
		if p1[0] != p2[0]:
			dist += 1
		if p1[1] != p2[1]:
			dist += 1
		return dist


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		x_values = [x1, x2, x3, x4]
		y_values = [y1, y2, y3, y4]
		distances = [(x2 - x1) ** 2 + (y2 - y1) ** 2, (x3 - x1) ** 2 + (y3 - y1) ** 2, (x4 - x1) ** 2 + (y4 - y1) ** 2]
		for distance in distances:
			if distance == 0:
				return 'No'
		if distances[0] == distances[1]:
			if distances[0] * 2 == distances[2]:
				return 'Yes'
			else:
				return 'No'
		if distances[0] == distances[2]:
			if distances[0] * 2 == distances[1]:
				return 'Yes'
			else:
				return 'No'
		if distances[1] == distances[2]:
			if distances[1] * 2 == distances[0]:
				return 'Yes'
			else:
				return 'No'
		return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		d1 = (x1 - x2) ** 2 + (y1 - y2) ** 2
		d2 = (x1 - x3) ** 2 + (y1 - y3) ** 2
		d3 = (x1 - x4) ** 2 + (y1 - y4) ** 2
		if d1 == 0 or d2 == 0 or d3 == 0:
			return 'No'
		elif d1 == d2 and 2 * d2 == d3 and ((x3 - x4) ** 2 + (y3 - y4) ** 2 == (x2 - x4) ** 2 + (y2 - y4) ** 2):
			return 'Yes'
		elif d3 == d2 and 2 * d2 == d1 and ((x3 - x2) ** 2 + (y3 - y2) ** 2 == (x4 - x2) ** 2 + (y4 - y2) ** 2):
			return 'Yes'
		elif d1 == d3 and 2 * d1 == d2 and ((x2 - x3) ** 2 + (y2 - y3) ** 2 == (x4 - x3) ** 2 + (y4 - y3) ** 2):
			return 'Yes'
		else:
			return 'No'


import math

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		a = Distance(x1, x2, y1, y2)
		b = Distance(x2, x3, y2, y3)
		c = Distance(x1, x3, y1, y3)
		if a == 0 or b == 0 or c == 0:
			return 'No'
		if a == b and a + b == c:
			return 'Yes'
		elif a == c and a + c == b:
			return 'Yes'
		elif b == c and b + c == a:
			return 'Yes'
		else:
			return 'No'

def Distance(x1, x2, y1, y2):
	return (y2 - y1) ** 2 + (x2 - x1) ** 2


import math

class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		a = math.sqrt(math.pow(x1 - x3, 2) + math.pow(y1 - y3, 2))
		b = math.sqrt(math.pow(x2 - x4, 2) + math.pow(y2 - y4, 2))
		while a != 0 and b != 0:
			if a == b:
				return 'Yes'
			else:
				return 'No'
		return 'No'


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		ans = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
		return round(ans, 2)

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		if x1 == x2 and x3 == x4 and (y1 == y2) and (y3 == y4):
			return 'No'
		dist1 = self.distance(x1, y1, x2, y2)
		dist2 = self.distance(x4, y4, x3, y3)
		dist3 = self.distance(x1, y1, x4, y4)
		dist4 = self.distance(x2, y2, x3, y3)
		if dist1 == dist2 and dist3 == dist4:
			return 'Yes'
		else:
			return 'No'


class Solution:

	def isSquare(self, x1, y1, x2, y2, x3, y3, x4, y4):
		L = []
		flag1 = False
		flag2 = False
		L.append(((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5)
		L.append(((x3 - x1) ** 2 + (y3 - y1) ** 2) ** 0.5)
		L.append(((x4 - x1) ** 2 + (y4 - y1) ** 2) ** 0.5)
		L.append(((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5)
		L.append(((x3 - x2) ** 2 + (y3 - y2) ** 2) ** 0.5)
		L.append(((x4 - x2) ** 2 + (y4 - y2) ** 2) ** 0.5)
		if L.count(L[0]) == 2 or L.count(L[0]) == 4:
			for i in range(1):
				L.remove(L[0])
				flag1 = True
		if L.count(L[0]) == 2 or L.count(L[0]) == 4:
			for i in range(1):
				L.remove(L[0])
				flag2 = True
		if flag1 == True and flag2 == True:
			return 'Yes'
		else:
			return 'No'