Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:  a < b < c;  a divides b, b divides c. 

Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has $\frac{n}{3}$ groups of three.

Help Xenia, find the required partition or else say that it doesn't exist.


-----Input-----

The first line contains integer n (3 ≤ n ≤ 99999) — the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.

It is guaranteed that n is divisible by 3.


-----Output-----

If the required partition exists, print $\frac{n}{3}$ groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.

If there is no solution, print -1.


-----Examples-----
Input
6
1 1 1 2 2 2

Output
-1

Input
6
2 2 1 1 4 6

Output
1 2 4
1 2 6

Difficulty: EASY
Tags: Implementation

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
a = int(input())
list = input().split()
list2 = []
for elements in list:
	elements = int(elements)
	list2.append(elements)
count1 = int(list2.count(1))
count2 = int(list2.count(2))
count3 = int(list2.count(3))
count4 = int(list2.count(4))
count6 = int(list2.count(6))
if 5 in list2 or 7 in list2:
	print(-1)
elif count2 < count4:
	print(-1)
elif count2 - count4 != count6 - count3:
	print(-1)
elif count1 != a / 3:
	print(-1)
else:
	if count4 != 0:
		print('1 2 4\n' * count4)
	if count3 != 0:
		print('1 3 6\n' * count3)
	if count2 - count4 != 0:
		print('1 2 6\n' * (count2 - count4))


n = int(input())
l = list(map(int, input().strip().split()))
has = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in l:
	has[i] += 1
partition = []
while True:
	prev_has = [a for a in has]
	if has[1] > 0:
		if has[2] > 0:
			if has[4] > 0:
				has[1] -= 1
				has[2] -= 1
				has[4] -= 1
				partition.append([1, 2, 4])
			elif has[6] > 0:
				has[1] -= 1
				has[2] -= 1
				has[6] -= 1
				partition.append([1, 2, 6])
		elif has[3] > 0:
			if has[6] > 0:
				has[1] -= 1
				has[3] -= 1
				has[6] -= 1
				partition.append([1, 3, 6])
	if has == prev_has:
		if sum(has) == 0:
			for k in partition:
				print(*k)
		else:
			print(-1)
		break


import sys, os, io, time, copy
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
import math
n = int(input())
arr = list(map(int, input().split()))
dic = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0}
for a in arr:
	dic[a] += 1
x = min(dic[1], dic[2], dic[4])
dic[1] -= x
dic[2] -= x
dic[4] -= x
y = min(dic[1], dic[2], dic[6])
dic[1] -= y
dic[2] -= y
dic[6] -= y
z = min(dic[1], dic[3], dic[6])
dic[1] -= z
dic[3] -= z
dic[6] -= z
flag = 0
for d in dic:
	if dic[d] != 0:
		flag = 1
if flag == 0:
	for i in range(x):
		print('1 2 4')
	for i in range(y):
		print('1 2 6')
	for i in range(z):
		print('1 3 6')
else:
	print(-1)


from math import *

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	x = n // 3
	z = [arr[:x], arr[x:2 * x], arr[2 * x:]]
	res = []
	for j in range(x):
		p = [z[0][0]]
		x = z[0][0]
		f = True
		for n in range(1, 3):
			for i in range(x):
				f = True
				if z[n][i] % x == 0 and z[n][i] > x:
					x = z[n][i]
					p.append(z[n][i])
					z[n].pop(i)
					f = False
					break
				if f:
					print(-1)
					return
		res.append(p.copy())
	print('\n'.join(map(lambda x: ' '.join(map(str, x)), res)))
main()


n = int(input())
a = list(map(int, input().split()))
t = [0] * 8
for x in a:
	t[x] += 1
if t[5] > 0 or t[7] > 0 or t[1] * 3 < n:
	print(-1)
else:
	a = t[4]
	c = t[3]
	b = t[2] - a
	if b < 0 or a + b + c != t[1] or b + c != t[6]:
		print(-1)
		return
	for i in range(a):
		print('1 2 4')
	for i in range(b):
		print('1 2 6')
	for i in range(c):
		print('1 3 6')


from collections import Counter
(n, b) = (int(input()), Counter(map(int, input().split())))
if b[5] or b[7]:
	print(-1)
else:
	(b[1], b[6]) = (b[1] - b[3], b[6] - b[3])
	if b[1] < 0 or b[6] < 0 or b[1] != b[2] or (b[4] + b[6] != b[1]):
		print(-1)
	else:
		c = [[1, 2, 4], [1, 2, 6], [1, 3, 6]]
		d = [4, 6, 3]
		for i in range(3):
			for j in range(b[d[i]]):
				print(' '.join(map(str, c[i])))


n = int(input())
S = []
a = list(map(int, input().split()))
Ans = [0] * 10
for i in a:
	Ans[i] += 1
for i in range(1, 8):
	for j in range(i + 1, 8):
		for k in range(j + 1, 8):
			while j % i == 0 and k % j == 0 and (Ans[i] > 0) and (Ans[j] > 0) and (Ans[k] > 0):
				S.append((i, j, k))
				Ans[i] -= 1
				Ans[j] -= 1
				Ans[k] -= 1
if len(S) == n // 3:
	for (i, j, k) in S:
		print(i, j, k, end=' ')
		print()
else:
	print(-1)


n = int(input())
arr = list(map(int, input().split()))
from collections import Counter
c = Counter(arr)
if 5 in arr or 7 in arr or arr.count(1) != n // 3 or (arr.count(2) + arr.count(3) != n // 3) or (3 in arr and arr.count(3) > arr.count(6)):
	print(-1)
else:
	for i in range(n // 3):
		print(1, end=' ')
		if c[2] > 0:
			print(2, end=' ')
			c[2] -= 1
			if c[4] > 0:
				print(4)
				c[4] -= 1
			else:
				print(6)
		else:
			print(3, end=' ')
			print(6)


import math
import re
import sys
from itertools import permutations
from collections import Counter
MOD = 1000000007

def inp():
	return map(int, input().split(' '))

def ninp():
	return int(input())
n = ninp()
a = sorted(list(inp()))
for i in range(n // 3):
	if not a[i] < a[i + n // 3] < a[i + 2 * (n // 3)] or a[i + n // 3] % a[i] != 0 or a[i + 2 * (n // 3)] % a[i + n // 3]:
		print(-1)
		exit(0)
else:
	for i in range(n // 3):
		print(*a[i::n // 3])


n = int(input())
a = list(map(int, input().split()))
b = [0] * 8
h = []
for i in a:
	b[i] += 1
v = min(b[1], b[2], b[4])
b[1] -= v
b[2] -= v
b[4] -= v
h.append(v)
v = min(b[1], b[3], b[6])
b[1] -= v
b[3] -= v
b[6] -= v
h.append(v)
v = min(b[1], b[2], b[6])
b[1] -= v
b[2] -= v
b[6] -= v
h.append(v)
if sum(h) * 3 < n:
	print(-1)
else:
	print('1 2 4 \n' * h[0], end='')
	print('1 3 6 \n' * h[1], end='')
	print('1 2 6 \n' * h[2], end='')


n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(1, 8):
	c.append(a.count(i))
if c[4] == 0 and c[6] == 0 and (c[5] - c[2] == c[1] - c[3]) and (c[0] - c[2] - c[3] == c[1] - c[3]) and (c[0] - c[2] - c[3] == c[5] - c[2]) and (c[5] >= c[2]) and (c[1] >= c[3]):
	for i in range(c[3]):
		print('1 2 4')
	for i in range(c[0] - c[2] - c[3]):
		print('1 2 6')
	for i in range(c[2]):
		print('1 3 6')
else:
	print(-1)


import io, os
import sys
from atexit import register
from collections import Counter
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda : os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0

def nextStr():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = input().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(nextStr())

def nextIntArr(n):
	return [nextInt() for i in range(n)]

def print(s, end='\n'):
	sys.stdout.write((str(s) + end).encode())
n = nextInt()
a = nextIntArr(n)
cnt = Counter(a)
res = []
if cnt[3]:
	if cnt[1] < cnt[3] or cnt[6] < cnt[3]:
		print(-1)
		exit(0)
	res.extend([(1, 3, 6)] * cnt[3])
	cnt[1] -= cnt[3]
	cnt[6] -= cnt[3]
	cnt[3] = 0
if cnt[2]:
	if cnt[2] != cnt[4] + cnt[6]:
		print(-1)
		exit(0)
	if cnt[1] != cnt[2]:
		print(-1)
		exit(0)
	while cnt[2]:
		cur = 4 if cnt[4] else 6
		res.append((1, 2, cur))
		cnt[1] -= 1
		cnt[2] -= 1
		cnt[cur] -= 1
if list(cnt.elements()):
	print(-1)
	exit(0)
for i in res:
	print(' '.join(map(str, i)))


import sys
n = int(sys.stdin.readline())
lis = list(map(int, sys.stdin.readline().split()))
numbs = {x: 0 for x in range(1, 8)}
for li in lis:
	numbs[li] += 1
if numbs[5] > 0 or numbs[7] > 0 or numbs[3] > numbs[6] or (numbs[3] > numbs[1]) or (numbs[4] > numbs[2]) or (numbs[4] > numbs[1]):
	print(-1)
else:
	ans = []
	for i in range(numbs[3]):
		ans.append([1, 3, 6])
		numbs[6] -= 1
		numbs[1] -= 1
		numbs[3] -= 1
	for i in range(numbs[1]):
		if numbs[2] > 0 and numbs[4] > 0:
			ans.append([1, 2, 4])
			numbs[1] -= 1
			numbs[2] -= 1
			numbs[4] -= 1
		elif numbs[2] > 0 and numbs[6] > 0:
			ans.append([1, 2, 6])
			numbs[1] -= 1
			numbs[2] -= 1
			numbs[6] -= 1
		else:
			ans.append(-1)
	if -1 not in ans:
		for an in ans:
			print(an[0], an[1], an[2])
	else:
		print(-1)


from collections import Counter
n = int(input())
cnt = Counter((int(x) for x in input().split()))
if cnt[5] or cnt[7]:
	print('-1')
	exit()
if cnt[1] != cnt[4] + cnt[6] or cnt[3] > cnt[6] or cnt[1] != cnt[2] + cnt[3]:
	print('-1')
	exit()
for i in range(cnt[3]):
	print('1 3 6')
for i in range(cnt[6] - cnt[3]):
	print('1 2 6')
for i in range(cnt[4]):
	print('1 2 4')


n = int(input())
arr = [int(i) for i in input().split()]
count = [0 for _ in range(7)]
for i in arr:
	count[i - 1] += 1
done = False
if count[4] or count[6]:
	done = True
	print(-1)
if not done and count[0] == count[1] + count[2] == count[3] + count[5] and (count[1] or count[5]) and (count[5] >= count[2]):
	for i in range(count[3]):
		print(1, 2, 4)
	for i in range(count[2]):
		print(1, 3, 6)
	for i in range(count[0] - count[2] - count[3]):
		print(1, 2, 6)
elif not done:
	print(-1)


from collections import Counter
a = [['1', '2', '4'], ['1', '2', '6'], ['1', '3', '6']]
av = []
n = int(input())
d = Counter(input().split())
s = 0
for i in a:
	v = min(d[i[0]], d[i[1]], d[i[2]])
	s += v
	d[i[0]] -= v
	d[i[1]] -= v
	d[i[2]] -= v
	av.append([i, v])
if s == n // 3:
	for (i, v) in av:
		st = ' '.join(i)
		for j in range(v):
			print(st)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
d = n // 3
(x1, x2, x3, x4, x6) = (l.count(1), l.count(2), l.count(3), l.count(4), l.count(6))
x = min(x1, x2, x4)
(x2, x1) = (x2 - x, x1 - x)
y = min(x1, x2, x6)
x6 -= y
x1 -= y
z = min(x1, x3, x6)
if x + y + z == d:
	print('1 2 4\n' * x, end='')
	print('1 2 6\n' * y, end='')
	print('1 3 6\n' * z, end='')
else:
	print(-1)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	ref = [[1, 2, 4], [1, 2, 6], [1, 3, 6]]
	d = {}
	one = 0
	two = 0
	three = 0
	four = 0
	six = 0
	for x in a:
		if x == 1:
			one += 1
		elif x == 2:
			two += 1
		elif x == 3:
			three += 1
		elif x == 4:
			four += 1
		elif x == 6:
			six += 1
	if one == n // 3:
		if two + three == n // 3 and four + six == n // 3:
			if three > six:
				flag = 0
			else:
				flag = 1
		else:
			flag = 0
	else:
		flag = 0
	if flag == 1:
		for i in range(n // 3):
			if one > 0 and two > 0 and (four > 0):
				print(1, 2, 4)
				(one, two, four) = (one - 1, two - 1, four - 1)
			elif one > 0 and two > 0 and (six > 0):
				print(1, 2, 6)
				(one, two, six) = (one - 1, two - 1, six - 1)
			elif one > 0 and three > 0 and (six > 0):
				print(1, 3, 6)
				(one, three, six) = (one - 1, three - 1, six - 1)
	else:
		print(-1)
for _ in range(1):
	solve()


from sys import *
from math import *
from string import *
from operator import *
from functools import reduce
setrecursionlimit(10 ** 7)
RI = lambda : list(map(int, input().split()))
RS = lambda : input().rstrip().split()
n = RI()[0]
num = RI()
allPos = [(1, 2, 4), (1, 2, 6), (1, 3, 6)]
ans = []
cnt = [0] * 8
for i in num:
	cnt[i] += 1
for i in allPos:
	while cnt[i[0]] and cnt[i[1]] and cnt[i[2]]:
		cnt[i[0]] -= 1
		cnt[i[1]] -= 1
		cnt[i[2]] -= 1
		ans.append(i)
if any((cnt[i] for i in range(1, 8))) or cnt[5] or cnt[7]:
	print(-1)
else:
	for i in ans:
		print(*i)


n = int(input())
s = list(map(int, input().split()))
if n % 3 != 0 or (n == 3 and s[0] != s[1] != s[2]):
	print(-1)
else:
	(a, b, c) = (s.count(1), s.count(2) + s.count(3), s.count(4) + s.count(6))
	if a == b and b == c and (a + b + c == n):
		q = a * '1'
		w = s.count(2) * '2' + s.count(3) * '3'
		e = s.count(4) * '4' + s.count(6) * '6'
		y = 'no'
		t = []
		for j in range(a):
			if w[j] == '2' and e[j] == '4' or (w[j] == '3' and e[j] == '6') or (w[j] == '2' and e[j] == '6'):
				t.append(q[j] + ' ' + w[j] + ' ' + e[j] + ' ')
				y = 'yes'
			else:
				y = 'no'
				break
		if y == 'yes':
			for g in t:
				print(g)
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
arr = [int(x) for x in input().split(' ')]
c = [0] * 8
for i in arr:
	c[i] += 1
n = n // 3
if c[1] != c[2] + c[3] or c[1] != c[4] + c[6] or c[5] > 0 or (c[7] > 0) or (c[4] > c[2]) or (c[3] > c[6]):
	print(-1)
else:
	for i in range(c[4]):
		print('1 2 4')
	for i in range(c[2] - c[4]):
		print('1 2 6')
	for i in range(c[3]):
		print('1 3 6')


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
c = []
b = [[i, a.count(i)] for i in range(8)]
if b[5][1] != 0 or b[7][1] != 0:
	print(-1)
else:
	tag = 1
	a1 = b[1][1]
	a2 = b[2][1]
	a3 = b[3][1]
	a4 = b[4][1]
	a6 = b[6][1]
	if a1 != n / 3:
		tag = 0
		print(-1)
	else:
		if a4 and a2 >= a4:
			for i in range(a4):
				c.append([1, 2, 4])
			a2 = a2 - a4
			a4 = 0
		if a2 < a4:
			print(-1)
			tag = 0
		if a6 and a2 + a3 == a6:
			for i in range(a2):
				c.append([1, 2, 6])
			for i in range(a3):
				c.append([1, 3, 6])
		else:
			if tag:
				print(-1)
			tag = 0
	if tag:
		for i in c:
			print('{} {} {}'.format(i[0], i[1], i[2]))


import sys
from collections import Counter
n = int(sys.stdin.readline())
arr = list(map(int, input().split()))
(onc, twoc, thc, foc, sixc) = (0, 0, 0, 0, 0)
z = n // 3
for e in arr:
	if e == 1:
		onc += 1
	elif e == 2:
		twoc += 1
	elif e == 3:
		thc += 1
	elif e == 4:
		foc += 1
	elif e == 6:
		sixc += 1
flag = 0
if onc == twoc + thc == foc + sixc == z:
	c = Counter(arr)
	ans = []
	for i in range(z):
		n1 = 1
		c[1] -= 1
		if c[2] > 0:
			n2 = 2
			c[2] -= 1
			if c[4] > 0:
				n3 = 4
				c[4] -= 1
			elif c[6] > 0:
				n3 = 6
				c[6] -= 1
			else:
				flag = 1
				break
		elif c[3] > 0:
			c[3] -= 1
			n2 = 3
			if c[6] > 0:
				n3 = 6
				c[6] -= 1
			else:
				flag = 1
				break
		else:
			flag = 1
			break
		ans.append((n1, n2, n3))
	if flag == 0:
		for e in ans:
			print(*e)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
p = a.count(1)
q = a.count(2)
r = a.count(3)
s = a.count(4)
t = a.count(6)
if p == n // 3 and q + r == n // 3 and (s + t == n // 3) and (s <= q) and (t >= r):
	for i in range(r):
		print(1, 3, 6)
	for i in range(s):
		print(1, 2, 4)
	for i in range(t - r):
		print(1, 2, 6)
else:
	print('-1')


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
c = [0] * 10
for i in mints():
	c[i] += 1
if n // 3 == c[1] and c[0] == 0 and (c[5] == 0) and (c[7] == 0) and (c[6] - c[3] == c[2] - c[4]) and (c[2] - c[4] >= 0):
	for i in range(c[4]):
		print(1, 2, 4)
	for i in range(c[2] - c[4]):
		print(1, 2, 6)
	for i in range(c[3]):
		print(1, 3, 6)
else:
	print(-1)


from collections import Counter
n = int(input())
x = list(map(int, input().split()))
cnt = Counter(x)
if cnt[1] != n // 3 or cnt[5] != 0 or cnt[7] != 0 or (cnt[3] > cnt[6]) or (cnt[4] > cnt[2]) or (cnt[2] + cnt[3] != cnt[6] + cnt[4]) or (cnt[2] > cnt[4] + cnt[6]) or (cnt[6] > cnt[2] + cnt[3]):
	print(-1)
else:
	for i in range(cnt[4]):
		print('1 2 4')
	for i in range(cnt[2] - cnt[4]):
		print('1 2 6')
	for i in range(cnt[3]):
		print('1 3 6')


def solve(n, a, one, two, three, four, five, six, seven):
	if five > 0 or seven > 0:
		return -1
	if two + three != one or four + six != one or six - three != two - four or (four > two) or (three > six):
		return -1
	ans = []
	if four != 0:
		ans += [[1, 2, 4]] * four
	if two - four > 0:
		ans += [[1, 2, 6]] * (two - four)
	if three != 0:
		ans += [[1, 3, 6]] * three
	return ans
n = int(input())
a = list(map(int, input().split()))
one = a.count(1)
two = a.count(2)
three = a.count(3)
four = a.count(4)
five = a.count(5)
six = a.count(6)
seven = a.count(7)
p = solve(n, a, one, two, three, four, five, six, seven)
if p == -1:
	print(p)
else:
	for it in p:
		print(*it)


n = int(input())
x = list(map(int, input().split()))
a = 0
b = 0
c = 0
d = 0
e = 0
for i in range(n):
	if x[i] == 1:
		a += 1
	if x[i] == 2:
		b += 1
	if x[i] == 3:
		c += 1
	if x[i] == 4:
		d += 1
	if x[i] == 6:
		e += 1
	if x[i] == 5 or x[i] == 7:
		print(-1)
		exit(0)
if a != b + c or b + c != d + e or c > e:
	print(-1)
	exit(0)
for i in range(d):
	print(1, 2, 4)
b -= d
for i in range(b):
	print(1, 2, 6)
for i in range(c):
	print(1, 3, 6)


length = int(input())
arr = list(map(int, input().split()))
ans = []
final = []
cnt = 0
if 5 in arr or 7 in arr:
	print(-1)
else:
	one = arr.count(1)
	two = arr.count(2)
	three = arr.count(3)
	four = arr.count(4)
	six = arr.count(6)
	for x in range(length // 3):
		if one > 0:
			one -= 1
			ans.append(1)
		else:
			print(-1)
			break
		if two > 0:
			two -= 1
			ans.append(2)
			if four > 0:
				four -= 1
				ans.append(4)
			elif six > 0:
				six -= 1
				ans.append(6)
			else:
				print(-1)
				break
		if three > 0 and len(ans) < 2:
			three -= 1
			ans.append(3)
			if six > 0:
				six -= 1
				ans.append(6)
			else:
				print(-1)
				break
		if len(ans) == 3:
			final.append(ans)
		else:
			print(-1)
			break
		ans = []
	else:
		for x in final:
			print(*x)


n = int(input())
a = [int(x) for x in input().split()]
d = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0}
for e in a:
	d[e] += 1
if d[5] != 0 or d[7] != 0 or (not d[1] == d[2] + d[3] == d[4] + d[6]) or (d[3] > d[6]) or (d[4] > d[2]):
	print(-1)
else:
	for i in range(d[3]):
		print('1 3 6')
	for i in range(d[6] - d[3]):
		print('1 2 6')
	for i in range(d[4]):
		print('1 2 4')


import collections as coll
(groups, impossible) = ([], False)
(n, nums) = (int(input()), coll.Counter(map(int, input().split(' '))))
x = n // 3
for x in range(x):
	group = []
	if nums[1] != 0:
		group.append(1)
		nums[1] -= 1
	else:
		impossible = True
		break
	if nums[2] != 0:
		group.append(2)
		nums[2] -= 1
		if nums[4] != 0:
			group.append(4)
			nums[4] -= 1
		elif nums[6] != 0:
			group.append(6)
			nums[6] -= 1
		else:
			impossible = True
			break
	elif nums[3] != 0 and nums[6] != 0:
		group.append(3)
		group.append(6)
		nums[3] -= 1
		nums[6] -= 1
	else:
		impossible = True
		break
	groups.append(group)
if impossible:
	print(-1)
else:
	for group in groups:
		print(*group)


class CodeforcesTask342ASolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.sequence = []

	def read_input(self):
		self.n = int(input())
		self.sequence = [int(x) for x in input().split(' ')]

	def process_task(self):
		counts = [0 for x in range(1, 8)]
		for x in range(self.n):
			counts[self.sequence[x] - 1] += 1
		if max(counts) > self.n // 3:
			self.result = '-1'
		elif counts[0] != self.n // 3:
			self.result = '-1'
		elif 7 in self.sequence or 5 in self.sequence:
			self.result = '-1'
		else:
			self.result = []
			while counts[3]:
				counts[3] -= 1
				if counts[1]:
					counts[0] -= 1
					counts[1] -= 1
					self.result.append('1 2 4\n')
			while counts[5]:
				counts[5] -= 1
				if counts[2]:
					counts[0] -= 1
					counts[2] -= 1
					self.result.append('1 3 6\n')
				elif counts[1]:
					counts[0] -= 1
					counts[1] -= 1
					self.result.append('1 2 6\n')
			if sum(counts):
				self.result = '-1'
			else:
				for r in self.result:
					print(r)
				self.result = ''

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


n = int(input())
a = sorted(list(map(int, input().split())))
for i in range(n // 3):
	if not a[i] < a[i + n // 3] < a[i + 2 * n // 3] or a[i + n // 3] % a[i] != 0 or a[i + 2 * n // 3] % a[i + n // 3] != 0:
		print(-1)
		exit()
else:
	for i in range(n // 3):
		print(*a[i::n // 3])


n = int(input())
a = list(map(int, input().split()))
o = t = th = f = s = 0
for i in range(n):
	if a[i] == 1:
		o += 1
	elif a[i] == 2:
		t += 1
	elif a[i] == 3:
		th += 1
	elif a[i] == 4:
		f += 1
	elif a[i] == 6:
		s += 1
n //= 3
if o == t + th == f + s == n and t >= f:
	x = 2
	y = 4
	for _ in range(n):
		if not t:
			x = 3
		if not f:
			y = 6
		print(1, x, y)
		t -= 1
		f -= 1
else:
	print(-1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
for _ in range(1):
	cnt = dict()
	ans = []
	for i in range(1, 8):
		cnt.setdefault(i, 0)
	n = int(input())
	nums = list(map(int, input().split()))
	for i in nums:
		cnt[i] += 1
	if cnt[5] != 0 or cnt[7] != 0:
		print(-1)
		break
	while cnt[3] > 0:
		ans.append((1, 3, 6))
		cnt[1] -= 1
		cnt[3] -= 1
		cnt[6] -= 1
	while cnt[4] > 0:
		ans.append((1, 2, 4))
		cnt[1] -= 1
		cnt[2] -= 1
		cnt[4] -= 1
	while cnt[6] > 0:
		ans.append((1, 2, 6))
		cnt[2] -= 1
		cnt[1] -= 1
		cnt[6] -= 1
	flag = 1
	for (num, val) in cnt.items():
		if val != 0:
			flag = 0
			break
	if flag == 0:
		print(-1)
	else:
		for i in range(len(ans)):
			print(ans[i][0], ans[i][1], ans[i][2])


def find(n, seq):
	grps = [[] for i in range(n // 3)]
	for i in range(len(seq)):
		ap = grps[i % (n // 3)]
		if len(ap) == 0:
			if seq[i] not in [1, 2]:
				return -1
		elif ap[-1] == '1':
			if seq[i] not in [2, 3, 4]:
				return -1
		elif ap[-1] == '2':
			if seq[i] not in [4, 6]:
				return -1
		elif ap[-1] in ['3']:
			if seq[i] not in [6]:
				return -1
		elif ap[-1] in ['4', '5', '6']:
			return -1
		ap.append(str(seq[i]))
	return '\n'.join([' '.join(x) for x in sorted(grps)])
n = int(input())
seq = sorted(list(map(int, input().split())))
print(find(n, seq))


n = int(input())
arr = list(map(int, input().split()))
dct = {1: 0, 2: 0, 3: 0, 4: 0, 6: 0}
count = 0
ans = []
for num in arr:
	if num == 1 or num == 2 or num == 3 or (num == 4) or (num == 6):
		dct[num] += 1
for i in range(dct[1]):
	res = [1]
	if dct[2] > 0:
		res.append(2)
		dct[2] -= 1
		if dct[4] > 0:
			res.append(4)
			dct[4] -= 1
		elif dct[6] > 0:
			res.append(6)
			dct[6] -= 1
	elif dct[3] > 0:
		res.append(3)
		dct[3] -= 1
		if dct[6] > 0:
			res.append(6)
			dct[6] -= 1
	if len(res) == 3:
		count += 1
		ans.append(res)
if not count:
	print(-1)
elif count == n // 3:
	for res in ans:
		print(' '.join([str(num) for num in res]))
else:
	print(-1)


n = int(input())
arr = map(int, input().split())
mp = dict()
mp[1] = 0
mp[2] = 0
mp[3] = 0
mp[4] = 0
mp[6] = 0
for num in arr:
	if num == 1:
		mp[1] = mp[1] + 1
	elif num == 2:
		mp[2] = mp[2] + 1
	elif num == 3:
		mp[3] = mp[3] + 1
	elif num == 4:
		mp[4] = mp[4] + 1
	elif num == 6:
		mp[6] = mp[6] + 1
sum0 = 0
sum1 = 0
sum2 = 0
if mp[1] != n // 3:
	print(-1)
else:
	while True:
		flag = True
		if mp[2] > 0 and mp[4] > 0:
			sum0 = sum0 + 1
			flag = False
			mp[2] = mp[2] - 1
			mp[4] = mp[4] - 1
		elif mp[2] > 0 and mp[6] > 0:
			sum1 = sum1 + 1
			flag = False
			mp[2] = mp[2] - 1
			mp[6] = mp[6] - 1
		elif mp[3] > 0 and mp[6] > 0:
			sum2 = sum2 + 1
			flag = False
			mp[3] = mp[3] - 1
			mp[6] = mp[6] - 1
		if flag == True:
			break
	if sum0 + sum1 + sum2 != n // 3:
		print(-1)
	else:
		for i in range(sum0):
			print(1, ' ', 2, ' ', 4)
		for i in range(sum1):
			print(1, ' ', 2, ' ', 6)
		for i in range(sum2):
			print(1, ' ', 3, ' ', 6)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
cnt = {}
for _ in range(8):
	cnt[_] = 0
n = int(input())
for x in list(map(int, input().split())):
	cnt[x] += 1
ans = []
for (x, y, z) in [(1, 2, 4), (1, 2, 6), (1, 3, 6)]:
	mnm = min(cnt[x], cnt[y], cnt[z])
	if mnm > 0:
		ans.extend([(x, y, z)] * mnm)
		cnt[x] -= mnm
		cnt[y] -= mnm
		cnt[z] -= mnm
if len(ans) * 3 == n:
	for (x, y, z) in ans:
		print(x, y, z)
else:
	print('-1')


n = int(input())
A = list(map(int, input().split()))
A.sort()
A1 = A[0:n // 3]
A2 = A[n // 3:n // 3 + n // 3]
A3 = A[n // 3 + n // 3:]
ans = []
for i in range(n // 3):
	if A2[i] == A1[i] or A3[i] == A2[i]:
		print(-1)
		exit()
	if A2[i] % A1[i] != 0 or A3[i] % A2[i] != 0:
		print(-1)
		exit()
	ans.append((A1[i], A2[i], A3[i]))
for i in range(n // 3):
	print(*ans[i])


n = int(input())
a = list(map(int, input().split()))
a.sort()
n = n / 3
ok = 1
if a.count(1) != n:
	ok = 0
if a.count(5) + a.count(7) > 0:
	ok = 0
p = a.count(2) - a.count(4)
if p < 0:
	ok = 0
if p + a.count(3) != a.count(6):
	ok = 0
if ok == 0:
	print(-1)
else:
	t4 = a.count(4)
	t26 = p
	t36 = a.count(6) - t26
	for i in range(0, t4):
		print(1, 2, 4)
	for i in range(0, t26):
		print(1, 2, 6)
	for i in range(0, t36):
		print(1, 3, 6)


n = int(input())
a = list(map(int, input().split()))
m = [None] + [0] * 7
ans = []
r = 0
for i in a:
	m[i] += 1
if m[7] > 0 or m[5] > 0:
	r = 1
elif m[3] > 0:
	if m[6] >= m[3] and m[1] >= m[3]:
		m[1] -= m[3]
		m[6] -= m[3]
		ans.append([1, 3, 6] * m[3])
	else:
		r = 1
if m[4] > 0:
	if m[4] <= m[2] and m[4] <= m[1]:
		ans.append([1, 2, 4] * m[4])
		m[2] -= m[4]
		m[1] -= m[4]
	else:
		r = 1
if m[6] > 0:
	if m[2] >= m[6] and m[1] >= m[6]:
		m[2] -= m[6]
		m[1] -= m[6]
		ans.append([1, 2, 6] * m[6])
	else:
		r = 1
for i in range(1, 8):
	if m[i] < 0:
		r = 1
if r == 1 or len(ans) == 0:
	print(-1)
else:
	for i in ans:
		for j in range(len(i) // 3):
			print(i[0], i[1], i[2], end=' ')
			print()


n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 8
for i in a:
	cnt[i] += 1
ans = 1
if cnt[5] > 0 or cnt[7] > 0:
	ans = 0
if cnt[4] > cnt[2]:
	ans = 0
if cnt[1] != n / 3:
	ans = 0
if cnt[2] - cnt[4] + cnt[3] != cnt[6]:
	ans = 0
if ans == 0:
	print('-1\n')
else:
	while cnt[4]:
		print('1 2 4\n')
		cnt[2] = cnt[2] - 1
		cnt[4] = cnt[4] - 1
	while cnt[2]:
		print('1 2 6\n')
		cnt[2] = cnt[2] - 1
	while cnt[3]:
		print('1 3 6\n')
		cnt[3] = cnt[3] - 1


def solve(n, items):
	grp_items = [0] * 8
	for item in items:
		grp_items[item] += 1
	if grp_items[1] == n / 3 and grp_items[5] == 0 and (grp_items[7] == 0) and (grp_items[2] == grp_items[4] + grp_items[6] - grp_items[3]) and (grp_items[6] >= grp_items[3]):
		while grp_items[1] > 0:
			if grp_items[3] > 0:
				print('1 3 6')
				grp_items[6] -= 1
				grp_items[3] -= 1
			elif grp_items[2] > 0:
				if grp_items[6] > 0:
					print('1 2 6')
					grp_items[6] -= 1
				elif grp_items[4] > 0:
					print('1 2 4')
					grp_items[4] -= 1
				else:
					print(-1)
				grp_items[2] -= 1
			else:
				print(-1)
			grp_items[1] -= 1
	else:
		print(-1)

def __starting_point():
	n = int(input())
	items = list(map(int, input().split(' ')))
	solve(n, items)
__starting_point()


from sys import stdin, stdout
import math
n = int(stdin.readline())
li = list(map(int, stdin.readline().split()))
d = {}
for i in range(1, 8):
	d[i] = li.count(i)
li2 = []
while True:
	if d[1] > 0 and d[2] > 0 and (d[4] > 0):
		li2.append([1, 2, 4])
		d[1] -= 1
		d[2] -= 1
		d[4] -= 1
	elif d[1] > 0 and d[2] > 0 and (d[6] > 0):
		li2.append([1, 2, 6])
		d[1] -= 1
		d[2] -= 1
		d[6] -= 1
	elif d[1] > 0 and d[3] > 0 and (d[6] > 0):
		li2.append([1, 3, 6])
		d[1] -= 1
		d[3] -= 1
		d[6] -= 1
	else:
		break
if len(li2) * 3 == n:
	for i in range(len(li2)):
		print(li2[i][0], li2[i][1], li2[i][2])
else:
	print(-1)


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp()
	l = li()
	c = Counter(l)
	for i in c:
		if c[i] > n // 3:
			pr(-1)
			return
	ans = []
	while True:
		if c[1] and c[2] and c[4]:
			ans.append([1, 2, 4])
			c[1] -= 1
			c[2] -= 1
			c[4] -= 1
		elif c[1] and c[2] and c[6]:
			ans.append([1, 2, 6])
			c[1] -= 1
			c[2] -= 1
			c[6] -= 1
		elif c[1] and c[3] and c[6]:
			ans.append([1, 3, 6])
			c[1] -= 1
			c[3] -= 1
			c[6] -= 1
		else:
			break
	if not sum(c.values()):
		for i in range(len(ans)):
			print(*ans[i])
	else:
		print(-1)
solve()


import math
from bisect import bisect_left, bisect, bisect_right
from itertools import accumulate

def index(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	raise ValueError

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return a[i - 1]
	raise ValueError

def find_le(a, x):
	i = bisect_right(a, x)
	if i:
		return a[i - 1]
	raise ValueError

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return a[i]
	raise ValueError

def find_ge(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return a[i]
	raise ValueError
l = [0 for _ in range(7)]
st = ''

def func(n, l1):
	p = n // 3
	s = ''
	for i in l1:
		l[i - 1] += 1
	z = l.count(0)
	if z > 4 or p != l[0] or (l[4] or l[6]):
		return -1
	if l[3] + l[5] != l[1] + l[2] or l[1] + l[2] != p:
		return -1
	while l[1] and l[3]:
		s += '1 2 4\n'
		l[3] -= 1
		l[1] -= 1
		l[0] -= 1
	while l[1] and l[5]:
		s += '1 2 6\n'
		l[5] -= 1
		l[1] -= 1
		l[0] -= 1
	while l[2] and l[5]:
		s += '1 3 6\n'
		l[5] -= 1
		l[2] -= 1
		l[0] -= 1
	for i in l:
		if i != 0:
			return -1
	return s
n = int(input())
l1 = list(map(int, input().split()))
print(func(n, l1))


n = int(input())
x = [0] * 8
arr = input().split()
for i in arr:
	x[int(i)] += 1
l = x.copy()
c = 0
group = [[1, 2, 4], [1, 2, 6], [1, 3, 6]]
for g in group:
	while l[g[0]] != 0 and l[g[1]] != 0 and (l[g[2]] != 0):
		l[g[0]] -= 1
		l[g[1]] -= 1
		l[g[2]] -= 1
		c += 1
if c == 0 or sum(l) != 0:
	print(-1)
else:
	l = x.copy()
	group = [[1, 2, 4], [1, 2, 6], [1, 3, 6]]
	for g in group:
		while l[g[0]] != 0 and l[g[1]] != 0 and (l[g[2]] != 0):
			print(*g)
			l[g[0]] -= 1
			l[g[1]] -= 1
			l[g[2]] -= 1


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
arr = szzz()
if arr[-1] == 5 or arr[-1] == 7:
	exit(print(-1))
lst = [0] * 8
for i in arr:
	lst[i] += 1
if lst[1] != lst[2] + lst[3] or lst[1] != lst[4] + lst[6] or lst[4] > lst[2]:
	exit(print(-1))
for i in range(lst[4]):
	print('1 2 4')
for i in range(lst[2] - lst[4]):
	print('1 2 6')
for i in range(lst[3]):
	print('1 3 6')


a = int(input())
l = list(map(int, input().split()))
(p, q, r, s, t) = (0, 0, 0, 0, 0)
for i in l:
	if i == 1:
		p += 1
	elif i == 2:
		q += 1
	elif i == 3:
		r += 1
	elif i == 4:
		s += 1
	elif i == 6:
		t += 1
if p == q + r == s + t == a // 3 and s <= q:
	for i in range(s):
		print(1, 2, 4)
	q -= s
	for i in range(q):
		print(1, 2, 6)
	for i in range(r):
		print(1, 3, 6)
else:
	print(-1)


from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
cnt = defaultdict(int)
for x in A:
	cnt[x] += 1
if cnt[5] or cnt[7] or cnt[3] > cnt[1] or (cnt[3] > cnt[6]):
	print(-1)
else:
	threes = 0
	fours = 0
	six = 0
	while cnt[3]:
		cnt[3] -= 1
		cnt[1] -= 1
		cnt[6] -= 1
		threes += 1
	if cnt[4] and (cnt[1] < cnt[4] or cnt[2] < cnt[4]):
		print(-1)
	else:
		while cnt[4]:
			cnt[4] -= 1
			cnt[2] -= 1
			cnt[1] -= 1
			fours += 1
		if cnt[6] and (cnt[1] < cnt[6] or cnt[2] < cnt[6]):
			print(-1)
		else:
			while cnt[6]:
				cnt[1] -= 1
				cnt[2] -= 1
				cnt[6] -= 1
				six += 1
			if sum(cnt.values()) != 0:
				print(-1)
			else:
				for i in range(threes):
					print(1, 3, 6)
				for i in range(fours):
					print(1, 2, 4)
				for i in range(six):
					print(1, 2, 6)


n = int(input())
a = list(map(int, input().split()))
c = [0] * 8
for i in a:
	c[i] += 1
if c[5] or c[7]:
	print(-1)
	return
t1 = c[3]
c[3] = 0
c[1] -= t1
c[6] -= t1
t2 = c[6]
c[1] -= t2
c[6] = 0
c[2] -= t2
t3 = c[4]
c[4] = 0
c[2] -= t3
c[1] -= t3
if c.count(0) != 8 or t1 < 0 or t2 < 0 or (t3 < 0):
	print(-1)
else:
	for i in range(t1):
		print('1 3 6')
	for i in range(t2):
		print('1 2 6')
	for i in range(t3):
		print('1 2 4')


n = int(input())
a = list(map(int, input().split()))
f = 1
res = []
if a.count(1) != n // 3:
	f = 0
elif a.count(2) + a.count(3) != a.count(4) + a.count(6):
	f = 0
elif a.count(3) > a.count(6):
	f = 0
else:
	f = 1
	for i in range(a.count(3)):
		res.append([1, 3, 6])
	for i in range(a.count(6) - a.count(3)):
		res.append([1, 2, 6])
	for i in range(a.count(2) - (a.count(6) - a.count(3))):
		res.append([1, 2, 4])
if len(res) < n // 3:
	f = 0
if f == 0:
	print(-1)
else:
	for i in range(len(res)):
		print(*res[i])


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, input().split()))

def ei():
	return map(int, input().split())

def ip():
	return int(stdin.readline())

def op(ans):
	return stdout.write(str(ans) + '\n')
n = ip()
c = Counter(input().split())
cnt = n // 3
if c['1'] == cnt and c['2'] + c['3'] == cnt and (c['4'] + c['6'] == cnt) and (c['2'] >= c['4']):
	for i in range(c['4']):
		print('1 2 4')
	for i in range(c['2'] - c['4']):
		print('1 2 6')
	for i in range(c['1'] - c['2']):
		print('1 3 6')
else:
	print(-1)


a = [0] * 8
n = int(input())
for i in map(int, input().split()):
	a[i] += 1
if a[1] == n // 3 and a[2] + a[3] == n // 3 and (a[4] + a[6] == n // 3) and (a[3] <= a[6]):
	print('1 2 4\n' * a[4] + '1 3 6\n' * a[3] + '1 2 6\n' * (a[6] - a[3]))
else:
	print(-1)


cnt = [0] * 8
n = int(input())
arr = list(map(int, input().split()))
for i in range(n):
	cnt[arr[i - 1]] = cnt[arr[i - 1]] + 1
if cnt[5] or cnt[7]:
	print(-1)
	exit()
if min(cnt[4], cnt[6] - cnt[3], cnt[3]) >= 0 and cnt[4] + cnt[6] == cnt[2] + cnt[3] and (cnt[4] + cnt[6] == cnt[1]):
	for i in range(cnt[4]):
		print('1 2 4')
	for i in range(cnt[6] - cnt[3]):
		print('1 2 6')
	for i in range(cnt[3]):
		print('1 3 6')
else:
	print(-1)


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
arr.append(2)
arr.append(3)
arr.append(4)
arr.append(6)
c = Counter(arr)
c[2] -= 1
c[3] -= 1
c[4] -= 1
c[6] -= 1
if c[1] != n // 3 or c[1] + c[2] + c[3] + c[4] + c[6] != n:
	print(-1)
elif c[4] > c[2]:
	print(-1)
elif c[6] != -c[4] + c[2] + c[3]:
	print(-1)
else:
	for i in range(c[4]):
		print(1, 2, 4)
	c[2] -= c[4]
	for i in range(c[2]):
		print(1, 2, 6)
	for i in range(c[3]):
		print(1, 3, 6)


n = int(input())
count = dict()
for i in range(1, 8):
	count[i] = 0
solutions = []
for i in map(int, input().split()):
	count[i] += 1
for i in range(n // 3):
	if count[1] > 0:
		if count[2] > 0:
			if count[4] > 0:
				count[1] -= 1
				count[2] -= 1
				count[4] -= 1
				solutions.append([1, 2, 4])
			elif count[6] > 0:
				count[1] -= 1
				count[2] -= 1
				count[6] -= 1
				solutions.append([1, 2, 6])
		elif count[3] > 0:
			if count[6] > 0:
				count[1] -= 1
				count[2] -= 1
				count[6] -= 1
				solutions.append([1, 3, 6])
if len(solutions) == n // 3:
	for (a, b, c) in solutions:
		print('{} {} {}'.format(a, b, c))
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0}
for i in a:
	b[i] += 1
if b[1] != n // 3:
	print(-1)
elif b[2] + b[3] != b[4] + b[6] or b[2] + b[3] != n // 3:
	print(-1)
elif b[6] < b[3] or b[2] < b[4]:
	print(-1)
else:
	for i in range(b[4]):
		print('1', '2', '4')
	for i in range(b[3]):
		print('1', '3', '6')
	for i in range(n // 3 - b[4] - b[3]):
		print('1', '2', '6')


n = int(input())
arr = [int(x) for x in input().split(' ')]
myMap = {}
for x in range(8):
	temp = arr.count(x)
	myMap[x] = arr.count(x)
ans = []

def func(a, b, c):
	g = min(myMap[a], myMap[b], myMap[c])
	for x in range(g):
		ans.append([str(a), str(b), str(c)])
	myMap[a] -= g
	myMap[b] -= g
	myMap[c] -= g
func(1, 2, 4)
func(1, 2, 6)
func(1, 3, 6)
if any([x for x in myMap.values() if x]):
	print(-1)
else:
	for item in ans:
		print(' '.join(item))


n = int(input())
line = map(int, input().split())
book = [0] * 8
for it in line:
	book[it] += 1
if book[1] == n // 3 and book[2] + book[3] == book[4] + book[6] and (book[3] <= book[6]) and (sum(book[1:5]) + book[6] == n):
	for _ in range(book[3]):
		print('1 3 6')
	for _ in range(book[4]):
		print('1 2 4')
	for _ in range(book[1] - book[3] - book[4]):
		print('1 2 6')
else:
	print(-1)


a = [0 for i in range(8)]
N = int(input())
b = list(map(int, input().split()))
for k in range(N):
	a[b[k - 1]] = a[b[k - 1]] + 1
if a[5] or a[7]:
	print(-1)
	return
(A, C) = (a[4], a[3])
B = a[6] - C
if A >= 0 and B >= 0 and (C >= 0) and (A + B == a[2]) and (A + B + C == a[1]):
	for i in range(A):
		print('1 2 4')
	for i in range(B):
		print('1 2 6')
	for i in range(C):
		print('1 3 6')
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = [0] * 8
count = n // 3
l = []
(k1, k2, k3) = (0, 0, 0)
flag = 0
for i in a:
	b[i] += 1
if b[5] > 0 or b[7] > 0 or b[1] != n // 3:
	print(-1)
	flag = 1
else:
	while count > 0:
		if b[1] > 0 and b[2] > 0 and (b[4] > 0):
			count -= 1
			b[1] -= 1
			b[2] -= 1
			b[4] -= 1
			k1 += 1
			l.append([1, 2, 4])
		elif b[1] > 0 and b[2] > 0 and (b[6] > 0):
			count -= 1
			b[1] -= 1
			b[2] -= 1
			b[6] -= 1
			k2 += 1
			l.append([1, 2, 6])
		elif b[1] > 0 and b[3] > 0 and (b[6] > 0):
			count -= 1
			b[1] -= 1
			b[3] -= 1
			b[6] -= 1
			k3 += 1
			l.append([1, 3, 6])
		else:
			break
if count != 0 and (k1 != 0 or k2 != 0 or k3 != 0) or flag == 1 or l == []:
	if flag == 0:
		print(-1)
else:
	for i in range(0, n // 3):
		print(' '.join(map(str, l[i])))


input()
ns = [int(x) for x in input().split()]
cs = [0] * 8
for x in ns:
	cs[x] += 1
if cs[5] or cs[7]:
	print(-1)
	exit(0)
if cs[4] > cs[2] or cs[4] > cs[1]:
	print(-1)
	exit(0)
p4 = cs[4]
cs[2] -= cs[4]
cs[1] -= cs[4]
if cs[6] != cs[2] + cs[3] or cs[6] != cs[1]:
	print(-1)
	exit(0)
for i in range(p4):
	print('1 2 4')
for i in range(cs[2]):
	print('1 2 6')
for i in range(cs[3]):
	print('1 3 6')


from sys import stdin, stdout
n = stdin.readline()
a = list(map(int, stdin.readline().split()))
cnt = [0] * 8
for i in a:
	cnt[i] += 1
c124 = c126 = c136 = 0
if cnt[4] > 0:
	c124 = cnt[4]
	cnt[2] -= cnt[4]
	cnt[1] -= cnt[4]
	cnt[4] = 0
if cnt[3] > 0:
	c136 = cnt[3]
	cnt[6] -= cnt[3]
	cnt[1] -= cnt[3]
	cnt[3] = 0
if cnt[1] > 0:
	c126 = cnt[1]
	cnt[6] -= cnt[1]
	cnt[2] -= cnt[1]
	cnt[1] = 0
if cnt.count(0) != 8:
	stdout.write('-1\n')
else:
	stdout.write('1 2 4\n' * c124)
	stdout.write('1 2 6\n' * c126)
	stdout.write('1 3 6\n' * c136)


import sys
import math
from _collections import deque
n = int(sys.stdin.readline())
an = [int(x) for x in sys.stdin.readline().split()]
ar = [0] * 8
for i in range(n):
	ar[an[i]] += 1
t = int(n / 3)
if ar[1] != t:
	print(-1)
	exit()
c = 0
d = []
for i in range(t):
	if ar[2] > 0 and ar[4] > 0:
		ar[2] -= 1
		ar[4] -= 1
		d.append('1 2 4')
	elif ar[2] > 0 and ar[6] > 0:
		ar[2] -= 1
		ar[6] -= 1
		d.append('1 2 6')
	elif ar[3] > 0 and ar[6] > 0:
		ar[3] -= 1
		ar[6] -= 1
		d.append('1 3 6')
	else:
		c += 1
if c != 0:
	print(-1)
else:
	for i in d:
		print(i)


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def def_value():
	return 0
n = inp()
a = inlist()
count = defaultdict(def_value)
for i in a:
	count[i] += 1
res = -1
tot = 0
output = []
if count[5] > 0 or count[7] > 0:
	print(res)
	sys.exit()
while count[1] > 0 and count[2] > 0 and (count[4] > 0):
	res = 1
	output.append([1, 2, 4])
	count[1] -= 1
	count[2] -= 1
	count[4] -= 1
	tot += 3
while count[1] > 0 and count[2] > 0 and (count[6] > 0):
	res = 1
	output.append([1, 2, 6])
	count[1] -= 1
	count[2] -= 1
	count[6] -= 1
	tot += 3
while count[1] > 0 and count[3] > 0 and (count[6] > 0):
	res = 1
	output.append([1, 3, 6])
	count[1] -= 1
	count[3] -= 1
	count[6] -= 1
	tot += 3
if tot != n:
	print(-1)
else:
	for ot in output:
		print(*ot)


n = int(input())
l = list(map(int, input().split()))
ls = set(l)
res = ''
if len(ls) < 3 or 5 in ls or 7 in ls:
	print(-1)
	exit()
else:
	lc = {1: l.count(1), 2: l.count(2), 3: l.count(3), 4: l.count(4), 6: l.count(6)}
	if lc[1] != n / 3:
		print(-1)
		exit()
	else:
		for i in range(lc[1]):
			r = [1]
			for j in range(2):
				rj2 = r[j] * 2
				rj3 = r[j] * 3
				if rj3 < 7 and lc[rj3] > 0:
					r.append(rj3)
					lc[rj3] -= 1
				elif rj2 < 7 and lc[rj2] > 0:
					r.append(rj2)
					lc[rj2] -= 1
				else:
					break
			if len(r) != 3:
				print(-1)
				exit()
			res += ' '.join(map(str, r)) + '\n'
print(res[:-1])


def calc(n, a):
	group_count = n // 3
	groups = [[] for _ in range(group_count)]
	a = sorted(a)
	i = 0
	for j in range(len(a)):
		is_placed = False
		start = i
		while not is_placed:
			if groups[i] and a[j] <= groups[i][-1]:
				print(-1)
				return
			if not groups[i]:
				is_placed = True
				groups[i].append(a[j])
			elif a[j] % groups[i][-1] == 0:
				groups[i].append(a[j])
				is_placed = True
			i += 1
			i %= group_count
			if start == i:
				print(-1)
				return
	for group in groups:
		print(' '.join([str(x) for x in group]))
n = int(input())
a = list(map(int, input().split()))
calc(n, a)


n = int(input())
l = list(map(int, input().split(' ')))
c1 = l.count(1)
c2 = l.count(2)
c3 = l.count(3)
c4 = l.count(4)
c6 = l.count(6)
if c1 == n // 3 and c2 + c3 == n // 3 and (c4 + c6 == n // 3) and (c4 <= c2) and (c6 >= c3):
	for i in range(c4):
		print('1 2 4')
	for i in range(c6 - c3):
		print('1 2 6')
	for i in range(c3):
		print('1 3 6')
else:
	print('-1')


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

def count_sort(arr, k):
	n = max(arr)
	s = [0] * 8
	alpha = []
	for i in arr:
		s[i] += 1
	c = s.copy()
	for i in range(0, 8):
		if s[i] > 0:
			alpha.append(i)
	for i in range(0, n):
		s[i + 1] = s[i + 1] + s[i]
	ans = [0] * k
	for i in range(0, k):
		ans[s[arr[i]] - 1] = arr[i]
		s[arr[i]] -= 1
	return (ans, c, alpha)
(arr, c, alpha) = count_sort(arr, n)
sol = []
flag = True
for _ in range(0, n // 3):
	count = 0
	i = 1
	if c[alpha[0]] > 0:
		a = [alpha[0]]
	else:
		alpha.pop(0)
		a = [alpha[0]]
	c[alpha[0]] -= 1
	while i < 8:
		i += a[-1]
		if count == 2:
			break
		if i < 8 and c[i] > 0 and (a[-1] < i) and (i % a[-1] == 0):
			count += 1
			a.append(i)
			c[i] -= 1
	if count != 2:
		flag = False
		break
	sol.append(a)
if not flag:
	print(-1)
else:
	for i in sol:
		print(i[0], i[1], i[2])


n = int(input())
arr = [int(x) for x in input().split()]
one = two = three = four = five = six = seven = 0
d = n // 3
for x in arr:
	if x == 1:
		one = one + 1
	elif x == 2:
		two = two + 1
	elif x == 3:
		three = three + 1
	elif x == 4:
		four = four + 1
	elif x == 5:
		five = five + 1
	elif x == 6:
		six = six + 1
	elif x == 7:
		seven = seven + 1
if d == one and five == 0 and (seven == 0):
	if four + six == two and four > 0 and (six > 0) and (two > 0):
		for i in range(d):
			if two > 0 and four > 0:
				print(1, 2, 4)
				two = two - 1
				four = four - 1
			elif two > 0 and six > 0:
				print(1, 2, 6)
				two = two - 1
				six = six - 1
	elif four + six == two + three and three <= six and (four > 0) and (six > 0) and (two > 0) and (three > 0):
		for i in range(d):
			if two > 0 and four > 0:
				print(1, 2, 4)
				two = two - 1
				four = four - 1
			elif two > 0 and six > 0:
				print(1, 2, 6)
				two = two - 1
				six = six - 1
			elif three > 0 and six > 0:
				print(1, 3, 6)
				three = three - 1
				six = six - 1
	elif two == four and two > 0 and (three == 0) and (six == 0):
		for i in range(d):
			if two > 0 and four > 0:
				print(1, 2, 4)
				two = two - 1
				four = four - 1
	elif two == six and two > 0 and (three == 0) and (four == 0):
		for i in range(d):
			if two > 0 and six > 0:
				print(1, 2, 6)
				two = two - 1
				six = six - 1
	elif three == six and six > 0 and (two == 0) and (four == 0):
		for i in range(d):
			if three > 0 and six > 0:
				print(1, 3, 6)
				three = three - 1
				six = six - 1
	elif two + three == six and six > 0 and (two > 0) and (three > 0):
		for i in range(d):
			if two > 0 and six > 0:
				print(1, 2, 6)
				two = two - 1
				six = six - 1
			elif three > 0 and six > 0:
				print(1, 3, 6)
				three = three - 1
				six = six - 1
	else:
		print(-1)
else:
	print(-1)


n = int(input())
arr = list(map(int, input().split()))
s1 = set(arr)
if 5 in arr or 7 in arr or len(s1) < 3:
	print(-1)
else:
	res = dict()
	flag = False
	third = 0
	for i in range(1, 7):
		res[i] = arr.count(i)
	if (res[2] > 0 or res[6] > 0) and res[2] - res[4] == res[6] - res[3] and (res[1] == n / 3):
		third = res[6] - res[3]
		if third < 0:
			flag = False
		else:
			flag = True
	if flag and res[4] + res[3] + third == n / 3:
		for i in range(res[4]):
			print(1, 2, 4)
		for i in range(res[3]):
			print(1, 3, 6)
		for i in range(third):
			print(1, 2, 6)
	else:
		print(-1)


n = int(input())
a = [0] * 7
ww = 0
b = [int(i) for i in input().split()]
ans = [[0] * 3 for i in range(n // 3)]
for i in b:
	a[i - 1] += 1
if a[4] > 0 or a[6] > 0:
	print(-1)
	exit(0)
for i in range(a[3]):
	if a[0] == 0 or a[1] == 0:
		print(-1)
		exit(0)
	else:
		(ans[ww][0], ans[ww][1], ans[ww][2]) = (1, 2, 4)
		ww += 1
		a[0] -= 1
		a[1] -= 1
a[3] = 0
if a[0] == a[1] + a[2] and a[0] == a[5]:
	for i in range(a[1]):
		(ans[ww][0], ans[ww][1], ans[ww][2]) = (1, 2, 6)
		ww += 1
	for i in range(a[2]):
		(ans[ww][0], ans[ww][1], ans[ww][2]) = (1, 3, 6)
		ww += 1
else:
	print(-1)
	exit(0)
for i in range(n // 3):
	for j in range(3):
		print(ans[i][j], end=' ')
	print()


import collections, math, itertools, bisect, heapq, copy

class Solution:

	def solve(self):
		n = int(input())
		A = list(map(int, input().rstrip().split()))
		d = collections.Counter(A)
		if len(d) > 5 or 7 in d or 5 in d or (len(d) <= 2):
			print(-1)
			return
		res = []
		for num in A:
			if num == 4:
				if 4 in d and 2 in d and (1 in d):
					d[4] -= 1
					d[2] -= 1
					d[1] -= 1
				else:
					print(-1)
					return
				if d[4] < 0 or d[2] < 0 or d[1] < 0:
					print(-1)
					return
				res.append('1 2 4')
			elif num == 6:
				if 1 in d:
					d[6] -= 1
					d[1] -= 1
				else:
					print(-1)
					return
				if 3 in d and d[3] > 0:
					d[3] -= 1
					if d[1] < 0 or d[6] < 0 or d[3] < 0:
						print(-1)
						return
					res.append('1 3 6')
				elif 2 in d and d[2] > 0:
					d[2] -= 1
					if d[1] < 0 or d[6] < 0 or d[2] < 0:
						print(-1)
						return
					res.append('1 2 6')
		if not res or len(res) != n // 3:
			print(-1)
			return
		for num in res:
			print(num)
solution = Solution()
solution.solve()


n = int(input())
a = list(map(int, input().split()))
num = [0] * 10
for k in a:
	if k == 5 or k == 7:
		print(-1)
		exit(0)
	num[k] += 1
p = min(num[1], num[2], num[4])
num[1] -= p
num[2] -= p
num[4] -= p
q = min(num[1], num[3], num[6])
num[1] -= q
num[3] -= q
num[6] -= q
k = min(num[1], num[2], num[6])
num[1] -= k
num[2] -= k
num[6] -= k
for i in range(7):
	if num[i + 1]:
		print(-1)
		exit(0)
for i in range(p):
	print(1, 2, 4)
for i in range(q):
	print(1, 3, 6)
for i in range(k):
	print(1, 2, 6)


from collections import Counter
n = int(input())
cnt = Counter(map(int, input().split()))
lst = list()
for (a, b, c) in [(1, 2, 4), (1, 2, 6), (1, 3, 6)]:
	mn = min(cnt[a], cnt[b], cnt[c])
	if mn > 0:
		lst.extend([(a, b, c)] * mn)
		cnt[a] -= mn
		cnt[b] -= mn
		cnt[c] -= mn
if len(lst) * 3 == n:
	for (a, b, c) in lst:
		print(a, b, c)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
d = {}
error = 0
l.sort()
for i in l:
	if i == 5 or i == 7:
		error += 1
	if i not in d:
		d[i] = 0
	d[i] += 1
if l.count(1) != int(n / 3) or l.count(2) + l.count(3) != int(n / 3) or len(d) < 3 or (error > 0) or (l.count(3) > 0 and l.count(6) < l.count(3)):
	print('-1')
else:
	for i in range(int(n / 3)):
		for j in range(i, n, int(n / 3)):
			print(l[j], end=' ')
		print()


from collections import Counter
n = int(input())
counter = Counter((int(x) for x in input().split(' ')))
output = []
valid_threes = [(1, 2, 4), (1, 2, 6), (1, 3, 6)]
while True:
	for three in valid_threes:
		if counter[three[0]] > 0 and counter[three[1]] > 0 and (counter[three[2]] > 0):
			output.append(f'{three[0]} {three[1]} {three[2]}')
			counter[three[0]] -= 1
			counter[three[1]] -= 1
			counter[three[2]] -= 1
			break
	else:
		break
if counter - Counter() == Counter():
	print('\n'.join(output))
else:
	print(-1)


def gint():
	return int(input())

def gint_arr():
	return list(map(int, input().split()))

def gfloat():
	return float(input())

def gfloat_arr():
	return list(map(float, input().split()))

def pair_int():
	return map(int, input().split())
INF = 1 << 31
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
n = gint()
a = gint_arr()
if 5 in a or 7 in a:
	print(-1)
	exit()
cnt = {}
for i in range(1, 7):
	cnt[i] = a.count(i)
res = []
fail = False
while sum(cnt.values()) and (not fail):
	seq = []
	if not cnt[1]:
		fail = True
		break
	else:
		seq.append(1)
		cnt[1] -= 1
	if not cnt[2] and (not cnt[3]):
		fail = True
	elif cnt[2]:
		seq.append(2)
		cnt[2] -= 1
		if not cnt[4]:
			if not cnt[6]:
				fail = True
			else:
				seq.append(6)
				cnt[6] -= 1
		else:
			seq.append(4)
			cnt[4] -= 1
	else:
		seq.append(3)
		cnt[3] -= 1
		if not cnt[6]:
			fail = True
		else:
			seq.append(6)
			cnt[6] -= 1
	if len(seq) != 3:
		fail = True
	else:
		res.append(seq)
if fail:
	print(-1)
else:
	for i in res:
		print(*i)


t = int(input())
a = list(map(int, input().split()))
n = 10 ** 6 + 1
dic = [0] * 8
for i in range(t):
	dic[a[i]] = dic[a[i]] + 1
if dic[5] != 0 or dic[7] != 0:
	print(-1)
elif dic[4] > dic[2] or dic[4] + dic[6] != dic[2] + dic[3] or dic[4] + dic[6] != dic[1]:
	print(-1)
else:
	for i in range(dic[4]):
		print(1, 2, 4, sep=' ')
	for i in range(dic[2] - dic[4]):
		print(1, 2, 6, sep=' ')
	for i in range(dic[3]):
		print(1, 3, 6, sep=' ')


n = int(input())
a = list(map(int, input().split()))
if 5 in a or 7 in a:
	print(-1)
	exit(0)
b = [0] * 8
for i in range(8):
	b[i] = a.count(i)
if b[2] + b[3] == n // 3 and b[1] == n // 3 and (b[4] + b[6] == n // 3) and (b[2] >= b[4]) and (b[6] >= b[3]):
	print('1 2 4\n' * b[4] + '1 3 6\n' * b[3] + '1 2 6\n' * (b[6] - b[3]))
else:
	print(-1)


n = int(input())
li = [int(x) for x in input().split()]
if 5 in li or 7 in li:
	print(-1)
elif li.count(1) != int(n / 3):
	print(-1)
elif li.count(1) < li.count(3):
	print(-1)
elif li.count(1) < li.count(2):
	print(-1)
elif li.count(1) < li.count(6):
	print(-1)
elif li.count(1) < li.count(4):
	print(-1)
else:
	one = li.count(1)
	two = li.count(2)
	three = li.count(3)
	four = li.count(4)
	six = li.count(6)
	lii = []
	while one > 0:
		if one > 0 and two > 0 and (four > 0):
			one -= 1
			two -= 1
			four -= 1
			lii.append([1, 2, 4])
		elif one > 0 and two > 0 and (six > 0):
			one -= 1
			two -= 1
			six -= 1
			lii.append([1, 2, 6])
		elif one > 0 and three > 0 and (six > 0):
			one -= 1
			three -= 1
			six -= 1
			lii.append([1, 3, 6])
		else:
			break
	if one > 0:
		print(-1)
	else:
		for i in lii:
			print(i[0], i[1], i[2])


n = int(input())
list1 = [int(x) for x in input().split()]
list_nums = [0] * 7
list_to_print = []
possible = True
if len(set(list1)) < 3:
	print(-1)
else:
	for i in range(len(list1)):
		if list1[i] == 7 or list1[i] == 5:
			possible = False
			break
		list_nums[list1[i]] += 1
	if list_nums[6] >= list_nums[3] and list_nums[3] <= list_nums[1] and (list_nums[6] != 0) and (list_nums[3] != 0) and (list_nums[1] != 0):
		for i in range(list_nums[3]):
			list_to_print.append([1, 3, 6])
		list_nums[6] -= list_nums[3]
		list_nums[1] -= list_nums[3]
		list_nums[3] = 0
	if list_nums[6] <= list_nums[2] and list_nums[2] <= list_nums[1] and (list_nums[6] != 0) and (list_nums[2] != 0) and (list_nums[1] != 0):
		for i in range(list_nums[6]):
			list_to_print.append([1, 2, 6])
		list_nums[2] -= list_nums[6]
		list_nums[1] -= list_nums[6]
		list_nums[6] = 0
	if list_nums[4] == list_nums[2] and list_nums[2] == list_nums[1]:
		for i in range(list_nums[4]):
			list_to_print.append([1, 2, 4])
	else:
		possible = False
	if possible:
		for w in range(len(list_to_print)):
			print(*list_to_print[w])
	else:
		print(-1)


import collections
N = int(input().strip())
A = list(map(int, input().strip().split()))
cnts = collections.Counter(A)
if 5 in cnts or 7 in cnts:
	print(-1)
elif cnts[1] != N // 3:
	print(-1)
else:
	c136 = cnts[3]
	c124 = cnts[4]
	c126 = N // 3 - c124 - c136
	if cnts[6] != c136 + c126:
		print(-1)
	elif cnts[2] != c124 + c126:
		print(-1)
	elif c126 < 0:
		print(-1)
	else:
		ans1 = [[1, 3, 6]] * c136
		ans2 = [[1, 2, 4]] * c124
		ans3 = [[1, 2, 6]] * c126
		for ans in ans1:
			print(*ans)
		for ans in ans2:
			print(*ans)
		for ans in ans3:
			print(*ans)


n = int(input())
l = list(map(int, input().split()))
flag = True
f2 = 0
if 7 in l:
	print(-1)
	f2 = 1
	flag = False
if 5 in l and flag == True:
	print(-1)
	f2 = 1
	flag = False
while flag == True:
	if l.count(1) != n / 3:
		print(-1)
		f2 = 1
		break
	c1 = l.count(1)
	c2 = 0
	c3 = 0
	c4 = 0
	c6 = 0
	if 2 in l:
		c2 = l.count(2)
	if 3 in l:
		c3 = l.count(3)
	if 4 in l:
		c4 = l.count(4)
	if 6 in l:
		c6 = l.count(6)
	if c4 > c2 or c4 > c1:
		print(-1)
		f2 = 1
		break
	else:
		c1 = c1 - c4
		c2 = c2 - c4
	if c6 > c2 + c3 or c6 != c2 + c3 or c6 == 0:
		print(-1)
		f2 = 1
		break
	flag = False
if f2 == 0:
	while c4 > 0:
		print('1 2 4')
		c4 -= 1
	while c2 > 0:
		print('1 2 6')
		c2 -= 1
	while c3 > 0:
		print('1 3 6')
		c3 -= 1


from sys import *
from collections import Counter
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
n = int(input())
arr = int_arr()
dic = {}
for (ele, ct) in Counter(arr).items():
	dic[ele] = ct
lst = []
ct = 0
flag = 0
req = n // 3
while 1 in dic and dic[1]:
	dic[1] -= 1
	if 2 in dic and 4 in dic and dic[2] and dic[4]:
		lst += [[1, 2, 4]]
		dic[2] -= 1
		dic[4] -= 1
		ct += 1
	elif 2 in dic and 6 in dic and dic[2] and dic[6]:
		lst += [[1, 2, 6]]
		dic[2] -= 1
		dic[6] -= 1
		ct += 1
	elif 3 in dic and 6 in dic and dic[3] and dic[6]:
		lst += [[1, 3, 6]]
		dic[3] -= 1
		dic[6] -= 1
		ct += 1
	elif ct == req:
		flag = 1
		break
	else:
		flag = 0
		break
if flag or ct == req:
	for i in lst:
		print(*i)
else:
	print(-1)


def count(N, L):
	ans = 0
	for i in L:
		if i == N:
			ans += 1
	return ans
for tyuiop in range(1):
	A = int(input())
	N = list(map(int, input().split()))
	ans = []
	if 7 in N:
		print(-1)
		ans = N[:len(N) // 3]
		continue
	if 5 in N:
		print(-1)
		ans = N[:len(N) // 3]
		continue
	if count(3, N) > count(6, N):
		print(-1)
		ans = N[:len(N) // 3]
		continue
	else:
		for i in range(count(3, N)):
			ans.append([1, 3, 6])
	if count(2, N) + count(3, N) != count(4, N) + count(6, N):
		print(-1)
		ans = N[:len(N) // 3]
		continue
	else:
		for i in range(count(6, N) - count(3, N)):
			ans.append([1, 2, 6])
		for i in range(count(2, N) - (count(6, N) - count(3, N))):
			ans.append([1, 2, 4])
	for i in ans:
		if len(ans) * 3 != len(N):
			print(-1)
			break
		print(*i)
if len(ans) * 3 != len(N):
	print(-1)


N = int(input())
n = N / 3
list = [0] * 8
line = input().split()
for i in range(N):
	x = int(line[i])
	list[x] += 1
if list[1] == n and list[2] + list[3] == n and (list[4] + list[6] == n) and (list[6] >= list[3]):
	for i in range(list[3]):
		print('1 3 6')
	for i in range(list[6] - list[3]):
		print('1 2 6')
	for i in range(list[4]):
		print('1 2 4')
else:
	print(-1)


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
import operator
n = int(input())
arr = list(map(int, input().split()))
cs = collections.Counter(arr)
ans = []
if cs[1] and cs[3] and cs[6]:
	mn = min(cs[1], cs[3], cs[6])
	for i in range(mn):
		ans.append([1, 3, 6])
	cs[1] -= mn
	cs[3] -= mn
	cs[6] -= mn
if cs[1] and cs[2] and cs[6]:
	mn = min(cs[1], cs[2], cs[6])
	for i in range(mn):
		ans.append([1, 2, 6])
	cs[1] -= mn
	cs[2] -= mn
	cs[6] -= mn
if cs[1] and cs[2] and cs[4]:
	mn = min(cs[1], cs[2], cs[4])
	for i in range(mn):
		ans.append([1, 2, 4])
	cs[1] -= mn
	cs[2] -= mn
	cs[4] -= mn
if sum(cs.values()) > 0:
	print(-1)
else:
	for k in ans:
		print(*k)


n = int(input())
arr = list(map(int, input().split()))
track = [0] * 7
for i in arr:
	track[i - 1] += 1
if track[6] != 0 or track[4] != 0:
	print(-1)
else:
	c1 = track[0] == track[3] + track[5]
	if c1:
		_124 = track[3]
		track[1] -= _124
		if track[1] >= 0:
			_126 = track[1]
			track[5] -= _126
			if track[5] == track[2]:
				_136 = track[2]
				for i in range(_124):
					print(1, 2, 4)
				for i in range(_126):
					print(1, 2, 6)
				for i in range(_136):
					print(1, 3, 6)
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
l = list(map(int, input().split()))
d = {}
for i in l:
	d[i] = d.get(i, 0) + 1
for i in range(1, 8):
	d[i] = d.get(i, 0)
if d[1] == d[2] + d[3] == d[4] + d[6] == n // 3 and d[4] <= d[2]:
	for i in range(d[4]):
		print(1, 2, 4)
	d[2] -= d[4]
	for i in range(d[2]):
		print(1, 2, 6)
	for i in range(d[3]):
		print(1, 3, 6)
else:
	print(-1)


n = int(input())
l = sorted([*map(int, input().split())])
for i in range(n // 3):
	if not l[i] < l[i + n // 3] < l[i + 2 * n // 3] or l[i + n // 3] % l[i] != 0 or l[i + 2 * n // 3] % l[i + n // 3] != 0:
		print(-1)
		exit()
for i in range(n // 3):
	print(*l[i::n // 3])
exit()


n = input()
a = [int(i) for i in input().split()]
g = 0
k = [0] * 7
flag = False
k[0] = a.count(1)
k[1] = a.count(2)
k[2] = a.count(3)
k[3] = a.count(4)
k[4] = a.count(5)
k[5] = a.count(6)
k[6] = a.count(7)
if k[0] == k[1] + k[2] == k[3] + k[5] and k[4] + k[6] == 0 and (k[2] <= k[5]) and (k[3] <= k[1]):
	flag = True
else:
	print(-1)
if flag:
	for i in range(k[0]):
		print(1, end=' ')
		if k[2] > 0:
			print(3, end=' ')
			print(6)
			k[5] -= 1
			k[2] -= 1
		else:
			print(2, end=' ')
			if k[5] > 0:
				print(6)
				k[5] -= 1
			else:
				print(4)


n = int(input())
a = list(map(int, input().split()))
ctr = [0] * 8
for i in a:
	ctr[i] += 1
res = ''
if ctr[1] != n // 3 or ctr[5] != 0 or ctr[7] != 0:
	print(-1)
else:
	count3 = min([ctr[1], ctr[3], ctr[6]])
	if ctr[3] == count3:
		ctr[1] -= count3
		ctr[3] -= count3
		ctr[6] -= count3
		res = '1 3 6\n' * count3 + res
		count2 = min(ctr[1], ctr[2], ctr[6])
		if ctr[6] == count2:
			ctr[1] -= count2
			ctr[2] -= count2
			ctr[6] -= count2
			res = '1 2 6\n' * count2 + res
			if ctr[1] == ctr[2] and ctr[2] == ctr[4]:
				res = '1 2 4\n' * ctr[1] + res
				print(res)
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
line = list(map(int, input().split()))
count_dict = {}
n_part = n // 3
for i in range(7):
	count_dict[i + 1] = line.count(i + 1)
if count_dict[5] or count_dict[7] or count_dict[1] < n_part or (count_dict[4] > count_dict[2]) or (count_dict[3] > count_dict[6]) or (count_dict[2] + count_dict[3] != count_dict[4] + count_dict[6]) or (not count_dict[2] and (not count_dict[3])):
	print('-1')
else:
	for _ in range(count_dict[4]):
		print('1 2 4')
	for _ in range(count_dict[2] - count_dict[4]):
		print('1 2 6')
	for _ in range(count_dict[3]):
		print('1 3 6')


z = int(input())
x = list(map(int, input().split()))
d = {}
for i in x:
	if d.get(i, 0) == 0:
		d[i] = 1
	else:
		d[i] += 1
s = []
if 1 in d and 2 in d and (4 in d):
	a = min(d[1], d[2], d[4])
	d[1] -= a
	d[2] -= a
	d[4] -= a
	for i in range(a):
		s.append(['1', '2', '4'])
if 1 in d and 3 in d and (6 in d):
	c = min(d[1], d[3], d[6])
	d[1] -= c
	d[3] -= c
	d[6] -= c
	for i in range(c):
		s.append(['1', '3', '6'])
if 1 in d and 2 in d and (6 in d):
	b = min(d[1], d[2], d[6])
	d[1] -= b
	d[2] -= b
	d[6] -= b
	for i in range(b):
		s.append(['1', '2', '6'])
if len(s) * 3 != z:
	print(-1)
else:
	for i in s:
		print(' '.join(i))


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
k = n // 3
x = Counter(arr)
if x[1] != k or x[1] != x[2] + x[3] or x[5] > 0 or (x[7] > 0) or (x[1] != x[4] + x[6]) or (x[4] > x[2]) or (x[3] > x[6]):
	print('-1')
	exit()
else:
	for i in range(x[4]):
		print('1 2 4')
	for j in range(x[2] - x[4]):
		print('1 2 6')
	for m in range(x[3]):
		print('1 3 6')


def main():
	n = int(input())
	s = input()
	(c1, c2, c3, c4, c6) = [s.count(_) for _ in '12346']
	if c1 * 3 != n or c2 < c4 or c1 != c2 + c3 or (c1 != c4 + c6):
		print(-1)
		return
	res = ['1 2 4'] * c1
	for i in range(c4, c2):
		res[i] = '1 2 6'
	for i in range(c2, c1):
		res[i] = '1 3 6'
	print('\n'.join(res))
main()


n = int(input()) // 3
s = input()
(c1, c2, c3, c4, c6) = [s.count(_) for _ in '12346']
if c1 != n or c2 < c4 or c1 != c2 + c3 or (c1 != c4 + c6):
	print(-1)
	exit()
print('1 2 4\n' * c4 + '1 3 6\n' * c3 + '1 2 6\n' * (n - c4 - c3))


def main(n, nums):
	ex = n // 3
	if 5 in nums or 7 in nums or nums.count(1) != ex:
		return -1
	else:
		s = ''
		q = nums.count(4)
		w = nums.count(6)
		e = nums.count(3)
		r = nums.count(2)
		if r != q + w - e or w != e + r - q or e > w or (q > r):
			return -1
		s += '1 2 4\n' * q
		s += '1 2 6\n' * (ex - q - e)
		s += '1 3 6\n' * e
		return s[:-1]

def init():
	n = int(input())
	nums = list(map(int, input().split()))
	print(main(n, nums))
init()


n = int(input())
L = [int(i) for i in input().split()]
d = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0}
for i in L:
	d[i] += 1
if (d[5] != 0 or d[7] != 0) or len(set(L)) < 3 or d[1] != d[2] + d[3] or (d[1] != d[4] + d[6]) or (d[4] > d[2]) or (d[3] > d[6]):
	print('-1')
else:
	ans = ''
	ans += '1 2 4\n' * d[4]
	ans += '1 2 6\n' * (d[2] - d[4])
	ans += '1 3 6\n' * d[3]
	print(ans)


n = int(input())
p = [7]
r = []
cnt = 0
for i in range(0, 8):
	p.append(0)
a = list(map(int, input().split()))
for i in a:
	p[i] = p[i] + 1
if p[5] > 0 or p[7] > 0:
	print('-1')
	exit(0)
if p[1] + p[2] < n / 3:
	print('-1')
	exit(0)
while p[1] > 0 and p[3] > 0 and (p[6] > 0):
	if p[3] > 0 and p[6] > 0:
		r.append('1 3 6')
		p[1] = p[1] - 1
		p[3] = p[3] - 1
		p[6] = p[6] - 1
		cnt = cnt + 1
while p[1] > 0 and p[2] > 0 and (p[4] > 0):
	if p[2] > 0 and p[4] > 0:
		r.append('1 2 4')
		p[1] = p[1] - 1
		p[4] = p[4] - 1
		p[2] = p[2] - 1
		cnt = cnt + 1
while p[1] > 0 and p[2] > 0 and (p[6] > 0):
	if p[2] > 0 and p[6] > 0:
		r.append('1 2 6')
		p[1] = p[1] - 1
		p[2] = p[2] - 1
		p[6] = p[6] - 1
		cnt = cnt + 1
if cnt != n / 3:
	print('-1')
	exit(0)
else:
	for i in r:
		print(i)
exit(0)


from collections import Counter
n = int(input())
inp = list(map(int, input().split()))
c = Counter(inp)
if c[5] > 0 or c[7] > 0 or c[1] != c[4] + c[6] or (c[1] != c[2] + c[3]) or (c[4] > c[2]):
	print(-1)
else:
	for i in range(c[4]):
		print('1 2 4')
	for o in range(c[2] - c[4]):
		print('1 2 6')
	for l in range(c[3]):
		print('1 3 6')


n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 8
for i in a:
	cnt[i] += 1
p = []
k = 7
if cnt[5] > 0 or cnt[7] > 0 or cnt[1] * 3 != n:
	print(-1)
	exit(0)
if cnt[6] > 0 and cnt[3] > 0:
	for i in range(cnt[3]):
		p.append([1, 3, 6])
		cnt[1] -= 1
		cnt[3] -= 1
		cnt[6] -= 1
if cnt[6] > 0 and cnt[2] > 0:
	for i in range(cnt[6]):
		p.append([1, 2, 6])
		cnt[1] -= 1
		cnt[2] -= 1
		cnt[6] -= 1
if cnt[4] > 0 and cnt[2] > 0:
	for i in range(cnt[4]):
		p.append([1, 2, 4])
		cnt[1] -= 1
		cnt[2] -= 1
		cnt[4] -= 1
if sum(cnt) != 0:
	print(-1)
	exit(0)
for i in p:
	for j in sorted(i):
		print(j, end=' ')
	print()


def solve():
	n = int(input())
	numArray = list(map(int, input().split()))
	numArray.sort()
	dictionary = {}
	(found1, found2, found3, found4, found6) = (0,) * 5
	for item in numArray:
		if item == 5 or item == 7:
			print(-1)
			return -1
		if item in dictionary.keys():
			dictionary[item] += 1
		else:
			dictionary[item] = 1
		if item == 1:
			found1 += 1
		if item == 2:
			found2 += 1
		if item == 3:
			found3 += 1
		if item == 4:
			found4 += 1
		if item == 6:
			found6 += 1
	if found1 != n / 3:
		print(-1)
		return -1
	if n / 3 != found6 + found4:
		print(-1)
		return -1
	if n / 3 != found2 + found3:
		print(-1)
		return -1
	if found2 < found4:
		print(-1)
		return -1
	count = dictionary[1]
	while count:
		n = 1
		prev = 1
		str1 = ''
		for item in dictionary.keys():
			if dictionary[item] > 0 and n <= 3 and (int(item) % prev == 0):
				dictionary[item] -= 1
				n += 1
				prev = int(item)
				str1 += str(item) + ' '
		print(str1.strip())
		count -= 1
	return ''
solve()


v = int(input())
a = list(map(int, input().split()))
a.sort()
k = a.count(1)
l = a.count(2)
m = a.count(3)
n = a.count(4)
o = a.count(6)
b = []
if v % 3 != 0:
	print(-1)
	exit()
t = min(k, l, n)
b += [[1, 2, 4]] * t
k -= t
l -= t
n -= t
z = min(k, l, o)
b += [[1, 2, 6]] * z
k -= z
l -= z
o -= z
f = min(k, m, o)
b += [[1, 3, 6]] * f
k -= f
m -= f
o -= f
x = len(b)
if x == len(a) // 3:
	for i in range(len(b)):
		print(*b[i])
else:
	print(-1)


n = int(input())
b = list(map(int, input().split()))
a = []
m = [0] * 8
for i in b:
	m[i] += 1
while m[1] > 0 and m[2] > 0 and (m[4] > 0):
	a.append(str(1) + ' ' + str(2) + ' ' + str(4))
	m[1] -= 1
	m[2] -= 1
	m[4] -= 1
while m[1] > 0 and m[2] > 0 and (m[6] > 0):
	a.append(str(1) + ' ' + str(2) + ' ' + str(6))
	m[1] -= 1
	m[2] -= 1
	m[6] -= 1
while m[1] > 0 and m[3] > 0 and (m[6] > 0):
	a.append(str(1) + ' ' + str(3) + ' ' + str(6))
	m[1] -= 1
	m[3] -= 1
	m[6] -= 1
if len(a) != n // 3:
	print(-1)
else:
	for i in a:
		print(i)


from collections import defaultdict
n = int(input())
d = defaultdict(int)
li = []
for _ in input().split():
	t = int(_)
	li.append(t)
	d[t] += 1
if len(set(li)) < 3:
	print(-1)
else:
	res = []
	f = 1
	partitions = n // 3
	li1 = sorted(list(set(li)))
	while partitions:
		t = []
		for i in li1:
			if len(t) == 0:
				if d[i]:
					t.append(i)
					d[i] -= 1
			elif d[i]:
				if i % t[-1] == 0:
					t.append(i)
					d[i] -= 1
				else:
					continue
			if len(t) == 3:
				break
		if len(t) == 3:
			res.append(t)
			partitions -= 1
		else:
			f = 0
			break
	if not f:
		print(-1)
	else:
		for i in res:
			print(*i)


n = int(input())
arr = [int(x) for x in input().split(' ')]
myMap = {}

def func():
	ans = []
	for x in myMap.values():
		if x > n // 3:
			return -1
	if myMap[3]:
		if myMap[6] >= myMap[3] and myMap[1] >= myMap[3]:
			for x in range(myMap[3]):
				ans.append(['1', '3', '6'])
			myMap[6] -= myMap[3]
			myMap[1] -= myMap[3]
		else:
			return -1
	if myMap[4]:
		if myMap[2] >= myMap[4] and myMap[1] >= myMap[4]:
			for x in range(myMap[4]):
				ans.append(['1', '2', '4'])
			myMap[2] -= myMap[4]
			myMap[1] -= myMap[4]
		else:
			return -1
	if myMap[1] == myMap[2] and myMap[2] == myMap[6]:
		for x in range(myMap[1]):
			ans.append(['1', '2', '6'])
	else:
		return -1
	return sorted(ans)
for x in range(8):
	temp = arr.count(x)
	myMap[x] = arr.count(x)
ans = func()
if ans == -1:
	print(-1)
else:
	for item in ans:
		print(' '.join(item))


n = int(input())
a = list(map(int, input().split()))
b = [0] * 8
for i in a:
	b[i] += 1
res = []
i = 1
while i < 4:
	while b[i] != 0:
		trio = False
		j = i + 1
		while j < 4:
			if j % i == 0 and b[j] != 0:
				k = j + 1
				while k < 8:
					if k % j == 0 and b[k] != 0:
						trio = True
						res.append([i, j, k])
						b[i] -= 1
						b[j] -= 1
						b[k] -= 1
					if trio:
						break
					k += 1
			if trio:
				break
			j += 1
		if not trio:
			break
	i += 1
if len(res) != n // 3:
	print(-1)
else:
	for i in res:
		print(' '.join(map(str, i)))


S = sorted
M = lambda : map(int, input().split())
n = int(input())
x = list(M())
(a, b, c, d, e) = (x.count(1), x.count(2), x.count(3), x.count(4), x.count(6))
if d > b or d + e != a or b + c != a or (a * 3 != n):
	print(-1)
else:
	for i in range(a):
		print(1, 2 if i < b else 3, 4 if i < d else 6)


n = int(input())
a = list(map(int, input().split()))
count = [0] * 7
for i in range(n):
	count[a[i] - 1] += 1
if count[4] == 0 and count[6] == 0 and (count[1] >= count[3]) and (count[0] == count[3] + count[5]) and (count[1] + count[2] == count[3] + count[5]):
	for j in range(count[3]):
		print('1 2 4')
	count[1] -= count[3]
	for k in range(count[1]):
		print('1 2 6')
	for l in range(count[2]):
		print('1 3 6')
else:
	print(-1)


def __starting_point():
	N = int(input())
	L = [0, 0, 0, 0, 0, 0, 0, 0]
	inp = input()
	for i in inp.split(' '):
		L[int(i)] += 1
	it = N // 3
	fnd = True
	ans = []
	for ic in range(it):
		Tl = []
		for el in range(len(L)):
			if L[el] != 0:
				if len(Tl) == 0:
					Tl.append(el)
					L[el] -= 1
				elif el % Tl[-1] == 0:
					Tl.append(el)
					L[el] -= 1
			if len(Tl) == 3:
				break
		if len(Tl) == 3:
			ans.append(str(Tl[0]) + ' ' + str(Tl[1]) + ' ' + str(Tl[2]))
		else:
			fnd = False
			break
	if fnd:
		for a in ans:
			print(a)
	else:
		print('-1')
__starting_point()


from sys import stdin, stdout, exit
import math
import bisect
import math
from math import gcd, floor, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
MOD: int = 1000000007

def fail():
	stdout.write('-1\n')
	exit()
n = int(stdin.readline())
l = list(map(int, stdin.readline().split()))
d = {1: 0, 2: 0, 3: 0, 4: 0, 6: 0}
for i in l:
	if i in (1, 2, 3, 4, 6):
		d[i] += 1
if (5 not in l and 7 not in l) and d[2] >= d[4] and (d[1] == d[4] + d[6]) and (d[2] + d[3] == d[4] + d[6]):
	for _ in range(d[4]):
		stdout.write('1 2 4\n')
	d[2] -= d[4]
	for _ in range(d[2]):
		stdout.write('1 2 6\n')
	for _ in range(d[3]):
		stdout.write('1 3 6\n')
else:
	fail()


from collections import Counter
n = int(input())
c = Counter(input().split())
cnt = n // 3
if c['1'] == cnt and c['2'] + c['3'] == cnt and (c['4'] + c['6'] == cnt) and (c['2'] >= c['4']):
	for i in range(c['4']):
		print('1 2 4')
	for i in range(c['2'] - c['4']):
		print('1 2 6')
	for i in range(c['1'] - c['2']):
		print('1 3 6')
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
(count1, count2, count3, count4, count6) = (0, 0, 0, 0, 0)
t = True
count1 = l.count(1)
count2 = l.count(2)
count3 = l.count(3)
count4 = l.count(4)
count6 = l.count(6)
count5 = l.count(5)
count7 = l.count(7)
x = count2 + count3
y = count4 + count6
c = 0
if count1 == n // 3 and x == n // 3 and (y == n // 3) and (count4 <= count2) and (y <= x):
	for i in range(count3):
		print(1, 3, 6)
	for i in range(count4):
		print(1, 2, 4)
		c += 1
	for i in range(count2 - c):
		print(1, 2, 6)
else:
	print('-1')


import sys
n = int(input())
a = [int(i) for i in input().split()]
d = dict()
if 5 in a or 7 in a:
	print(-1)
	sys.exit()
for i in a:
	if i in d.keys():
		d[i] += 1
	else:
		d[i] = 1
for i in range(1, 7):
	if i not in d.keys():
		d[i] = 0
if d[4] > d[2] or d[4] > d[1] or d[1] != n // 3 or (d[2] - d[4] + d[3] != d[6]):
	print(-1)
	sys.exit()
for _ in range(d[2] - d[4]):
	print('1 2 6')
for _ in range(d[4]):
	print('1 2 4')
for _ in range(d[3]):
	print('1 3 6')


from collections import Counter

def main():
	input()
	c = Counter(map(int, input().split()))
	if c[5] or c[7] or c[2] < c[4] or (c[2] + c[3] != c[1]) or (c[1] != c[4] + c[6]):
		print(-1)
		return
	res = [None] * c[1]
	for i in range(c[4]):
		res[i] = '1 2 4'
	for i in range(c[4], c[2]):
		res[i] = '1 2 6'
	for i in range(c[2], c[1]):
		res[i] = '1 3 6'
	print('\n'.join(res))
main()


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(8):
	d[i] = 0
for i in a:
	d[i] += 1
if d[5] or d[7]:
	print(-1)
	exit()
if d[1] != n // 3:
	print(-1)
	exit()
n24 = 0
n36 = 0
n26 = 0
if d[2] and d[4]:
	n24 += d[4]
	d[2] -= d[4]
	d[4] = 0
	if d[2] < 0:
		print(-1)
		exit()
if d[2] and d[6]:
	n26 += d[2]
	d[6] -= d[2]
	d[2] = 0
	if d[6] < 0:
		print(-1)
		exit()
if d[3] and d[6]:
	n36 += d[6]
	d[3] -= d[6]
	d[6] = 0
	if d[3] < 0:
		print(-1)
		exit()
if d[2] or d[4] or d[3] or d[6]:
	print(-1)
	exit()
for i in range(n24):
	print(1, 2, 4)
for i in range(n36):
	print(1, 3, 6)
for i in range(n26):
	print(1, 2, 6)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
cnt = {}
for _ in range(8):
	cnt[_] = 0
n = int(input())
for x in list(map(int, input().split())):
	cnt[x] += 1
if cnt[1] * 3 == n and cnt[1] == cnt[2] + cnt[3] and (cnt[1] == cnt[6] + cnt[4]) and (cnt[6] == cnt[3] + cnt[2] - cnt[4]) and (cnt[4] <= cnt[2]) and (cnt[3] <= cnt[6]):
	for _ in range(cnt[3]):
		print('1 3 6')
		cnt[1] -= 1
		cnt[3] -= 1
		cnt[6] -= 1
	for _ in range(cnt[6]):
		print('1 2 6')
		cnt[1] -= 1
		cnt[2] -= 1
		cnt[6] -= 1
	for _ in range(cnt[4]):
		print('1 2 4')
		cnt[1] -= 1
		cnt[2] -= 1
		cnt[4] -= 1
else:
	print('-1')


count = {}
ans = []

def mx(a, b, c):
	ans.append((a, b, c))
	count[a] -= 1
	count[b] -= 1
	count[c] -= 1
n = int(input())
nums = list(map(int, input().split()))
if 5 in nums or 7 in nums or nums.count(1) != n // 3:
	print(-1)
else:
	for i in [1, 2, 3, 4, 6]:
		count[i] = nums.count(i)
	while count[2] > 0 and count[4] > 0:
		mx(1, 2, 4)
	while count[2] > 0 and count[6] > 0:
		mx(1, 2, 6)
	while count[3] > 0 and count[6] > 0:
		mx(1, 3, 6)
if sum(count.values()) > 0:
	print(-1)
else:
	for (a, b, c) in ans:
		print(a, b, c)


import math
n = int(input())
lst = list(map(int, input().strip().split(' ')))
if 7 in lst or 5 in lst:
	print(-1)
else:
	c1 = lst.count(1)
	c2 = lst.count(2)
	c3 = lst.count(3)
	c4 = lst.count(4)
	c6 = lst.count(6)
	if c2 + c3 != c4 + c6 and c1 != c2 + c3:
		print(-1)
	else:
		c = 0
		l = []
		f = 0
		while c < c1:
			if c3 > 0 and c6 > 0:
				l.append('1 3 6')
				c3 -= 1
				c6 -= 1
			elif c2 > 0 and c6 > 0:
				l.append('1 2 6')
				c2 -= 1
				c6 -= 1
			elif c2 > 0 and c4 > 0:
				l.append('1 2 4')
				c2 -= 1
				c4 -= 1
			else:
				print(-1)
				f = 1
				break
			c += 1
		if f == 0:
			for j in range(len(l)):
				print(l[j])
			print()


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	tmp = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			cnt = 0
			while n % i == 0:
				n = n // i
				cnt += 1
			tmp.append((i, cnt))
	if n > 1:
		tmp.append((n, 1))
	return tmp

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def s(b):
	ans = []
	while b > 0:
		tmp = b % 10
		ans.append(tmp)
		b = b // 10
	return ans

def main():
	n = ii()
	arr = li()
	d = defaultdict(int)
	flag = 1
	for i in arr:
		d[i] += 1
	ans = []
	for i in range(min(d[1], d[2], d[4])):
		ans.append((1, 2, 4))
		d[1] -= 1
		d[2] -= 1
		d[4] -= 1
	for i in range(min(d[1], d[2], d[6])):
		ans.append((1, 2, 6))
		d[1] -= 1
		d[2] -= 1
		d[6] -= 1
	for i in range(min(d[1], d[3], d[6])):
		ans.append((1, 3, 6))
		d[1] -= 1
		d[3] -= 1
		d[6] -= 1
	if len(ans) == n // 3:
		for i in ans:
			print(*i)
	else:
		print(-1)
main()


import collections
import sys
n = int(input())
sequence = collections.Counter(map(int, input().split()))
answers = []
if sequence[5] > 0 or sequence[7] > 0:
	print(-1)
	sys.exit()
if sequence[3] and sequence[3] <= sequence[1] and (sequence[3] <= sequence[6]):
	for i in range(sequence[3]):
		answers.append([1, 3, 6])
	sequence[1] -= sequence[3]
	sequence[6] -= sequence[3]
	sequence[3] = 0
if sequence[6] and sequence[6] <= sequence[1] and (sequence[6] <= sequence[2]):
	for i in range(sequence[6]):
		answers.append([1, 2, 6])
	sequence[1] -= sequence[6]
	sequence[2] -= sequence[6]
	sequence[6] = 0
if sequence[4] and sequence[4] == sequence[2] == sequence[1]:
	for i in range(sequence[4]):
		answers.append([1, 2, 4])
if len(answers) == n / 3:
	for answer in answers:
		print(*answer)
else:
	print(-1)


def minGroup(b, i, j, k):
	a1 = min(b[i], b[j], b[k])
	b[i] = b[i] - a1
	b[j] = b[j] - a1
	b[k] = b[k] - a1
	if b[i] < 0 or b[j] < 0 or b[k] < 0:
		return (b, -1)
	else:
		return (b, a1)
n = int(input())
a = list(map(int, input().split(' ')))
a = sorted(a)
b = [0] * 8
temp = n // 3
for i in a:
	b[i] += 1
t = ['124', '126', '136']
c = ''
(b, a1) = minGroup(b, 1, 2, 4)
if a1 == -1:
	print('-1')
	quit()
(b, a2) = minGroup(b, 1, 2, 6)
if a2 == -1:
	print('-1')
	quit()
(b, a3) = minGroup(b, 1, 3, 6)
if a3 == -1:
	print('-1')
	quit()
if a1 + a2 + a3 != temp:
	print('-1')
	quit()
else:
	print('1 2 4\n' * a1, '1 2 6\n' * a2, '1 3 6\n' * a3, sep='')


n = int(input())
(a, l, k) = (list(map(int, input().split())), [0] * 5, n // 3)
for i in a:
	if i == 5 or i == 7:
		exit(print(-1))
	elif i == 3:
		l[4] += 1
	else:
		l[i // 2] += 1
if l[2] + l[3] != k or l[0] != k or l[4] + abs(l[1] - l[2]) != l[3]:
	print(-1)
else:
	exec('print(1,2,4);' * l[2] + 'print(1,2,6);' * (l[1] - l[2]) + 'print(1,3,6);' * l[4])


n = int(input())
d = list(map(int, input().split()))
d.sort()
ans = []
for i in range(n // 3):
	a = d[i]
	b = d[i + n // 3]
	c = d[i + 2 * n // 3]
	if a < b and b < c and (b % a == 0) and (c % b == 0):
		ans.append([a, b, c])
	else:
		break
if len(ans) == n / 3:
	for i in ans:
		for j in i:
			print(j, end=' ')
		print()
else:
	print(-1)


n = int(input())
nums = list(map(int, input().split(' ')))
if 7 in nums or 5 in nums:
	print(-1)
	exit()
else:
	one = nums.count(1)
	two = nums.count(2)
	three = nums.count(3)
	four = nums.count(4)
	six = nums.count(6)
	if one == n // 3 and two + three == n // 3 and (four + six == n // 3) and (four <= two) and (six >= three):
		for i in range(three):
			print(1, 3, 6)
		for i in range(four):
			print(1, 2, 4)
		for i in range(six - three):
			print(1, 2, 6)
	else:
		print(-1)


n = int(input())
a = [0] * 8
c = []
s = 0
count = 3
b = list(map(int, input().split()))
for i in b:
	a[i] += 1
if len(set(b)) <= 2:
	print(-1)
else:
	for i in range(n // 3):
		if count < 3:
			s = 1
		count = 0
		for j in range(8):
			if count == 3:
				break
			if a[j] != 0:
				if count == 0:
					c.append(j)
					count += 1
					a[j] -= 1
				elif j % c[-1] == 0:
					c.append(j)
					a[j] -= 1
					count += 1
	if count < 3:
		s = 1
	if s == 0:
		for i in range(1, n + 1):
			if i % 3 == 0:
				print(c[i - 1])
			else:
				print(c[i - 1], end=' ')
	else:
		print(-1)


import sys
n = int(input())
l = list(map(int, input().split()))
if 5 in l or 7 in l:
	print(-1)
elif 3 in l and (not 6 in l):
	print(-1)
else:
	d = {1: 0, 2: 0, 3: 0, 4: 0, 6: 0}
	for i in l:
		d[i] += 1
	ans = []
	for i in range(n // 3):
		if d[1] > 0 and d[2] > 0 and (d[4] > 0):
			x = [1, 2, 4]
			d[1] -= 1
			d[2] -= 1
			d[4] -= 1
		elif d[1] > 0 and d[3] > 0 and (d[6] > 0):
			x = [1, 3, 6]
			d[1] -= 1
			d[3] -= 1
			d[6] -= 1
		elif d[1] > 0 and d[2] > 0 and (d[6] > 0):
			x = [1, 2, 6]
			d[1] -= 1
			d[2] -= 1
			d[6] -= 1
		else:
			continue
		ans.append(x)
	if d[1] > 0 or d[2] > 0 or d[3] > 0 or (d[4] > 0) or (d[6] > 0):
		print(-1)
	else:
		for i in ans:
			print(*i)


n = int(input())
l = list(map(int, input().split()))
s = set(l)
if len(s) < 3 or 5 in l or 7 in l:
	print(-1)
else:
	d = {1: 0, 2: 0, 3: 0, 4: 0, 6: 0}
	for i in l:
		d[i] = d.get(i, 0) + 1
	if 6 in s and 4 in s:
		if d[1] == d[6] + d[4]:
			c = abs(d[6] - d[3])
			rem = d[2] - c
			if rem <= 0:
				print(-1)
			elif rem != d[4]:
				print(-1)
			else:
				for i in range(rem):
					print(1, 2, 4)
				for i in range(d[3]):
					print(1, 3, 6)
				for i in range(d[2] - rem):
					print(1, 2, 6)
		else:
			print(-1)
	elif 6 in d:
		if d[1] == d[6]:
			if d[2] + d[3] == d[6]:
				for i in range(d[3]):
					print(1, 3, 6)
				for i in range(d[6] - d[3]):
					print(1, 2, 6)
			else:
				print(-1)
		else:
			print(-1)
	elif 4 in d:
		if d[1] == d[4] and d[2] == d[4]:
			for i in range(d[2]):
				print(1, 2, 4)
		else:
			print(-1)
	else:
		print(-1)


from collections import Counter

def go():
	n = int(input())
	c = Counter([int(i) for i in input().split(' ')])
	o = ''
	if len(c) < 3 or 5 in c or 7 in c:
		return -1
	while len(c) > 2:
		forward = False
		if 1 in c and 2 in c and (4 in c):
			o += '1 2 4\n'
			if c[1] == 1:
				c.pop(1)
			else:
				c[1] -= 1
			if c[2] == 1:
				c.pop(2)
			else:
				c[2] -= 1
			if c[4] == 1:
				c.pop(4)
			else:
				c[4] -= 1
			forward = True
		elif 1 in c and 2 in c and (6 in c):
			o += '1 2 6\n'
			if c[1] == 1:
				c.pop(1)
			else:
				c[1] -= 1
			if c[2] == 1:
				c.pop(2)
			else:
				c[2] -= 1
			if c[6] == 1:
				c.pop(6)
			else:
				c[6] -= 1
			forward = True
		elif 1 in c and 3 in c and (6 in c):
			o += '1 3 6\n'
			if c[1] == 1:
				c.pop(1)
			else:
				c[1] -= 1
			if c[3] == 1:
				c.pop(3)
			else:
				c[3] -= 1
			if c[6] == 1:
				c.pop(6)
			else:
				c[6] -= 1
			forward = True
		if not forward:
			break
	if len(c) != 0:
		return -1
	return o
print(go())


n = int(input())
l = [int(i) for i in input().split()]
f = 1
from collections import Counter
c = Counter(l)
ans = []
while c:
	if c[1] and c[2] and c[4]:
		ans.append([1, 2, 4])
		c[1] -= 1
		c[2] -= 1
		c[4] -= 1
	elif c[1] and c[2] and c[6]:
		ans.append([1, 2, 6])
		c[1] -= 1
		c[2] -= 1
		c[6] -= 1
	elif c[1] and c[3] and c[6]:
		ans.append([1, 3, 6])
		c[1] -= 1
		c[3] -= 1
		c[6] -= 1
	else:
		break
if not sum(c.values()):
	for i in range(len(ans)):
		print(*ans[i])
else:
	print(-1)


from __future__ import division, print_function
import math
import os
import sys
from sys import stdin, stdout
from io import BytesIO, IOBase
from itertools import accumulate
from collections import deque
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def main():
	n = int(input())
	l = [[1, 2, 6], [1, 2, 4], [1, 3, 6]]
	arr = list(map(int, input().split()))
	ans = []
	if 5 in arr or 7 in arr:
		print(-1)
	else:
		one = arr.count(1)
		four = arr.count(4)
		if one != n // 3:
			print(-1)
		else:
			two = arr.count(2)
			three = arr.count(3)
			if 4 in arr:
				for i in range(four):
					ans.append([1, 2, 4])
				two -= four
				one -= four
			if two < 0 or three < 0:
				print(-1)
			else:
				if two > 0:
					for i in range(two):
						ans.append([1, 2, 6])
				if three > 0:
					for i in range(three):
						ans.append([1, 3, 6])
				if len(ans) != n // 3:
					print(-1)
				else:
					for i in ans:
						print(*i)
main()


n = int(input())
a = list(map(int, input().split()))
d = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0}
for i in a:
	d[i] += 1
if (d[5] != 0 or d[7] != 0) or len(set(a)) < 3 or d[1] != d[2] + d[3] or (d[4] > d[2]) or (d[6] < d[3]):
	print(-1)
else:
	res = ''
	res += '1 2 4\n' * d[4]
	res += '1 3 6\n' * d[3]
	res += '1 2 6\n' * (d[2] - d[4])
	print(res)


n = int(input())
p = True
a = [int(x) for x in input().split()]
a.sort()
l = []
for i in range(n // 3):
	if a[i + 2 * n // 3] % a[i + n // 3] == 0 and a[i + n // 3] % a[i] == 0 and (a[i] < a[i + n // 3] < a[i + 2 * n // 3]):
		l.append([a[i], a[i + n // 3], a[i + 2 * n // 3]])
	else:
		p = False
if p is False and len(l) != n // 3:
	print(-1)
else:
	for i in l:
		print(*i)


n = int(input())
array = input().split()
count_1 = 0
count_2 = 0
count_3 = 0
count_4 = 0
count_6 = 0
for element in array:
	if element is '1':
		count_1 += 1
	elif element is '2':
		count_2 += 1
	elif element is '3':
		count_3 += 1
	elif element is '4':
		count_4 += 1
	elif element is '6':
		count_6 += 1
if count_1 == len(array) / 3 and count_1 == count_2 + count_3 and (count_3 <= count_6) and (count_2 == count_4 + count_6 - count_3):
	for i in range(count_4):
		print('1 2 4')
	for i in range(count_2 - count_4):
		print('1 2 6')
	for i in range(count_3):
		print('1 3 6')
else:
	print(-1)


from collections import defaultdict

def main():
	n = int(input())
	a = map(int, input().split(' '))
	m = defaultdict(int)
	for ai in a:
		m[ai] += 1
	if m[5] > 0 or m[7] > 0:
		return '-1'
	twos = 0
	threes = 0
	fours = 0
	threes += m[3]
	m[1] -= m[3]
	m[6] -= m[3]
	m[3] = 0
	if m[1] < 0 or m[6] < 0:
		return '-1'
	fours += m[4]
	m[1] -= m[4]
	m[2] -= m[4]
	m[4] = 0
	if m[2] < 0 or m[1] < 0:
		return '-1'
	twos += m[2]
	m[1] -= m[2]
	m[6] -= m[2]
	m[2] = 0
	if m[1] < 0 or m[6] < 0:
		return '-1'
	l = []
	for i in range(fours):
		l.append('1 2 4')
	for i in range(twos):
		l.append('1 2 6')
	for i in range(threes):
		l.append('1 3 6')
	if len(l) == 0:
		return '-1'
	for i in range(6):
		if m[i] > 0:
			return '-1'
	return '\n'.join(l)
print(main())


def gen_ans(b, c):
	if infArr[1] and infArr[b] and infArr[c]:
		ans.append(f'1 {b} {c}')
		infArr[1] -= 1
		infArr[b] -= 1
		infArr[c] -= 1
		return True
	return False
n = int(input())
arr = map(int, input().split())
infArr = [0] * 8
for m in arr:
	infArr[m] += 1
ans = []
while True:
	if gen_ans(3, 6):
		pass
	elif gen_ans(2, 6):
		pass
	elif gen_ans(2, 4):
		pass
	else:
		break
if sum(infArr) > 0:
	print(-1)
else:
	print('\n'.join(ans))


def check(n, temp):
	value = 0
	result = list()
	if 5 in temp or 7 in temp:
		value = -1
		return (value, result)
	k = n // 3
	a = list()
	b = list()
	c = list()
	temp.sort()
	for i in temp:
		if i == 1:
			a.append(i)
		if i in (2, 3):
			b.append(i)
		if i in (4, 6):
			c.append(i)
	if len(a) != k or len(b) != k or len(c) != k:
		value = -1
		return (value, result)
	else:
		for i in range(k):
			if b[i] == 3 and c[i] == 4:
				value = -1
				return (value, result)
			result.append((a[i], b[i], c[i]))
	return (value, result)
n = int(input().rstrip())
temp = list(map(int, input().rstrip().split()))
k = n // 3
(value, arr) = check(n, temp)
if value == -1:
	print(value)
else:
	for i in range(k):
		print(arr[i][0], arr[i][1], arr[i][2])


n = int(input())
nums = list(map(int, input().split()))
counts = [0 for i in range(8)]
for n in nums:
	counts[n] += 1
if counts[1] != counts[2] + counts[3] or counts[2] != counts[4] + counts[6] - counts[3] or counts[3] != counts[6] - (counts[2] - counts[4]) or (counts[4] > counts[2]) or (counts[5] != 0) or (counts[7] != 0):
	print(-1)
else:
	for i in range(counts[4]):
		print(1, 2, 4)
	for i in range(counts[6] - counts[3]):
		print(1, 2, 6)
	for i in range(counts[3]):
		print(1, 3, 6)


n = int(input()) // 3
x = input()
c1 = x.count('1')
c2 = x.count('2')
c3 = x.count('3')
c4 = x.count('4')
c6 = x.count('6')
if c1 != n or c2 < c4 or c1 != c2 + c3 or (c1 != c4 + c6):
	print(-1)
	exit()
print('1 2 4\n' * c4 + '1 3 6\n' * c3 + '1 2 6\n' * (n - c4 - c3))


n = int(input())
a = list(map(int, input().split()))
dic = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0}
ans = []
for item in a:
	dic[item] += 1
if dic[5] > 0 or dic[7] > 0:
	print(-1)
	exit()
while dic[3] > 0:
	ans.append((1, 3, 6))
	dic[1] -= 1
	dic[3] -= 1
	dic[6] -= 1
while dic[6] > 0:
	ans.append((1, 2, 6))
	dic[1] -= 1
	dic[2] -= 1
	dic[6] -= 1
while dic[4] > 0:
	ans.append((1, 2, 4))
	dic[1] -= 1
	dic[2] -= 1
	dic[4] -= 1
for item in dic.values():
	if item != 0:
		print(-1)
		exit()
for item in ans:
	print(*item)


n = int(input())
a = [int(i) for i in input().split()]
results = []
dp = [0] * 8
for i in a:
	dp[i] += 1
if dp[7] == dp[5] == 0 and dp[4] <= dp[2] and (dp[3] + dp[2] - dp[4] == dp[6]) and (dp[1] == n // 3):
	for i in range(dp[4]):
		print(1, 2, 4)
		dp[2] -= 1
	for i in range(dp[2]):
		print(1, 2, 6)
		dp[6] -= 1
	for i in range(dp[6]):
		print(1, 3, 6)
else:
	print(-1)


import sys, threading, os.path
import collections, heapq, math, bisect
import string
from platform import python_version
import itertools
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('input.txt'):
		input = open('input.txt', 'r')
	else:
		input = sys.stdin
	n = int(input.readline())
	lis = list(map(int, input.readline().split()))
	dict1 = {}
	for x in lis:
		if x in dict1:
			dict1[x] += 1
		else:
			dict1[x] = 1
	impossib = False
	if 1 not in dict1 or dict1[1] != n / 3:
		impossib = True
	if 3 in dict1 and (6 not in dict1 or dict1[6] < dict1[3]):
		impossib = True
	allres = []
	for i in range(int(n / 3)):
		allres.append([1])
	if 1 in dict1:
		dict1[1] = 0
	for i in range(int(n / 3)):
		if 3 in dict1 and dict1[3] > 0:
			allres[i].append(3)
			dict1[3] -= 1
		elif 2 in dict1 and dict1[2] > 0:
			allres[i].append(2)
			dict1[2] -= 1
	for i in range(int(n / 3)):
		if 6 in dict1 and dict1[6] > 0 and (len(allres[i]) < 3):
			allres[i].append(6)
			dict1[6] -= 1
	for i in range(int(n / 3)):
		if 4 in dict1 and dict1[4] > 0 and (len(allres[i]) < 3):
			allres[i].append(4)
			dict1[4] -= 1
	for (key, value) in dict1.items():
		if value > 0:
			impossib = True
	if impossib:
		output = -1
	else:
		output = '\n'.join((str(e[0]) + ' ' + str(e[1]) + ' ' + str(e[2]) for e in allres))
	if os.path.exists('output.txt'):
		open('output.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


n = int(input())
a = list(map(int, input().split()))
one = a.count(1)
two = a.count(2)
three = a.count(3)
four = a.count(4)
six = a.count(6)
if one == n // 3 and two + three == n // 3 and (four + six == n // 3) and (four <= two) and (six >= three):
	for i in range(three):
		print(1, 3, 6)
	for i in range(four):
		print(1, 2, 4)
	for i in range(six - three):
		print(1, 2, 6)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
c = [0] * 8
for i in range(n):
	c[a[i]] += 1
x = min(c[1], c[2], c[4])
c[1] -= x
c[2] -= x
c[4] -= x
y = min(c[1], c[2], c[6])
c[1] -= y
c[2] -= y
c[6] -= y
z = min(c[1], c[3], c[6])
if 3 * (x + y + z) != n:
	print(-1)
else:
	for i in range(x):
		print(1, 2, 4)
	for i in range(y):
		print(1, 2, 6)
	for i in range(z):
		print(1, 3, 6)


n = int(input())
z = list(map(int, input().split()))
o1 = z.count(1)
o2 = z.count(2)
o3 = z.count(3)
o4 = z.count(4)
o6 = z.count(6)
if 5 in z or 7 in z:
	print(-1)
else:
	l1 = []
	l2 = []
	l3 = []
	c = 0
	k1 = [1, 2, 4]
	k2 = [1, 3, 6]
	k3 = [1, 2, 6]
	p = min(o1, o2, o4)
	for i in range(p):
		c = c + 3
		l1.append(k1)
	o1 = o1 - p
	o2 = o2 - p
	o4 = o4 - p
	p1 = min(o1, o2, o6)
	for i in range(p1):
		l2.append(k3)
		c = c + 3
		o1 -= 1
		o2 -= 1
		o6 -= 1
	p2 = min(o1, o3, o6)
	for i in range(p2):
		l3.append(k2)
		c = c + 3
		o1 -= 1
		o3 -= 1
		o6 -= 1
	if c == n:
		if len(k1) != 0:
			for i in l1:
				print(*i)
		if len(k2) != 0:
			for i in l2:
				print(*i)
		if len(k3) != 0:
			for i in l3:
				print(*i)
	else:
		print(-1)


n = int(input())
arr = list(map(int, input().split()))
d = {1: 0, 2: 0, 3: 0, 4: 0, 6: 0}
boolean = 1
for i in arr:
	if i == 5 or i == 7:
		print(-1)
		boolean = 0
		break
	else:
		d[i] += 1
if boolean != 0:
	if d[1] == n // 3 and d[6] - d[3] + d[4] == d[2] and (d[6] >= d[3]) and (d[2] >= d[4]):
		for i in range(d[4]):
			print(1, 2, 4, sep=' ')
		for i in range(d[3]):
			print(1, 3, 6, sep=' ')
		for i in range(d[6] - d[3]):
			print(1, 2, 6, sep=' ')
	else:
		print(-1)


from collections import Counter
lens = int(input())
arrs = Counter([int(x) for x in input().split()])
if arrs[5] > 0 or arrs[7] > 0:
	print(-1)
elif arrs[4] + arrs[6] != arrs[1]:
	print(-1)
elif arrs[2] + arrs[3] != arrs[1]:
	print(-1)
elif arrs[4] > arrs[2]:
	print(-1)
else:
	for i in range(1, arrs[4] + 1):
		print(*[1, 2, 4])
	for i in range(1, arrs[3] + 1):
		print(*[1, 3, 6])
	for i in range(1, arrs[6] - arrs[3] + 1):
		print(*[1, 2, 6])


from collections import Counter

def main():
	n = int(input())
	numbers = list(map(int, input().split()))
	number_count = Counter(numbers)
	if number_count.get(7, 0) > 0:
		print(-1)
		return
	if number_count.get(5, 0) > 0:
		print(-1)
		return
	one_count = number_count.get(1, 0)
	two_count = number_count.get(2, 0)
	three_count = number_count.get(3, 0)
	four_count = number_count.get(4, 0)
	six_count = number_count.get(6, 0)
	if four_count <= two_count and four_count + six_count == one_count:
		two_count -= four_count
		one_count -= four_count
		if six_count == three_count + two_count and six_count == one_count:
			for i in range(four_count):
				print('1 2 4')
			for i in range(three_count):
				print('1 3 6')
			for i in range(two_count):
				print('1 2 6')
	else:
		print(-1)
main()


input()
lit = input()
c = str.count
a = c(lit, '1')
a2 = c(lit, '2')
a3 = c(lit, '3')
a4 = c(lit, '4')
a6 = c(lit, '6')
a5 = c(lit, '5')
a7 = c(lit, '7')
ans = ''
k = min(a, a2, a4)
ans += '1 2 4n' * min(a, a2, a4)
a -= k
a2 -= k
a4 -= k
k = min(a, a2, a6)
ans += '1 2 6n' * min(a, a2, a6)
a -= k
a2 -= k
a6 -= k
k = min(a, a3, a6)
ans += '1 3 6n' * min(a, a3, a6)
a -= k
a3 -= k
a6 -= k
if a + a2 + a3 + a4 + a6 + a5 + a7 > 0:
	print('-1')
else:
	l = ans.split('n')
	for i in l:
		print(i)


n = int(input())
b = [0] * 8
a = [int(x) for x in input().split()]
for i in a:
	b[i] += 1
k1 = k2 = k3 = 0
if b[5] == b[7] == 0:
	if b[3] > 0:
		b[6] -= b[3]
		b[1] -= b[3]
		k2 = b[3]
		b[3] = 0
	if b[6] > 0:
		k1 = b[6]
		b[1] -= b[6]
		b[2] -= b[6]
		b[6] = 0
	if b[4] > 0:
		k3 = b[4]
		b[1] -= b[4]
		b[2] -= b[4]
		b[4] = 0
	if b[1] == b[2] == b[3] == b[4] == b[6] == 0:
		for i in range(k3):
			print('1 2 4')
		for i in range(k1):
			print('1 2 6')
		for i in range(k2):
			print('1 3 6')
	else:
		print('-1')
else:
	print('-1')


n = int(input())
arr = list(map(int, input().split()))
counts = [0] * 8
for x in arr:
	counts[x] += 1
if counts[5] != 0 or counts[7] != 0 or (not counts[1]):
	print(-1)
else:
	f = 1
	ans = []
	c = min(counts[1], counts[3], counts[6])
	if counts[3] and counts[6]:
		for x in range(c):
			ans.append((1, 3, 6))
		counts[1] -= c
		counts[3] -= c
		counts[6] -= c
	if counts[2]:
		a = min(counts[1], counts[2], counts[4])
		if counts[4] and counts[1]:
			for x in range(a):
				ans.append((1, 2, 4))
			counts[4] -= a
			counts[2] -= a
			counts[1] -= a
		b = min(counts[1], counts[2], counts[6])
		if counts[6] and counts[2] and counts[1]:
			for x in range(b):
				ans.append((1, 2, 6))
			counts[1] -= b
			counts[2] -= b
			counts[6] -= b
	for x in counts:
		if x:
			print(-1)
			f = 0
			break
	if f:
		for x in ans:
			print(x[0], x[1], x[2])


n = int(input())
l = list(map(int, input().split()))
(a, b, c, d, e) = (l.count(1), l.count(2), l.count(3), l.count(4), l.count(6))
ans = ''
if 5 in l or 7 in l or a != b + c or (a != d + e) or (d > b):
	print(-1)
else:
	for _ in range(d):
		ans += '1 2 4\n'
	for _ in range(b - d):
		ans += '1 2 6\n'
	for _ in range(c):
		ans += '1 3 6\n'
print(ans[:-1])


import sys
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
L = [0] * 8
for item in A:
	L[item] += 1
if L[1] != N // 3:
	print(-1)
elif L[7] > 0 or L[5] > 0:
	print(-1)
elif L[3] + L[2] != N // 3:
	print(-1)
elif L[4] + L[6] != N // 3:
	print(-1)
elif L[2] < L[4]:
	print(-1)
else:
	for i in range(L[3]):
		sys.stdout.write('1 3 6\n')
	L[6] -= L[3]
	for i in range(L[6]):
		sys.stdout.write('1 2 6\n')
	for i in range(L[4]):
		sys.stdout.write('1 2 4\n')


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for val in a:
	d[val] += 1
res = []
ok = True
while d[4] > 0:
	if d[1] == 0 or d[2] == 0:
		ok = False
		break
	res.append([1, 2, 4])
	for x in (1, 2, 4):
		d[x] -= 1
if ok:
	while d[3] > 0:
		if d[1] == 0 or d[6] == 0:
			ok = False
			break
		res.append([1, 3, 6])
		for x in (1, 3, 6):
			d[x] -= 1
	if ok:
		while d[2] > 0:
			if d[1] == 0 or d[6] == 0:
				ok = False
				break
			res.append([1, 2, 6])
			for x in (1, 2, 6):
				d[x] -= 1
if not ok or sum(d.values()) > 0:
	print(-1)
else:
	for i in range(len(res)):
		print(' '.join(map(str, res[i])))


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
f = n // 3
d = Counter(l)
t = []
for i in d:
	t.append(d[i] > f)
if 5 in d or 7 in d or any(t) or (d[1] != f) or (d[3] > d[6]) or (d[2] < d[4]) or (d[3] + d[2] != d[4] + d[6]):
	print(-1)
else:
	while f:
		if d[3] != 0 and d[6] != 0:
			print(1, 3, 6)
			d[3] -= 1
			d[1] -= 1
			d[6] -= 1
		elif d[2] != 0 and d[4] != 0:
			print(1, 2, 4)
			d[2] -= 1
			d[1] -= 1
			d[4] -= 1
		elif d[2] != 0 and d[6] != 0:
			print(1, 2, 6)
			d[2] -= 1
			d[1] -= 1
			d[6] -= 1
		f -= 1


from collections import defaultdict
n = int(input())
l = [int(x) for x in input().split()]
dic = defaultdict(int)
for x in l:
	dic[x] += 1
first = dic[1]
second = dic[2] + dic[3]
third = dic[4] + dic[6]
N = len(l)
if 7 in l:
	print('-1')
elif not (first == N // 3 and second == N // 3 and (third == N // 3)):
	print('-1')
elif dic[6] < dic[3]:
	print('-1')
else:
	for _ in range(dic[4]):
		print('1 2 4')
	for _ in range(dic[6] - dic[3]):
		print('1 2 6')
	for _ in range(dic[3]):
		print('1 3 6')


_ = input()
numbers = {i: 0 for i in range(8)}
for num in input().split():
	num = int(num)
	numbers[num] += 1
if numbers[7] > 0 or numbers[5] > 0:
	print(-1)
	exit()
group63 = group62 = 0
while numbers[6] != 0 and numbers[3] != 0 and (numbers[1] != 0):
	numbers[6] -= 1
	numbers[3] -= 1
	numbers[1] -= 1
	group63 += 1
while numbers[6] != 0 and numbers[2] != 0 and (numbers[1] != 0):
	numbers[6] -= 1
	numbers[2] -= 1
	numbers[1] -= 1
	group62 += 1
group4 = 0
while numbers[4] != 0 and numbers[2] != 0 and (numbers[1] != 0):
	numbers[4] -= 1
	numbers[2] -= 1
	numbers[1] -= 1
	group4 += 1
for num in numbers.values():
	if num != 0:
		print(-1)
		exit()
for i in range(group4):
	print(1, 2, 4)
for i in range(group62):
	print(1, 2, 6)
for i in range(group63):
	print(1, 3, 6)


def solution():
	n = int(input())
	max_count = n // 3
	counter = {}
	for ch in input().split():
		counter[ch] = counter.get(ch, 0) + 1
		if counter[ch] > max_count or ch in ('5', '7'):
			return -1
	ans = []
	p1 = ['1 2 4']
	p2 = ['1 3 6']
	p3 = ['1 2 6']
	if counter.get('1', 0) < max_count != max_count:
		return -1
	if counter.get('2', 0) < counter.get('4', 0):
		return -1
	if counter.get('6', 0) < counter.get('3', 0):
		return -1
	if counter.get('4'):
		counter['2'] -= counter['4']
		ans.extend(p1 * counter['4'])
	if counter.get('3'):
		counter['6'] -= counter['3']
		ans.extend(p2 * counter['3'])
	if counter.get('2', 0) == counter.get('6', 0):
		ans.extend(p3 * counter.get('2', 0))
	else:
		return -1
	return '\n'.join(ans)
print(solution())


n = int(input())
a = list(map(int, input().split()))
dic = {}
f = 0
for i in range(n):
	if a[i] == 5 or a[i] == 7:
		f = 1
		break
	dic[a[i]] = dic.get(a[i], 0) + 1
if f:
	print(-1)
else:
	six = dic.get(6, 0)
	four = dic.get(4, 0)
	three = dic.get(3, 0)
	two = dic.get(2, 0)
	one = dic.get(1, 0)
	if four + six == one:
		six -= three
		two -= four
		if two == six and two >= 0 and (six >= 0):
			for k in range(dic.get(4, 0)):
				print(1, 2, 4)
			for k in range(dic.get(6, 0) - dic.get(3, 0)):
				print(1, 2, 6)
			for j in range(dic.get(3, 0)):
				print(1, 3, 6)
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
l = list(map(int, input().split()))
if 5 not in l and 7 not in l:
	try:
		if 2 in l and 4 not in l and (6 not in l):
			raise Exception
		if l.count(1) != n // 3 or l.count(4) > l.count(2):
			raise Exception
		if l.count(3) > l.count(6) or l.count(2) + l.count(3) != l.count(4) + l.count(6):
			raise Exception
	except Exception as e:
		print(-1)
	else:
		if l.count(3) != 0:
			for j in range(l.count(3)):
				print(1, 3, 6)
			for j in range(l.count(6) - l.count(3)):
				print(1, 2, 6)
			for j in range(l.count(2) - l.count(6) + l.count(3)):
				print(1, 2, 4)
		else:
			for j in range(l.count(6)):
				print(1, 2, 6)
			for j in range(l.count(2) - l.count(6)):
				print(1, 2, 4)
else:
	print(-1)


import sys
n = int(input())
a = map(int, input().split(' '))
d = dict()
for i in range(1, 8):
	d[i] = 0
for x in a:
	d[x] += 1
check = d[1] == n // 3
check &= d[5] == 0 and d[7] == 0
check &= d[2] > 0 or d[3] > 0
if d[2] and (not d[3]):
	check &= d[2] == n // 3
	check &= d[4] + d[6] == n // 3
elif d[3] and (not d[2]):
	check &= d[3] == n // 3
	check &= d[6] == n // 3
else:
	check &= d[2] + d[3] == n // 3
	check &= d[4] + d[6] == n // 3
	check &= d[3] <= d[6]
if not check:
	print(-1)
	sys.exit(0)
ans = []
for i in range(d[3]):
	ans.append([1, 3, 6])
d[6] -= d[3]
for j in range(d[6]):
	ans.append([1, 2, 6])
for k in range(d[4]):
	ans.append([1, 2, 4])
ans.sort()
for [i, j, k] in ans:
	print(i, j, k)


from functools import reduce
from collections import Counter
import time
import datetime

def time_t():
	print('Current date and time: ', datetime.datetime.now())
	print('Current year: ', datetime.date.today().strftime('%Y'))
	print('Month of year: ', datetime.date.today().strftime('%B'))
	print('Week number of the year: ', datetime.date.today().strftime('%W'))
	print('Weekday of the week: ', datetime.date.today().strftime('%w'))
	print('Day of year: ', datetime.date.today().strftime('%j'))
	print('Day of the month : ', datetime.date.today().strftime('%d'))
	print('Day of week: ', datetime.date.today().strftime('%A'))

def ip():
	return int(input())

def sip():
	return input()

def mip():
	return map(int, input().split())

def mips():
	return map(str, input().split())

def lip():
	return list(map(int, input().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)
n = ip()
arr = lip()
four = arr.count(4)
two = arr.count(2)
three = arr.count(3)
six = arr.count(6)
one = arr.count(1)
if six + four + three + two + one < n:
	print(-1)
else:
	lst = []
	if four + six == one:
		if two >= four:
			two = two - four
			for i in range(four):
				lst.append([1, 2, 4])
			if two + three == six:
				for i in range(three):
					lst.append([1, 3, 6])
				for i in range(two):
					lst.append([1, 2, 6])
				for item in lst:
					print(*item)
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
t = 0
ans = []
boo = True
for i in range(0, n // 3):
	a = []
	a.append(arr[i])
	if arr[i + n // 3] > arr[i] and arr[i + n // 3] % arr[i] == 0:
		a.append(arr[i + n // 3])
	else:
		print(-1)
		boo = False
		break
	if arr[i + n // 3 + n // 3] > arr[i + n // 3] and arr[i + n // 3 + n // 3] % arr[i + n // 3] == 0:
		a.append(arr[i + n // 3 + n // 3])
	else:
		print(-1)
		boo = False
		break
	ans.append(a)
if boo:
	for i in ans:
		for j in i:
			print(j, end=' ')
		print()


import collections
n = int(input())
A = [int(x) for x in input().split()]
if 5 in A or 7 in A:
	print(-1)
	exit()
Dict = collections.Counter(A)
if Dict[1] == n // 3 and Dict[6] >= Dict[3]:
	if Dict[2] == Dict[6] - Dict[3] + Dict[4]:
		p = Dict[4]
		q = Dict[3]
		r = n // 3 - p - q
		for i in range(p):
			print('1 2 4')
		for i in range(q):
			print('1 3 6')
		for i in range(r):
			print('1 2 6')
	else:
		print(-1)
else:
	print(-1)


from collections import Counter

def Sol(arr):
	data = Counter(arr)
	if data[5] > 0 or data[7] > 0 or (data[4] == 0 and data[6] == 0):
		print(-1)
		return
	if data[3] > data[6]:
		print(-1)
		return
	count = data[4] + data[6]
	if data[3] == 0:
		if count != data[1] or count != data[2]:
			print(-1)
			return
	elif count != data[1] or count - data[3] != data[2] or count - data[2] != data[3]:
		print(-1)
		return
	temp = data[4]
	for i in range(temp):
		print(1, 2, 4)
	if data[3] > 0:
		temp = data[3]
		for i in range(temp):
			print(1, 3, 6)
		temp = data[6] - data[3]
		for i in range(temp):
			print(1, 2, 6)
	else:
		temp = data[6]
		for i in range(temp):
			print(1, 2, 6)
	return
n = int(input())
arr = list(map(int, input().split()))
Sol(arr)


n = int(input())
A = list(map(int, input().split()))
A.sort()
D = []
Diff = n // 3
Bool = False
for val in range(Diff):
	if A[val] < A[val + Diff] and A[val + Diff] < A[val + 2 * Diff]:
		if A[val + Diff] % A[val] == 0 and A[val + 2 * Diff] % A[val + Diff] == 0:
			pass
		else:
			Bool = True
			break
	else:
		Bool = True
		break
if Bool == True:
	print(-1)
else:
	for val in range(Diff):
		print(A[val], A[val + Diff], A[val + 2 * Diff])


n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 8
for i in a:
	cnt[i] += 1
p = []
k = 7
while sum(cnt) > 0:
	while True:
		if cnt[k] == 0:
			k -= 1
			if k == 0:
				break
			continue
		t = []
		if cnt[k] > 0 and len(t) < 3:
			t.append(k)
			cnt[k] -= 1
		if len(t) != 0:
			fl = False
			for i in range(1, k)[::-1]:
				if i != k and k % i == 0 and (cnt[i] > 0):
					fl = True
					break
			if fl == False:
				print(-1)
				exit(0)
			for i in range(1, k)[::-1]:
				if k % i == 0 and cnt[i] > 0:
					if cnt[i] > 0 and len(t) < 3:
						t.append(i)
						cnt[i] -= 1
						if len(t) == 2:
							if cnt[1] > 0:
								t.append(1)
								cnt[1] -= 1
								break
			if 3 in t and 2 in t:
				print(-1)
				exit(0)
			if len(t) != 3:
				print(-1)
				exit(0)
			p.append(t)
for i in p:
	for j in sorted(i):
		print(j, end=' ')
	print()


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	n = I()
	arr = L()
	lis = [0, 0, 0, 0, 0, 0, 0]
	for i in range(n):
		lis[arr[i] - 1] += 1
	if lis[4] == 0 and lis[6] == 0:
		x1 = min(lis[0], lis[1], lis[3])
		lis[0] -= x1
		lis[1] -= x1
		lis[3] -= x1
		x2 = min(lis[0], lis[1], lis[5])
		lis[0] -= x2
		lis[1] -= x2
		lis[5] -= x2
		x3 = min(lis[0], lis[2], lis[5])
		lis[0] -= x3
		lis[2] -= x3
		lis[5] -= x3
		if x1 + x2 + x3 == 0 or sum(lis) != 0:
			print(-1)
		else:
			for i in range(x1):
				print(1, 2, 4)
			for i in range(x2):
				print(1, 2, 6)
			for i in range(x3):
				print(1, 3, 6)
	else:
		print(-1)
main()


n = int(input())
numbers = [int(x) for x in input().split(' ')]
possibilities = {1: numbers.count(1), 2: numbers.count(2), 3: numbers.count(3), 4: numbers.count(4), 6: numbers.count(6)}
if possibilities[1] == n // 3 and possibilities[2] + possibilities[3] == n // 3 and (possibilities[4] + possibilities[6] == n // 3) and (possibilities[4] <= possibilities[2]) and (possibilities[6] >= possibilities[3]):
	for i in range(possibilities[3]):
		print(1, 3, 6)
	for i in range(possibilities[4]):
		print(1, 2, 4)
	for i in range(possibilities[6] - possibilities[3]):
		print(1, 2, 6)
else:
	print(-1)


n = int(input())
a = [0 for _ in range(8)]
for v in list(map(int, input().split())):
	a[v] += 1
res = 0
res_a = []
nums = [[1, 3, 6], [1, 2, 6], [1, 2, 4]]
for row in nums:
	(i, j, k) = row
	while a[i] > 0 and a[j] > 0 and (a[k] > 0):
		a[i] -= 1
		a[j] -= 1
		a[k] -= 1
		res_a.append([i, j, k])
		res += 1
if res * 3 != n:
	print(-1)
else:
	for row in res_a:
		print(*row)


n = int(input())
l = list(map(int, input().split()))
if 5 in l or 7 in l:
	print(-1)
elif l.count(1) == n // 3:
	c1 = l.count(1)
	c2 = l.count(2)
	c3 = l.count(3)
	c4 = l.count(4)
	c6 = l.count(6)
	l = []
	flag = 0
	while c4 > 0 and c2 > 0:
		flag = 1
		l.append([1, 2, 4])
		c4 -= 1
		c1 -= 1
		c2 -= 1
	while c2 > 0 and c6 > 0:
		flag = 1
		l.append([1, 2, 6])
		c2 -= 1
		c6 -= 1
		c1 -= 1
	while c3 > 0 and c6 > 0:
		flag = 1
		l.append([1, 3, 6])
		c1 -= 1
		c3 -= 1
		c6 -= 1
	if flag == 0:
		print(-1)
	elif c1 == 0 and c2 == 0 and (c3 == 0) and (c4 == 0) and (c6 == 0):
		for i in l:
			print(*i)
	else:
		print(-1)
else:
	print(-1)


from collections import Counter
n = int(input())
c = Counter(input().split())
one = c['1'] if '1' in c else 0
two = c['2'] if '2' in c else 0
three = c['3'] if '3' in c else 0
four = c['4'] if '4' in c else 0
six = c['6'] if '6' in c else 0
if one == n // 3 and '5' not in c and ('7' not in c) and (one == four + six) and (six >= three) and (two >= four) and (three <= six) and (two + three == four + six):
	for i in range(four):
		print(1, 2, 4)
	for i in range(three):
		print(1, 3, 6)
	remtwo = abs(four - two)
	for i in range(remtwo):
		print(1, 2, 6)
else:
	print(-1)


def f():
	n = int(input()) // 3
	t = input()
	if '5' in t:
		return -1
	a = t.count('1')
	if a != n:
		return -1
	b = t.count('2')
	c = t.count('3')
	if b + c != n:
		return -1
	d = t.count('4')
	if d > b:
		return -1
	f = t.count('6')
	if f < c:
		return -1
	return '1 2 4\n' * d + '1 3 6\n' * c + '1 2 6\n' * (n - d - c)
print(f())


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
import math
n = ii()
a = li()
o = a.count(1)
t = a.count(2)
th = a.count(3)
f = a.count(4)
s = a.count(6)
if o == n // 3 and t + th == n // 3 and (f + s == n // 3) and (f <= t) and (s >= th):
	for i in range(th):
		print(1, 3, 6)
	for i in range(f):
		print(1, 2, 4)
	for i in range(s - th):
		print(1, 2, 6)
else:
	print(-1)


n = int(input())
array = list(map(int, input().split()))
oneCount = array.count(1)
twoCount = array.count(2)
threeCount = array.count(3)
fourCount = array.count(4)
sixCount = array.count(6)
splitCount = n // 3
if oneCount != splitCount or threeCount > sixCount or twoCount + threeCount != fourCount + sixCount or (oneCount + twoCount + threeCount + fourCount + sixCount != n):
	print(-1)
else:
	ans = []
	for i in range(splitCount):
		if threeCount > 0:
			ans.append([1, 3, 6])
			threeCount -= 1
			sixCount -= 1
		elif fourCount > 0:
			ans.append([1, 2, 4])
			fourCount -= 1
			twoCount -= 1
		else:
			ans.append([1, 2, 6])
			sixCount -= 1
			twoCount -= 1
	[print(*i) for i in ans]