Given an array of stick lengths, use $3$ of them to construct a non-degenerate triangle with the maximum possible perimeter. Return an array of the lengths of its sides as $3$ integers in non-decreasing order.

If there are several valid triangles having the maximum perimeter: 

Choose the one with the longest maximum side. 
If more than one has that maximum, choose from them the one with the longest minimum side. 
If more than one has that maximum as well, print any one them.

If no non-degenerate triangle exists, return $\left[{-1}\right]$.

Example 

$sticks=[1,2,3,4,5,10]$   

The triplet $(1,2,3)$ will not form a triangle.  Neither will $(4,5,10)$ or $(2,3,5)$, so the problem is reduced to $(2,3,4)$ and $(3,4,5)$.  The longer perimeter is $3+4+5=12$.  

Function Description  

Complete the maximumPerimeterTriangle function in the editor below.  

maximumPerimeterTriangle has the following parameter(s):  

int sticks[n]: the lengths of sticks available   

Returns   

int[3] or int[1]:  the side lengths of the chosen triangle in non-decreasing order or -1    

Input Format

The first line contains single integer $n$, the size of array $sticks$. 

The second line contains $n$ space-separated integers $sticks[i]$, each a stick length.

Constraints

$3\leq n\leq50$
$1\leq sticks[i]\leq10^9$

Sample Input 0
5
1 1 1 3 3

Sample Output 0
1 3 3

Explanation 0

There are $2$ possible unique triangles: 

$(1,1,1)$ 
$(1,3,3)$

The second triangle has the largest perimeter, so we print its side lengths on a new line in non-decreasing order.

Sample Input 1
3
1 2 3

Sample Output 1
-1

Explanation 1

The triangle $(1,2,3)$ is degenerate and thus can't be constructed, so we print -1 on a new line.

Sample Input 2
6
1 1 1 2 3 5

Sample Output 2
1 1 1

Explanation 2

The triangle (1,1,1) is the only valid triangle.

Source: hackerrank | Difficulty: EASY
Tags: Greedy algorithms


Solutions:
from itertools import *
n = int(input())
l = sorted(map(int, input().split()))
ans = (-1, -1, -1)
for (i, j, k) in product(*repeat(range(n), 3)):
	if i < j < k and l[i] + l[j] > l[k]:
		ans = max(ans, (l[k], l[i], l[j]))
if ans[0] == -1:
	print(-1)
else:
	print(ans[1], ans[2], ans[0])


N = int(input())
L = sorted([int(n) for n in input().split()])
top = 0
for a in range(N):
	for b in range(N):
		for c in range(N):
			if a != b and a != c and (b != c):
				test = sorted([a, b, c])
				testL = [L[n] for n in test]
				if testL[0] + testL[1] > testL[2]:
					if sum(testL) > top:
						top = sum(testL)
						topl = testL
if top > 0:
	print(' '.join([str(n) for n in topl]))
else:
	print('-1')


n = int(input())
l = list(map(int, input().split()))
longest_triangle = [0, 0, 0]
longest_perim = 0
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			t = [l[i], l[j], l[k]]
			perim = sum(t)
			t.sort()
			if t[0] + t[1] > t[2]:
				if perim > longest_perim:
					longest_triangle = t
					longest_perim = perim
				elif perim == longest_perim:
					if t[2] > longest_triangle[2]:
						longest_triangle = t
						longest_perim = perim
					elif t[0] > longest_triangle[0]:
						longest_triangle = t
						longest_perim = perim
if longest_perim == 0:
	print(-1)
else:
	print(' '.join(map(str, longest_triangle)))


N = int(input())
sticks = list(map(int, input().split()))
sticks.sort()
sticks.reverse()
maximum = None
for (index, stick) in enumerate(sticks):
	if index > len(sticks) - 3:
		break
	if sticks[index + 1] + sticks[index + 2] > sticks[index]:
		maximum = (sticks[index + 2], sticks[index + 1], sticks[index])
		break
if maximum:
	print(' '.join(map(str, maximum)))
else:
	print(-1)


n = int(input())
a = list(sorted(map(int, input().split()), key=lambda x: -x))
answer = None
for i in range(len(a) - 2):
	if answer is None:
		for j in range(i + 1, len(a)):
			if answer is None:
				for k in range(j + 1, len(a)):
					if a[i] < a[j] + a[k]:
						answer = (a[i], a[j], a[k])
						break
if answer is None:
	print(-1)
else:
	print(answer[2], answer[1], answer[0])


N = int(input())
max_perimeter = 0
sticks = list(map(int, input().split()))
(A, B, C) = (-1, -1, -1)
for i in range(len(sticks)):
	for j in range(len(sticks)):
		for k in range(len(sticks)):
			if i == k or i == j or j == k:
				continue
			a = sticks[i]
			b = sticks[j]
			c = sticks[k]
			s = (a + b + c) / 2
			area = s * (s - a) * (s - b) * (s - c)
			if area < 0:
				continue
			area = area ** 0.5
			if area > 0.001:
				if a + b + c > max_perimeter:
					max_perimeter = a + b + c
					A = a
					B = b
					C = c
if not (A == -1 and B == -1 and (C == -1)):
	bT = sorted([A, B, C])
	print('{:d} {:d} {:d}'.format(bT[0], bT[1], bT[2]))
else:
	print(-1)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
m = 0
x = []
f = False
for i in range(n - 1, 1, -1):
	if l[i] + l[i - 1] > l[i - 2] and l[i] + l[i - 2] > l[i - 1] and (l[i - 1] + l[i - 2] > l[i]):
		f = True
		if m <= l[i] + l[i - 1] + l[i - 2]:
			m = l[i] + l[i - 1] + l[i - 2]
			x.append([l[i - 2], l[i - 1], l[i]])
if f == False:
	print('-1')
else:
	for i in range(3):
		print(x[len(x) - 1][i], end=' ')


def solution(ls):
	ls.sort()
	for i in range(len(ls) - 1, 1, -1):
		for j in range(i - 1, 0, -1):
			for k in range(j - 1, -1, -1):
				if ls[j] + ls[k] > ls[i]:
					return str(ls[k]) + ' ' + str(ls[j]) + ' ' + str(ls[i])
	return '-1'
n = int(input())
ls = list(map(int, input().split(' ')))
print(solution(ls))


n = int(input().strip())
arr = [int(elem) for elem in input().strip().split()]
arr = sorted(arr, reverse=True)
maxA = 0
aa = [-1]
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		for k in range(j + 1, n):
			if arr[i] < arr[j] + arr[k]:
				if arr[i] + arr[j] + arr[k] > maxA:
					maxA = arr[i] + arr[j] + arr[k]
					aa = [arr[i], arr[j], arr[k]]
print(' '.join((str(a) for a in sorted(aa))))


is_nice_triangle = lambda x, y, z: x + y > z and x + z > y and (y + z > x)
n = int(input())
nums = list(map(int, input().split(' ')))
nums.sort(reverse=True)
for i in range(0, len(nums))[:-2]:
	current = (nums[i + 2], nums[i + 1], nums[i])
	if is_nice_triangle(*current):
		print(*current)
		break
else:
	print(-1)


import sys, itertools
test = sys.stdin.readlines()
n = int(test[0])
case = list(map(lambda x: int(x), test[1].split()))
rlt = []
for i in itertools.combinations(case, 3):
	a = list(i)
	a.sort()
	if a[0] + a[1] > a[2]:
		if rlt == []:
			rlt = [a, sum(a)]
		elif sum(a) == rlt[-1]:
			if max(a) == max(rlt[0]):
				if min(a) == min(rlt[0]):
					continue
				elif min(a) > min(rlt[0]):
					rlt = [a, sum(a)]
			elif max(a) > max(rlt[0]):
				rlt = [a, sum(a)]
		elif sum(a) > rlt[-1]:
			rlt = [a, sum(a)]
if rlt == []:
	print(-1)
else:
	a = rlt[0]
	print(a[0], a[1], a[2])


size = int(input())
li = input().split(' ')
lis = [int(i) for i in li]
lis.sort(reverse=True)
sum = -1
for i in range(0, size, 1):
	for j in range(i + 1, size, 1):
		for k in range(j + 1, size, 1):
			temp = lis[i] + lis[j] + lis[k]
			if temp > sum and lis[i] < lis[j] + lis[k]:
				sum = temp
				(l1, l2, l3) = (lis[i], lis[j], lis[k])
if sum != -1:
	print(l3, l2, l1, sep=' ')
else:
	print('-1')


a = input()
total = [int(c) for c in input().split()]
total.sort(reverse=True)
maxPerim = 0
totalLen = len(total)
maxa = 0
maxb = 0
maxc = 0
for a in range(totalLen):
	aperim = total[a]
	for b in range(a + 1, totalLen):
		bperim = total[b]
		for c in range(b + 1, totalLen):
			cperim = total[c]
			if aperim + bperim > cperim and bperim + cperim > aperim and (aperim + cperim > bperim):
				perim = aperim + bperim + cperim
				if perim > maxPerim:
					maxPerim = perim
					maxa = aperim
					maxb = bperim
					maxc = cperim
				if perim == maxPerim:
					if max([maxa, maxb, maxc]) < max([aperim, bperim, cperim]):
						maxa = aperim
						maxb = bperim
						maxc = cperim
					elif max([maxa, maxb, maxc]) == max([aperim, bperim, cperim]):
						if min([maxa, maxb, maxc]) < min([aperim, bperim, cperim]):
							maxa = aperim
							maxb = bperim
							maxc = cperim
if maxPerim == 0:
	print(-1)
else:
	temp = [maxa, maxb, maxc]
	temp.sort()
	print(str(temp[0]) + ' ' + str(temp[1]) + ' ' + str(temp[2]))


def solve(ip):
	res = [-1]
	found = False
	ip.sort(reverse=True)
	for (i, a) in enumerate(ip):
		for (j, b) in enumerate(ip[i + 1:]):
			for (k, c) in enumerate(ip[i + j + 2:]):
				if a < b + c and b < a + c:
					return '{} {} {}'.format(c, b, a)
	return ''.join((str(x) for x in res))
n = int(input())
ip = list(map(int, input().split(' ')))
res = solve(ip)
print(res)


n = int(input().strip())
l = [int(t) for t in input().strip().split()]
l = sorted(l, reverse=True)
l1 = 0
while l1 < len(l) - 2:
	l2 = l1 + 1
	while l2 < len(l) - 1:
		l3 = l2 + 1
		min_l = l[l1] - l[l2]
		if l[l3] > min_l:
			print('%d %d %d' % (l[l3], l[l2], l[l1]))
			exit(0)
		else:
			l2 += 1
	l1 += 1
print(-1)


n = int(input())
sides = [int(a) for a in input().strip().split()]
ascending_sides = sorted(sides)
triangle_found = False
for i in range(n - 1, 1, -1):
	if ascending_sides[i - 2] + ascending_sides[i - 1] > ascending_sides[i]:
		triangle_found = True
		print(*ascending_sides[i - 2:i + 1])
		break
if triangle_found == False:
	print(-1)


def can_tri(a, b, c):
	if a < b + c and c < a + b and (b < a + c):
		return True
	return False

def main():
	n = int(input())
	l = sorted(list(map(int, input().split())))
	ans = None
	max_num = -1
	ans_pair = -1
	for i in range(n):
		for j in range(i + 1, n):
			if i == j:
				continue
			for k in range(j + 1, n):
				if i == k or k == j:
					continue
				if can_tri(l[i], l[k], l[j]) and max_num < l[i] + l[k] + l[j]:
					max_num = l[i] + l[k] + l[j]
					tmp = sorted([l[i], l[k], l[j]])
					ans = sorted([l[i], l[k], l[j]])
					ans_pair = '{} {} {}'.format(tmp[0], tmp[1], tmp[2])
				elif max_num == l[i] + l[k] + l[j]:
					if sorted([l[i], l[k], l[j]])[0] > ans[0]:
						tmp = sorted([l[i], l[k], l[j]])
						ans = sorted([l[i], l[k], l[j]])
						ans_pair = '{} {} {}'.format(tmp[0], tmp[1], tmp[2])
	print(ans_pair)
main()


from itertools import combinations

def get_best_2(r):
	m = 0
	current = []
	for i in r:
		mn = min(i)
		if mn > m:
			m = mn
			current = i
	return sorted(current)

def get_best(r):
	m = 0
	current = []
	for i in r:
		mx = max(i)
		if mx > m:
			m = mx
			current = [i]
		if mx == m:
			current.append(i)
	return get_best_2(current)

def is_valid(a, b, c):
	return a + b > c and b + c > a and (c + a > b)
n = int(input())
L = [int(i) for i in input().split(' ')]
combos = combinations(L, 3)
max_side_length = -1
result = []
for c in combos:
	if is_valid(*c):
		s = sum(c)
		if s > max_side_length:
			max_side_length = s
			result = [c]
		if s == max_side_length:
			result.append(c)
result = get_best(result)
if max_side_length == -1:
	print(max_side_length)
print(*result)


n = int(input().strip())
arr = [int(i) for i in input().strip().split(' ')]

def tri(arr, n):
	length = len(arr)
	i = length - 3
	while i >= 0:
		if arr[i] > arr[i + 2] - arr[i + 1] and arr[i + 2] < arr[i + 1] + arr[i]:
			return str(arr[i]) + ' ' + str(arr[i + 1]) + ' ' + str(arr[i + 2])
		i -= 1
	return -1
a = sorted(arr)
print(tri(a, n))


n = int(input())
l = [int(item) for item in input().split(' ')]
l.sort()
per = 0
tri = []
for i in range(n - 2):
	k = l[i] + l[i + 1]
	if k > l[i + 2]:
		s = k + l[i + 2]
		if s > per:
			per = s
			tri = l[i:i + 3]
if per == 0:
	print(-1)
else:
	print(' '.join(map(str, tri)))


from itertools import combinations

def is_invalid_triangle(a, b, c):
	return a + b <= c or b + c <= a or c + a < b

def find_max_triangle(sides):
	triangles = [triangle_sides for triangle_sides in combinations(sides, 3) if not is_invalid_triangle(*triangle_sides)]
	if len(triangles) == 0:
		return []
	perimeters = [sum(triangle_sides) for triangle_sides in triangles]
	max_perimeter = max(perimeters)
	results = [triangle_sides for (perimeter, triangle_sides) in zip(perimeters, triangles) if perimeter == max_perimeter]
	if len(results) == 1:
		return results
	longest_sides = [max(triangle_sides) for triangle_sides in results]
	max_longest_side = max(longest_sides)
	results = [result for (result, longest_side) in zip(results, longest_sides) if longest_side == max_longest_side]
	if len(results) == 1:
		return results
	shortest_sides = [min(triangle_sides) for triangle_sides in results]
	max_shortest_side = max(shortest_sides)
	results = [result for (result, shortest_side) in zip(results, shortest_sides) if shortest_side == max_shortest_side]
	return results
N = int(input())
sides = sorted([int(side) for side in input().split()])
results = find_max_triangle(sides)
if results:
	print('{0} {1} {2}'.format(*results[0]))
else:
	print('-1')


n = int(input())
l = list(map(int, input().split()))
bestp = 0
best = (0, 0, 0)
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			(a, b, c) = (l[i], l[j], l[k])
			if not (a + b > c and a + c > b and (b + c > a)):
				continue
			if a + b + c > bestp:
				bestp = a + b + c
				best = (a, b, c)
print(-1 if bestp == 0 else ' '.join(map(str, sorted(list(best)))))


from operator import itemgetter
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a.reverse()
l = []
longest = 0
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		for k in range(j + 1, n):
			if a[j] + a[k] > a[i]:
				if a[i] + a[j] + a[k] == longest:
					l.append([a[i], a[j], a[k]])
				elif a[i] + a[j] + a[k] > longest:
					l = []
					l.append([a[i], a[j], a[k]])
					longest = a[i] + a[j] + a[k]
if l != []:
	l.sort(key=itemgetter(0))
	l.reverse()
	temp = []
	prev = l[0][0]
	for i in l:
		if i[0] == prev:
			temp.append(i)
		else:
			break
	temp.sort(key=itemgetter(2))
	temp.reverse()
	print(' '.join(map(str, [temp[0][2], temp[0][1], temp[0][0]])))
else:
	print('-1')


def triangulo(A):
	A.sort(reverse=True)
	a = b = c = 0
	for i in range(n - 2):
		a = A[i]
		for j in range(i + 1, n - 1):
			b = A[j]
			for k in range(j + 1, n):
				c = A[k]
				if a < b + c and c > a - b:
					return (a, b, c)
	return (-1, -1)
n = int(input())
A = list(map(int, input().split()))
aristas = triangulo(A)
if len(aristas) == 3:
	aux = [str(i) for i in aristas]
	aux.reverse()
	print(' '.join(aux))
else:
	print(-1)


def isTriangle(a, b, c):
	if a + b > c and a + c > b and (b + c > a):
		return True
	else:
		return False
inputs = []
num_input = int(input())
all_size = input().split(' ')
for i in all_size:
	inputs.append(int(i))
inputs.sort()
triangle = []
found = False
inputs.reverse()
for i in range(len(inputs)):
	a = inputs[i]
	for j in range(i + 1, len(inputs)):
		b = inputs[j]
		for k in range(j + 1, len(inputs)):
			c = inputs[k]
			if isTriangle(a, b, c):
				triangle = [a, b, c]
				found = True
				break
		if found:
			break
	if found:
		break
if found:
	print(str(triangle[2]) + ' ' + str(triangle[1]) + ' ' + str(triangle[0]))
else:
	print(-1)


N = int(input())
L = list(map(int, input().split()))
L = sorted(L)[::-1]
if L[0] - L[1] >= L[2]:
	ans = -1
	while len(L) > 2:
		if L[0] - L[1] < L[2]:
			ANS = L[0:3][::-1]
			ans = ' '.join((str(x) for x in ANS))
			break
		L.pop(0)
	print(ans)
else:
	ANS = L[0:3][::-1]
	print(' '.join((str(x) for x in ANS)))


import itertools

def isDegenerate(a):
	lines = sorted(list(a[0]), reverse=True)
	check = lines[0] - lines[1] - lines[2]
	if check >= 0:
		return True
	else:
		return False

def solve(n, l):
	a = set(itertools.combinations(l, 3))
	d = {}
	for i in a:
		d[i] = sum(i)
	s = sorted(d.items(), key=lambda x: (x[1], max(x[0]), min(x[0])), reverse=True)
	s = list(filter(lambda x: not isDegenerate(x), s))
	if len(s) > 0:
		print(*sorted(s[0][0]))
	else:
		print(-1)
n = int(input())
l = list(map(int, input().split()))
solve(n, l)


import heapq
n = int(input())
a = [int(i) for i in input().split(' ')]
sol = 0
t1 = [0, 0, 0]
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			peri = a[i] + a[j] + a[k]
			maxside = max(a[i], a[j], a[k])
			rem = peri - maxside
			if maxside < rem:
				if peri >= sol:
					sol = peri
					t2 = [a[i], a[j], a[k]]
					if max(t1) < max(t2) or (max(t1) == max(t2) and min(t1) < min(t2)):
						t1 = t2
if sum(t1) != 0:
	print(' '.join((str(i) for i in sorted(t1))))
else:
	print('-1')


n = int(input())
ans = -1
use = '-1'
l = list(map(int, input().split()))
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		for k in range(n):
			if k == i or k == j:
				continue
			if l[i] >= l[j] + l[k] or l[j] >= l[i] + l[k] or l[k] >= l[i] + l[j]:
				continue
			elif l[i] + l[j] + l[k] > ans:
				ans = max(ans, l[i] + l[j] + l[k])
				use = ' '.join(list(map(str, list(sorted([l[i], l[j], l[k]])))))
print(use)


n = int(input())
m = list(map(int, input().split()))

def big_tri(arr):
	arr.sort(reverse=True)
	i = 0
	tri = -1
	while i < len(arr) - 2:
		if arr[i + 1] + arr[i + 2] > arr[i]:
			tri = [arr[i + 2], arr[i + 1], arr[i]]
			break
		i += 1
	return tri
ans = big_tri(m)
if ans == -1:
	print(ans)
else:
	print(*ans, sep=' ')


n = eval(input())
line = input()
L = []
for element in line.split():
	L.append(int(element))
s = 0
l = []
L = sorted(L)
for i in range(n - 2):
	for j in range(i + 1, n - 1, 1):
		for k in range(j + 1, n, 1):
			if L[i] + L[j] > L[k]:
				s = L[i] + L[j] + L[k]
				l = [L[i], L[j], L[k]]
if s == 0:
	print('-1')
else:
	print(l[0], l[1], l[2])


import math
n = int(input().strip())
sides = [int(a) for a in input().strip().split()]
sides.sort()
answer = []
for (idx, s1) in enumerate(sides):
	if idx == len(sides) - 2:
		break
	for (idx2, s2) in enumerate(sides[idx + 1:]):
		for s3 in sides[idx + 1 + idx2 + 1:]:
			if s3 < s1 + s2:
				if not answer or s1 + s2 + s3 > answer[0] + answer[1] + answer[2]:
					answer = [s1, s2, s3]
				elif s1 + s2 + s3 == answer[0] + answer[1] + answer[2]:
					if s3 > answer[2]:
						answer = [s1, s2, s3]
					elif s3 == answer[2]:
						if s1 > answer[0]:
							answer = [s1, s2, s3]
if not answer:
	print(-1)
else:
	print(str(answer[0]) + ' ' + str(answer[1]) + ' ' + str(answer[2]))


n = int(input().strip())
a = [int(x) for x in input().strip().split()]
a.sort()
perimeter = 0
lmax = 0
lmin = 0
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		for k in range(j + 1, n):
			(x, y, z) = (a[i], a[j], a[k])
			(s1, s2, s3) = (x ** 2 + y ** 2 - z ** 2, y ** 2 + z ** 2 - x ** 2, z ** 2 + x ** 2 - y ** 2)
			(b1, b2, b3) = (2 * x * y, 2 * y * z, 2 * z * x)
			newtri = False
			if -b1 < s1 and s1 < b1 and (-b2 < s2) and (s2 < b2) and (-b3 < s3) and (s3 < b3):
				if x + y + z > perimeter:
					newtri = True
				elif x + y + z == perimeter:
					if max(x, y, z) > lmax:
						newtri = True
					elif max(x, y, z) == lmax:
						if min(x, y, z) > lmin:
							newtri = True
			if newtri:
				lmax = max(x, y, z)
				lmin = min(x, y, z)
				perimeter = x + y + z
				(x0, y0, z0) = (x, y, z)
if perimeter == 0:
	print(-1)
else:
	print(x0, y0, z0)


def main():
	longest = [0, 0, 0]
	n = int(input())
	if n < 3:
		print(-1)
		return
	sides = [int(i) for i in input().split()]
	triangle = [0, 0, 0]
	for i in range(n - 2):
		a = sides[i]
		if a < longest[0]:
			continue
		for j in range(i + 1, n - 1):
			b = sides[j]
			if b < longest[0]:
				continue
			for k in range(j + 1, n):
				c = sides[k]
				if c < longest[0]:
					continue
				current = [a, b, c]
				(x, y, z) = current = sorted(current)
				if z >= x + y:
					continue
				p = x + y + z
				if p > sum(triangle):
					triangle = current
				elif p == sum(triangle):
					if z > triangle[2]:
						triangle = current
					elif z == triangle[2]:
						if x > triangle[0]:
							triangle = current
	if triangle == [0, 0, 0]:
		print(-1)
	else:
		print(' '.join([str(i) for i in triangle]))
main()


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
i = 0
j = 1
k = 2
ans = ''
while k < n:
	if l[i] < l[j] + l[k]:
		ans = str(l[k]) + ' ' + str(l[j]) + ' ' + str(l[i])
		break
	elif i + 1 == j:
		i += 1
		if j + 1 == k:
			j += 1
			k += 1
		else:
			j += 1
	else:
		i += 1
print(-1 if len(ans) == 0 else ans)


import sys

def find_max_perimeter(m):
	for i in range(len(m) - 2):
		for j in range(i + 1, len(m) - 1):
			for k in range(j + 1, len(m)):
				if m[i] < m[k] + m[j]:
					return [m[k], m[j], m[i]]
	return [-1]
n = sys.stdin.readline()
m = [int(x) for x in sys.stdin.readline().split()]
print(' '.join([str(x) for x in find_max_perimeter(sorted(m)[::-1])]))


n = int(input())
l = sorted([int(x) for x in input().split()], reverse=True)
for x in range(n - 2):
	temp = l[x:x + 3]
	if temp[0] < temp[1] + temp[2]:
		print(*reversed(temp))
		break
else:
	print(-1)


from itertools import combinations
n = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)

def solve():
	possibles = list(combinations(l, 3))
	for possible in possibles:
		(x, y, z) = map(int, possible)
		if (x + y - z) * (y + z - x) * (z + x - y) > 0:
			print(*sorted([x, y, z]), sep=' ')
			return
	print(-1)
solve()


def solve(arr):
	temp = arr[-3:]
	while len(arr) >= 3:
		if temp[0] + temp[1] > temp[2]:
			return temp
		else:
			arr.pop()
			temp = arr[-3:]
	return [-1]
n = int(input())
arr = sorted(map(int, input().split()))
print(*solve(arr))


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
m = 0
res = []
for i in range(len(a) - 2):
	for j in range(i + 1, len(a) - 1):
		for k in range(j + 1, len(a)):
			if a[i] < a[j] + a[k]:
				if a[i] + a[j] + a[k] > m:
					m = a[i] + a[j] + a[k]
					res = [a[i], a[j], a[k]]
res.sort()
if m == 0:
	print(-1)
else:
	print(*res)


n = int(input().strip())
l = list(map(int, input().strip().split(' ')))
l.sort(reverse=True)

def perimeterAux(arr, n):
	if n < 3:
		return -1
	for i in range(n - 2):
		if arr[i] < arr[i + 1] + arr[i + 2]:
			return i
	return -1

def perimeter(arr, n):
	i = perimeterAux(arr, n)
	if i == -1:
		print(-1)
	else:
		print(arr[i + 2], arr[i + 1], arr[i])
perimeter(l, n)


from itertools import combinations
import math
from operator import itemgetter

def herons(a, b, c):
	s = (a + b + c) / 2
	if s * (s - a) * (s - b) * (s - c) > 0:
		return math.sqrt(s * (s - a) * (s - b) * (s - c))
possible = []
n = int(input())
sides = list(map(int, input().split()))
for elem in list(combinations(sides, 3)):
	if herons(elem[0], elem[1], elem[2]) and (elem[0], elem[1], elem[2]) not in possible:
		possible.append(elem)
if not possible:
	print(-1)
else:
	for j in range(len(possible)):
		possible[j] = (possible[j], sum(possible[j]))
	possible = sorted(possible, key=itemgetter(1))
	ans = sorted(list(possible[-1][0]))
	print(ans[0], ans[1], ans[2])


from itertools import combinations, permutations
n = int(input())
s = [int(i) for i in input().strip().split()]

def isTri(t):
	return all((tp[0] + tp[1] > tp[2] for tp in permutations(t, 3)))

def triSortKey(t):
	return (sum(t), min(t))
try:
	maxtri = max((t for t in combinations(s, 3) if isTri(t)), key=triSortKey)
	print(' '.join((str(i) for i in sorted(maxtri))))
except ValueError:
	print(-1)


def is_triangle(a, b, c):
	return a + b > c and a + c > b and (b + c > a)

def find_max(a):
	for i in range(n):
		for j in range(n):
			for k in range(n):
				if i != j and i != k and (j != k) and is_triangle(a[i], a[j], a[k]):
					return ' '.join(map(str, sorted([a[i], a[j], a[k]])))
	return -1
n = int(input())
sticks = list(map(int, input().split(' ')))
sticks.sort(reverse=True)
print(find_max(sticks))


nsticks = int(input())
sticks = sorted([int(x) for x in input().split(' ')], reverse=True)

def largest_triangle(sticks):
	for (i, s) in enumerate(sticks[:-2]):
		if s < sticks[i + 1] + sticks[i + 2]:
			return '{} {} {}'.format(sticks[i + 2], sticks[i + 1], s)
	return '-1'
print(largest_triangle(sticks))


from itertools import combinations
n = int(input())
l = [int(x) for x in input().split()]
combs = combinations(range(n), 3)
elems = []
for c in combs:
	elems.append(sorted([l[c[0]], l[c[1]], l[c[2]]]))
sols = []
for (x, y, z) in elems:
	if x + y > z and x + z > y and (y + z > x):
		sols.append((x, y, z))
sols.sort()
print(*(sols[-1] if sols != [] else [-1]), sep=' ')


import sys
n = input()
l = list(map(int, input().split()))
l.sort()
res = list()
for i in range(0, int(n) - 2):
	if l[i] + l[i + 1] > l[i + 2]:
		res = [l[i], l[i + 1], l[i + 2]]
if res:
	print(' '.join(map(str, res)))
else:
	print(-1)


import sys
import operator
from itertools import combinations
n = input().strip().split(' ')
num = [int(num_temp) for num_temp in input().strip().split(' ')]
num.sort(reverse=True)
(i, j, k) = (0, 0, 0)
tri_lst = []
tri_lst_s = []
current_max = 0
coms = list(combinations(num, 3))
for tris in coms:
	i = tris[0]
	j = tris[1]
	k = tris[2]
	summ = i + j + k
	if (i + j > k and j + k > i and (k + i > j)) and summ >= current_max:
		current_max = summ
		tri_lst.append(sorted([i, j, k], reverse=True))
if len(tri_lst):
	tri_lst.sort(key=sum)
	tri_lst_s = tri_lst[::-1]
	if len(tri_lst_s) > 1:
		max = 0
		max_lst = []
		min_lst = []
		for x in tri_lst_s:
			if x[0] >= max:
				max_lst.append(x)
				max = x[0]
		if len(max_lst) > 1:
			min = max
			for x in tri_lst_s:
				if x[2] <= min:
					min_lst.append(x)
					min = x[2]
			if len(min_lst) > 1:
				tri_lst_s[0].sort()
				print(*tri_lst_s[0])
			else:
				min_lst.sort()
				print(*min_lst)
		else:
			max_lst.sort().sort()
			print(*max_lst)
	else:
		tri_lst_s[0].sort()
		print(*tri_lst_s[0])
else:
	print(-1)


n = int(input())
a = [int(arr_temp) for arr_temp in input().strip().split(' ')]
a.sort()
s1 = 0
s2 = 0
s3 = 0
sum2 = 0
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		sum2 = a[i] + a[j]
		for k in range(j + 1, n):
			if sum2 <= a[k]:
				break
			if s1 + s2 + s3 == sum2 + a[k]:
				if s3 < a[k]:
					(s1, s2, s3) = [a[i], a[j], a[k]]
				if s3 == a[k]:
					if s1 < a[k]:
						(s1, s2, s3) = [a[i], a[j], a[k]]
			if s1 + s2 + s3 <= sum2 + a[k]:
				(s1, s2, s3) = [a[i], a[j], a[k]]
if s1 == 0:
	print(-1)
else:
	print(s1, s2, s3)


from itertools import combinations
from collections import defaultdict
input()
l = sorted(map(int, input().split()), reverse=True)
d = defaultdict(list)
triangles = list(combinations(l, 3))
for t in triangles:
	d[sum(t)].append(t)
for sum_ in sorted(d.keys(), reverse=True):
	aux = [t for t in d[sum_] if t[1] + t[2] > t[0]]
	if aux:
		print(*sorted(aux[0]), sep=' ')
		break
else:
	print(-1)


from itertools import combinations
input()

def f(a, b, c):
	if a >= b + c or b >= a + c or c >= a + b:
		return -1
	return a + b + c
best = -1
R = (-1,)
for c in combinations((int(x) for x in input().split()), 3):
	r = f(*c)
	if best < r:
		best = r
		R = c
print(' '.join((str(x) for x in sorted(R))))


def isTriangle(x, y, z):
	length_list = [x, y, z]
	length_list.sort()
	if length_list[0] + length_list[1] > length_list[2]:
		return True
	else:
		return False

def maxPerim(arr):
	for i in range(len(arr) - 2):
		if isTriangle(arr[i], arr[i + 1], arr[i + 2]):
			return [arr[i + 2], arr[i + 1], arr[i]]
	return -1
n = int(input())
l = [int(temp) for temp in input().split(' ')]
l.sort(reverse=True)
output = maxPerim(l)
if output == -1:
	print(-1)
else:
	for elem in output:
		print(elem, end=' ')


input()
ll = list(map(int, input().strip().split()))
ll.sort(reverse=True)
foundSolution = False
for i in range(len(ll) - 2):
	if ll[i] < ll[i + 1] + ll[i + 2]:
		print(ll[i + 2], ll[i + 1], ll[i])
		foundSolution = True
		break
if not foundSolution:
	print(-1)


N = int(input())
ar = [int(i) for i in input().split(' ')]
d = 0
c = max(ar)
ar.remove(max(ar))
b = max(ar)
ar.remove(max(ar))
for i in range(N - 2):
	a = max(ar)
	ar.remove(a)
	if b + a > c:
		d = 1
		break
	else:
		c = b
		b = a
if d == 1:
	print(a, b, c, sep=' ')
else:
	print('-1')


n = eval(input())
t = []
a = sorted([int(x) for x in input().split()], reverse=True)
for i in range(n - 2):
	if a[i] < a[i + 1] + a[i + 2]:
		t = reversed([str(x) for x in a[i:i + 3]])
		break
print(' '.join(t) if t else -1)


from itertools import combinations

def is_degenerated(sides):
	degenerated = False
	for i in range(3):
		if sides[i] >= sum(sides[:i]) + sum(sides[i + 1:]):
			degenerated = True
	return degenerated
input()
sticks = [int(x) for x in input().split()]
result = (0, 0, 0)
for case in combinations(sticks, 3):
	if is_degenerated(case):
		continue
	if sum(case) > sum(result):
		result = case
	elif sum(case) == sum(result):
		if max(case) > max(result):
			result = case
		elif max(case) == max(result):
			if min(case) > min(result):
				result = case
if result == (0, 0, 0):
	print(-1)
else:
	print(*sorted(result), sep=' ')


n = int(input())
sticks = [int(i) for i in input().split(' ')]
lens = sorted(sticks, reverse=True)

def func(a):
	if len(a) <= 2:
		print(-1)
		return
	if a[1] + a[2] > a[0]:
		print('%s %s %s' % (a[2], a[1], a[0]))
		return
	else:
		func(a[1:])
func(lens)


n = int(input().strip())
sides = [int(x) for x in input().split(' ')]
sides.sort(reverse=True)
per = ()
longPer = 0

def isTriange(t):
	if t[0] + t[1] > t[2] and t[0] + t[2] > t[1] and (t[1] + t[2] > t[0]):
		return True
	else:
		return False
if n > 2:
	for i in range(len(sides) - 2):
		t = (sides[i], sides[i + 1], sides[i + 2])
		if isTriange(t):
			curPer = sum(t)
			if longPer < curPer:
				longPer = curPer
				per = t
if longPer == 0:
	print(-1)
else:
	print(' '.join(map(str, sorted(per))))


n = int(input()) - 3
sticks = sorted(list(map(int, input().split())))
while n > -1:
	if sticks[n] + sticks[n + 1] > sticks[n + 2]:
		break
	n -= 1
print(int(n) if n < 0 else ' '.join(map(str, sticks[n:n + 3])))


n = int(input())
l = [int(t) for t in input().strip().split()]
l = sorted(l, reverse=True)
for i in range(n - 2):
	if l[i] < l[i + 1] + l[i + 2]:
		break
if l[i] < l[i + 1] + l[i + 2]:
	print(l[i + 2], l[i + 1], l[i])
else:
	print(-1)


n = int(input().strip())
ar = [int(a) for a in input().strip().split(' ')]
ar.sort()
a = False
for i in range(len(ar) - 1, 1, -1):
	if a == False and ar[i] < ar[i - 1] + ar[i - 2]:
		print(ar[i - 2], ar[i - 1], ar[i])
		a = True
if a == False:
	print('-1')


n = int(input())
edges = sorted(list(map(int, input().split())), reverse=True)
res = -1
for x in range(0, n - 2):
	if edges[x] < edges[x + 1] + edges[x + 2]:
		res = x
		break
if res == -1:
	print(-1)
else:
	print(edges[x + 2], edges[x + 1], edges[x])


import math
from itertools import permutations
n = int(input())
arr = [int(temp_arr) for temp_arr in input().split(' ')]
possible_triangles = list(set(permutations(arr, 3)))
triangles = []
for pos in possible_triangles:
	pos = list(sorted(pos))
	if pos[2] < pos[1] + pos[0]:
		triangles.append(pos)
if len(triangles) == 0:
	print(-1)
else:
	(max_val, max_ind) = (0, 0)
	for (i, tri) in enumerate(triangles):
		if sum(tri) > max_val:
			max_val = sum(tri)
			max_ind = i
	res = [str(tri) for tri in triangles[max_ind]]
	print(' '.join(res))


def checktriangle(a, b, c):
	if a + b <= c:
		return -1
	elif a + c <= b:
		return -1
	elif b + c <= a:
		return -1
	return a + b + c
n = int(input().strip())
arr = [int(x) for x in input().strip().split()]
arr.sort(reverse=True)
flag = 0
(a, b, c) = (arr[0], arr[1], arr[2])
cind = 2
aind = 0
bind = 1
while flag == 0:
	r = checktriangle(a, b, c)
	if r == -1:
		if cind == n - 1:
			if bind == n - 2:
				if aind == n - 3:
					print('-1')
					flag = 1
				else:
					aind += 1
					bind = aind + 1
					cind = bind + 1
					a = arr[aind]
					b = arr[bind]
					c = arr[cind]
			else:
				bind += 1
				cind = bind + 1
				b = arr[bind]
				c = arr[cind]
		else:
			cind += 1
			c = arr[cind]
	else:
		print(str(c) + ' ' + str(b) + ' ' + str(a))
		flag = 1


N = int(input().strip())
s = [int(x) for x in input().strip().split(' ')]
s.sort(reverse=True)
for i in range(N - 2):
	if s[i] < s[i + 1] + s[i + 2]:
		if s[i + 1] < s[i] + s[i + 2]:
			if s[i + 2] < s[i + 1] + s[i]:
				print(s[i + 2], s[i + 1], s[i])
				break
else:
	print(-1)


n = int(input().strip())
lengths = sorted([int(i) for i in input().strip().split(' ')])
one_side = lengths[0]
two_side = lengths[1]
third_side = lengths[2]
largest = 0
for i in range(len(lengths) - 2):
	for k in range(i + 1, len(lengths) - 1):
		for j in range(k + 1, len(lengths)):
			if lengths[i] <= lengths[k] <= lengths[j] and lengths[i] + lengths[k] > lengths[j]:
				if lengths[i] + lengths[k] + lengths[j] > largest:
					largest = lengths[i] + lengths[k] + lengths[j]
					one_side = lengths[i]
					two_side = lengths[k]
					third_side = lengths[j]
			elif lengths[k] <= lengths[j] <= lengths[i] and lengths[j] + lengths[k] > lengths[i]:
				if lengths[i] + lengths[k] + lengths[j] > largest:
					largest = lengths[i] + lengths[k] + lengths[j]
					one_side = lengths[i]
					two_side = lengths[k]
					third_side = lengths[j]
			elif lengths[j] <= lengths[i] <= lengths[k] and lengths[j] + lengths[i] > lengths[k]:
				if lengths[i] + lengths[k] + lengths[j] > largest:
					largest = lengths[i] + lengths[k] + lengths[j]
					one_side = lengths[i]
					two_side = lengths[k]
					third_side = lengths[j]
if one_side + two_side <= third_side:
	print(-1)
else:
	print('%d %d %d' % (one_side, two_side, third_side))


import itertools

def calc_triangle_perim(sides):
	return sum(sides)

def check_valid_triangle(sides):
	for side in sides:
		other_sides = sum(sides) - side
		if side > other_sides:
			return False
		elif side == other_sides:
			return False
	else:
		return True

def find_all_combs(s):
	return set(list(itertools.combinations(s, 3)))
n = int(input())
s = input()
s = s.split()
for i in range(len(s)):
	s[i] = int(s[i])
sides = find_all_combs(s)
valid = []
for i in sides:
	if check_valid_triangle(list(i)):
		valid.append(sorted(i))
max_triangle = ''
if len(valid) == 0:
	print('-1')
if len(valid) == 1:
	t = valid[0]
	for i in range(len(t)):
		max_triangle += str(t[i]) + ' '
	print(max_triangle)
if len(valid) > 1:
	max_ = 0
	max_idx = 0
	for i in range(len(valid)):
		if calc_triangle_perim(valid[i]) > max_:
			max_ = calc_triangle_perim(valid[i])
			max_idx = i
	t = valid[max_idx]
	for i in range(len(t)):
		max_triangle += str(t[i]) + ' '
	print(max_triangle)


def check_tri(a, b, c):
	valid = False
	if a + b > c and a + c > b and (c + b > a):
		valid = True
	return valid
input()
ls = [int(x) for x in input().split()]
max_lengths = (0, 0, 0)
import itertools
for subset in itertools.combinations(ls, 3):
	if sum(subset) > sum(max_lengths) and check_tri(subset[0], subset[1], subset[2]):
		max_lengths = subset
		P = sum(max_lengths)
	elif sum(subset) == sum(max_lengths) and check_tri(subset[0], subset[1], subset[2]):
		if max(subset) > max(max_lengths):
			max_lengths = subset
			P = sum(max_lengths)
		elif max(subset) == max(max_lengths) and min(subset) > min(max_lengths):
			max_lengths = subset
			P = sum(max_lengths)
if sum(max_lengths) > 0:
	ls = sorted(max_lengths)
	for e in ls:
		print(e, end=' ')
else:
	print(-1)


(n, sticks) = (int(input()), sorted(map(int, input().strip().split())))
found = False
for i in range(len(sticks) - 3, -1, -1):
	if sticks[i] + sticks[i + 1] > sticks[i + 2]:
		print(*sticks[i:i + 3], sep=' ')
		found = True
		break
if not found:
	print(-1)


n = int(input())
sticks = [int(data) for data in input().strip().split()]
sticks.sort(reverse=True)
for i in range(len(sticks) - 2):
	if sticks[i + 1] + sticks[i + 2] > sticks[i]:
		print(sticks[i + 2], sticks[i + 1], sticks[i])
		break
else:
	print('-1')


import sys
n = int(input())
A = sorted(list(map(int, input().split())))
count = 0
for i in range(0, len(A) - 2):
	T1 = A[-1 - i]
	T2 = A[-2 - i]
	T3 = A[-3 - i]
	if T1 < T2 + T3:
		[sys.stdout.write('%d ' % X) for X in sorted([T1, T2, T3])]
		count = 1
		break
if count == 0:
	print('-1')


import sys
ln = int(input())
li = [int(s) for s in input().strip().split(' ')]
li.sort()
count = 0
for j in range(len(li) - 1, 1, -1):
	if li[j - 1] + li[j - 2] > li[j]:
		print(str(li[j - 2]) + ' ' + str(li[j - 1]) + ' ' + str(li[j]))
		count += 1
		break
if count == 0:
	print('-1')


import itertools
n = int(input())
a = list(map(int, input().split()))
k = set(a)
l = []
for p in k:
	c = a.count(p)
	if c > 3:
		c = 3
	l.extend([p] * c)
co = itertools.combinations(l, 3)
final = [0, 0, 0]
for i in co:
	if all([i[0] + i[1] > i[2], i[2] + i[1] > i[0], i[0] + i[2] > i[1]]):
		if max(i) > max(final):
			final = list(i)
		elif all([max(i) == max(final), min(i) > min(final)]):
			final = list(i)
if final == [0, 0, 0]:
	print(-1)
else:
	final.sort()
	for i in final:
		print(i, end=' ')


n = int(input())
ar = sorted([int(i) for i in input().strip().split()])
triangle = 0
perimeter = 0
if n > 2:
	for i in range(len(ar)):
		if i <= len(ar) - 3:
			if ar[i] < ar[i + 1] + ar[i + 2] and ar[i + 1] < ar[i] + ar[i + 2] and (ar[i + 2] < ar[i + 1] + ar[i]):
				if ar[i] + ar[i + 1] + ar[i + 2] > perimeter:
					triangle = (ar[i], ar[i + 1], ar[i + 2])
					perimeter = ar[i] + ar[i + 1] + ar[i + 2]
if perimeter == 0:
	print('-1')
else:
	for i in sorted(triangle):
		print(i, end=' ')


from itertools import combinations

def MaxPT(perimeters, triangles):
	if not perimeters:
		return -1
	else:
		maxp = max(perimeters)
		max_perimeters = [t for t in triangles if triangles[t] == maxp]
		if len(max_perimeters) == 1:
			return ' '.join(map(str, max_perimeters[0]))
		else:
			max_long_side = max([t[2] for t in max_perimeters])
			max_perimeters = [t for t in max_perimeters if t[2] == max_long_side]
			max_short_side = max([t[0] for t in max_perimeters])
			max_perimeters = [t for t in max_permimeters if t[0] == max_short_side]
			return ' '.join(map(str, max_perimeters[0]))
triangles = {}
perimeters = []
n = int(input().strip())
sticks = list(map(int, input().strip().split()))
combs = combinations(sticks, 3)
for t in combs:
	if not any((i for i in t if i >= sum(t) - i)):
		triangles[tuple(sorted(t))] = sum(t)
		perimeters.append(sum(t))
print(MaxPT(perimeters, triangles))


n = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
p = False
(a, b, c) = (0, 0, 0)
for i in range(n - 2):
	(a, b, c) = (l[i], l[i + 1], l[i + 2])
	if a + b > c and b + c > a and (a + c > b):
		p = True
		break
if p:
	print(c, b, a)
else:
	print('-1')


n = int(input())
arr = [int(t) for t in input().split(' ')]
arr.sort(reverse=True)
x = ''
for i in range(n - 2):
	if arr[i] < arr[i + 1] + arr[i + 2]:
		x = str(arr[i + 2]) + ' ' + str(arr[i + 1]) + ' ' + str(arr[i])
		break
if x:
	print(x)
else:
	print(-1)


import itertools
n = int(input().strip())
l = list(map(int, input().strip().split(' ')))

def max_triangle(a, b):
	if max(a) > max(b):
		return a
	elif max(b) > max(a):
		return b
	if min(a) > min(b):
		return a
	elif min(b) > min(a):
		return b
	return a

def perimeter(t):
	if t == None:
		return -1
	if t[0] + t[1] <= t[2] or t[0] + t[2] <= t[1] or t[1] + t[2] <= t[0]:
		return -1
	return sum(t)
max_triangle = None
for t in itertools.combinations(l, 3):
	p = perimeter(t)
	if p > perimeter(max_triangle):
		max_triangle = t
if max_triangle == None:
	print('-1')
else:
	print(' '.join(map(str, sorted(max_triangle))))


n = int(input())
y = [int(o) for o in input().strip().split(' ')]
y.sort()
trip = []
i = 0
while i <= len(y) - 3:
	a = y[i:i + 3]
	b = a[0:2]
	c = a[-1]
	if sum(b) > c:
		trip.append(a)
	i = i + 1
if len(trip) == 0:
	print(-1)
else:
	maxv = []
	for i in trip:
		maxv.append(max(i))
	k = max(maxv)
	if maxv.count(k) == 1:
		print(*trip[maxv.index(k)])
	else:
		minle = []
		for i in trip:
			if max(i) == k:
				minle.append(i)
		min1 = []
		for i in minle:
			min1.append(min(i))
		k1 = min(min1)
		print(*trip[min1.index(k1)])


found = False
num = int(input())
sticks = sorted([int(i) for i in input().split()], reverse=True)
for i in range(len(sticks) - 2):
	if sticks[i] < sticks[i + 1] + sticks[i + 2]:
		found = True
		break
print(sticks[i + 2], sticks[i + 1], sticks[i]) if found else print(-1)


n = int(input())
sides = input().split(' ')
sides = [int(no) for no in sides]
sides.sort()
max = -1
e = n - 3
while max == -1 and e >= 0:
	if sides[e + 2] < sides[e + 1] + sides[e]:
		max = sides[e + 2] + sides[e + 1] + sides[e]
	else:
		e -= 1
if max > 0:
	print(sides[e], sides[e + 1], sides[e + 2])
else:
	print(max)


n = int(input())
sticks = list(map(int, input().strip().split(' ')))
sticks.sort()
sticks.reverse()
i = 0
triangle_exists = False
while i < len(sticks) - 2:
	if sticks[i] + sticks[i + 1] <= sticks[i + 2] or sticks[i] + sticks[i + 2] <= sticks[i + 1] or sticks[i + 1] + sticks[i + 2] <= sticks[i]:
		i += 1
		continue
	else:
		triangle_exists = True
		break
if triangle_exists:
	print(sticks[i + 2], sticks[i + 1], sticks[i])
else:
	print(-1)


n = int(input())
l = sorted([int(x) for x in input().split()])
for i in range(n - 1, 1, -1):
	for j in range(i - 1, 0, -1):
		for k in range(j - 1, -1, -1):
			if l[k] + l[j] > l[i]:
				print(l[k], l[j], l[i])
				exit()
print(-1)


n = int(input())
lrr = list(map(int, input().split(' ')))
lrr = sorted(lrr)
triple = ()
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			if lrr[k] < lrr[i] + lrr[j]:
				if not triple:
					triple = (lrr[i], lrr[j], lrr[k])
				elif triple[2] < lrr[k] or (triple[2] == lrr[k] and triple[0] < lrr[i]):
					triple = (lrr[i], lrr[j], lrr[k])
if triple:
	print(' '.join((str(x) for x in triple)))
else:
	print(-1)


import sys
n = int(input().strip())

def prepareIntList(inputList):
	newList = []
	for elem in inputList:
		newList.append(int(elem))
		newList = sorted(newList, reverse=True)
	return newList
sticks = input().strip().split()
sticks = prepareIntList(sticks)

def found(result):
	return len(result) != 0
result = []
posX = 0
while not found(result) and posX < n - 2:
	posY = posX + 1
	while not found(result) and posY < n - 1:
		posZ = posY + 1
		while not found(result) and posZ < n:
			if sticks[posX] < sticks[posY] + sticks[posZ]:
				result.append(sticks[posZ])
				result.append(sticks[posY])
				result.append(sticks[posX])
			posZ += 1
		posY += 1
	posX += 1
if not found(result):
	print('-1')
else:
	for elem in result:
		print(elem, end=' ')
	print()


from itertools import combinations
from operator import itemgetter
_ = input()
l = [int(el) for el in input().strip().split()]
triangles = [sorted(tr) for tr in combinations(l, 3)]

def is_valid(triangle):
	return triangle[2] < triangle[0] + triangle[1] and triangle[1] < triangle[0] + triangle[2] and (triangle[0] < triangle[1] + triangle[2])
max_triangles = []
max_len = 0
for triangle in triangles:
	if not is_valid(triangle):
		continue
	current_len = sum(triangle)
	if current_len > max_len:
		max_triangles = [triangle]
		max_len = current_len
	elif current_len == max_len:
		max_triangles.append(triangle)
if not max_triangles:
	print(-1)
else:
	max_triangles.sort(reverse=True)
	max_triangles.sort(key=itemgetter(2), reverse=True)
	longest = max_triangles[0][0]
	max_triangles = [mt for mt in max_triangles if mt[0] == longest]
	if len(max_triangles) > 1:
		longest = max_triangles[0][2]
		max_triangles = [mt for mt in max_triangles if mt[2] == longest]
	for mt in max_triangles:
		print(*mt, sep=' ')
		break


import sys
import datetime
n = int(input().strip())
l = [int(a_temp) for a_temp in input().strip().split(' ')]
s = 0
for i in range(0, n):
	for j in range(0, n):
		if i != j:
			for k in range(0, n):
				if k != i:
					if k != j:
						if (l[i] + l[j] > l[k]) & (l[k] + l[j] > l[i]) & (l[i] + l[k] > l[j]):
							ts = l[i] + l[j] + l[k]
							if ts > s:
								s = ts
								e = sorted([l[i], l[j], l[k]])
							elif ts == s:
								if max(l[i], l[j], l[k]) > e[2]:
									e = sorted([l[i], l[j], l[k]])
								elif min(l[i], l[j], l[k]) > e[0]:
									e = sorted([l[i], l[j], l[k]])
if s == 0:
	print(-1)
else:
	print(e[0], e[1], e[2])


n = int(input())
l = [int(a0) for a0 in input().split(' ')]
l.sort()
c = l.pop()
b = l.pop()
a = l.pop()
while l:
	if c < b + a:
		break
	else:
		c = b
		b = a
		a = l.pop()
if c >= b + a:
	print(-1)
else:
	print(a, b, c)


n = int(input().strip())
l = [int(x) for x in input().strip().split()]
l = sorted(l)
for i in reversed(range(2, n)):
	if l[i] < l[i - 1] + l[i - 2]:
		print(l[i - 2], l[i - 1], l[i], end=' ')
		exit(0)
print(-1)


n = int(input())
arr = sorted([int(x) for x in input().strip().split()])
for i in range(n - 1, 1, -1):
	(a, b, c) = (arr[i - 2], arr[i - 1], arr[i])
	if a + b > c and a + c > b and (b + c > a):
		print(a, b, c)
		break
else:
	print(-1)


n = int(input())
l = sorted(map(int, input().split()), reverse=True)
(a, b, c, perim) = (0, 0, 0, 0)
for s1 in range(len(l) - 2):
	for s2 in range(s1 + 1, len(l) - 1):
		for s3 in range(s2 + 1, len(l)):
			t = l[s1] + l[s2] + l[s3]
			if t <= perim:
				break
			elif l[s2] + l[s3] > l[s1]:
				(a, b, c, perim) = (l[s3], l[s2], l[s1], t)
if perim != 0:
	print(a, b, c)
else:
	print(-1)


def sumtriang(longest, other1, other2):
	if longest >= other1 + other2:
		return False
	else:
		return True
n = int(input())
sides = sorted([int(x) for x in input().split()])
longest = sides[n - 1]
seclong = sides[n - 2]
thirdlong = sides[n - 3]
i = 1
while not sumtriang(longest, seclong, thirdlong):
	if n - 3 - i < 0:
		break
	longest = sides[n - 1 - i]
	seclong = sides[n - 2 - i]
	thirdlong = sides[n - 3 - i]
	i += 1
if not sumtriang(longest, seclong, thirdlong):
	print(-1)
else:
	print(thirdlong, seclong, longest)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
for i in range(0, n - 2):
	x = a[n - 1 - i]
	y = a[n - 2 - i]
	z = a[n - 3 - i]
	if y + z > x:
		print(str(z) + ' ' + str(y) + ' ' + str(x))
		exit()
print(-1)


import itertools
n = int(input())
a = list(map(int, input().split()))
k = set(a)
l = []
for p in k:
	c = a.count(p)
	if c > 3:
		c = 3
	l.extend([p] * c)
co = itertools.combinations(l, 3)
final = [0, 0, 0]
for i in co:
	if all([i[0] + i[1] > i[2], i[2] + i[1] > i[0], i[0] + i[2] > i[1]]):
		if max(i) > max(final):
			final = list(i)
		elif all([max(i) == max(final), min(i) > min(final)]):
			final = list(i)
if final == [0, 0, 0]:
	print(-1)
else:
	final.sort()
	for i in final:
		print(i, end=' ')


n = int(input().strip())
arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
arr = sorted(arr, reverse=True)
found = False
for i in range(len(arr) - 2):
	if arr[i] < arr[i + 1] + arr[i + 2]:
		print('{} {} {}'.format(arr[i + 2], arr[i + 1], arr[i]))
		found = True
		break
if not found:
	print('-1')


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
r = []
for i in range(2, n):
	for j in range(1, i):
		for k in range(j):
			if a[k] + a[j] > a[i]:
				r.append([a[i], a[j], a[k]])
if len(r) == 0:
	print(-1)
else:
	m = max([sum(r[i]) for i in range(len(r))])
	k = []
	for j in range(len(r)):
		if sum(r[j]) == m:
			k.append(r[j])
	k.sort()
	re = k[-1][:]
	re.reverse()
	print(' '.join([str(num) for num in re]))


def check(a, b, c):
	if a + b > c and b + c > a and (c + a > b):
		return 1
	else:
		return 0
p = []
n = int(input().strip())
t = input().split(' ')
for i in range(len(t)):
	t[i] = int(t[i])
x = sorted(t, reverse=True)
for i in range(len(x) - 2):
	s = x[i:i + 3]
	if check(s[0], s[1], s[2]) == 1:
		if sum(s) >= sum(p):
			if sum(s) == sum(p):
				if max(s) > max(p):
					p = s
				elif min(s) > min(p):
					p = s
			else:
				p = s
if len(p) < 3:
	print('-1')
else:
	p = sorted(p)
	print(p[0], p[1], p[2])


n = int(input().strip())
sticks = input().strip().split(' ')
sticks = [int(stick) for stick in sticks]
sticks.sort(reverse=True)
output = '-1'
found = False
for i in range(2, n):
	if found:
		break
	for j in range(i - 1):
		if found:
			break
		for k in range(j + 1, i):
			if sticks[j] < sticks[i] + sticks[k]:
				found = True
				output = '%s %s %s' % (sticks[i], sticks[k], sticks[j])
				break
print(output)