General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.

All soldiers in the battalion have different beauty that is represented by a positive integer. The value a_{i} represents the beauty of the i-th soldier.

On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.

Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.


-----Input-----

The first line contains two integers n, k (1 ≤ n ≤ 50; 1 ≤ k ≤  $\frac{n(n + 1)}{2}$) — the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^7) — the beauties of the battalion soldiers.

It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.


-----Output-----

Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer c_{i} (1 ≤ c_{i} ≤ n) — the number of soldiers in the detachment on the i-th day of the pageant and c_{i} distinct integers p_{1, }i, p_{2, }i, ..., p_{c}_{i}, i — the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.

Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.


-----Examples-----
Input
3 3
1 2 3

Output
1 1
1 2
2 3 2

Input
2 1
7 12

Output
1 12

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Complete search

Constructive algorithms


Solutions:
(n, k) = map(int, input().split())
soldiers = list(map(int, input().split()))
count = 0
seen = {0: 0}
beauties = [0]
while count != k:
	for beauty in beauties:
		bits = seen[beauty]
		for (i, x) in enumerate(soldiers):
			if bits & 1 << i != 0 or beauty + x in seen:
				continue
			new_bits = bits | 1 << i
			seen[beauty + x] = new_bits
			beauties.append(beauty + x)
			group = []
			for (j, y) in enumerate(soldiers):
				if new_bits & 1 << j != 0:
					group.append(y)
			print(' '.join(map(str, [len(group)] + group)))
			count += 1
			if count == k:
				break
		if count == k:
			break


import random

def S(L):
	Ans = []
	s = 0
	for item in L:
		s += item
		Ans.append(s)
	return Ans
(n, k) = map(int, input().split())
B = list(map(int, input().split()))
Sums = []
s = 0
for i in range(n):
	s += B[i]
	Sums.append(s)
if k <= n:
	for i in range(k):
		print(i + 1, end='')
		for j in range(i + 1):
			print(' ' + str(B[j]), end='')
		print()
else:
	Ans = []
	length = 1
	Taken = {}
	Sums = S(B)
	while len(Ans) < k:
		if length > n:
			length = 1
			random.shuffle(B)
			Sums = S(B)
		for i in range(n):
			if i + length - 1 >= n:
				break
			x = Sums[i + length - 1] - Sums[i] + B[i]
			if x in Taken:
				continue
			Taken[x] = True
			L = [length]
			done = True
			for j in range(i, i + length):
				if B[j] in L[1:]:
					done = False
					break
				L.append(B[j])
			if done:
				Ans.append(list(L))
		length += 1
	for i in range(k):
		item = Ans[i]
		print(item[0], end='')
		for z in range(1, len(item)):
			print(' ' + str(item[z]), end='')
		print()


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
(cur_len, res) = (1, [])
while k > 0 and cur_len <= n:
	for i in range(cur_len, n + 1):
		print(cur_len, *res, a[i - 1])
		k -= 1
		if k == 0:
			break
	res.append(a[cur_len - 1])
	cur_len += 1


from collections import *
import sys
input = sys.stdin.readline

def ri():
	return int(input())

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

def getKthBit(n, k):
	return (n & 1 << k - 1) >> k - 1
(n, K) = rl()
aa = rl()
aa.sort()
for i in range(n + 1):
	if K == 0:
		break
	smalls = aa[:n - i]
	bigs = aa[n - i:]
	for small in smalls:
		print(len(bigs) + 1, ' '.join([str(x) for x in bigs]), small)
		K -= 1
		if K == 0:
			break


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
C = []
U = len(A)
c = 0
g = 0
for i in range(k):
	print(len(C + [A[g]]), ' '.join(map(str, C + [A[g]])))
	g += 1
	if g == len(A):
		g = 0
		C.append(max(A))
		A.remove(max(A))


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
t = [[i] for i in p]
for i in range(1, n):
	t += [t[-1] + i for i in t[:n - i]]
print('\n'.join((str(len(i)) + ' ' + ' '.join(map(str, i)) for i in t[:k])))


import sys

def fastio():
	from io import StringIO
	from atexit import register
	nonlocal input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, k) = I()
a = I()
a.sort(reverse=1)
p = [0] * (n + 1)
for i in range(1, n + 1):
	p[i] += p[i - 1] + a[i - 1]
s = set()
window = 1
ans = []
while k and window <= n:
	for i in range(window, n + 1):
		print(window, *ans, a[i - 1])
		k -= 1
		if not k:
			break
	ans.append(a[window - 1])
	window += 1


from sys import stdin

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])
(n, k) = arr_inp(1)
c = sorted(arr_inp(1))[::-1]
for i in range(min(n, k)):
	print(1, c[i])
	k -= 1
tem = []
for i in range(min(n - 1, k)):
	tem.append(c[i])
	for j in range(n - 1, i, -1):
		print(i + 2, end=' ')
		print(*tem + [c[j]])
		k -= 1
		if not k:
			return


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, k) = value()
a = sorted(array())
ma = set()
setNo = 1
while True:
	t = ma
	for i in a:
		if k < setNo:
			exit()
		if i not in t:
			print(len(ma) + 1, *ma, i)
			setNo += 1
	key = -1
	for i in a:
		if i not in ma:
			key = max(key, i)
	ma.add(key)


(n, k) = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
j = 0
c = 0
for i in range(k):
	b = [a[i - c]]
	for l in range(n - j, n):
		b.append(a[l])
	print(j + 1, *b)
	if i - c == n - j - 1:
		c += n - j
		j += 1


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort(reverse=True)
elems = []
j = -1
cnt = 0
for i in range(n):
	if cnt == k:
		break
	j += 1
	fixed = l[0:j]
	for z in range(j, n):
		if cnt == k:
			continue
		print(j + 1, *fixed + [l[z]])
		cnt += 1
		if cnt == k:
			break


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cnt = n
while k:
	for i in range(cnt):
		print(n - cnt + 1, a[i])
		for j in range(cnt, n):
			print(a[j])
		k -= 1
		if k == 0:
			break
	cnt -= 1


(n, k) = map(int, input().split())
l = sorted(map(int, input().split()), reverse=True)
c = 0
for i in range(n):
	for x in l[i:]:
		if c == k:
			exit()
		c += 1
		print(i + 1, end=' ')
		for y in l[:i]:
			print(y, end=' ')
		print(x, end=' ')
		print()