There are n piles of pebbles on the table, the i-th pile contains a_{i} pebbles. Your task is to paint each pebble using one of the k given colors so that for each color c and any two piles i and j the difference between the number of pebbles of color c in pile i and number of pebbles of color c in pile j is at most one.

In other words, let's say that b_{i}, c is the number of pebbles of color c in the i-th pile. Then for any 1 ≤ c ≤ k, 1 ≤ i, j ≤ n the following condition must be satisfied |b_{i}, c - b_{j}, c| ≤ 1. It isn't necessary to use all k colors: if color c hasn't been used in pile i, then b_{i}, c is considered to be zero.


-----Input-----

The first line of the input contains positive integers n and k (1 ≤ n, k ≤ 100), separated by a space — the number of piles and the number of colors respectively.

The second line contains n positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 100) denoting number of pebbles in each of the piles.


-----Output-----

If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) .

Otherwise in the first line output "YES" (without quotes). Then n lines should follow, the i-th of them should contain a_{i} space-separated integers. j-th (1 ≤ j ≤ a_{i}) of these integers should be equal to the color of the j-th pebble in the i-th pile. If there are several possible answers, you may output any of them.


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

Output
YES
1
1 4
1 2 4
1 2 3 4

Input
5 2
3 2 4 1 3

Output
NO

Input
5 4
3 2 4 3 5

Output
YES
1 2 3
1 3
1 2 3 4
1 3 4
1 1 2 3 4

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms

Implementation

Constructive algorithms


Solutions:
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
mn = min(a)
if max(a) - mn > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		arr = [1] * mn
		arr += [1 + i for i in range(a[i] - mn)]
		print(' '.join(map(str, arr)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if (max(a) - min(a)) / k > 1:
	print('NO')
	exit(0)
print('YES')
for i in range(n):
	for j in range(a[i]):
		print(j % k + 1, end=' ')
	print()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
brr = [int(i) for i in arr]
brr.sort()
if brr[-1] - brr[0] > k:
	print('NO')
	exit()
print('YES')
for i in arr:
	for j in range(1, i + 1):
		x = j % k if j % k != 0 else k
		print(x, end=' ')
	print()


(a, b) = [int(i) for i in input().split()]
lst = [int(i) for i in input().split()]
if max(lst) - min(lst) > b:
	print('NO')
else:
	print('YES')
	for i in range(a):
		print(*[1 for j in range(min(lst))] + [t + 1 for t in range(lst[i] - min(lst))])


(n, k) = list(map(int, input().split(' ')))
nums = list(map(int, input().split(' ')))
pebbles = [[] for i in range(len(nums))]
smallest = min(nums)
prefix = smallest * [1]
nums = list([x - smallest for x in nums])
for c in range(1, k + 1):
	for (i, e) in enumerate(nums):
		if e != 0:
			pebbles[i].append(c)
			nums[i] -= 1
if any([x > 0 for x in nums]):
	print('NO')
else:
	print('YES')
	prefix = ' '.join(map(str, prefix))
	for p in pebbles:
		print(prefix + ' ' + ' '.join(map(str, p)))


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
l = min(a)
h = max(a)
if k < h - l:
	print('NO')
else:
	print('YES')
	for i in a:
		p = [1] * l
		y = i - l
		j = 1
		while y > 0:
			y -= 1
			p.append(j)
			j += 1
		print(' '.join([str(m) for m in p]))


(n, colors) = map(int, input().split())
piles = list(map(int, input().split()))
min_size = min(piles)
max_size = max(piles)
if max_size > min_size + colors:
	print('NO')
else:
	print('YES')
	for pile in piles:
		color1 = min(pile, min_size + 1)
		pile_colors = ['1' for _ in range(color1)]
		pile_colors.extend([str(idx) for (idx, _) in enumerate(range(color1, pile), start=2)])
		print(' '.join(pile_colors))


def paint(number_of_piles, number_of_colors, pebbles_for_piles):
	min_num_pebbles = min(pebbles_for_piles)
	max_num_pebbles = max(pebbles_for_piles)
	if max_num_pebbles - min_num_pebbles > number_of_colors:
		print('NO')
	else:
		print('YES')
		for i in range(number_of_piles):
			current_colors = []
			last = 0
			for j in range(pebbles_for_piles[i] - 1):
				current_colors.append(j % number_of_colors + 1)
				last += 1
			current_colors.append(last % number_of_colors + 1)
			print(' '.join(map(str, current_colors)))
(number_of_piles, number_of_colors) = list(map(int, input().split()))
pebbles_for_piles = list(map(int, input().split()))
paint(number_of_piles, number_of_colors, pebbles_for_piles)


def mi():
	return map(int, input().split())
(n, m) = mi()
a = list(mi())
(ma, mi) = (max(a), min(a))
if ma - mi > m:
	print('NO')
else:
	print('YES')
	for i in a:
		print(*[1] * mi + list(range(1, i - mi + 1)))


from itertools import chain
(n, k) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
(_max, _min) = (max(l), min(l))

def to_ans(v):
	return [1 for i in range(min(_min + 1, v))] + [i for i in range(2, 1 + v - _min)]
if k + _min < _max:
	print('NO')
else:
	print('YES')
	for ans in map(to_ans, l):
		print(*ans)


from collections import Counter

def isPosibleToPaintPibbles(pilePebbles, colors):
	minPile = 101
	maxPile = 0
	for i in range(len(pilePebbles)):
		maxPile = max(maxPile, pilePebbles[i])
		minPile = min(minPile, pilePebbles[i])
	return maxPile - minPile <= colors

def generatePaintedPibbles(pilePebbles, colors):
	paintedPiles = []
	for i in range(len(pilePebbles)):
		color = 1
		paintedPile = []
		for _ in range(pilePebbles[i]):
			paintedPile.append(color)
			color = 1 if color == colors else color + 1
		paintedPiles.append(paintedPile)
	return paintedPiles

def printPaintedPibbles(paintPilePebbles):
	for pile in paintPilePebbles:
		pileRaw = ''
		for pibble in pile:
			pileRaw += str(pibble) + ' '
		print(pileRaw)
vals = [int(x) for x in input().split()]
n = vals[0]
k = vals[1]
pilePebbles = [int(x) for x in input().split()]
if isPosibleToPaintPibbles(pilePebbles, k):
	print('YES')
	paintedPilePeebles = generatePaintedPibbles(pilePebbles, k)
	printPaintedPibbles(paintedPilePeebles)
else:
	print('NO')


def main():
	from sys import stdin, stdout
	(n, k) = map(int, stdin.readline().split())
	a = tuple(map(int, stdin.readline().split()))
	minim = min(a)
	maxim = max(a)
	arr = list(a)
	for i in range(n):
		arr[i] -= minim
	if max(arr) > k:
		stdout.write('NO')
	else:
		stdout.write('YES\n')
		for i in a:
			stdout.write('1 ' * minim)
			for j in range(i - minim):
				stdout.write(str(j % k + 1) + ' ')
			stdout.write('\n')
main()


import sys
(n, k) = [int(x) for x in sys.stdin.readline().strip().split()]
arr = [int(x) for x in sys.stdin.readline().strip().split()]
if max(arr) - min(arr) > k:
	print('NO')
else:
	print('YES')
	for i in arr:
		for j in range(i):
			print(j % k + 1, end=' ')
		print('')


def painting_pebbles(n_stacks, stacks, colours):
	for i in range(n_stacks):
		colorful_stack = []
		for j in range(stacks[i]):
			color = j % colours + 1
			colorful_stack.append(str(color))
		print(' '.join(colorful_stack))

def main():
	(n_stacks, colours) = map(int, input().split())
	stacks = list(map(int, input().split()))
	if max(stacks) - min(stacks) > colours:
		print('NO')
	else:
		print('YES')
		painting_pebbles(n_stacks, stacks, colours)
main()


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, k) = get_ints()
Arr = get_array()
mini = min(Arr)
maxi = max(Arr)
if maxi > mini + k:
	print('NO')
	exit()
print('YES')
for i in range(n):
	times = Arr[i]
	for i in range(times):
		if i != times - 1:
			print(i % k + 1, end=' ')
		else:
			print(i % k + 1)


(n, k) = [int(tamanho_pilha) for tamanho_pilha in input().split()]
tamanhos_pilhas = [int(tamanho_pilha) for tamanho_pilha in input().split()]
if k < 1:
	print('NO')
	exit(0)
menor_pilha = 101
for tamanho_pilha in tamanhos_pilhas:
	menor_pilha = min(menor_pilha, tamanho_pilha)
solucao = []
for i in range(n):
	solucao.append(list())
	for j in range(101):
		solucao[i].append(1)
menor_pilha += 1
for i in range(n):
	prox_cor = 2
	for j in range(menor_pilha, tamanhos_pilhas[i]):
		if prox_cor > k:
			print('NO')
			exit(0)
		solucao[i][j] = prox_cor
		prox_cor += 1
print('YES')
for i in range(n):
	for j in range(tamanhos_pilhas[i]):
		print('%d ' % solucao[i][j], end='')
	print('')


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
if max(a) - min(a) > k:
	print('NO')
else:
	print('YES')
	l = []
	for i in a:
		rem = i % k
		x = i - rem
		y = rem
		temp = []
		t = 1
		for j in range(k):
			temp += [t] * (i // k)
			t += 1
		t = 1
		for j in range(rem):
			temp += [t]
			t += 1
		l.append(temp)
	for i in l:
		print(*i)


import sys
import math
(n, k) = [int(x) for x in sys.stdin.readline().split()]
an = [int(x) for x in sys.stdin.readline().split()]
valarr = []
vmax = 0
vmi = 0
vmin = 101
vi = 0
for i in range(n):
	v = [int(an[i] / k)] * k
	for j in range(an[i] % k):
		v[j] += 1
	valarr.append(v)
	if an[i] > vmax:
		vmax = an[i]
		vmi = i
	if an[i] < vmin:
		vmin = an[i]
		vi = i
for i in range(k):
	if valarr[vmi][i] - valarr[vi][i] > 1:
		print('NO')
		exit()
print('YES')
for i in range(n):
	t = []
	for j in range(k):
		t.extend([str(j + 1)] * valarr[i][j])
	print(' '.join(t))


from itertools import cycle
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 1):
	for j in range(i + 1, n):
		if abs(a[i] - a[j]) > k:
			print('NO')
			exit()
print('YES')
for i in range(n):
	c = cycle(range(k))
	print(' '.join(map(str, [next(c) + 1 for _ in range(a[i])])))


line = input().split()
n = int(line[0])
k = int(line[1])
line = input().split()
cnt = [0 for i in range(n)]
minCnt = 200
maxCnt = -1
for i in range(n):
	cnt[i] = int(line[i])
	if cnt[i] > maxCnt:
		maxCnt = cnt[i]
	if cnt[i] < minCnt:
		minCnt = cnt[i]
if maxCnt - minCnt > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(cnt[i]):
			print(j % k + 1, end=' ')
		print()


(n, k) = map(int, input().strip().split(' '))
lst = list(map(int, input().strip().split(' ')))
m1 = max(lst)
m2 = min(lst)
if k < m1 - m2:
	print('NO')
else:
	print('YES')
	for j in range(n):
		if lst[j] <= k:
			for i in range(1, lst[j] + 1):
				print(i, end=' ')
			print()
		else:
			for i in range(1, lst[j] + 1):
				k1 = i % k
				if k1 == 0:
					k1 = k
				print(k1, end=' ')
			print()


(n, m) = map(int, input().split())
d = list(map(int, input().split()))
sd = sorted(d)
if max(d) - min(d) > m:
	print('NO')
	exit()
(h, *t) = range(1, m + 1)
ans = [h] * (min(d) + 1) + t
print('YES')
for i in d:
	[print(j, end=' ') for j in ans[:i]]
	print()


entrada = list(map(int, input().split(' ')))
bolitas = list(map(int, input().split(' ')))
lista = sorted(bolitas)
if lista[-1] - lista[0] > entrada[1]:
	print('NO')
else:
	print('YES')
	for i in range(entrada[0]):
		s = '1 ' * (lista[0] - 1)
		for j in range(bolitas[i] - lista[0] + 1):
			if j + 1 > entrada[1]:
				s += '1 '
			else:
				s += str(j + 1) + ' '
		print(s)


(n, k) = map(int, input().split())
f = list(map(int, input().split()))
if max(f) - min(f) > k:
	print('NO')
else:
	print('YES')
	for i in f:
		g = [0] * i
		l = 1
		for s in range(1, i + 1):
			g[s - 1] = l
			l += 1
			if l > k:
				l = 1
		print(*g)


def main():
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	(mi, ma) = (min(l), max(l))
	if ma - mi > k:
		print('NO')
		return
	print('YES')
	res = ['1'] * (mi + 1)
	for i in range(2, k + 1):
		res.append(str(i))
	for a in l:
		print(' '.join(res[:a]))

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = set(a)
d = {}
if max(s) - min(a) > k:
	print('NO')
	exit()
s = sorted(list(s))
color = 1
d[s[0]] = [1] * s[0]
for i in range(min(s) + 1, max(s) + 1):
	d[i] = d[i - 1] + [color]
	color += 1
print('YES')
for i in a:
	print(*d[i])


import math
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
if max((abs(x - y) for x in a for y in a)) > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(a[i]):
			print(j % k + 1, end=' ')
		print()


class CodeforcesTask509BSolution:

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

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

	def process_task(self):
		mx_dist = max(self.piles) - min(self.piles)
		if mx_dist > self.n_k[1]:
			self.result = 'NO'
		else:
			pile_order = ' '.join([str(x + 1) for x in range(self.n_k[1])])
			results = []
			for pile in self.piles:
				pl = []
				pl += [pile_order for x in range(pile // self.n_k[1])]
				pl.append(' '.join([str(x + 1) for x in range(self.n_k[1])][:pile % self.n_k[1]]))
				results.append(' '.join(pl))
				if results[-1][0] == ' ':
					results[-1] = results[-1][1:]
			self.result = 'YES\n{0}'.format('\n'.join(results))

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


import math
(n, m) = map(int, input().split())
x = [int(x) for x in input().split()]
l = min(x)
r = max(x)
if abs(l - r) > m:
	print('NO')
else:
	print('YES')
	for i in x:
		c = 0
		while c < i:
			y = 1
			while y <= m and c < i:
				print(y, end=' ')
				y += 1
				c += 1
		print()


(n, k) = map(int, input().split(' '))
balls = list(map(int, input().split(' ')))
if max(balls) - min(balls) > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		col = list()
		for j in range(balls[i]):
			col.append(j % k + 1)
		print(' '.join([str(k) for k in col]))


def main():
	(n, k) = read()
	a = read()
	if max(a) - min(a) > k:
		return 'NO'
	print('YES')
	for i in a:
		print('1 ' * min(a) + ' '.join(map(str, range(1, i - min(a) + 1))))

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return list(map(int, inputs.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


(n, m) = [int(x) for x in input().split()]
L = [int(x) for x in input().split()]
ans = [[] for i in range(n)]
less = min(L)
for i in range(n):
	L[i] -= less
	ans[i] += [1] * less
for i in range(1, m + 1):
	for j in range(n):
		if L[j] > 0:
			L[j] -= 1
			ans[j].append(i)
if sum(L) > 0:
	print('NO')
	exit()
print('YES')
for i in range(n):
	for j in ans[i]:
		print(j, end=' ')
	print()


(n, k) = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
L = [[-1 for j in range(A[i])] for i in range(n)]
for l in L:
	for i in range(len(l)):
		l[i] = i % k + 1
valid = True
for color in range(1, k + 1):
	mini = 200
	maxi = 0
	for l in L:
		mini = min(mini, l.count(color))
		maxi = max(maxi, l.count(color))
	if maxi - mini > 1:
		valid = False
if valid:
	print('YES')
	for l in L:
		for i in l:
			print(i, end=' ')
		print()
else:
	print('NO')


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 main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

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

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	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
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

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

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
from collections import OrderedDict
(n, k) = nninp()
a = llinp()
color = [[] for i in range(k)]
ans = []
for i in range(n):
	l = []
	col = 1
	for j in range(a[i]):
		l.append(col)
		col += 1
		if col > k:
			col = 1
	for c in range(1, k + 1):
		color[c - 1].append(l.count(c))
	ans.append(l)
for c in color:
	if max(c) - min(c) > 1:
		print('NO')
		exit()
print('YES')
for c in ans:
	print(*c)


__author__ = 'artyom'

def main():
	(n, k) = read(3)
	mn = 101
	mx = 0
	a = read(3)
	for v in a:
		if v < mn:
			mn = v
		if v > mx:
			mx = v
	if mx - mn > k:
		write('NO')
		return
	write('YES')
	for v in a:
		write([1] * mn + list(range(1, v - mn + 1)))

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='\n')
main()


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
colors = [str(i) for i in range(1, k + 1)]
minnum = min(a)
if minnum > 0:
	a = [i - minnum for i in a]
if max(a) > k:
	print('NO')
elif minnum > 0:
	print('YES')
	for i in range(n):
		print(' '.join([colors[0] for j in range(minnum)] + colors[0:a[i]]))
else:
	print('YES')
	for i in range(n):
		print(' '.join(colors[:a[i]]))


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
d = {}
k = list(set(z))
m = min(k)
for i in range(m, m + b + 1):
	if i in k:
		k.remove(i)
if k:
	print('NO')
else:
	print('YES')
	k = [*range(1, b + 1)]
	for i in z:
		print('1 ' * m + ' '.join(map(str, k[:i - m])))


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
temparr = get_ints()
arr = get_ints()
n = temparr[0]
k = temparr[1]
mins = min(arr)
maxs = max(arr)
maxsmin = mins + k
if maxsmin < maxs:
	print('NO')
else:
	print('YES')
	ans = []
	for i in arr:
		temp = []
		for j in range(i):
			jj = j % k
			jj += 1
			temp.append(str(jj))
		ans.append(temp[:])
	for i in ans:
		print(' '.join(i))


(n, k) = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
maxm = max(a)
minm = min(a)
if maxm / k - minm / k > 1:
	print('NO')
else:
	print('YES')
	for x in a:
		i = 1
		while i <= x:
			s = i % k
			if s == 0:
				s = k
			print(s, end=' ')
			i += 1
		print()


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
l = []
q = []
for i in range(n):
	l.append([0 for j in range(k)])
for i in range(n):
	f = a[i] // k
	m = a[i] % k
	h = []
	for x in range(f):
		for j in range(k):
			l[i][j] = l[i][j] + 1
			h.append(j + 1)
	for j in range(m):
		l[i][j] = l[i][j] + 1
		h.append(j + 1)
	q.append(h)
f = 1
for j in range(k):
	for i in range(n):
		for k in range(i + 1, n):
			if abs(l[i][j] - l[k][j]) > 1:
				f = 0
				break
		if f == 0:
			break
	if f == 0:
		break
if f:
	print('YES')
	for i in range(len(q)):
		for j in range(len(q[i]) - 1):
			print(q[i][j], end=' ')
		print(q[i][len(q[i]) - 1])
else:
	print('NO')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
q = min(arr)
if max(arr) - q > k:
	print('NO')
else:
	print('YES')
	ans = '1 ' * (q - 1) + '1'
	for i in range(1, k + 1):
		ans += ' ' + str(i)
	ans = ans.split()
	for i in arr:
		for j in range(i):
			print(ans[j], end=' ')
		print()


(a, b) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
if max(s) - b > min(s):
	print('NO')
else:
	print('YES')
	for i in range(a):
		print(' '.join([str(j % b + 1) for j in range(s[i])]))


(n, k1) = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
dp = [[-1] * 100 for i in range(100)]
for i in range(n):
	for j in range(a[i]):
		dp[i][j] = 0
for i in range(1, 2):
	index = -1
	mini = float('inf')
	for j in range(n):
		count = 0
		for k in range(100):
			if dp[j][k] == 0:
				count += 1
			elif dp[j][k] == -1:
				break
		if count < mini and count != 0:
			index = j
			mini = count
	count = 0
	if index == -1:
		continue
	for k in range(100):
		if dp[index][k] == 0 and count < mini:
			dp[index][k] = i
			count += 1
		elif count == mini:
			break
	for j in range(n):
		count = 0
		for k in range(100):
			if dp[j][k] == 0 and count <= mini:
				dp[j][k] = i
				count += 1
			elif count == mini:
				break
y = max(a)
y1 = min(a)
r = 1
for i in range(y1 + 1, y):
	if r < k1:
		r += 1
	else:
		break
	for j in range(n):
		dp[j][i] = r
flag = 0
for i in range(n):
	for j in range(a[i]):
		if dp[i][j] == 0:
			flag = 1
			break
	if flag == 1:
		break
if flag == 1:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(a[i]):
			print(dp[i][j], end=' ')
		print()


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
mn = min(a)
mx = max(a)
if mx - mn > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(a[i]):
			l = [1] * a[i]
			for p in range(mn + 1, a[i]):
				l[p] += l[p - 1]
		print(' '.join((str(x) for x in l)))


def ans(v1, v2):
	x = int(v1 / v2)
	y = int(v1 % v2)
	s = ''
	for i in range(0, x):
		for j in range(1, v2 + 1):
			s += str(j) + ' '
	for i in range(0, y):
		s += str(i + 1) + ' '
	return s
(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = a[:]
b.sort()
if b[-1] - b[0] > k:
	print('NO')
else:
	print('YES')
	for j in a:
		print(ans(j, k))


import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
(n, k) = sp()
arr = l()
if max(arr) - min(arr) > k:
	out('NO')
	exit()
out('YES\n')
minele = min(arr)
for i in range(n):
	for j in range(min(arr[i], minele + 1)):
		out('1 ')
	if arr[i] >= minele + 1:
		printer = 2
		for j in range(minele + 1, arr[i]):
			out(str(printer) + ' ')
			printer += 1
	out('\n')


(numberOfPiles, colors) = map(int, input().split())
pilesElements = [int(x) for x in input().split()]
maxElement = max(pilesElements)
minElement = min(pilesElements)
if maxElement - minElement > colors:
	print('NO')
else:
	print('YES')
	for i in range(numberOfPiles):
		pileRow = []
		for j in range(pilesElements[i]):
			pileRow.append(str(j % colors + 1))
		print(' '.join(pileRow))


(n, k) = list(map(int, input().split()))
nrr = list(map(int, input().split()))
if abs(max(nrr) - min(nrr)) > k:
	print('NO')
else:
	print('YES')
	kst = [1 for x in range(min(nrr))]
	lst = [kst for _ in nrr]
	p = len(kst)
	for (i, x) in enumerate(nrr):
		kst = lst[i]
		if p < x and x - p != k:
			kst = lst[i] + list(range(2, 2 + x - p))
		elif x - p == k:
			kst = lst[i] + list(range(1, 1 + x - p))
		print(*kst)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
if max(a) - min(a) > k:
	print('NO')
else:
	items = []
	for i in range(len(a)):
		l = [x for x in range(1, a[i] + 1)]
		if max(l) > k:
			i = 0
			temp = 1
			while i < len(l):
				if temp > k:
					temp = 1
				if l[i] > k:
					l[i] = temp
					temp += 1
				i += 1
		items.append(l)
	flag = 0
	for i in range(len(items)):
		for j in range(i + 1, len(items)):
			freq1 = [0] * 100
			freq2 = [0] * 100
			for k in range(len(items[i])):
				freq1[items[i][k]] += 1
			for k in range(len(items[j])):
				freq2[items[j][k]] += 1
			ans = []
			for k in range(len(freq1)):
				ans.append(abs(freq1[k] - freq2[k]))
			if max(ans) > 1:
				print('NO')
				flag = 1
				break
		if flag == 1:
			break
	if flag == 0:
		print('YES')
		for i in items:
			for j in i:
				print(j, end=' ')
			print()


def _print(_list):
	if _list == []:
		print('NO')
	else:
		from sys import stdout
		print('YES')
		for pile in _list:
			for e in pile:
				stdout.write(str(e) + ' ')
			print()
from math import ceil

def paint(piles, colors):
	if max(piles) - min(piles) > colors:
		return []
	res = []
	for p in piles:
		aux = []
		for i in range(p):
			aux += [i % colors + 1]
		res += [aux]
	return res
(n, colors) = [int(k) for k in input().split(' ')]
piles = [int(k) for k in input().split(' ')]
result = paint(piles, colors)
_print(result)


g = input()
(n, k) = [int(x) for x in g.split()]
r = input()
li = []
for y in r.split():
	li.append(int(y))
m = max(li)
t = min(li)
if m - t > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		lis = []
		u = li[i]
		jai = int(u / k)
		veer = u % k
		while jai > 0:
			for i in range(k):
				lis.append(i + 1)
			jai -= 1
		for ihj in range(veer):
			lis.append(ihj + 1)
		lis = sorted(lis)
		print(' '.join(map(str, lis)))


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(n, k) = lst()
	a = lst()
	f = 1
	mn = min(a)
	ans = [[] for i in range(n)]
	for i in range(n):
		v = 1
		sz = 0
		while sz < a[i]:
			if sz < mn:
				ans[i] += [1]
				sz += 1
				continue
			if v > k:
				f = 0
				break
			ans[i] += [v]
			v += 1
			sz += 1
		if f == 0:
			break
	if f:
		print('YES')
		for l in ans:
			print(*l)
	else:
		print('NO')


(piles, colors) = map(int, input().split())
pebbles = list(map(int, input().split()))

def maxPebbles(pebbles, colors):
	return max(pebbles) - min(pebbles) > colors

def painted(j, colors):
	return 1 + j % colors
if maxPebbles(pebbles, colors):
	print('NO')
else:
	print('YES')
	for i in pebbles:
		for j in range(i):
			print(painted(j, colors), end=' ')
		print()


(n, k) = map(int, input().split())
a = list(map(int, input().strip().split()))[:n]
if max(a) > min(a) + k:
	print('NO')
	exit()
print('YES')
for x in a:
	for i in range(x):
		print(1 + i % k, end=' ')
	print()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if max((abs(x - y) for x in arr for y in arr)) > k:
	print('NO')
	exit()
print('YES')
for i in range(n):
	for j in range(arr[i]):
		print(j % k + 1, end=' ')
	print()


(numPilhas, cores) = map(int, input().split())
pedrasPorPilha = list(map(int, input().split()))
if max(pedrasPorPilha) - min(pedrasPorPilha) > cores:
	print('NO')
else:
	print('YES')
	for i in range(numPilhas):
		pilhaLinha = []
		for j in range(pedrasPorPilha[i]):
			pilhaLinha.append(str(j % cores + 1))
		print(' '.join(pilhaLinha))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if max(arr) - min(arr) > k:
	print('NO')
else:
	print('YES')
	arrc = []
	i = 0
	while i < k:
		arrc.append(i + 1)
		i += 1
	c = 0
	for i in arr:
		printthis = []
		j = 0
		while j < i:
			printthis.append(arrc[j % k])
			j += 1
		print(*sorted(printthis))


import sys, math, bisect
from random import randint
inf = float('inf')
mod = 998244353

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def primesInRange(n):
	ans = []
	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
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def primeFactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n // i
	if n > 2:
		factors.append(n)
	return factors

def isPrime(n, k=5):
	if n < 2:
		return True
	for i in range(0, k):
		a = randint(1, n - 1)
		if pow(a, n - 1, n) != 1:
			return False
	return True
from collections import deque, defaultdict, Counter
import heapq, string
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if max(arr) - min(arr) > k:
	print('NO')
else:
	ans = [[0] * i for i in arr]
	c = min(arr)
	k = 1
	for i in range(n):
		for j in range(min(arr)):
			ans[i][j] = 1
	while c < max(arr):
		for i in range(n):
			if len(ans[i]) > c:
				ans[i][c] = k
		c += 1
		k += 1
	print('YES')
	for i in ans:
		print(*i)


keeper = input()
(n, m) = keeper.split(' ')
keeper2 = input()
tp = keeper2.split(' ')
map_object = map(int, tp)
arr = list(map_object)
if max(arr) - min(arr) > int(m):
	print('NO')
else:
	print('YES')
	for x in arr:
		for y in range(0, int(x)):
			print(int(y) % int(m) + 1, end=' ')
		print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
min_a = min(a)
max_a = max(a)
ans = [[0] * max_a for i in range(n)]
if max_a - min_a > k:
	print('NO')
else:
	print('YES')
	for i in range(max_a):
		for j in range(n):
			ans[j][i] = i % k + 1
	for i in range(n):
		for j in range(a[i] - 1):
			print(ans[i][j], end=' ')
		print(ans[i][n - 1])


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
x = min(a)
r = [[] for i in range(n)]
for i in range(n):
	r[i].extend((1,) * x)
	a[i] -= x
for j in range(1, k + 1):
	for i in range(n):
		if a[i] > 0:
			r[i].append(j)
			a[i] -= 1
if all((v == 0 for v in a)):
	print('YES')
	for i in range(n):
		print(*r[i])
else:
	print('NO')


(n, k) = [int(x) for x in input().split()]
list1 = [int(x) for x in input().split()]
mini = min(list1)
maxi = max(list1)
rem = maxi - (mini + 1)
min_color = rem + 1
if k < min_color:
	print('NO')
else:
	print('YES')
	pile = 0
	while pile < n:
		pt = 1
		for i in range(list1[pile]):
			if i < mini:
				print(pt, end=' ')
			else:
				print(pt, end=' ')
				pt += 1
		pile += 1
		print()


(n, k) = map(int, input().split())
heaps = list(map(int, input().split()))
mas = [[] for i in range(n)]
color = 0
flag = 0
r = 0
while True:
	count = 0
	color += 1
	if color > k:
		color = 1
	for i in range(n):
		if len(mas[i]) < heaps[i]:
			mas[i].append(color)
		else:
			count += 1
		if count == n:
			flag = 1
			break
	if flag == 1:
		break
flag = 0
for i in range(k):
	pr = []
	for j in range(n):
		ans = 0
		for g in mas[j]:
			if g == i + 1:
				ans += 1
		pr.append(ans)
	pr.sort()
	if pr[-1] - pr[0] > 1:
		flag = 1
		break
if flag == 0:
	print('YES')
	for i in mas:
		print(*i)
else:
	print('NO')


from math import ceil, floor
import copy
(num_piles, num_colors) = map(int, input().split())
p = list(map(int, input().split()))
piles = sorted(copy.deepcopy(p))
p_h = [[p[x] % num_colors if p[x] % num_colors != 0 else num_colors, ceil(p[x] / num_colors)] for x in range(num_piles)]
p_l = []
peebles_high_colors = [[piles[x] % num_colors if piles[x] % num_colors != 0 else num_colors, ceil(piles[x] / num_colors)] for x in range(num_piles)]
peebles_lower_colors = []
for i in range(num_piles):
	i1 = num_colors - peebles_high_colors[i][0]
	i2 = 0
	if i1 != 0:
		i2 = (piles[i] - peebles_high_colors[i][1] * peebles_high_colors[i][0]) // i1
	else:
		i2 = piles[i] - peebles_high_colors[i][1] * peebles_high_colors[i][0]
	peebles_lower_colors.append([i1, i2])
	j1 = num_colors - p_h[i][0]
	j2 = 0
	if j1 != 0:
		j2 = (p[i] - p_h[i][1] * p_h[i][0]) // j1
	else:
		j2 = p[i] - (p[i] - p_h[i][1] * p_h[i][0])
	p_l.append([j1, j2])

def check():
	if peebles_high_colors[num_piles - 1][0] <= peebles_high_colors[0][0]:
		if peebles_high_colors[num_piles - 1][1] - peebles_high_colors[0][1] > 1:
			return False
	elif peebles_high_colors[num_piles - 1][1] - peebles_lower_colors[0][1] > 1:
		return False
	return True

def prtline(i):
	cur_color = 1
	aux = 0
	max = p_h[i][1]
	for j in range(p_h[i][0] * p_h[i][1]):
		if aux >= max:
			aux = 0
			cur_color += 1
		print(cur_color, end=' ')
		aux += 1
	max = p_l[i][1]
	for j in range(p_l[i][0] * p_l[i][1]):
		if aux >= max:
			aux = 0
			cur_color += 1
		print(cur_color, end=' ')
		aux += 1
	print()

def prt():
	global p
	for i in range(num_piles):
		prtline(i)
if check():
	print('YES')
	prt()
else:
	print('NO')


(n, k) = map(int, input().split())
pilhas = list(map(int, input().split()))
if max(pilhas) - min(pilhas) > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		print(' '.join([str(j % k + 1) for j in range(pilhas[i])]))


arr = [int(x) for x in input().split()]
(n, k) = (arr[0], arr[1])
arr = [int(x) for x in input().split()]
for i in range(n):
	arr[i] = [arr[i], i]
arr = sorted(arr, key=lambda x: x[0])
p1 = [0 for i in range(k)]
ans = [[0 for i in range(k)] for i in range(n)]
mini = 0
ind = -1
flag = False
for i in range(n):
	pile = arr[i][0]
	c = pile // k
	m = pile % k
	for j in range(m):
		ans[i][j] += c + 1
		if j == ind and ans[i][j] > mini + 1:
			print('NO')
			flag = True
			break
	for j in range(m, k):
		ans[i][j] = c
		if j == ind and ans[i][j] > mini + 1:
			print('NO')
			flag = True
			break
		if i == 0 and j == m:
			mini = ans[i][j]
			ind = j
	if flag:
		break
else:
	for i in range(n):
		arr[i].append(i)
	arr = sorted(arr, key=lambda x: x[1])
	print('YES')
	for ele in arr:
		p = ans[ele[2]]
		for i in range(k):
			if p[i] > 0:
				while p[i] > 0:
					print(i + 1, end=' ')
					p[i] -= 1
		print()


def f(arr, k):
	ans = [0] * k
	for i in range(len(arr)):
		ans[arr[i]] += 1
	return ans
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = [[-1] * a[i] for i in range(n)]
for i in range(n):
	ind = 0
	for j in range(a[i]):
		ans[i][j] = ind
		ind = (ind + 1) % k
lim = True
for i in range(n):
	for j in range(i + 1, n):
		if abs(a[i] - a[j]) > k:
			lim = False
if lim:
	print('YES')
	for i in range(n):
		for j in range(len(ans[i])):
			print(ans[i][j] + 1, end=' ')
		print()
else:
	print('NO')


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
flag = 1
if max(A) - min(A) > k:
	print('NO')
	flag = 0
if flag:
	print('YES')
	for i in A:
		for j in range(i):
			print(j % k + 1, end=' ')
		print()


(n, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
l = min(a)
h = max(a)
if h - l > k:
	print('NO')
	exit()
print('YES')
for x in a:
	for i in range(x):
		print(1 + i % k, end=' ')
	print()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
flag = 0
for i in l:
	for j in l:
		if abs(i - j) > k:
			flag = 1
			break
	if flag == 1:
		break
if flag == 0:
	print('YES')
	for i in range(n):
		count = 1
		for j in range(l[i]):
			if count <= k:
				print(count, end=' ')
				count += 1
			else:
				count = 1
				print(count, end=' ')
				count += 1
		print()
else:
	print('NO')


(n, k) = [int(i) for i in input().strip().split()]
arr = [int(i) for i in input().strip().split()]
if max(arr) - min(arr) > k:
	print('NO')
else:
	print('YES')
	for i in arr:
		print(*[j % k + 1 for j in range(i)])


(n_piles, n_colors) = map(int, input().split())
pile_sizes = list(map(int, input().split()))
(max_size, min_size) = (1, 100)
for size in pile_sizes:
	if size > max_size:
		max_size = size
	if size < min_size:
		min_size = size
if max_size - min_size <= n_colors:
	print('YES')
	for size in pile_sizes:
		painted_pebbles = [str(p % n_colors + 1) for p in range(size)]
		print(' '.join(painted_pebbles))
else:
	print('NO')


from math import *
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if max(arr) - min(arr) > k:
	print('NO')
	exit(0)
print('YES')
for i in range(n):
	cur = 0
	for j in range(arr[i]):
		if j % k == 0:
			cur = 0
		cur += 1
		print(cur, end=' ')
	print()


(n, k) = list(map(int, input().split()))
piles = list(map(int, input().split()))
min_pebbles = min(piles)
pebble_colors = [[1 for j in range(min_pebbles)] for i in range(n)]
for i in range(1, k + 1):
	for j in range(n):
		pebbles_left = piles[j] - len(pebble_colors[j])
		if pebbles_left > 0:
			pebble_colors[j].append(i)
b = True
for j in range(n):
	if piles[j] != len(pebble_colors[j]):
		b = False
		print('NO')
		break
if b:
	print('YES')
	for colors in pebble_colors:
		for j in colors:
			print(j, end=' ')
		print()


(n, k) = map(int, input().split())
san = list(map(int, input().split()))
if max(san) > k + min(san):
	print('NO')
else:
	print('YES')
	for i in san:
		for j in range(1, i + 1):
			if j % k != 0:
				print(j % k, end=' ')
			else:
				print(k, end=' ')
		else:
			print(' ')


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
m = min(A)
ma = max(A)
if ma - (m - m % k) > k + m % k:
	print('NO')
else:
	B = [i for i in range(1, k + 1)] * 1000
	print('YES')
	for i in A:
		print(*B[:i])


imin = 105
imax = -105
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
	if a[i] > imax:
		imax = a[i]
	if a[i] < imin:
		imin = a[i]
if imax - imin > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		out = []
		for j in range(a[i]):
			out.append(j % k + 1)
		print(' '.join((str(e) for e in out)))


(a, b) = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
store = [[-1] * x[i] for i in range(a)]
bad = [[0] * a for _ in range(b)]
storeind = [0] * a
filled = True
curr = 0
while filled:
	filled = False
	for i in range(len(store)):
		if store[i][-1] == -1:
			filled = True
			store[i][storeind[i]] = curr % b + 1
			storeind[i] += 1
			bad[curr % b][i] += 1
	curr += 1
for i in bad:
	if max(i) - min(i) > 1:
		print('NO')
		quit()
print('YES')
for i in store:
	print(' '.join([str(x) for x in i]))


(n, k) = map(int, input().split())
piles = list(map(int, input().split()))
if max(piles) - min(piles) <= k:
	print('YES')
	for pile in piles:
		(answer, c) = ([], 1)
		for i in range(pile):
			answer.append(c)
			c = 1 if c == k else c + 1
		print(' '.join(map(str, sorted(answer))))
else:
	print('NO')


def paint(total_stacks, stacks, colours):
	for i in range(total_stacks):
		all_stack = []
		for j in range(stacks[i]):
			color = j % colours + 1
			all_stack.append(str(color))
		out_color = ' '.join(all_stack)
		print(out_color)

def main():
	(total_stacks, colours) = map(int, input().split())
	stacks = list(map(int, input().split()))
	not_valid = max(stacks) - min(stacks) > colours
	if not_valid:
		print('NO')
	else:
		print('YES')
		paint(total_stacks, stacks, colours)
main()


def paint(i, colors):
	painted = []
	curColor = 1
	while i != 0:
		if curColor == colors + 1:
			curColor = 1
		painted.append(str(curColor))
		i -= 1
		curColor += 1
	print(' '.join(painted))
colors = list(map(int, input().split()))[1]
columns = list(map(int, input().split()))
colsDiff = max(columns) - min(columns)
if colors - colsDiff < 0:
	print('NO')
	exit(0)
print('YES')
for i in columns:
	paint(i, colors)


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
res = [[] for i in range(n)]
c = 0
while True:
	z = 0
	for i in arr:
		if i > 0:
			z += 1
	if z == 0:
		break
	if z == n:
		for i in range(n):
			arr[i] -= 1
			res[i].append(1)
	else:
		c += 1
		if c > k:
			break
		for (i, j) in enumerate(arr):
			if j > 0:
				arr[i] -= 1
				res[i].append(c)
if c > k:
	print('NO')
else:
	print('YES')
	for i in res:
		for j in i:
			print(j, end=' ')
		print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = 0
possible = True
for i in range(n - 1):
	for j in range(i + 1, n):
		if abs(a[i] - a[j]) > k:
			possible = False
			break
if not possible:
	print('NO')
else:
	print('YES')
	for p in a:
		s = ''
		c = 1
		for _ in range(p):
			s += str(c) + ' '
			c = 1 if c == k else c + 1
		print(s[:-1])


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
for i in range(n - 1):
	if abs(ls[i + 1] - ls[i]) > k:
		print('NO')
		break
else:
	m = min(ls)
	M = max(ls)
	if M - m > k:
		print('NO')
	else:
		print('YES')
		for i in range(n):
			for j in range(ls[i]):
				if (j + 1) % k != 0:
					print((j + 1) % k, end=' ')
				else:
					print(k, end=' ')
			print()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ma = max(l)
mi = min(l)
t = ma - mi
if t <= k:
	print('YES')
	for i in range(0, len(l)):
		j = mi
		while j > 0:
			print(1, end=' ')
			j -= 1
		a = 1
		b = l[i]
		while b > mi:
			print(a, end=' ')
			a += 1
			b -= 1
		print()
else:
	print('NO')


def pinta_as_pedras(cor_atual):
	global pilhas_pedras
	global coloridas
	global pilhas_pintadas
	for i in range(len(pilhas_pedras)):
		if pilhas_pedras[i] > 0:
			pilhas_pedras[i] = pilhas_pedras[i] - 1
			coloridas[i] += str(cor_atual) + ' '
		if pilhas_pedras[i] == 0:
			pilhas_pintadas[i] = True
(n, k) = map(int, input().split())
pilhas_pedras = list(map(int, input().split()))
coloridas = ['' for i in range(n)]
pilhas_pintadas = {}
cor_atual = 1
while len(pilhas_pintadas.keys()) < len(pilhas_pedras):
	if len(pilhas_pintadas.keys()) > 0 and cor_atual > 0:
		if cor_atual == 1:
			pinta_as_pedras(cor_atual)
		cor_atual += 1
	pinta_as_pedras(cor_atual)
if cor_atual > k:
	print('NO')
else:
	print('YES')
	for c in coloridas:
		print(c.strip())


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if max(l) - min(l) > k:
	print('NO')
	quit()
print('YES')
res = ['1'] * (min(l) + 1)
for i in range(2, k + 1):
	res.append(str(i))
for a in l:
	print(' '.join(res[:a]))


inp = lambda : map(int, input().split())
(n, m) = inp()
a = [*inp()]
if max(a) - min(a) > m:
	print('NO')
	quit()
print('YES')
ans = [str(i + 1) for i in range(m)] * (max(a) // m + 1)
for i in range(n):
	print(' '.join(sorted(ans[:a[i]])))


def _aux(pilas, k, out):
	if max(pilas) == 0:
		return True
	if max(pilas) > k:
		return False
	for i in range(n):
		if pilas[i] != 0:
			pilas[i] -= 1
			out[i].append(k)
	return _aux(pilas, k - 1, out)
(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
m = min(a)
out = [[k] * m for i in range(n)]
for i in range(n):
	a[i] -= m
if _aux(a, k, out):
	print('YES')
	for d in out:
		print(*d)
else:
	print('NO')


(num_iles, num_colors) = map(int, input().split())
pile_pebbles = list(map(int, input().split()))
size_max = 1
size_min = 100
for pebbles in pile_pebbles:
	if pebbles < size_min:
		size_min = pebbles
	if pebbles > size_max:
		size_max = pebbles
dif = size_max - size_min
if dif > num_colors:
	print('NO')
else:
	print('YES')
	for pebbles in pile_pebbles:
		pebbles_painted = [str(p % num_colors + 1) for p in range(pebbles)]
		print(' '.join(pebbles_painted))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
if max(a) - min(a) > k:
	print('NO')
else:
	print('YES')
	m = min(a)
	for num in a:
		print(*[1] * m + list(range(1, 1 + num - m)))


(n, k) = map(int, input().split())
pebles = list(map(int, input().split()))
minm = min(pebles)
maxm = max(pebles)
if maxm - minm > k:
	print('NO')
else:
	print('YES')
	for i in pebles:
		j = [1] * minm + list(range(1, i - minm + 1))
		print(*j)


def verifyPebbles(k, piles):
	for i in range(0, len(piles) - 1):
		for j in range(i + 1, len(piles)):
			diff = abs(piles[i] - piles[j])
			if diff >= k + 1:
				return False
	return True

def getColor(color, k):
	if color > k:
		return 1
	return color

def paintPebbles(k, piles):
	res = ''
	if not verifyPebbles(k, piles):
		res = 'NO'
		return res
	res = 'YES\n'
	for pile in piles:
		pileStr = ''
		color = 1
		for i in range(0, pile):
			color = getColor(color, k)
			pileStr += str(color) + ' '
			color += 1
		pileStr.strip()
		res += pileStr + '\n'
	return res

def run():
	(n, k) = list(map(int, input().split()))
	piles = list(map(int, input().split()))
	print(paintPebbles(k, piles))
run()


def result(color, numberOfColors):
	if color > numberOfColors:
		print('NO')
	else:
		print('YES')
		for aColor in colorful:
			print(aColor.strip())

def paint(color, piles, colorful, painted):
	for i in range(len(piles)):
		if piles[i] > 0:
			piles[i] = piles[i] - 1
			colorful[i] += str(color) + ' '
		if piles[i] == 0:
			painted[i] = True
	return painted
(numberOfPiles, numberOfColors) = map(int, input().split())
colorful = ['' for i in range(numberOfPiles)]
numberOfPebbles = map(int, input().split())
piles = list(numberOfPebbles)
color = 1
painted = {}
while len(painted.keys()) < len(piles):
	if len(painted.keys()) > 0 and color > 0:
		if color == 1:
			paint(color, piles, colorful, painted)
		color += 1
	paint(color, piles, colorful, painted)
result(color, numberOfColors)


def yes_or_no(colors, color_count):
	last = colors[-1]
	first = colors[0]
	for i in range(color_count):
		if not -2 < last[0][i] - first[0][i] < 2:
			return 'NO'
	return 'YES'
color_count = int(input().split()[1])
piles = list(map(int, input().split()))
for i in range(len(piles)):
	piles[i] = (piles[i], i)
new_piles = sorted(piles)
colors = []
for i in range(len(new_piles)):
	pile = new_piles[i][0]
	default = pile // color_count + 1
	more_counts = pile % color_count
	pile_colors = [default] * more_counts
	pile_colors += [default - 1] * (color_count - more_counts)
	colors.append((pile_colors, new_piles[i][1]))
yes_no = yes_or_no(colors, color_count)
print(yes_no)
if yes_no == 'YES':
	for vector in [item[0] for item in sorted(colors, key=lambda x: x[1])]:
		for i in range(len(vector)):
			count = vector[i]
			for j in range(count):
				print(i + 1, end=' ')
		print()


import sys
input = sys.stdin.buffer.readline
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
c = 1
maxi = max(a)
out = [[] for i in range(n)]
while maxi > 0:
	mini = min(a)
	for i in range(n):
		if a[i] <= mini + 1:
			out[i].extend([c] * a[i])
			a[i] = 0
		else:
			out[i].extend([c] * (mini + 1))
			a[i] -= mini + 1
	c += 1
	maxi -= mini + 1
if c <= k + 1:
	print('YES')
	for row in out:
		print(*row)
else:
	print('NO')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
low = min(a)
high = max(a)
if high - low > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(low):
			print('1', end=' ')
		for j in range(a[i] - low):
			print(1 + j, end=' ')
		print('')


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
y = min(x)
if k < max(x) - y:
	print('NO')
else:
	print('YES')
	for i in range(n):
		print('1 ' * y, end='')
		if x[i] - y >= 1:
			for j in range(1, x[i] - y + 1):
				print(j, end=' ')
		print('\n')


a = input().split()
(n, k) = (int(a[0]), int(a[1]))
a = input().split()
x = int(a[0])
max = x
min = x
indmax = 0
indmin = 0
col = [x]
for b in range(n - 1):
	x = int(a[b + 1])
	col.append(x)
	if x > max:
		max = x
		indmax = b + 1
	elif x < min:
		min = x
		indmin = b + 1
if max - min > k:
	print('NO')
else:
	print('YES')
	u = str(1) + (' ' + str(1)) * (col[indmin] - 1)
	for x in range(n):
		if x == indmin:
			print(u)
		else:
			y = u
			for z in range(col[x] - col[indmin]):
				y += ' ' + str(1 + z)
			print(y)


[n, k] = list(map(int, input().split()))
pebbles = list(map(int, input().split()))
max_num = max(pebbles)
min_num = min(pebbles)
if max_num - min_num > k:
	print('NO')
else:
	print('YES')
	for pebble in pebbles:
		color = 1
		output = ''
		for i in range(1, pebble + 1):
			if i > min_num + 1:
				color += 1
			output += f'{color} '
		print(output)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
mn = min(arr)
mx = max(arr)
if mx - mn > k:
	print('NO')
	exit()
print('YES')
cs = [1] * mn + list(range(1, k + 1))
for c in arr:
	for i in range(c):
		print(cs[i], end=' ')
	print()


(n, v) = map(int, input().split())
l = [int(x) for x in input().split()]
if max(l) - min(l) > v:
	print('NO')
else:
	print('YES')
	for i in l:
		k = []
		for j in range(i):
			k.append(j % v + 1)
		print(*sorted(k))


import math

def printColoresPiles(piles):
	for pile in piles:
		s = str(pile[0])
		for i in range(1, len(pile), 1):
			s = s + ' ' + str(pile[i])
		print(s)
(n, k) = list(map(int, input().split()))
piles = list(map(int, input().split()))
max_pile = max(piles)
min_pile = min(piles)
if max_pile - min_pile > k:
	print('NO')
else:
	print('YES')
	colored_piles = []
	for pile in piles:
		colored_piles.append([])
		color = 0
		for i in range(pile):
			colored_piles[len(colored_piles) - 1].append(color + 1)
			color = (color + 1) % k
	printColoresPiles(colored_piles)


import sys
f = sys.stdin
(n, k) = list(map(int, f.readline().strip().split()))
a = [int(u) for u in f.readline().strip().split()]
min_a = min(a)
max_a = max(a)
if max_a > min_a + k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		d = [''] * a[i]
		for j in range(a[i]):
			if j <= min_a:
				d[j] = '1'
			else:
				d[j] = str(1 + j - min_a)
		print(' '.join(d))


__author__ = '1'
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
mx = max(a)
mn = min(a)
c = mx // k
mc = mx % k
if c > 0 and mn < (c - 1) * k + mc:
	print('NO')
else:
	print('YES')
	for i in a:
		[print(j % k + 1, end=' ') for j in range(i)]
		print('')


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
if max(A) - min(A) > k:
	print('NO')
else:
	print('YES')
	M = [[0] * n for i in range(k)]
	Res = [[] for i in range(n)]
	flag = True
	while flag:
		flag = False
		for i in range(k):
			m = min(M[i])
			for j in range(n):
				if M[i][j] <= m and len(Res[j]) < A[j]:
					M[i][j] += 1
					Res[j].append(i + 1)
					flag = True
	for line in Res:
		print(*line)


(num_pilhas, c_cores) = map(int, input().split())
pilhas = list(map(int, input().split()))
if max(pilhas) - min(pilhas) > c_cores:
	print('NO')
else:
	print('YES')
	for i in range(num_pilhas):
		pilhas_colorida = []
		for j in range(pilhas[i]):
			cor = j % c_cores + 1
			pilhas_colorida.append(str(cor))
		print(' '.join(pilhas_colorida))


(n, c) = map(int, input().split())
l = list(map(int, input().split()))
mn = min(l)
mx = max(l)
if mx - mn > c:
	print('NO')
else:
	print('YES')
	for i in range(n):
		h = l[i]
		for j in range(mn):
			print(1, end=' ')
		for j in range(h - mn):
			print(j + 1, end=' ')
		print()


(n, k) = [int(x) for x in input().split()]
piles = [int(x) for x in input().split()]
min_val = min(piles)
max_val = max(piles)
if max_val - min_val > k:
	print('NO')
	quit()
else:
	print('YES')
	for i in range(n):
		line = '1'
		for j in range(2, piles[i] + 1):
			if j <= min_val:
				line += ' 1'
			else:
				line += ' ' + str(j - min_val)
		print(line)


(n, k) = map(int, input().split())
list1 = list(map(int, input().split()))
minn = 100000
maxx = 0
for i in range(n):
	if list1[i] > maxx:
		maxx = list1[i]
	if list1[i] < minn:
		minn = list1[i]
if maxx - minn > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(list1[i]):
			print(j % k + 1, end=' ')
		print('')


(n, k) = map(int, input().split())
ai = list(map(int, input().split()))
temp = max(ai)
temp2 = min(ai)
if temp - temp2 > k:
	print('NO')
else:
	print('YES')
	for i in ai:
		i2 = i // k
		i3 = i - i2 * k
		for i in range(k):
			if i2 > 0:
				print((str(i + 1) + ' ') * i2, end='')
			else:
				break
		for i in range(k):
			if i3 > 0:
				print(i + 1, end=' ')
			else:
				break
			i3 -= 1
		print()


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
no = 0
p = x = min(a)
q = y = max(a)
small = [0] * k
big = [0] * k
p2 = p // k
p3 = p % k
for i in range(k):
	if x > 0:
		if p3 > 0:
			small[i] = p2 + 1
			p3 -= 1
		else:
			small[i] = p2
		x -= small[i]
	else:
		break
q2 = q // k
q3 = q % k
for i in range(k):
	if y > 0:
		if q3 > 0:
			big[i] = q2 + 1
			q3 -= 1
		else:
			big[i] = q2
		y -= big[i]
	else:
		break
for i in range(k):
	if abs(big[i] - small[i]) > 1:
		no = 1
		break
if no == 1:
	print('NO')
else:
	print('YES')
	for i in range(n):
		num = 1
		for j in range(a[i]):
			if num <= k:
				print(num, '', end='')
			else:
				num = 1
				print(num, '', end='')
			num += 1
		print('')


(n, k) = input().split()
(n, k) = (int(n), int(k))
amounts = [int(i) for i in input().split()]
if max(amounts) - min(amounts) > k:
	print('NO')
else:
	print('YES')
	for amount in amounts:
		count = amount // k
		leftover = amount % k
		for i in range(k):
			print((str(i + 1) + ' ') * count, end='')
		print(' '.join([str(i + 1) for i in range(leftover)]))


(n, k) = map(int, input().split())
x = 1
l = list(map(int, input().split()))
for i in range(len(l) - 1):
	if max(l) - min(l) > k:
		print('NO')
		x = 0
		break
if x == 1:
	print('YES')
	for a in range(len(l)):
		cur = []
		times = l[a] // k
		for i in range(1, k + 1):
			cur = cur + [str(i) for j in range(times)]
		for i in range(1, l[a] - times * k + 1):
			cur = cur + [str(i)]
		for i in range(len(cur)):
			cur[i] = int(cur[i])
		cur = list(sorted(cur))
		for i in range(len(cur)):
			cur[i] = str(cur[i])
		print(' '.join(cur))


(n, k) = input().split(sep=None, maxsplit=2)
(n, k) = (int(n), int(k))
u = input().split(sep=None, maxsplit=n)
u = [int(i) for i in u]
low = min(u)
high = max(u)
ones = ['1' for i in range(low)]
if low + k - high < 0:
	print('NO')
else:
	print('YES')
	for i in u:
		x = [str(i + 1) for i in range(i - low)]
		print(' '.join(ones + x))


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
if max(l) > min(l) + k:
	print('NO')
	exit()
j = 0
print('YES')
clr = [[0 for j in range(1095)] for i in range(n)]
while j < 101:
	for c in range(1, k + 1):
		for i in range(n):
			clr[i][j] = c
		j += 1
for i in range(n):
	for j in range(l[i]):
		print(clr[i][j], end=' ')
	print()


(_, k) = map(int, input().split())
pebbles = list(map(int, input().split()))
res = []
if max(pebbles) - min(pebbles) > k:
	print('NO')
else:
	print('YES')
	for i in pebbles:
		for j in range(i):
			res.append(str(j % k + 1))
		print(' '.join(res))
		res = []


import sys
fin = sys.stdin
fout = sys.stdout
(n, k) = map(int, fin.readline().split())
nums = list(map(int, fin.readline().split()))
nums = sorted([(nums[i], i) for i in range(n)])
if nums[-1][0] - nums[0][0] > k:
	print('NO', file=fout)
else:
	print('YES', file=fout)
	ans = [[0 for i in range(k)] for j in range(n)]
	for pile in range(n):
		min_c = nums[pile][0] // k
		min_cnt = nums[pile][0] % k
		for i in range(min_cnt):
			ans[nums[pile][1]][i] = min_c + 1
		for i in range(min_cnt, k):
			ans[nums[pile][1]][i] = min_c
	for pile in range(n):
		for color in range(k):
			for cnt in range(ans[pile][color]):
				print(color + 1, end=' ', file=fout)
		print('', file=fout)
fout.close()


(n_piles, n_colors) = map(int, input().split())
piles = list(map(int, input().split()))
max_pile = 0
min_pile = piles[0]
for p in piles:
	if p > max_pile:
		max_pile = p
	if p < min_pile:
		min_pile = p
if max_pile - min_pile > n_colors:
	print('NO')
else:
	print('YES')
	for pile in piles:
		for i in range(pile):
			print(i % n_colors + 1, end=' ')
		print()


(n, k) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
pebbles = []
for i in range(len(l)):
	pebbles.append((l[i], i, []))
pebbles.sort(key=lambda pebble: -pebble[0])
for i in range(pebbles[0][0]):
	pebbles[0][2].append(min(k, i + 1))
bigger = pebbles[0][2][-1]
cnt = pebbles[0][2].count(bigger)
if cnt - pebbles[-1][0] >= 2:
	print('NO')
else:
	print('YES')
	for i in range(1, n):
		pebbles[i][2].extend(pebbles[0][2][::-1][:pebbles[i][0]])
	pebbles.sort(key=lambda pebble: pebble[1])
	for pebble in pebbles:
		line = ''
		for c in pebble[2]:
			line += str(c) + ' '
		print(line)


nk = input()
(ns, ks) = nk.split(' ')
n = int(ns)
k = int(ks)
kuchi_s = input()
kuchi = list(map(int, kuchi_s.split(' ')))
kuchi_index = [[0, i] for i in range(n)]
for i in range(n):
	kuchi_index[i][0] = kuchi[i]
kuchi_index.sort(key=lambda x: x[0])
flag = 1
counter = 1
paint = [[] for i in range(n)]
k_temp = k
if kuchi_index[0][0] + k < kuchi_index[n - 1][0]:
	print('NO')
else:
	for i in range(n):
		st_num = kuchi_index[i][0] // k
		for j in range(k):
			for e in range(st_num):
				paint[kuchi_index[i][1]].append(j + 1)
		for e in range(kuchi_index[i][0] - len(paint[kuchi_index[i][1]])):
			paint[kuchi_index[i][1]].append(e + 1)
	print('YES')
	for i in range(n):
		for j in paint[i]:
			print(j, end=' ')
		print()


def STR():
	return list(input())

def INT():
	return int(input())

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

def MAP2():
	return map(float, input().split())

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

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]

def check(arr, n, col):
	for i in range(n):
		for j in range(n):
			for k in range(col):
				if i != j:
					if abs(arr[i + 1][k] - arr[j + 1][k]) > 1:
						return False
	return True
(n, col) = MAP()
arr = LIST()
cnt = defaultdict(list)
for i in range(n):
	cnt[i + 1] = [0] * col
res = []
for i in range(n):
	v = []
	for j in range(1, arr[i] + 1):
		x = j % col
		if x == 0:
			x = col
		v.append(x)
		cnt[i + 1][x - 1] += 1
	res.append(v)
if check(cnt, n, col):
	print('YES')
	for i in res:
		print(*i)
else:
	print('NO')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
if b[-1] - b[0] > k:
	print('NO')
else:
	print('YES')
	for v in a:
		for i in range(b[0]):
			print(end='1 ')
		for i in range(v - b[0]):
			print((i + 1) % k + 1, end=' ')
		print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
mi = min(a)
ma = max(a)
if ma - mi > k:
	print('NO')
else:
	print('YES')
	grid = [None for _ in range(n)]
	for i in range(n):
		grid[i] = [1 for _ in range(mi)]
	for i in range(n):
		x = 2
		for j in range(min(a[i] - mi, k - 1)):
			grid[i].append(x)
			x += 1
		if a[i] > k:
			grid[i].append(1)
	for i in range(n):
		for j in range(a[i]):
			print(grid[i][j], end=' ')
		print()


import sys
(n, k) = list(map(int, input().split()))
keeps = list(map(int, input().split()))
min_k = min(keeps)
ans = [0] * n
for i in range(n):
	ans[i] = ['1'] * min(min_k + 1, keeps[i])
	j = 2
	while j <= k and len(ans[i]) < keeps[i]:
		ans[i].append(str(j))
		j += 1
	if len(ans[i]) < keeps[i]:
		print('NO')
		return
print('YES')
for i in range(n):
	print(' '.join(ans[i]))


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, k) = f()
l = il()
mx = 0
for i in range(n):
	for j in range(n):
		mx = max(mx, abs(l[i] - l[j]))
if mx > k:
	exit(print('NO'))
print('YES')
for i in l:
	for j in range(1, i + 1):
		if j % k == 0:
			print(k, end=' ')
		else:
			print(j % k, end=' ')
	print()


R = lambda : list(map(int, input().split()))
(n, k) = R()
a = R()
r = [[] for _ in range(n)]
x = min(a)
m = 1
for i in range(n):
	for j in range(x):
		r[i].append(m)
		a[i] -= 1
flg = True
xfl = True
while max(a) > 0:
	m += 1
	if m > k:
		flg = False
		break
	mk = m
	if xfl and 1 in a:
		mk = 1
		m -= 1
		xfl = False
	for i in range(n):
		if a[i] > 0:
			r[i].append(mk)
			a[i] -= 1
print('YES' if flg else 'NO')
if flg:
	for i in range(n):
		print(' '.join([str(u) for u in r[i]]))


from sys import *
from bisect import *
from collections import *
INF = 1000000000.0
Input = []
MOD = 1000000007

def Out(x):
	stdout.write(str(x) + '\n')

def In():
	return stdin.readline().strip()

def inputGrab():
	for line in stdin:
		Input.extend(map(str, line.strip().split()))

def main():
	(n, k) = map(int, In().split())
	v = map(int, In().split())
	v = list(v)
	Max = -1
	Min = 110
	for i in v:
		Min = min(i, Min)
		Max = max(i, Max)
	pile = [[] for i in range(110)]
	if abs(Max - Min) > k:
		print('NO')
	else:
		print('YES')
		Color = 1
		changed = True
		while changed:
			Min = 110
			changed = False
			for i in range(len(v)):
				if v[i] != 0:
					pile[i].append(Color)
					v[i] -= 1
					Min = min(Min, v[i])
					changed = True
			Color += 1
			if Color > k:
				Color = 1
		for i in range(n):
			for y in pile[i]:
				print(y, end=' ')
			print()
main()


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
if max(a) > min(a) + k:
	print('NO')
else:
	print('YES')
	l = [x for x in range(1, k + 1)] * 100
	for x in a:
		print(*l[:x])


R = lambda : map(int, input().split())
(n, k) = R()
L = list(R())
(ma, mi) = (max(L), min(L))
(d1, v1) = divmod(ma, k)
(d2, v2) = divmod(mi, k)
f = 0
if d1 - d2 > 1:
	f = 1
else:
	if v1 > 0:
		d1 += 1
	if v2 > 0:
		d2 += 1
	if d1 - d2 > 1:
		f = 1
	elif d1 - d2 == 1:
		if v1 > v2:
			f = 1
if f:
	print('NO')
else:
	print('YES')
	for i in L:
		p = (i + k - 1) // k
		l = [j for j in range(1, k + 1)] * p
		print(*l[:i])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if max(a) - min(a) > k:
	print('NO')
else:
	print('YES')
	temp = [1] * (min(a) + 1) + list(range(2, max(a)))
	for i in range(n):
		print(' '.join(map(str, temp[:a[i]])))


(n, k) = [int(i) for i in input().split()]
inp = input().split()
a = []
for i in range(n):
	a.append([int(inp[i]), i])
a.sort()
if a[0][0] + k < a[-1][0]:
	print('NO')
	exit(0)
b = [[] for i in range(n)]
for i in range(n):
	b[a[i][1]] += [1] * a[0][0]
	b[a[i][1]] += [j for j in range(1, a[i][0] - a[0][0] + 1)]
print('YES')
for i in range(n):
	print(' '.join(map(str, b[i])))


def solve(k, arr):
	s = sorted(arr)
	(_min, _max) = (s[0], s[-1])
	if _max - _min > k:
		return None
	res = [[] for _ in range(len(arr))]
	for i in range(_max):
		color = i % k + 1
		pile = i % len(arr)
		for j in range(len(arr)):
			if len(res[j]) < arr[j]:
				res[j].append(color)
	return res
parse = lambda : list(map(int, input().split()))
(n, k) = parse()
res = solve(k, parse())
if res is None:
	print('NO')
else:
	print('YES')
	print('\n'.join([' '.join(map(str, i)) for i in res]))


(n, colors) = map(int, input().split())
piles = [int(num) for num in input().split()]
if max(piles) - min(piles) > colors:
	print('NO')
else:
	print('YES')
	for i in range(n):
		out = ''
		for j in range(piles[i]):
			aux = str(j % colors + 1)
			out += aux + ' '
		print(out.strip())


(n, k) = map(int, input().split())
piles = list(map(int, input().split()))
(minimum, maximum) = (min(piles), max(piles))
if maximum - minimum > k:
	print('NO')
else:
	base_qnt = minimum + 1
	res = [[] for _ in range(n)]
	for (idx, pile) in enumerate(res):
		qnt = piles[idx]
		diff = qnt - base_qnt
		res[idx].extend([1] * (base_qnt - 1 if diff < 0 else base_qnt))
		res[idx].extend(range(2, 2 + diff))
	print('YES')
	print('\n'.join(map(lambda pile: ' '.join(map(str, pile)), res)))


(qtd_piles, qtd_colors) = map(int, input().split())
piles = list(map(int, input().split()))
diff = max(piles) - min(piles)
if diff > qtd_colors:
	print('NO')
else:
	print('YES')
	for pile in piles:
		for i in range(pile):
			print(i % qtd_colors + 1, end=' ')
		print()


def solve(n, k, seq):
	ans = []
	for outerIndex in range(n):
		maxAllowed = seq[outerIndex] + k
		for innerIndex in range(n):
			if maxAllowed < seq[innerIndex]:
				print('NO')
				return
	for i in seq:
		temp = []
		start = 1
		if i > k:
			end = k + 1
			remainder = i % k
			if remainder > 0:
				temp.extend(list(range(1, remainder + 1)))
			if i // k > 1:
				theList = list(range(start, end))
				for _ in range(1, i // k):
					temp.extend(theList)
		else:
			end = i + 1
		temp.extend(list(range(start, end)))
		ans.append(temp)
	print('YES')
	for arr in ans:
		for ele in arr:
			print(ele, end=' ')
		print(' ')
(n, k) = list(map(int, input().split()))
seq = list(map(int, input().split()))
solve(n, k, seq)


(n, k) = map(int, input().split())
(highest, lowest) = (0, 101)
a = []
for i in input().split():
	i = int(i)
	a.append(i)
	if i > highest:
		highest = i
	if i < lowest:
		lowest = i
if highest - lowest > k:
	print('NO')
	exit()
print('YES')
m = highest - k
if m < 0:
	m = 0
for i in a:
	if i <= m:
		print(*[1 for x in range(m)])
	else:
		if m > 0:
			print(*[1 for x in range(m)], end=' ')
		print(*[x for x in range(1, i - m + 1)])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [[0 for j in range(a[i])] for i in range(n)]
i = 0
c = 1
j = 0
repeat = False
out = False
m = max(a)
while True:
	for i in range(n):
		if j < a[i]:
			b[i][j] = c
		if a[i] + k <= j:
			out = True
	j += 1
	c += 1
	if c > k:
		c = 1
	for i in range(n):
		if a[i] + k <= j:
			out = True
	if j >= m:
		break
	if out:
		break
for i in range(n):
	for j in range(a[i]):
		if b[i][j] == 0:
			print('NO')
			exit(0)
print('YES')
for i in range(n):
	print(' '.join(list(map(str, b[i]))))


def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if max(arr) - min(arr) > k:
		print('NO')
	else:
		print('YES')
		l = []
		for i in range(k):
			l.append(i + 1)
		p = [*l] * 100
		l += p
		for x in arr:
			print(*l[:x])
main()


(n, k) = map(int, input().split())
counts = list(map(int, input().split()))
if max(counts) - min(counts) > k:
	print('NO')
	exit()
print('YES')
i = min(counts)
piles = [[1] * i for _ in counts]
for (count, pile) in zip(counts, piles):
	pile.extend(range(1, count - i + 1))
for pile in piles:
	print(' '.join(map(str, pile)))


(n, k) = map(int, input().split())
piles = [int(x) for x in input().split()]
max_pile = 0
min_pile = piles[0]
for i in range(n):
	pile = piles[i]
	max_pile = max(pile, max_pile)
	min_pile = min(pile, min_pile)
if max_pile - min_pile > k:
	print('NO')
else:
	print('YES')
	for pile in piles:
		res = []
		for i in range(pile):
			res.append(str(i % k + 1))
		print(' '.join(res))


import copy
import sys

def inputData():
	s = input()
	(n, k) = [int(i) for i in s.split()]
	s = input()
	a = [int(i) for i in s.split()]
	return (n, k, a)

def isOK(a, k):
	return max(a) - min(a) <= k

def build(a, k):
	a0 = min(a)
	d = {}
	d[a0] = [(0, a0)]
	lst = [(0, a0 + 1)]
	d[a0 + 1] = lst
	color = 1
	for i in range(a0 + 2, max(a) + 1):
		lst = copy.deepcopy(lst)
		lst.append((color, 1))
		color += 1
		d[i] = lst
	for i in a:
		l = d[i]
		for (c, n) in l:
			for i in range(n):
				print(c + 1, end=' ')
		print()
(n, k, a) = inputData()
if not isOK(a, k):
	print('NO')
else:
	print('YES')
	build(a, k)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
_min = min(a)
_max = max(a)
if _max - _min > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		c = 1
		for j in range(a[i]):
			print(c, end=' ')
			if j >= _min:
				c += 1
		print()


(n, k) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
mi = min(arr)
ma = max(arr)
if ma - mi > k:
	print('NO')
else:
	print('YES')
	for x in arr:
		for y in range(0, x):
			print(y % k + 1, '', end='')
		print()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.setrecursionlimit(int(pow(10, 6)))
	sys.stdin = open('input.txt', 'r')
except:
	pass
(n, k) = L()
A = L()
if max(A) - min(A) > k:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(A[i]):
			print(j % k + 1, end=' ')
		print()
endtime = time.time()


(n, colors) = map(int, input().split())
lens = list(map(int, input().split()))
q = [[] for i in range(n)]

def end():
	for i in range(n):
		if lens[i] != len(q[i]):
			return False
	return True
mi = min(lens)
for i in range(n):
	while len(q[i]) < min(lens[i], 1 + mi):
		q[i].append(1)
k = 1
while not end():
	k += 1
	for i in range(n):
		if len(q[i]) < lens[i]:
			q[i].append(k)
ma = max(map(max, q))
if ma <= colors:
	print('YES')
	for w in q:
		for i in w:
			print(i, end=' ')
		print()
else:
	print('NO')


(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
t = sorted(ar)
if t[n - 1] - t[0] > k:
	print('NO')
	exit(0)
res = []
for x in range(n):
	res.append([x % k for x in range(1, ar[x] + 1)])
for x in range(n):
	for y in range(len(res[x])):
		if res[x][y] == 0:
			res[x][y] = k
print('YES')
for x in res:
	print(' '.join(map(str, x)))


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)
(n, k) = [int(n1) for n1 in input().split()]
a = [int(n1) for n1 in input().split()]
x = min(a)
count = 0
for i in range(n):
	if a[i] - x <= k:
		pass
	else:
		count = 1
		print('NO')
		break
if count == 0:
	print('YES')
	for j in range(n):
		print(*[1] * x, end=' ')
		b = a[j] - x
		print(*list(range(1, b + 1)))


(n, k) = tuple(map(int, input().split()))
li = [int(i) for i in input().split()]
kli = [i for i in range(1, k + 1)]
sli = sorted(li)
wli = [1 for i in range(sli[0])]
kli = wli + kli
for i in li:
	if i > len(kli):
		print('NO')
		break
else:
	print('YES')
	for i in li:
		print(' '.join(map(str, kli[0:i])))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
min1 = min(a)
max1 = max(a)
if max1 - min1 > k:
	print('NO')
else:
	print('YES')
	for i in a:
		for j in range(1, i + 1):
			t = j % k
			if t == 0:
				t = k
			print(t, end=' ')
		print()


(a, b) = input().split(' ')
colors = int(b)
l = list(range(1, colors + 1)) * (int(100 / colors) + 5)
num = list(map(int, input().split(' ')))
if min(num) + colors < max(num):
	print('NO')
else:
	print('YES')
	for x in num:
		for n in range(x):
			print(l[n], end=' ')
		print()


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
(a_min, a_max) = (min(a), max(a))
if a_max - a_min > k:
	print('NO')
else:
	print('YES')
	for ai in a:
		print(' '.join(map(str, [1] * a_min + list(range(1, ai - a_min + 1)))))


(n, k) = map(int, input().split())
data = list(map(int, input().split()))
need = 0
res = [list() for _ in range(n)]

def custom_min(data):
	min = None
	for x in data:
		if min is None or x < min:
			min = x
	return 1 if min == 0 else min

def not_all_zeros(data):
	for x in data:
		if x != 0:
			return True
	return False
color = 1
min_v = custom_min(data)
while not_all_zeros(data) != 0:
	min_v = custom_min(data)
	if color > k:
		print('NO')
		break
	for i in range(len(data)):
		if data[i] != 0:
			val = min_v + 1 if data[i] > min_v and color == 1 else min_v
			data[i] -= val
			res[i].append((color, val))
	color += 1
else:
	print('YES')
	for l in res:
		s = []
		for x in l:
			s += [str(x[0])] * x[1]
		print(' '.join(s))


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(n, k) = iia()
arr = iia()
(big, small) = (max(arr), min(arr))
if big - small > k:
	print('NO')
else:
	print('YES')
	for i in arr:
		print(*[1] * small + list(range(1, i - small + 1)))


number_of_colours = int(input().split()[1])
piles = list(map(int, input().split()))
for i in range(len(piles) - 1):
	if max(piles) - min(piles) > number_of_colours:
		print('NO')
		break
else:
	print('YES')
	for i in range(len(piles)):
		color = 1
		level = 0
		result = ''
		while level < piles[i] - 1:
			result += f'{color} '
			color += 1
			level += 1
			if color > number_of_colours:
				color = 1
		result += str(color)
		print(result)


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
if max(z) - min(z) > b:
	print('NO')
else:
	print('YES')
	for i in z:
		for j in range(i):
			print(1 + j % b, end=' ')
		print()


entrada = input().split()
n = int(entrada[0])
k = int(entrada[1])
pilhas = list(map(int, input().split()))
pilhasordenadas = sorted(pilhas)
res = {}
if pilhasordenadas[n - 1] - pilhasordenadas[0] > k:
	print('NO')
else:
	print('YES')
	for e in pilhas:
		res = []
		j = 1
		for i in range(e):
			if j > k:
				j = 1
			res.append(j)
			j += 1
		print(*res)


(n, k1) = map(int, input().split())
arr = list(map(int, input().split()))
arr1 = []
m = [i for i in range(1, k1 + 1)]
for i in range(n):
	k = 0
	j = 0
	ar = []
	while k < arr[i]:
		if j == k1:
			j = 0
		ar.append(m[j])
		k += 1
		j += 1
	l = [0] * (k1 + 1)
	for i in ar:
		l[i] += 1
	arr1.append(l)
flag = True
for i in range(n):
	for j in range(i + 1, n):
		for k in range(k1 + 1):
			if abs(arr1[i][k] - arr1[j][k]) > 1:
				flag = False
				break
		if flag == False:
			break
	if flag == False:
		break
if not flag:
	print('NO')
else:
	print('YES')
	ans = []
	k1 = -1
	for i in arr1:
		ans1 = []
		k1 = -1
		for j in i:
			k1 += 1
			ans1 += [k1] * j
		ans.append(ans1)
		ans1 = []
	for i in ans:
		print(*i)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
m = min(a)
c = []
if max(a) - min(a) > k:
	print('NO')
else:
	for i in a:
		d = []
		for j in range(m):
			d.append(1)
		c.append(d)
	for i in range(n):
		if a[i] > m:
			co = 1
			for j in range(m, a[i]):
				c[i].append(co)
				co += 1
	print('YES')
	for i in c:
		print(*i)