Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him?

Given an array consisting of distinct integers. Is it possible to partition the whole array into k disjoint non-empty parts such that p of the parts have even sum (each of them must have even sum) and remaining k - p have odd sum? (note that parts need not to be continuous).

If it is possible to partition the array, also give any possible way of valid partitioning.


-----Input-----

The first line will contain three space separated integers n, k, p (1 ≤ k ≤ n ≤ 10^5; 0 ≤ p ≤ k). The next line will contain n space-separated distinct integers representing the content of array a: a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).


-----Output-----

In the first line print "YES" (without the quotes) if it is possible to partition the array in the required way. Otherwise print "NO" (without the quotes).

If the required partition exists, print k lines after the first line. The i^{th} of them should contain the content of the i^{th} part. Print the content of the part in the line in the following way: firstly print the number of elements of the part, then print all the elements of the part in arbitrary order. There must be exactly p parts with even sum, each of the remaining k - p parts must have odd sum.

As there can be multiple partitions, you are allowed to print any valid partition.


-----Examples-----
Input
5 5 3
2 6 10 5 9

Output
YES
1 9
1 5
1 10
1 6
1 2

Input
5 5 3
7 14 2 9 5

Output
NO

Input
5 3 1
1 2 3 7 5

Output
YES
3 5 1 3
1 7
1 2

Difficulty: MEDIUM_HARD
Tags: Number theory

Complete search

Implementation

Constructive algorithms
Skill types: Complete search

Starter code:

Solutions:
def solve():
	(n, k, p) = map(int, input().split())
	a = list(map(int, input().split()))
	even = list(filter(lambda x: x % 2 == 0, a))
	odd = list(filter(lambda x: x % 2 == 1, a))
	if (len(odd) - (k - p)) % 2 != 0:
		print('NO')
		return
	ans = [[] for _ in range(k)]
	for i in range(k - p):
		if odd:
			ans[i].append(odd.pop())
		else:
			print('NO')
			return
	for i in range(k - p, k):
		if even:
			ans[i].append(even.pop())
		elif len(odd) >= 2:
			ans[i].append(odd.pop())
			ans[i].append(odd.pop())
		else:
			print('NO')
			return
	ans[0] += even
	ans[0] += odd
	print('YES')
	for part in ans:
		print(len(part), ' '.join(map(str, part)))
solve()


import sys

def devu_and_partitionong_of_the_array(n, k, p, numbers):
	Even = []
	Odd = []
	Sets = [[] for i in range(k)]
	for j in range(n):
		if numbers[j] % 2 == 0:
			Even.append(numbers[j])
		else:
			Odd.append(numbers[j])
	if len(Odd) < k - p or (len(Odd) - (k - p)) % 2 != 0 or (len(Odd) - (k - p)) / 2 + len(Even) < p:
		print('NO\n')
	else:
		for i in range(k - p):
			Sets[i].append(Odd.pop())
		for i in range(k - p, k):
			if len(Even) != 0:
				Sets[i].append(Even.pop())
			elif len(Odd) != 0:
				Sets[i].append(Odd.pop())
				Sets[i].append(Odd.pop())
		while len(Even) != 0:
			Sets[0].append(Even.pop())
		while len(Odd) != 0:
			Sets[0].append(Odd.pop())
		print('YES\n')
		for l in range(k):
			size = len(Sets[l])
			sys.stdout.write(str(size))
			for m in range(size):
				sys.stdout.write(' ' + str(Sets[l][m]))
			print('\n')
line1 = list(map(int, input().split()))
line2 = list(map(int, input().split()))
devu_and_partitionong_of_the_array(line1[0], line1[1], line1[2], line2)


class part_array:

	def __init__(self):
		self.count = 0
		self.num_list = []

	def AddNumber(self, n):
		self.num_list.append(n)
		self.count += 1

	def AddNumberList(self, li):
		self.num_list.extend(li)
		self.count += len(li)

def print_solution_and_exit(e, o):
	print('YES')
	for part in e:
		print(part.count, ' '.join(map(str, part.num_list)))
	for part in o:
		print(part.count, ' '.join(map(str, part.num_list)))
	exit()

def print_solution_error():
	print('NO')
	exit()
(n, k, p) = map(lambda t: int(t), input().split())
numbers = list(map(lambda t: int(t), input().split()))
odds = list(filter(lambda t: t % 2 == 1, numbers))
evens = list(filter(lambda t: t % 2 == 0, numbers))
odd_parts = []
even_parts = []
if k - p > len(odds):
	print_solution_error()
while len(even_parts) < p and len(evens) > 0:
	part = part_array()
	part.AddNumber(evens.pop())
	even_parts.append(part)
while len(odd_parts) < k - p and len(odds) > 0:
	part = part_array()
	part.AddNumber(odds.pop())
	odd_parts.append(part)
needed_odd_parts = k - p - len(odd_parts)
if len(even_parts) == p and needed_odd_parts > 0:
	excess_odds = len(odds) - needed_odd_parts
	if excess_odds < 0 or excess_odds % 2 == 1:
		print_solution_error()
	for i in range(needed_odd_parts):
		part = part_array()
		part.AddNumber(odds.pop())
		odd_parts.append(part)
needed_even_parts = p - len(even_parts)
if len(odd_parts) == k - p and needed_even_parts > 0:
	excess_evens = len(evens) - needed_even_parts
	if len(odds) % 2 == 1 or excess_evens + len(odds) // 2 < 0:
		print_solution_error()
	while needed_even_parts > 0:
		if len(evens) > 0:
			part = part_array()
			part.AddNumber(evens.pop())
			even_parts.append(part)
		else:
			part = part_array()
			part.AddNumber(odds.pop())
			part.AddNumber(odds.pop())
			even_parts.append(part)
		needed_even_parts -= 1
needed_even_parts = p - len(even_parts)
needed_odd_parts = k - p - len(odd_parts)
if needed_odd_parts > 0 or needed_even_parts > 0:
	print('needed_even_parts', needed_even_parts, 'needed_odd_parts', needed_odd_parts)
	print_solution_and_exit()
if len(odds) % 2 == 1:
	print_solution_error()
if len(odd_parts) > 0:
	odd_parts[0].AddNumberList(odds)
	odd_parts[0].AddNumberList(evens)
else:
	even_parts[0].AddNumberList(odds)
	even_parts[0].AddNumberList(evens)
ods = []
evens = []
print_solution_and_exit(even_parts, odd_parts)
print('DEBUG')
print(numbers)
print(evens)
print(odds)


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')
(n, k, p) = map(int, input().split())
l = list(map(int, input().split()))
e = []
o = []
ans = 'YES'
for i in l:
	if i % 2:
		o.append(i)
	else:
		e.append(i)
lans = []
if len(e) >= p:
	for i in range(p):
		lans.append([e.pop()])
else:
	for i in e:
		lans.append([i])
	for i in range(p - len(e)):
		if len(o) < 2:
			ans = 'NO'
			break
		lans.append([o.pop(), o.pop()])
	e = []
if ans == 'NO':
	print(ans)
else:
	if len(o) < k - p:
		ans = 'NO'
	elif (len(o) - k + p) % 2:
		ans = 'NO'
	else:
		ans = 'YES'
		for i in range(k - p):
			lans.append([o.pop()])
		if len(o):
			lans[0].extend(o)
		if len(e):
			lans[0].extend(e)
	print(ans)
	if ans == 'YES':
		for i in lans:
			if len(i):
				print(len(i), *i)


(n, k, p) = map(int, input().split())
(oc, ec) = ([], [])
for i in map(int, input().split()):
	if i & 1:
		oc.append(i)
	else:
		ec.append(i)
l = len(oc)
if l < k - p or l & 1 != k - p & 1 or len(ec) + (l - (k - p)) / 2 < p:
	print('NO')
	exit()
res = []
q = k - p
while p:
	if len(ec):
		res.append([ec.pop()])
	elif len(oc) >= 2:
		res.append(oc[-2:])
		del oc[-2:]
	else:
		print('NO')
		exit(0)
	p -= 1
while q:
	if len(oc):
		res.append([oc.pop()])
	else:
		print('NO')
		exit(0)
	q -= 1
if len(ec):
	res[0] += ec
if len(oc) % 2 == 0:
	res[0] += oc
print('YES')
for s in res:
	print(len(s), *s)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
(n, k, p) = ilele()
A = alele()
even = []
odd = []
for i in A:
	if i % 2 == 0:
		even.append([i])
	else:
		odd.append([i])
if len(odd) < k - p:
	Y(0)
else:
	l = k - p
	while len(odd) > l:
		x = odd.pop()
		if len(even) > 0:
			if sum(even[-1]) % 2 == 0:
				even.append(x)
			else:
				even[-1].append(x[0])
		else:
			even.append(x)
	r = 0
	while len(even) > p and r < 1000000.0:
		x = even.pop()
		for i in x:
			r += 1
			if len(odd) > 0:
				odd[0].append(i)
			elif len(even) > 0:
				even[0].append(i)
	if len(even) != p or len(odd) != k - p:
		Y(0)
	else:
		for i in even:
			if sum(i) % 2 != 0:
				Y(0)
				exit(0)
		for i in odd:
			if sum(i) % 2 == 0:
				Y(0)
				exit(0)
		Y(1)
		for i in even:
			print(len(i), *i)
		for i in odd:
			print(len(i), *i)


(n, k, p) = [int(c) for c in input().split()]
a = [int(c) for c in input().split()]
nech = []
ch = []
for i in range(len(a)):
	if a[i] % 2 == 0:
		ch.append(a[i])
	else:
		nech.append(a[i])
needed_nech = k - p
free_nech = len(nech) - needed_nech
av_ch = len(ch) + free_nech // 2
sets = []
if free_nech < 0 or free_nech % 2 != 0 or av_ch < p:
	print('NO')
else:
	print('YES')
	while needed_nech > 0:
		sets.append([nech.pop()])
		needed_nech -= 1
	while p > 0:
		if len(ch) > 0:
			sets.append([ch.pop()])
		else:
			sets.append([nech.pop(), nech.pop()])
		p -= 1
	sets[0] = sets[0] + nech + ch
for i in range(len(sets)):
	print(len(sets[i]), ' '.join(map(str, sets[i])))


(n, k, p) = map(int, input().split())
lis = list(map(int, input().split()))
q = k - p
ev = []
od = []
res = []
for i in lis:
	if i % 2:
		od.append(i)
	else:
		ev.append(i)
res = []
while p:
	if len(ev) > 0:
		res.append([ev.pop()])
	elif len(od) > 1:
		res.append([od[-1], od[-2]])
		del od[-2:]
	else:
		print('NO')
		exit()
	p -= 1
while q:
	if len(od) > 0:
		res.append([od.pop()])
	else:
		print('NO')
		exit()
	q -= 1
if len(ev):
	res[0] += ev
if len(od) % 2 == 0:
	res[0] += od
else:
	print('NO')
	exit()
print('YES')
for i in res:
	print(len(i), *i)


(n, k, p) = map(int, input().split())
a = list(map(int, input().split()))
odd = [i for i in a if i % 2 == 1]
even = [i for i in a if i % 2 == 0]
g = [[] for i in range(k)]
if len(odd) < k - p or (len(odd) - (k - p)) % 2 == 1:
	print('NO')
	exit()
for i in range(k - p):
	g[i].append(odd.pop())
m = len(even)
for i in range(m):
	g[(k - p + i) % k].append(even.pop())
for i in range(0, len(odd), 2):
	idx = (k - p + m + i // 2) % k
	g[idx].append(odd[i])
	g[idx].append(odd[i + 1])
if any([len(i) == 0 for i in g]):
	print('NO')
	exit()
print('YES')
for i in g:
	print(str(len(i)) + ' ' + ' '.join([str(j) for j in i]))


(n, k, p) = map(int, input().split())
l = [int(i) for i in input().split()]
odd = [i for i in l if i & 1]
even = [i for i in l if i & 1 == 0]
if len(odd) < k - p:
	print('NO')
	exit()
if len(odd) % 2 != (k - p) % 2:
	print('NO')
	exit()
ans = []
for i in range(k):
	ans.append([])
i = 0
for o in odd:
	if i < k - p:
		ans[i].append(o)
		i += 1
	elif i < k:
		ans[i].append(o)
		if len(ans[i]) >= 2:
			i += 1
	else:
		ans[0].append(o)
for e in even:
	if i < k:
		ans[i].append(e)
		i += 1
	else:
		ans[0].append(e)
t = 0
for f in ans:
	cur = sum(f)
	if len(f) == 0:
		t = 1000000000
	if cur % 2 == 1:
		t += 1
ans.reverse()
if t != k - p:
	print('NO')
	exit()
print('YES')
for i in ans:
	print(len(i), *i)


(n, k, p) = map(int, input().split())
s = k - p
a = b = c = ''
for i in input().split():
	i = ' ' + i
	if i[-1] in '13579':
		if s > 0:
			a += '\n1' + i
		elif s & 1:
			if p >= 0:
				b += i
			else:
				c += i
		else:
			if p > 0:
				b += '\n2' + i
			else:
				c += i
			p -= 1
		s -= 1
	elif p > 0:
		a += '\n1' + i
		p -= 1
	else:
		c += i
if s > 0 or s & 1 or p > 0:
	print('NO')
else:
	print('YES')
	if a:
		print(str(1 + c.count(' ')) + c + a[2:] + b)
	else:
		print(str(2 + c.count(' ')) + c + b[2:])


(n, k, p) = map(int, input().split())
ar = list(map(int, input().split()))
q = k - p
(zeros, ones) = ([], [])
res = []
for a in ar:
	if a % 2:
		ones += [a]
	else:
		zeros += [a]
while p:
	if len(zeros):
		res += [[zeros.pop()]]
	elif len(ones) >= 2:
		res += [ones[-2:]]
		del ones[-2:]
	else:
		print('NO')
		exit(0)
	p -= 1
while q:
	if len(ones):
		res += [[ones.pop()]]
	else:
		print('NO')
		exit(0)
	q -= 1
if len(zeros):
	res[0] += zeros
if len(ones) % 2 == 0:
	res[0] += ones
else:
	print('NO')
	exit(0)
print('YES')
for s in res:
	print(len(s), *s)


from sys import stdin

def solve():
	(n, k, p) = map(int, stdin.readline().split())
	seq = list(map(int, stdin.readline().split()))
	odd = []
	even = []
	for i in range(n):
		if seq[i] & 1:
			odd.append(seq[i])
		else:
			even.append(seq[i])
	if len(odd) < k - p:
		print('NO')
		return
	if p == 0:
		if k & 1 != len(odd) & 1:
			print('NO')
			return
		else:
			print('YES')
			for i in range(k - 1):
				print(1, odd.pop())
			lastone = [len(odd) + len(even)]
			while len(odd) > 0:
				lastone.append(odd.pop())
			while len(even) > 0:
				lastone.append(even.pop())
			print(' '.join(map(lambda x: str(x), lastone)))
		return
	remaining_odds = len(odd) - k + p
	if remaining_odds & 1:
		print('NO')
		return
	if remaining_odds // 2 + len(even) < p:
		print('NO')
		return
	print('YES')
	for i in range(k - p):
		print(1, odd.pop())
	remainingCnt = p
	while remainingCnt > 1 and len(odd) > 0:
		print(2, odd.pop(), odd.pop())
		remainingCnt -= 1
	if remainingCnt > 1:
		while remainingCnt > 1 and len(even) > 0:
			print(1, even.pop())
			remainingCnt -= 1
	lastone = [len(odd) + len(even)]
	while len(odd) > 0:
		lastone.append(odd.pop())
	while len(even) > 0:
		lastone.append(even.pop())
	print(' '.join(map(lambda x: str(x), lastone)))
solve()


(n, k, p) = list(map(int, input().split()))
l = list(map(int, input().split()))
even = list([x for x in l if x % 2 == 0])
odd = list([x for x in l if x % 2 == 1])
if (len(odd) - (k - p)) % 2 != 0:
	print('NO')
	return
ans = [[] for _ in range(k)]
for i in range(k - p):
	if odd:
		ans[i].append(odd.pop())
	else:
		print('NO')
		return
for i in range(k - p, k):
	if even:
		ans[i].append(even.pop())
	elif len(odd) >= 2:
		ans[i].append(odd.pop())
		ans[i].append(odd.pop())
	else:
		print('NO')
		return
ans[0] += even + odd
print('YES')
for i in ans:
	print(len(i), ' '.join(map(str, i)))


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global 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, p) = I()
o = k - p
a = I()
nums = [[], []]
for i in range(n):
	nums[a[i] % 2].append([a[i]])

def NO():
	print('NO')
	exit()
if o > len(nums[1]):
	NO()
ans = [[], []]
for i in range(o):
	if nums[1]:
		ans[1].append(nums[1].pop())
	else:
		NO()
if len(nums[1]) % 2:
	NO()
while nums[1]:
	nums[0].append(nums[1].pop() + nums[1].pop())
for i in range(p):
	if nums[0]:
		ans[0].append(nums[0].pop())
	else:
		NO()
if p:
	for i in nums[0]:
		ans[0][0] += i
else:
	for i in nums[0]:
		ans[1][0] += i
if len(ans[0]) != p or len(ans[1]) != o:
	NO()
print('YES')
if p:
	for i in ans[0]:
		print(len(i), *i)
if o:
	for i in ans[1]:
		print(len(i), *i)


(n, k, p) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
(odd, even) = ([], [])
for temp in a:
	if temp % 2 == 0:
		even.append(temp)
	else:
		odd.append(temp)
if False and len(odd) % 2 != (k - p) % 2:
	print('NO')
else:
	ans = []
	for i in range(k):
		ans.append([])
	i = 0
	for o in odd:
		if i < k - p:
			ans[i].append(o)
			i += 1
		elif i < k:
			ans[i].append(o)
			if len(ans[i]) >= 2:
				i += 1
		else:
			ans[0].append(o)
	for o in even:
		if i < k:
			ans[i].append(o)
			i += 1
		else:
			ans[0].append(o)
	t = 0
	for f in ans:
		cur = sum(f)
		if len(f) == 0:
			t = 1000000000
		if cur % 2 == 1:
			t += 1
	ans.reverse()
	if t != k - p:
		print('NO')
	else:
		print('YES')
		for f in ans:
			print(len(f), ' '.join(map(str, f)))


import io
import os
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def printd(*args, **kwargs):
	pass

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
(n, ptot, peven) = rint()
podd = ptot - peven
a = list(rint())
even = []
odd = []
for i in range(n):
	if a[i] % 2:
		odd.append(a[i])
	else:
		even.append(a[i])
lo = len(odd)
le = len(even)
lreso = lo - podd
printd(even)
printd(odd)
printd(peven)
printd(podd)
if podd > lo or lreso % 2 == 1 or lreso // 2 + le < peven:
	print('NO')
	exit()
print('YES')
if peven == 0:
	ocnt = 0
	for i in range(podd - 1):
		print(1, odd[i])
		ocnt += 1
	print(lo - ocnt + le, *even, *odd[ocnt:])
	exit()
ocnt = 0
for i in range(podd):
	print(1, odd[i])
	ocnt += 1
ecnt = 0
for i in range(min(le, peven - 1)):
	print(1, even[i])
	ecnt += 1
if ecnt < peven - 1:
	for i in range(ecnt, peven - 1):
		print(2, *odd[ocnt:ocnt + 2])
		ocnt += 2
	print(lo - ocnt, *odd[ocnt:])
else:
	print(lo - ocnt + le - ecnt, *odd[ocnt:], *even[ecnt:])


(n, k, p) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
odd = []
even = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
groups = [[] for i in range(k)]
for i in range(k - p):
	if len(odd) == 0:
		print('NO')
		exit()
	groups[i].append(odd.pop())
if len(odd) % 2 == 1:
	print('NO')
	exit()
l = len(even)
for i in range(len(even)):
	groups[(k - p + i) % k].append(even.pop())
for i in range(0, len(odd), 2):
	groups[(k - p + l + i // 2) % k].append(odd[i])
	groups[(k - p + l + i // 2) % k].append(odd[i + 1])
for i in groups:
	if len(i) == 0:
		print('NO')
		exit()
print('YES')
for i in groups:
	print(str(len(i)) + ' ' + ' '.join([str(j) for j in i]))


def main():
	import sys
	tokens = [int(i) for i in sys.stdin.read().split()]
	tokens.reverse()
	(n, k, p) = [tokens.pop() for i in range(3)]
	a = [tokens.pop() for i in range(n)]
	odd = [i for i in a if i & 1]
	even = [i for i in a if i & 1 == 0]
	if len(odd) < k - p or (len(odd) - (k - p)) % 2 == 1 or len(odd) + 2 * len(even) < k + p:
		print('NO')
		return
	result = []
	for i in range(k - p):
		result.append([odd.pop()])
	while len(result) < k and odd:
		result.append([odd.pop(), odd.pop()])
	while len(result) < k and even:
		result.append([even.pop()])
	if len(result) < k:
		print('NO')
		return
	result[-1].extend(odd)
	result[-1].extend(even)
	print('YES')
	print('\n'.join((' '.join(map(str, [len(i)] + i)) for i in result)))
main()


(n, k, p) = map(int, input().split())
l = list(map(int, input().split()))
(odd, even) = ([], [])
for i in l:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
if (len(odd) - (k - p)) % 2 != 0:
	print('NO')
	exit(0)
ans = [[] for _ in range(k)]
for i in range(k - p):
	if odd:
		ans[i].append(odd.pop())
	else:
		print('NO')
		exit(0)
for i in range(k - p, k):
	if even:
		ans[i].append(even.pop())
	elif len(odd) >= 2:
		ans[i].append(odd.pop())
		ans[i].append(odd.pop())
	else:
		print('NO')
		exit(0)
ans[0] += even + odd
print('YES')
for i in ans:
	print(len(i), *i)


import sys
inputStr = input()
inputArr = inputStr.split(' ')
n = int(inputArr[0])
k = int(inputArr[1])
p = int(inputArr[2])
arr = list(map(int, input().split(' ')))
odds = []
evens = []
for i in range(len(arr)):
	if arr[i] % 2:
		odds.append(i)
	else:
		evens.append(i)
ans = []
oddPointer = 0
evenPointer = 0
for i in range(k - p):
	if oddPointer >= len(odds):
		print('NO')
		quit()
	oddArr = [odds[oddPointer]]
	oddPointer += 1
	ans.append(oddArr)
for i in range(p):
	if oddPointer < len(odds):
		if oddPointer + 1 >= len(odds):
			print('NO')
			quit()
		else:
			oddArr = [odds[oddPointer], odds[oddPointer + 1]]
			oddPointer += 2
			ans.append(oddArr)
	elif evenPointer < len(evens):
		evenArr = [evens[evenPointer]]
		evenPointer += 1
		ans.append(evenArr)
	else:
		print('NO')
		quit()
if (len(odds) - oddPointer) % 2:
	print('NO')
	quit()
for i in range(oddPointer, len(odds)):
	ans[0].append(odds[i])
for i in range(evenPointer, len(evens)):
	ans[0].append(evens[i])
print('YES')
for i in range(len(ans)):
	sys.stdout.write(str(len(ans[i])))
	sys.stdout.write(' ')
	for j in range(len(ans[i])):
		sys.stdout.write(str(arr[ans[i][j]]))
		sys.stdout.write(' ')
	sys.stdout.write('\n')
sys.stdout.flush()


from sys import exit

def numline(f=int):
	return map(f, input().split())
(n, k, p) = numline()
a = numline()
b = [[], []]
for i in a:
	b[i % 2].append(i)
if (len(b[1]) + k - p) % 2 == 1 or len(b[1]) < k - p:
	print('NO')
	exit(0)
ol = [[] for i in range(p)] + [[b[1][i]] for i in range(k - p)]
cl = 0
for i in range(k - p, len(b[1]), 2):
	ol[cl].append(b[1][i])
	ol[cl].append(b[1][i + 1])
	cl = (cl + 1) % k
for i in b[0]:
	ol[cl].append(i)
	cl = (cl + 1) % k
for i in ol:
	if len(i) > 0:
		continue
	print('NO')
	exit(0)
print('YES')
for i in ol:
	print(' '.join(map(str, [len(i)] + i)))


(n, k, p) = map(int, input().split())
a = list(map(int, input().split()))
odd = []
even = []
for el in a:
	if el & 1:
		odd.append(el)
	else:
		even.append(el)
if (len(odd) - (k - p)) % 2:
	print('NO')
	exit()
ans = [[] for _ in range(k)]
for i in range(k - p):
	if odd:
		ans[i].append(odd.pop())
	else:
		print('NO')
		exit()
for i in range(k - p, k):
	if even:
		ans[i].append(even.pop())
	elif len(odd) >= 2:
		ans[i].append(odd.pop())
		ans[i].append(odd.pop())
	else:
		print('NO')
		exit()
ans[0] += even
ans[0] += odd
print('YES')
for a in ans:
	print(len(a), ' '.join(map(str, a)))


import os, io
from sys import stdout
import collections
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result

def distance(xa, ya, xb, yb):
	return ((ya - yb) ** 2 + (xa - xb) ** 2) ** 0.5

def digitsSum(n):
	if n == 0:
		return 0
	r = 0
	while n > 0:
		r += n % 10
		n //= 10
	return r

def isValid(i, j, n, m):
	return i >= 0 and i < n and (j >= 0) and (j < m)

def print_grid(grid):
	for line in grid:
		print(' '.join(map(str, line)))

def kadane(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def ceil(n, d):
	if n % d == 0:
		return n // d
	else:
		return n // d + 1

def _abs(a, b):
	return int(abs(a - b))

def evenodd(l):
	even = [e for e in l if e & 1 == 0]
	odd = [e for e in l if e & 1]
	return (even, odd)
(n, k, p) = list(map(int, input().split()))
l = list(map(int, input().split()))
(even, odd) = evenodd(l)
rest = k - p
reven = []
rodd = []
(i, j) = (0, 0)
while i < len(even) and p > 0:
	reven.append([even[i]])
	p -= 1
	i += 1
while j < len(odd) - 1 and p > 0:
	reven.append([odd[j], odd[j + 1]])
	p -= 1
	j += 2
if i == len(even) and j >= len(odd) - 1 and (p > 0):
	print('NO')
	exit()
if p == 0:
	even = even[i:]
	odd = odd[j:]
	(i, j) = (0, 0)
	while j < len(odd) and rest > 0:
		rodd.append([odd[j]])
		rest -= 1
		j += 1
	if j == len(odd) and rest > 0:
		print('NO')
		exit()
	if rest == 0:
		odd = odd[j:]
		if len(even) or len(odd):
			oddRemaining = len(odd)
			if oddRemaining % 2 == 1:
				print('NO')
				exit()
			elif not len(reven):
				rodd[0] += odd + even
			else:
				reven[0] += odd + even
		print('YES')
		for e in reven:
			print(len(e), ' '.join(list(map(str, e))))
		for e in rodd:
			print(len(e), ' '.join(list(map(str, e))))


(n, k, p) = map(int, input().split())
l = [int(i) for i in input().split()]
odd = [i for i in l if i & 1]
even = [i for i in l if i & 1 == 0]
if len(odd) % 2 != (k - p) % 2:
	print('NO')
	exit()
ans = []
for i in range(k):
	ans.append([])
i = 0
for o in odd:
	if i < k - p:
		ans[i].append(o)
		i += 1
	elif i < k:
		ans[i].append(o)
		if len(ans[i]) >= 2:
			i += 1
	else:
		ans[0].append(o)
for e in even:
	if i < k:
		ans[i].append(e)
		i += 1
	else:
		ans[0].append(e)
cnt = 0
for i in ans:
	if sum(i) & 1:
		cnt += 1
if cnt != k - p or any((len(f) == 0 for f in ans)):
	print('NO')
	exit()
print('YES')
for i in ans:
	print(len(i), *i)


import sys

def minp():
	return sys.stdin.readline().strip()
(n, k, p) = map(int, minp().split())
even = []
odd = []
for i in map(int, minp().split()):
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if len(odd) < k - p:
	print('NO')
else:
	ans = []
	for i in range(k - p):
		ans.append([odd[-1]])
		del odd[-1]
	if len(odd) % 2 == 1:
		print('NO')
	else:
		fail = False
		for i in range(p):
			if len(odd) != 0:
				ans.append([odd[-1], odd[-2]])
				del odd[-1]
				del odd[-1]
			elif len(even) != 0:
				ans.append([even[-1]])
				del even[-1]
			else:
				fail = True
		if fail:
			print('NO')
		else:
			while len(odd) != 0:
				ans[-1].append(odd[-1])
				del odd[-1]
				ans[-1].append(odd[-1])
				del odd[-1]
			while len(even) != 0:
				ans[-1].append(even[-1])
				del even[-1]
			print('YES')
			an = []
			for i in ans:
				an.append(str(len(i)) + ' ' + ' '.join(map(str, i)))
			print('\n'.join(an))