Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case.

Input

You are given 8 pairs of integers, a pair per line — the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide.

Output

Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers — point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct.

If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed.

Examples

Input

0 0
10 11
10 0
0 11
1 1
2 2
2 1
1 2


Output

YES
5 6 7 8
1 2 3 4


Input

0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7


Output

NO


Input

0 0
4 4
4 0
0 4
1 2
2 3
3 2
2 1


Output

YES
1 2 3 4
5 6 7 8

Note

Pay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes.

Difficulty: MEDIUM_HARD
Tags: Geometry

Mathematics

Complete search
Skill types: Complete search

Starter code:

Solutions:
from math import *

def a(x1, y1, x2, y2, x3, y3, x4, y4):
	b = sorted([[x1, y1], [x2, y2], [x3, y3], [x4, y4]])
	(x1, y1) = b[0]
	(x2, y2) = b[1]
	(x3, y3) = b[2]
	(x4, y4) = b[3]
	a1 = sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
	a2 = sqrt((x4 - x2) ** 2 + (y4 - y2) ** 2)
	a3 = sqrt((x4 - x3) ** 2 + (y4 - y3) ** 2)
	a4 = sqrt((x1 - x3) ** 2 + (y1 - y3) ** 2)
	return a1 == a2 == a3 == a4 and a1 != 0 and (a4 != 0) and (abs(abs(degrees(asin((y2 - y1) / a1) - asin((y3 - y1) / a4))) - 90) <= 10 ** (-8))

def b(x1, y1, x2, y2, x3, y3, x4, y4):
	b = sorted([[x1, y1], [x2, y2], [x3, y3], [x4, y4]])
	(x1, y1) = b[0]
	(x2, y2) = b[1]
	(x3, y3) = b[2]
	(x4, y4) = b[3]
	a1 = sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
	a2 = sqrt((x4 - x2) ** 2 + (y4 - y2) ** 2)
	a3 = sqrt((x4 - x3) ** 2 + (y4 - y3) ** 2)
	a4 = sqrt((x1 - x3) ** 2 + (y1 - y3) ** 2)
	return a1 == a3 and a2 == a4 and (a1 != 0) and (a4 != 0) and (abs(abs(degrees(asin((y2 - y1) / a1) - asin((y3 - y1) / a4))) - 90) <= 10 ** (-8))
c = [list(map(int, input().split())) for i in range(8)]
z = False
for i in range(5):
	for j in range(i + 1, 6):
		for k in range(j + 1, 7):
			for l in range(k + 1, 8):
				if a(*c[i] + c[j] + c[k] + c[l]):
					d = []
					e = []
					for m in range(8):
						if m not in [i, j, k, l]:
							d += c[m]
							e.append(m + 1)
					if b(*d):
						print('YES')
						print(i + 1, j + 1, k + 1, l + 1)
						print(*e)
						z = True
						break
			if z:
				break
		if z:
			break
	if z:
		break
if not z:
	print('NO')


from sys import stdin, stdout
from itertools import permutations as p
from itertools import combinations as com

def sqr_or_rec(a, b, c, d):
	x = (a[1] - b[1]) ** 2 + (a[0] - b[0]) ** 2
	y = (c[1] - b[1]) ** 2 + (c[0] - b[0]) ** 2
	w = (c[1] - d[1]) ** 2 + (c[0] - d[0]) ** 2
	z = (a[1] - d[1]) ** 2 + (a[0] - d[0]) ** 2
	hypo1 = (a[1] - c[1]) ** 2 + (a[0] - c[0]) ** 2
	hypo2 = (b[1] - d[1]) ** 2 + (b[0] - d[0]) ** 2
	if len(set([x, y, w, z])) == 1 and hypo1 == x + y and (hypo2 == hypo1) and (hypo2 == w + z):
		return 0
	elif len(set([x, y, w, z])) == 2 and hypo1 == x + y and (hypo2 == hypo1) and (hypo2 == w + z):
		return 1
	else:
		return -1
x = []
for i in range(8):
	(l, m) = map(int, input().split())
	x.append([l, m])
(sqr, rec) = ([], [])
for g in p(list(range(8)), 4):
	(a, b, c, d) = (x[g[0]], x[g[1]], x[g[2]], x[g[3]])
	if sqr_or_rec(a, b, c, d) == 0:
		y = sorted(g)
		if y not in sqr:
			sqr.append(y)
	elif sqr_or_rec(a, b, c, d) == 1:
		y = sorted(g)
		if y not in rec:
			rec.append(y)
if len(sqr) == 0 or (len(sqr) == 1 and len(rec) == 0):
	print('NO')
else:
	if len(sqr) >= 2:
		for q in com(sqr, 2):
			if len(set(q[0] + q[1])) == 8:
				print('YES')
				for k in sqr[0]:
					stdout.write(str(k + 1) + ' ')
				print()
				for k in sqr[1]:
					stdout.write(str(k + 1) + ' ')
				print()
				exit()
	for q in rec:
		if len(set(q + sqr[0])) == 8:
			print('YES')
			for k in sqr[0]:
				stdout.write(str(k + 1) + ' ')
			print()
			for k in q:
				stdout.write(str(k + 1) + ' ')
			print()
			exit()
	print('NO')


from itertools import combinations

def get_center(points):
	center = []
	for d in range(len(points[0])):
		c = sum((p[d] for p in points))
		center.append(c / 4)
	return tuple(center)

def all_the_same(xs):
	if len(xs) <= 1:
		return True
	(first, *ys) = xs
	return all((y == first for y in ys))

def distance(p1, p2):
	return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2

def all_distance(points):
	stack = list(points)
	distances = []
	while len(stack) > 1:
		point = stack.pop()
		distances.extend([distance(point, p) for p in stack])
	return distances

def is_rect(points):
	center = get_center(points)
	l = [distance(center, p) for p in points]
	return all_the_same(l)

def is_sqr(points):
	if not is_rect(points):
		return False
	distances = all_distance(points)
	distances.sort()
	return all_the_same(distances[:-2])

def main(points):
	idcs = list(range(0, 8))
	for group in combinations(idcs, 4):
		xs = [points[i] for i in group]
		ys = [points[i] for i in idcs if i not in group]
		if is_rect(xs) and is_rect(ys):
			if is_sqr(xs):
				print('YES')
				print(' '.join([str(i + 1) for i in group]))
				print(' '.join([str(i + 1) for i in idcs if i not in group]))
				break
			elif is_sqr(ys):
				print('YES')
				print(' '.join([str(i + 1) for i in idcs if i not in group]))
				print(' '.join([str(i + 1) for i in group]))
				break
	else:
		print('NO')
all_points = []
for _ in range(8):
	all_points.append(list(map(int, input().split())))
main(all_points)


from math import sin, pi
from copy import deepcopy

def check(a, b, c):
	liste = [[a, b, c], [b, c, a], [b, a, c]]
	for element in liste:
		(a, b, c) = element
		if (b[0] - a[0]) * (c[0] - b[0]) + (b[1] - a[1]) * (c[1] - b[1]) == 0:
			return True
	return False

def check_square(liste):
	(a, b, c) = liste
	liste = [[a, b, c], [b, c, a], [b, a, c]]
	for element in liste:
		(a, b, c) = element
		if (b[0] - a[0]) ** 2 + (b[1] - a[1]) ** 2 == (b[0] - c[0]) ** 2 + (b[1] - c[1]) ** 2:
			return True
	return False
tempo = [0 for i in range(8)]
perm = []
for i in range(5):
	tempo[i] = 1
	for j in range(i + 1, 6):
		tempo[j] = 1
		for k in range(j + 1, 7):
			tempo[k] = 1
			for l in range(k + 1, 8):
				tempo[l] = 1
				copy = deepcopy(tempo)
				perm.append(copy)
				tempo[l] = 0
			tempo[k] = 0
		tempo[j] = 0
	tempo[i] = 0
entry = []
for i in range(8):
	(x, y) = list(map(int, input().split(' ')))
	entry.append((x, y))
bool = False
for permutation in perm:
	first_set = []
	second_set = []
	for i in range(8):
		if permutation[i] == 1:
			first_set.append(entry[i])
		else:
			second_set.append(entry[i])
	(a, b, c, d) = first_set
	(w, x, y, z) = second_set
	if check(a, b, c) and check(b, c, d) and check(c, d, a):
		if check(w, x, y) and check(x, y, z) and check(y, z, w):
			if check_square(first_set[:-1]):
				bool = True
			elif check_square(second_set[:-1]):
				(first_set, second_set) = (second_set, first_set)
				bool = True
	if bool:
		break
if not bool:
	print('NO')
else:
	index_square = []
	index_rectangle = []
	for element in first_set:
		index_square.append(str(entry.index(element) + 1))
	for element in second_set:
		index_rectangle.append(str(entry.index(element) + 1))
	print('YES\n' + ' '.join(index_square) + '\n' + ' '.join(index_rectangle))


from itertools import permutations as p
l = [list(map(int, input().split())) + [_] for _ in range(1, 9)]

def dist(a, b):
	return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2

def rect(a, b, c, d):
	return dist(a, b) == dist(c, d) and dist(a, c) == dist(b, d) and (dist(a, d) == dist(b, c)) and (dist(a, b) * dist(b, c) != 0)

def sq(a, b, c, d):
	return rect(a, b, c, d) and dist(a, b) == dist(b, c)
for t in p(l):
	if sq(*t[:4]) and rect(*t[4:]):
		print('YES')
		print(' '.join([str(_[2]) for _ in t[:4]]))
		print(' '.join([str(_[2]) for _ in t[4:]]))
		exit()
print('NO')


import sys
import math
MAX = 100000000000000000000000

def is_inverse(a, b):
	if b == 0:
		return a == MAX or a == -MAX
	if a == 0:
		return b == MAX or b == -MAX
	if a == MAX or a == -MAX:
		return b == 0 or b == -0
	if b == MAX or b == -MAX:
		return a == 0 or a == -0
	return a == -(1 / b)

def slope(a, b):
	a -= 1
	b -= 1
	(y1, y2) = (pts[a][1], pts[b][1])
	(x1, x2) = (pts[a][0], pts[b][0])
	dx = x1 - x2
	dy = y1 - y2
	if dx == 0:
		return MAX
	return dy / dx

def dist(a, b):
	a -= 1
	b -= 1
	(y1, y2) = (pts[a][1], pts[b][1])
	(x1, x2) = (pts[a][0], pts[b][0])
	dx = x1 - x2
	dy = y1 - y2
	return dx ** 2 + dy ** 2

def is_valid_square(vals):
	(first, second, third, fourth) = (vals[0], vals[1], vals[2], vals[3])
	points = [first, second, third, fourth]
	for i in points:
		for j in [x for x in points if x != i]:
			for k in [z for z in points if z != i and z != j]:
				for l in [y for y in points if y != j and y != k and (y != i)]:
					if slope(i, j) == slope(k, l) and is_inverse(slope(i, k), slope(i, j)) and (dist(i, j) == dist(i, k) == dist(k, l) == dist(j, l)):
						return True
	return False

def is_valid_rectangle(vals):
	(first, second, third, fourth) = (vals[0], vals[1], vals[2], vals[3])
	points = [first, second, third, fourth]
	for i in points:
		for j in [x for x in points if x != i]:
			for k in [z for z in points if z != i and z != j]:
				for l in [y for y in points if y != j and y != k and (y != i)]:
					if slope(i, j) == slope(k, l) and is_inverse(slope(i, k), slope(i, j)) and (dist(i, j) == dist(k, l)) and (dist(i, k) == dist(j, l)):
						return True
	return False

def partition_pts(cur_set):
	if len(cur_set) == 4:
		(square_set, rect_set) = (cur_set, [x for x in range(1, 9) if x not in cur_set])
		if is_valid_square(cur_set) and is_valid_rectangle(rect_set):
			print('YES')
			(r1, r2) = ('', '')
			for x in cur_set:
				r1 += str(x) + ' '
			for x in rect_set:
				r2 += str(x) + ' '
			print(r1)
			print(r2)
			sys.exit(0)
		else:
			return
	for i in [x for x in range(1, 9) if x not in cur_set]:
		partition_pts(cur_set + [i])
pts = []
for i in range(8):
	pts.append([int(x) for x in sys.stdin.readline().split()])
partition_pts([])
print('NO')


from itertools import combinations, permutations
from math import sqrt
EPS = 1e-06

def sd(x, y):
	return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2

def is_square(points):
	for perm in permutations(points):
		if sd(perm[0], perm[1]) == sd(perm[1], perm[2]) == sd(perm[2], perm[3]) == sd(perm[3], perm[0]) and sd(perm[0], perm[2]) == 2 * sd(perm[0], perm[1]) and (sd(perm[1], perm[3]) == 2 * sd(perm[0], perm[1])) and (sqrt(sd(perm[0], perm[1])) * sqrt(sd(perm[1], perm[2])) > EPS):
			return True
	return False

def is_rect(points):
	for perm in permutations(points):
		if sd(perm[0], perm[1]) == sd(perm[2], perm[3]) and sd(perm[1], perm[2]) == sd(perm[3], perm[0]) and (sd(perm[0], perm[2]) == sd(perm[0], perm[1]) + sd(perm[1], perm[2])) and (sd(perm[1], perm[3]) == sd(perm[1], perm[2]) + sd(perm[2], perm[3])) and (sqrt(sd(perm[0], perm[1])) * sqrt(sd(perm[1], perm[2])) > EPS):
			return True
	return False
AMOUNT = 8
points = []
for _ in range(AMOUNT):
	points += [list(map(int, input().split()))]
found = False
to_choose = list(range(AMOUNT))
for for_square in combinations(to_choose, r=4):
	(square, rect) = ([], [])
	for i in range(AMOUNT):
		if i in for_square:
			square += [points[i]]
		else:
			rect += [points[i]]
	if is_square(square) and is_rect(rect):
		print('YES')
		print(' '.join(map(lambda x: str(x + 1), for_square)))
		print(' '.join(map(lambda x: str(x + 1), [y for y in range(AMOUNT) if y not in for_square])))
		found = True
		break
if not found:
	print('NO')


import itertools
import math
import os
import sys
eps = 1e-08
coord = [[]] + [list(map(int, input().split())) for _ in range(8)]
idx = list(range(1, 9))

def perpendicular(v1, v2):
	return sum([x * y for (x, y) in zip(v1, v2)]) < eps

def all_perpendicular(vs):
	return all([perpendicular(vs[i], vs[(i + 1) % 4]) for i in range(4)])

def rect_sides(vs):
	ls = list(map(lambda v: math.hypot(*v), vs))
	return abs(ls[0] - ls[2]) < eps and abs(ls[1] - ls[3]) < eps

def square_sides(vs):
	ls = list(map(lambda v: math.hypot(*v), vs))
	l = ls[0]
	for lx in ls:
		if abs(lx - l) > eps:
			return False
	return True

def coords_to_vecs(cs):
	return [[cs[(i + 1) % 4][0] - cs[i][0], cs[(i + 1) % 4][1] - cs[i][1]] for i in range(4)]

def is_square(coords):
	for p in itertools.permutations(coords):
		vs = coords_to_vecs(p)
		if all_perpendicular(vs) and square_sides(vs):
			return True
	return False

def is_rect(coord):
	for p in itertools.permutations(coord):
		vs = coords_to_vecs(p)
		if all_perpendicular(vs) and rect_sides(vs):
			return True
	return False
for comb in itertools.combinations(idx, 4):
	fsi = list(comb)
	ssi = list(set(idx) - set(comb))
	fs = [coord[i] for i in fsi]
	ss = [coord[i] for i in ssi]
	if is_square(fs) and is_rect(ss):
		print('YES')
		print(' '.join(map(str, fsi)))
		print(' '.join(map(str, ssi)))
		sys.exit(0)
	if is_square(ss) and is_rect(fs):
		print('YES')
		print(' '.join(map(str, ssi)))
		print(' '.join(map(str, fsi)))
		sys.exit(0)
print('NO')


import math
from itertools import permutations

def dist_cube(a, b):
	return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2

def area(x1, y1, x2, y2, x3, y3):
	return abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))

def in_triangle(x1, y1, x2, y2, x3, y3, x, y):
	A = area(x1, y1, x2, y2, x3, y3)
	A1 = area(x, y, x2, y2, x3, y3)
	A2 = area(x1, y1, x, y, x3, y3)
	A3 = area(x1, y1, x2, y2, x, y)
	return abs(A - (A1 + A2 + A3)) < 1e-06

class CodeforcesTask135BSolution:

	def __init__(self):
		self.result = ''
		self.points = []

	def read_input(self):
		for x in range(8):
			self.points.append([int(y) for y in input().split(' ')])

	def process_task(self):
		sol = []
		for perm in permutations([x + 1 for x in range(8)]):
			sq = []
			for p in perm[:4]:
				sq.append(self.points[p - 1])
			rc = []
			for p in perm[4:]:
				rc.append(self.points[p - 1])
			sq_dists = [dist_cube(sq[0], sq[1]), dist_cube(sq[1], sq[2]), dist_cube(sq[2], sq[3]), dist_cube(sq[3], sq[1]), dist_cube(sq[0], sq[2]), dist_cube(sq[0], sq[3])]
			rc_dists = [dist_cube(rc[0], rc[1]), dist_cube(rc[1], rc[2]), dist_cube(rc[2], rc[3]), dist_cube(rc[3], rc[1]), dist_cube(rc[0], rc[2]), dist_cube(rc[0], rc[3])]
			sq_cnt = [sq_dists.count(x) for x in list(set(sq_dists))]
			sq_cnt.sort(reverse=True)
			rc_cnt = [rc_dists.count(x) for x in list(set(rc_dists))]
			rc_cnt.sort(reverse=True)
			if len(set(sq_dists)) == 2 and sq_cnt[0] == 4 and (sq_cnt[1] == 2) and (rc_cnt == [4, 2] and 2 == len(set(rc_dists)) or (len(set(rc_dists)) == 3 and rc_cnt == [2, 2, 2])):
				if len(set(rc_dists)) == 3 and rc_cnt == [2, 2, 2]:
					do_ = False
					for j in range(4):
						rcc = rc[:j] + rc[j + 1:]
						if in_triangle(rcc[0][0], rcc[0][1], rcc[1][0], rcc[1][1], rcc[2][0], rcc[2][1], rc[j][0], rc[j][1]):
							do_ = True
							break
					if not do_:
						sol = perm
						break
				else:
					sol = perm
					break
		if sol:
			self.result = 'YES\n{0}\n{1}'.format(' '.join([str(x) for x in sol[:4]]), ' '.join([str(x) for x in sol[4:]]))
		else:
			self.result = 'NO'

	def get_result(self):
		return self.result
Solution = CodeforcesTask135BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


def L(a, b):
	return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2

def fs(a, b, c, d):
	return L(a, b) == L(b, c) == L(c, d) == L(d, a) == L(a, c) / 2

def fr(a, b, c, d):
	return L(a, b) == L(c, d) and L(b, c) == L(d, a) and (L(a, c) == L(b, d))

def gs(a, b, c, d):
	return fs(a, b, c, d) or fs(a, b, d, c) or fs(a, c, b, d)

def gr(a, b, c, d):
	return fr(a, b, c, d) or fr(a, b, d, c) or fr(a, c, b, d)

def hr(q):
	return gr(t[q[0]], t[q[1]], t[q[2]], t[q[3]])
t = [(0, 0)] + [list(map(int, input().split())) for i in range(8)]
p = {1, 2, 3, 4, 5, 6, 7, 8}
for i in range(1, 6):
	for j in range(i + 1, 7):
		for k in range(j + 1, 8):
			for l in range(k + 1, 9):
				if gs(t[i], t[j], t[k], t[l]):
					q = list(p - {i, j, k, l})
					if hr(q):
						print('YES')
						print(i, j, k, l)
						print(' '.join(map(str, q)))
						exit(0)
print('NO')