Fillomino is a classic logic puzzle. (You do not need to know Fillomino in order to solve this problem.) In one classroom in Yunqi town, some volunteers are playing a board game variant of it:

Consider an $n$ by $n$ chessboard. Its rows are numbered from $1$ to $n$ from the top to the bottom. Its columns are numbered from $1$ to $n$ from the left to the right. A cell on an intersection of $x$-th row and $y$-th column is denoted $(x, y)$. The main diagonal of the chessboard is cells $(x, x)$ for all $1 \le x \le n$.

A permutation of $\{1, 2, 3, \dots, n\}$ is written on the main diagonal of the chessboard. There is exactly one number written on each of the cells. The problem is to partition the cells under and on the main diagonal (there are exactly $1+2+ \ldots +n$ such cells) into $n$ connected regions satisfying the following constraints:

Every region should be connected. That means that we can move from any cell of a region to any other cell of the same region visiting only cells of the same region and moving from a cell to an adjacent cell.

The $x$-th region should contain cell on the main diagonal with number $x$ for all $1\le x\le n$.

The number of cells that belong to the $x$-th region should be equal to $x$ for all $1\le x\le n$.

Each cell under and on the main diagonal should belong to exactly one region.


-----Input-----

The first line contains a single integer $n$ ($1\le n \le 500$) denoting the size of the chessboard.

The second line contains $n$ integers $p_1$, $p_2$, ..., $p_n$. $p_i$ is the number written on cell $(i, i)$. It is guaranteed that each integer from $\{1, \ldots, n\}$ appears exactly once in $p_1$, ..., $p_n$.


-----Output-----

If no solution exists, output $-1$.

Otherwise, output $n$ lines. The $i$-th line should contain $i$ numbers. The $j$-th number on the $i$-th line should be $x$ if cell $(i, j)$ belongs to the the region with $x$ cells.


-----Examples-----

Input
3
2 3 1
Output
2
2 3
3 3 1
Input
5
1 2 3 4 5
Output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5


-----Note-----

The solutions to the examples are illustrated in the following pictures:

Source: codeforces | Difficulty: MEDIUM
Tags: Greedy algorithms

Graph traversal

Implementation

Constructive algorithms


Solutions:
def main():
	n = int(input())
	p = list(map(int, input().split()))
	board = [[0 for _ in range(n)] for _ in range(n)]
	for i in range(n):
		board[i][i] = p[i]
		px = i
		py = i
		for j in range(p[i] - 1):
			if py == 0:
				px += 1
			elif board[px][py - 1] == 0:
				py -= 1
			else:
				px += 1
			if px >= n or py < 0:
				print(-1)
				return
			board[px][py] = p[i]
	for i in range(n):
		print(' '.join([str(x) for x in board[i][0:i + 1]]))
main()


def printMatrix(matrix):
	s = [[str(e) for e in row] for row in matrix]
	lens = [max(map(len, col)) for col in zip(*s)]
	fmt = '\t'.join(('{{:{}}}'.format(x) for x in lens))
	table = [fmt.format(*row) for row in s]
	print('_________________')
	print('\n'.join(table))
	print('`````````````````')
n = int(input())
arr = [int(x) for x in input().split()]
mat = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	mat[i][i] = arr[i]
for i in range(n):
	cnt = 1
	at = [i, i]
	while cnt != mat[i][i]:
		if at[1] > 0 and mat[at[0]][at[1] - 1] == 0:
			at[1] -= 1
			mat[at[0]][at[1]] = arr[i]
		else:
			at[0] += 1
			mat[at[0]][at[1]] = arr[i]
		cnt += 1
for i in range(n):
	print(*mat[i][:i + 1])


import sys

def read_ints():
	return [int(i) for i in sys.stdin.readline().strip().split()]

def read_int():
	return int(sys.stdin.readline().strip())

def print_ints(seq):
	print(' '.join((str(i) for i in seq)))
n = read_int()
pp = read_ints()
diags = [pp]
for i in range(1, n):
	diags.append([j for j in diags[-1] if j > i])
for i in range(n):
	row = []
	for j in range(i + 1):
		row.append(diags[j][i - j])
	row.reverse()
	print_ints(row)


def main():
	n = int(input())
	w = [[0 for j in range(n)] for i in range(n)]
	d = [int(v) for v in input().split()]
	for i in range(n):
		w[i][i] = d[i]
	for s in range(n):
		meet = False
		for j in range(n - s):
			i = s + j
			if w[i][j] == s + 1:
				meet = True
			elif meet:
				w[i][j - 1] = w[i][j]
			else:
				w[i + 1][j] = w[i][j]
	for i in range(n):
		for j in range(i + 1):
			print(w[i][j], end=' ')
		print()
main()


import sys
import math
n = int(sys.stdin.readline())
p = [int(i) for i in sys.stdin.readline().split()]
ans = [[]] * n
for i in range(n):
	ans[i] = [0] * (i + 1)
for i in range(n):
	num = p[i]
	at = (i, i)
	ans[at[0]][at[1]] = num
	for j in range(num - 1):
		if at[1] != 0 and ans[at[0]][at[1] - 1] == 0:
			at = (at[0], at[1] - 1)
			ans[at[0]][at[1]] = num
		else:
			at = (at[0] + 1, at[1])
			ans[at[0]][at[1]] = num
for i in range(n):
	print(' '.join([str(s) for s in ans[i]]))


n = int(input())
diag = list(map(int, input().split()))
a = [[0] * i for i in range(1, n + 1)]
for i in range(n):
	(j, k) = (i, i)
	for l in range(diag[i]):
		a[j][k] = diag[i]
		if k != 0 and a[j][k - 1] == 0:
			k -= 1
		else:
			j += 1
for i in a:
	print(*i)


def main():
	N = int(input())
	P = list(map(int, input().split()))
	Ans = [[0] * N for _ in range(N)]
	OH = OW = 0
	for Val in P:
		H = OH
		W = OW
		for _ in range(Val):
			Ans[H][W] = Val
			if W - 1 >= 0 and (not Ans[H][W - 1]):
				W -= 1
			else:
				H += 1
		OH += 1
		OW += 1
	for i in range(N):
		print(*Ans[i][:i + 1])
main()


n = int(input())
a = list(map(int, input().split()))
ans = [[0] * i for i in range(1, n + 1)]
for i in range(n):
	ans[i][i] = a[i]
	x = y = i
	while a[i] > 1:
		if y - 1 >= 0 and ans[x][y - 1] == 0:
			y -= 1
		else:
			x += 1
		ans[x][y] = ans[i][i]
		a[i] -= 1
for x in ans:
	print(*x)


n = int(input())
start = list(map(int, input().split()))
grid = [[0 for _ in range(n)] for _ in range(n)]
for x in range(len(start)):
	grid[x][x] = start[x]
for x in grid:
	x.insert(0, -1)
	x.append(-1)
z = [-1 for _ in range(n)]
grid.insert(0, z)
grid.append(z)
for x in start:
	curPos = [start.index(x) + 1, start.index(x) + 1]
	for _ in range(x - 1):
		if grid[curPos[1]][curPos[0] - 1] == 0:
			grid[curPos[1]][curPos[0] - 1] = x
			curPos[0] -= 1
		elif grid[curPos[1] + 1][curPos[0]] == 0:
			grid[curPos[1] + 1][curPos[0]] = x
			curPos[1] += 1
		else:
			print(-1)
			exit()
for x in grid[1:-1]:
	print(' '.join(list(map(str, [y for y in x if y != 0 and y != -1]))))


n = int(input())
l = list(map(int, input().split()))
s = [[0 for i in range(k)] for k in range(1, n + 1)]
for i in range(n):
	s[i][i] = l[i]
for i in range(n):
	a = 1
	x = i
	y = i
	while a != s[i][i]:
		if y != 0:
			if s[x][y - 1] == 0:
				s[x][y - 1] = s[i][i]
				a += 1
				y -= 1
				continue
		if x != n - 1:
			if s[x + 1][y] == 0:
				s[x + 1][y] = s[i][i]
				a += 1
				x += 1
				continue
for i in s:
	print(*i)


n = int(input())
arr = [0] + list(map(int, input().split()))
minima = 0
ans = [[0 for i in range(n + 1)] for j in range(n + 1)]
for i in range(1, n + 1):
	ans[i][n + 1 - i] = arr[i]
	if arr[i] == 1:
		minima = i
minima2 = 0
for k in range(n, 1, -1):
	for i in range(minima, k):
		j = k - i
		ans[i][j] = ans[i + 1][j]
		if ans[i][j] == n + 2 - k:
			minima2 = i
	for i in range(minima - 1, 0, -1):
		j = k - i
		ans[i][j] = ans[i][j + 1]
		if ans[i][j] == n + 2 - k:
			minima2 = i
	minima = minima2
for i in range(n, 0, -1):
	for j in range(1, n + 2 - i):
		print(ans[j][i], end=' ')
	print()


n = int(input())
p = [int(i) for i in input().split()]
T = []
for i in range(n):
	row = [0] * i + [p[i]]
	T.append(row)
for i in range(n - 1, -1, -1):
	s = [i, i]
	left = p[i] - 1
	while left:
		down_possible = s[0] + 1 < n and T[s[0] + 1][s[1]] == 0
		if down_possible:
			s[0] += 1
			T[s[0]][s[1]] = p[i]
			left -= 1
			continue
		left_possible = s[1] - 1 >= 0 and T[s[0]][s[1] - 1] == 0
		if left_possible:
			s[1] -= 1
			T[s[0]][s[1]] = p[i]
			left -= 1
			continue
		print(-1)
		exit()
for r in T:
	print(' '.join((str(s) for s in r)))


ans = []
n = int(input())
cells = [int(x) for x in input().split(' ')]
for i in range(n):
	ans.append([-1] * n)
for i in range(n):
	ans[i][i] = cells[i]
	amount = cells[i] - 1
	x = i - 1
	y = i
	while amount > 0:
		if x > 0 and ans[y][x] == -1:
			ans[y][x] = cells[i]
			x -= 1
			amount -= 1
		elif x == 0 and ans[y][x] == -1:
			ans[y][x] = cells[i]
			y += 1
			amount -= 1
		else:
			x += 1
			y += 1
for i in range(n):
	ans_str = ''
	for x in range(i + 1):
		ans_str += str(ans[i][x]) + ' '
	print(ans_str)


import sys
import collections
input = sys.stdin.readline

def main():
	N = int(input())
	P = [int(x) for x in input().split()]
	A = [[0] * N for j in range(N)]
	for (i, p) in enumerate(P):
		A[i][i] = p
	for i in range(N):
		count = A[i][i]
		q = collections.deque()
		q.append((i, i))
		while q:
			(ci, cj) = q.pop()
			A[ci][cj] = A[i][i]
			count -= 1
			if count == 0:
				break
			if cj - 1 >= 0 and A[ci][cj - 1] == 0:
				q.append((ci, cj - 1))
				continue
			if ci + 1 < N and A[ci + 1][cj] == 0:
				q.append((ci + 1, cj))
				continue
	for (i, a) in enumerate(A):
		print(*a[:i + 1])
main()


n = int(input())
perm = list(map(int, input().split()))
grid = [[0] * n for i in range(n)]
for i in range(n):
	r = i
	c = i
	for j in range(perm[i]):
		grid[r][c] = perm[i]
		if c == 0 or grid[r][c - 1]:
			r += 1
		else:
			c -= 1
for (i, row) in enumerate(grid):
	print(*row[:i + 1])


N = int(input())
Diag = list(map(int, input().split()))
Board = [[0] * x + [y] for (x, y) in enumerate(Diag)]
for (i, nb) in enumerate(Diag):
	(x, y) = (i, i)
	left = nb - 1
	while left:
		if x > 0 and Board[y][x - 1] == 0:
			x -= 1
		else:
			y += 1
		left -= 1
		Board[y][x] = nb
for line in Board:
	print(' '.join(map(str, line)))


def solve(board, a, steps):
	if steps == len(board):
		return
	n = len(a)
	imin = 0
	for i in range(n):
		j = i + steps
		board[j][i] = a[i]
		if a[i] == steps + 1:
			imin = i
	a = a[:imin] + a[imin + 1:]
	solve(board, a, steps + 1)

def run(m, a):
	board = [[0] * i for i in range(1, m + 1)]
	solve(board, a, 0)
	for i in range(len(board)):
		print(' '.join(map(str, board[i])))
m = int(input())
a = list(map(int, input().split()))
run(m, a)


n = int(input())
permutation = list(map(int, input().split()))
matrix = [[0] * n for _ in range(n)]

def recursion(nor, curi, curj, p):
	if nor == 0:
		return
	if curj - 1 >= 0 and matrix[curi][curj - 1] == 0:
		matrix[curi][curj - 1] = p
		recursion(nor - 1, curi, curj - 1, p)
	else:
		matrix[curi + 1][curj] = p
		recursion(nor - 1, curi + 1, curj, p)
i = 0
for p in permutation:
	matrix[i][i] = p
	recursion(p - 1, i, i, p)
	i += 1
for j in range(1, n + 1):
	print(*matrix[j - 1][:j])


def solve(x, y, k, n, val):
	if x < 0 or y < 0 or x >= n or (y > x) or (k[0] <= 0) or (mat[x][y] != 0):
		return
	mat[x][y] = val
	k[0] -= 1
	solve(x - 1, y, k, n, val)
	solve(x, y - 1, k, n, val)
	solve(x + 1, y, k, n, val)
n = int(input())
list1 = list(map(int, input().split()))
mat = [[0 for i in range(n)] for j in range(n)]
for i in range(len(list1)):
	solve(i, i, [list1[i]], n, list1[i])
for i in range(len(mat)):
	for j in range(i + 1):
		print(mat[i][j], end=' ')
	print()


n = int(input())
arr = list(map(int, input().split()))
t = [[None for x in range(n)] for x in range(n)]
for i in range(n):
	t[i][i] = arr[i]

def solve():
	k = 0
	while k < n:
		count = t[k][k] - 1
		num = t[k][k]
		if k == n - 1:
			if t[k][k - 1] != None and t[k][k] != 1:
				print(-1)
				return
		if k > 0 and k < n - 1 and (t[k][k - 1] != None) and (t[k + 1][k] != None) and (t[k][k] != 1):
			print(-1)
			return
		i = k
		j = k - 1
		k += 1
		while count > 0:
			if j < 0:
				i += 1
				j = 0
			if t[i][j] == None:
				t[i][j] = num
				count -= 1
				j -= 1
			else:
				j += 1
				i += 1
	for i in range(len(t)):
		for j in range(i + 1):
			print(t[i][j], end=' ')
		print()
solve()


n = int(input())
L = [int(x) for x in input().split()]
Arem = [(i + 1) * [0] for i in range(n)]
for k in range(n):
	Arem[k][k] = L[k]
for k in range(n):
	counter = 1
	i = k
	j = k
	while counter < L[k]:
		if j >= 1 and Arem[i][j - 1] == 0:
			Arem[i][j - 1] = L[k]
			j = j - 1
		elif i < n - 1 and Arem[i + 1][j] == 0:
			Arem[i + 1][j] = L[k]
			i = i + 1
		counter += 1
for liste in Arem:
	for elem in liste:
		print(elem, end=' ')
	print()


n = int(input())
v = list(map(int, input().split()))
A = []
a = 0
for i in range(1, n + 1):
	A.append([0 for i in range(i)])
for i in range(n):
	A[i][i] = v[i]
for i in range(n):
	b = A[i][i]
	if i == 0:
		for j in range(b):
			A[j][0] = b
	else:
		j = i
		c = i
		d = b - 1
		while d > 0:
			d -= 1
			if c > -1 and A[j][c - 1] == 0:
				A[j][c - 1] = b
				c -= 1
			elif j + 1 < n:
				A[j + 1][c] = b
				j += 1
			else:
				a = 1
				break
if a:
	print(-1)
else:
	for i in range(n):
		print(*A[i], sep=' ')


def dfs(i, j, c, s):
	if c == 0:
		return
	if i + 1 < n and ans[i + 1][j] == 0:
		ans[i + 1][j] = s
		dfs(i + 1, j, c - 1, s)
	elif j - 1 >= 0 and ans[i][j - 1] == 0:
		ans[i][j - 1] = s
		dfs(i, j - 1, c - 1, s)
from pprint import pprint
n = int(input())
arr = [int(w) for w in input().split(' ')]
ans = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
	for j in range(n):
		if i == j:
			ans[i][j] = arr[i]
i = n - 1
while i >= 0:
	dfs(i, i, arr[i] - 1, arr[i])
	i = i - 1
for item in ans:
	for x in item:
		if x > 0:
			print(x, end=' ')
		else:
			break
	print('')


from sys import stdin, stdout
from collections import deque
import bisect
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))
n = int(input())
l = RL(int)
ans = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	row = i
	col = i
	num = l[i] - 1
	ans[i][i] = l[i]
	while num > 0:
		if ans[row][col - 1] == 0 and col >= 1:
			ans[row][col - 1] = l[i]
			col -= 1
		else:
			ans[row + 1][col] = l[i]
			row += 1
		num -= 1
for i in range(n):
	print(*ans[i][:i + 1])


def get_input(first=False):
	l = [int(e) for e in input().split()]
	if first:
		return l[0]
	return l

def next_diagonal(diag, n):
	new_diag = []
	k = len(diag) - 1
	unused = set([n - i for i in range(k)])
	for i in range(k):
		if diag[i] in unused:
			new_diag.append(diag[i])
			unused.remove(diag[i])
		else:
			new_diag.append(diag[i + 1])
			unused.remove(diag[i + 1])
	return new_diag

def fill_sol(sol, diag, n):
	o = n - len(diag)
	for (i, d) in enumerate(diag):
		sol[i + o][i] = d
n = get_input(True)
diag = get_input()
sol = [[None] * i for i in range(1, n + 1)]
fill_sol(sol, diag, n)
for _ in range(n - 1):
	diag = next_diagonal(diag, n)
	fill_sol(sol, diag, n)
for b in sol:
	print(*b)


import sys
from collections import deque

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

def rl_types(types):
	str_list = [x for x in sys.stdin.readline().strip().split(' ')]
	return [types[i](str_list[i]) for i in range(len(str_list))]

def pr(something):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')

def solve(array):
	return array
_ = int(rl())
vals = [int(x) for x in rl().split(' ')]
n = len(vals)
rows = []
for i in range(n):
	rows.append(deque([vals[i]]))
remaining = vals
for i in range(1, n):
	remaining = [v for v in remaining if not v == i]
	for j in range(0, n - i):
		rows[i + j].appendleft(remaining[j])
for r in rows:
	pra(r)


n = int(input())
diagonal = [int(s) for s in input().split()]
array = []
for i in range(n):
	array.append([0] * i + [diagonal[i]])
possible = True

def is_allowed(ar, x, y):
	if x < 0:
		return False
	if y < 0:
		return False
	if x > len(ar) - 1:
		return False
	if y > len(ar[x]) - 1:
		return False
	if ar[x][y]:
		return False
	return True

def next_step(ar, x, y):
	if is_allowed(ar, x, y - 1):
		return (x, y - 1)
	if is_allowed(ar, x + 1, y):
		return (x + 1, y)
for (i, dn) in enumerate(diagonal):
	cursor = [i, i]
	if not possible:
		break
	for j in range(dn):
		(x, y) = cursor
		if array[x][y] == 0:
			array[x][y] = dn
		cursor = next_step(array, x, y)
		if cursor is None and j < dn - 1:
			possible = False
			break
if not possible:
	print(-1)
else:
	for l in array:
		print(' '.join([str(k) for k in l]))


def helper(a):
	pool = [[0] * (i + 1) for i in range(len(a))]
	for i in range(len(a)):
		pool[i][i] = a[i]
		count = a[i] - 1
		cx = i
		cy = i
		while count > 0:
			if cy > 0 and pool[cx][cy - 1] == 0:
				pool[cx][cy - 1] = a[i]
				count -= 1
				cy -= 1
			elif cx < len(a) - 1 and pool[cx + 1][cy] == 0:
				pool[cx + 1][cy] = a[i]
				count -= 1
				cx += 1
			else:
				return [[-1]]
	return pool
n = int(input())
a = list(map(int, input().split(' ')))
res = helper(a)
for j in range(len(res)):
	print(' '.join(map(str, res[j])))


n = int(input())
p = list(map(int, input().split()))
l = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
	l[i][i] = p[i]
j = 0
while True:
	m = j
	k = j
	d = l[j][j] - 1
	z = True
	while d > 0 and m >= 0 and (m < n) and (k >= 0) and (k < n):
		if m - 1 >= 0 and l[k][m - 1] == 0 and (z == True):
			l[k][m - 1] = l[j][j]
			m = m - 1
			d = d - 1
		elif k + 1 < n:
			l[k + 1][m] = l[j][j]
			k = k + 1
			d = d - 1
	j += 1
	if j == n:
		break
for i in range(n):
	for j in range(i + 1):
		print(l[i][j], end=' ')
	print()


from importlib import import_module
import math
MOD = 10 ** 9 + 7
phi = (1 + pow(5, 1 / 2)) / 2
phi_hat = (1 - pow(5, 1 / 2)) / 2
ln = len

class CodeJam:

	def __init__(self):
		self.np = import_module('numpy')
		self.sp = import_module('scipy')

class Tool:

	def __init__(self):
		self.functools = import_module('functools')
		self.itertools = import_module('itertools')
		self.operator = import_module('operator')
		self.collections = import_module('collections')

	def count_to_dict(self, arr):
		counter = self.collections.Counter(arr)
		return dict(counter.most_common())

class Sort:

	def __init__(self):
		self.heapq = import_module('heapq')

class Input:

	def __init__(self):
		self.inp = input

	@property
	def s(self):
		return self.inp()

	@property
	def i(self):
		return int(self.s)

	@property
	def arr(self):
		return self.inp().split(' ')

	@property
	def iarr(self):
		return list(map(int, self.arr))
F = lambda i: int((pow(phi, i) - pow(phi_hat, i)) / pow(5, 1 / 2))
L = lambda i: int(pow(phi, i) + pow(phi_hat, i))

def prime_factors(n):
	factors = []
	i = 2
	while i * i <= n:
		while n % i == 0:
			n = n // i
			factors.append(i)
		i += 1
	return factors + [n] * (n != 1)

def fprint(*args, **kwargs):
	print(*args, **kwargs, flush=True)
pass

def solve(inp, t):
	n = inp.i
	arr = inp.iarr
	res = [[None] * n for _ in range(n)]
	for i in range(n):
		p = arr[i]
		(x, y) = (i, i)
		while p != 0:
			res[x][y] = arr[i]
			p -= 1
			if y != 0 and (not res[x][y - 1]):
				y -= 1
			else:
				x += 1
	for i in range(n):
		for j in range(n):
			if res[i][j] != None:
				print(res[i][j], end=' ')
		print('')

def main():
	inp = Input()
	for t in range(1):
		solve(inp, t)
main()


n = int(input())
diag = list(map(int, input().split()))
grid = [[0 for x in range(n)] for y in range(n)]
for d in range(n):
	for i in range(n - d):
		grid[d + i][i] = diag[i]
	diag.remove(d + 1)
for line in grid:
	print(*(c for c in line if c))


n = int(input())
l = list(map(int, input().split()))
m = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	m[i][i] = l[i]
for i in range(n - 1, -1, -1):
	t = m[i][i] - 1
	x = i
	y = i
	while t:
		if x < n - 1 and m[x + 1][y] == 0:
			m[x + 1][y] = m[i][i]
			x += 1
		else:
			m[x][y - 1] = m[i][i]
			y -= 1
		t -= 1
for i in range(n):
	print(*m[i][:i + 1])


import sys
import os.path
from collections import *
import math
import bisect
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = int(input())
arr = [int(x) for x in input().split()]
brr = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	brr[i][i] = arr[i]
for j in range(n):
	y = brr[j][j] - 1
	x = brr[j][j]
	index1 = j
	index2 = j
	while y:
		if index2 > 0 and brr[index1][index2 - 1] == 0:
			y -= 1
			index2 -= 1
			brr[index1][index2] = x
		else:
			index1 += 1
			y -= 1
			brr[index1][index2] = x
for i in range(n):
	for j in range(i + 1):
		print(brr[i][j], end=' ')
	print()


import sys
input = sys.stdin.buffer.readline
n = int(input())
p = list(map(int, input().split()))
board = [[0] * i for i in range(1, n + 1)]
for i in range(n):
	y = i
	x = i
	for j in range(p[i]):
		board[y][x] = p[i]
		if x == 0 or board[y][x - 1]:
			y += 1
		else:
			x -= 1
for row in board:
	print(*row)


n = int(input())
p = list(map(int, input().split()))
grid = [[None] * (i + 1) for i in range(n)]
for i in range(n):
	currx = i
	curry = i
	num = p[i]
	for j in range(num):
		grid[curry][currx] = num
		if currx > 0 and grid[curry][currx - 1] is None:
			currx -= 1
		else:
			curry += 1
for i in range(n):
	print(' '.join(map(str, grid[i])))


import math
import sys
input = sys.stdin.readline

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

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
l = inlt()
z = [[0 for i in range(j + 1)] for j in range(n)]
for i in range(n):
	z[i][i] = l[i]
for i in range(l[0]):
	z[i][0] = l[0]
for i in range(1, n):
	k = l[i] - 1
	(x, y) = (i, i - 1)
	while k and x < n:
		cnt = 0
		while k and y >= 0 and (z[x][y] == 0):
			cnt = 1
			z[x][y] = l[i]
			y -= 1
			k -= 1
		x += 1
		y += 1
for each in z:
	print(*each)


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)

def number_to_list(a):
	b = []
	while a >= 1:
		c = a % 10
		a = int(a / 10)
		b.append(c)
	return list(reversed(b))

def str_list_to_int_list(a):
	a = list(map(int, a))
	return a

def make_1d_array(n, inti=0):
	a = [inti for _ in range(n)]
	return a

def make_2d_array(n, m, inti=0):
	a = [[inti for _ in range(m)] for _ in range(n)]
	return a

def make_3d_array(n, m, k, inti=0):
	a = [[[inti for _ in range(k)] for _ in range(m)] for _ in range(n)]
	return a

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

def solve(i1, j1, p1, val):
	m = n
	if i1 < 0 or j1 < 0 or j1 >= m or (i1 >= n) or (i1 < j1) or (ans[i1][j1] != -1) or (val <= 0):
		return val
	ans[i1][j1] = p1
	val = solve(i1 - 1, j1, p1, val - 1)
	if val <= 0:
		return val
	val = solve(i1, j1 - 1, p1, val)
	if val <= 0:
		return val
	val = solve(i1 + 1, j1, p1, val)
	if val <= 0:
		return val
	val = solve(i1, j1 + 1, p1, val)
	return val
import sys, os.path
from collections import defaultdict, deque
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input1()))
for t1 in range(1):
	(n,) = I()
	p = I()
	ans = [[-1 for j in range(n)] for i in range(n)]
	for i in range(n):
		temp = p[i]
		solve(i, i, temp, temp)
	for i in range(len(ans)):
		ans1 = []
		for j in range(len(ans[i])):
			if i >= j:
				ans1.append(ans[i][j])
			else:
				break
		print(*ans1)


t = 1
for _ in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	n = len(ls)
	res = [[0 for _ in range(n)] for i in range(n)]
	for i in range(n):
		res[i][i] = ls[i]
	for i in range(n):
		k = ls[i] - 1
		cur_row = i
		cur_col = i
		while k != 0:
			if cur_col - 1 >= 0 and res[cur_row][cur_col - 1] == 0:
				res[cur_row][cur_col - 1] = ls[i]
				cur_col -= 1
				k -= 1
			else:
				cur_row += 1
				cur_col += 1
	for i in range(n):
		for j in range(n):
			if i >= j:
				print(res[i][j], end=' ')
		print()


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def fi():
	return float(input())

def si():
	return input()

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

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

def li():
	return list(mi())

def lsi():
	return list(msi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

def lcm(x, y):
	return x * y // gcd(x, y)
mod = 1000000007

def modInverse(b, m):
	g = gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def ceil2(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def modu(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	if inv == -1:
		return -999999999
	else:
		return inv * a % m
from math import log, factorial, cos, tan, sin, radians, floor, sqrt, ceil
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def gcd1(a):
	if len(a) == 1:
		return a[0]
	ans = a[0]
	for i in range(1, len(a)):
		ans = gcd(ans, a[i])
	return ans

def mykey(x):
	return (x[1], -x[0])
from itertools import combinations_with_replacement

def main():
	for _ in range(1):
		n = ii()
		a = li()
		l = []
		for i in range(1, n + 1):
			x = [-1] * i
			x[-1] = a[i - 1]
			l.append(x)
		for i in range(n):
			x = a[i] - 1
			j = k = i
			while x:
				if k - 1 >= 0 and j < n and (l[j][k - 1] == -1):
					l[j][k - 1] = l[i][i]
					k -= 1
				elif j + 1 < n and k >= 0 and (l[j + 1][k] == -1):
					l[j + 1][k] = l[i][i]
					j += 1
				x -= 1
		for i in range(n):
			print(*l[i])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


n = int(input())
a = list(map(int, input().split()))
ans = [[-1] * n for i in range(n)]

def yo(ans, temp, k, i, j):
	if temp == 1:
		return
	if j - 1 >= 0 and ans[i][j - 1] == -1:
		ans[i][j - 1] = k
		yo(ans, temp - 1, k, i, j - 1)
	elif i + 1 < n:
		ans[i + 1][j] = k
		yo(ans, temp - 1, k, i + 1, j)
for k in range(n):
	ans[k][k] = a[k]
	yo(ans, a[k], a[k], k, k)
temp = 0
for i in ans:
	print(*i[:temp + 1])
	temp += 1


import sys
import math
LI = lambda : [int(k) for k in input().split()]
input = lambda : sys.stdin.readline().rstrip()
IN = lambda : int(input())
S = lambda : input()
n = IN()
dia = LI()
flag = 1
board = [[0 for i in range(j + 1)] for j in range(n)]
for i in range(n):
	board[i][i] = dia[i]
for i in range(1, dia[0]):
	board[i][0] = dia[0]
for i in range(1, dia[-1]):
	board[-1][n - i - 1] = dia[-1]
for i in range(1, n - 1):
	if flag == 0:
		break
	check = dia[i] - 1
	cr = i
	cc = i
	while check:
		if cc >= 0 and cr < n and (board[cr][cc - 1] == 0):
			board[cr][cc - 1] = dia[i]
			cc -= 1
		elif cc >= 0 and cr < n and (board[cr + 1][cc] == 0):
			board[cr + 1][cc] = dia[i]
			cr += 1
		else:
			flag = 0
			break
		check -= 1
if flag == 0:
	print(-1)
else:
	for ele in board:
		for it in ele:
			print(it, end=' ')
		print()


n = int(input())
p = list(map(int, input().split()))
a = []
for i in range(n):
	a.append([0 for j in range(i + 1)])
	a[i][-1] = p[i]
for i in range(n):
	p = q = i
	c = a[p][q]
	for j in range(c - 1):
		if q - 1 >= 0 and a[p][q - 1] == 0:
			a[p][q - 1] = c
			q -= 1
		else:
			a[p + 1][q] = c
			p += 1
for i in range(n):
	print(*a[i])


from collections import Counter
import math
import itertools

def filldia(a, d, n):
	flag = 0
	if a[d - 1][0] > d:
		a[d][0] = a[d - 1][0]
		flag = 1
	if a[n - 1][n - d] > d:
		a[n - 1][n - d - 1] = a[n - 1][n - d]
		if flag == 0:
			flag = 2
	if flag == 1:
		h = 0
		for j in range(d, n - 1):
			if a[j][j - d + 1] == d:
				h = 1
			if a[j][j - d + 1] > d:
				if h == 0:
					if j < n - 1 and a[j + 1][j - d + 1] == 0:
						a[j + 1][j - d + 1] = a[j][j - d + 1]
					else:
						return -1
				elif j - d > -1 and a[j][j - d] == 0:
					a[j][j - d] = a[j][j - d + 1]
				else:
					return -1
	elif flag == 2:
		for j in range(d, n - 1):
			if j - d > -1 and a[j][j - d] == 0:
				a[j][j - d] = a[j][j - d + 1]
			else:
				return -1
	if d == n - 1:
		return a
	else:
		ans = filldia(a, d + 1, n)
		return ans

def main():
	n = int(input())
	p = list(map(int, input().split()))
	f = []
	for _ in range(n):
		f.append([0] * n)
	for i in range(n):
		f[i][i] = p[i]
	if n == 1:
		ans = 1
	else:
		ans = filldia(f, 1, n)
	if ans == -1:
		print(-1)
	elif ans == 1:
		print(1)
	else:
		for i in range(n):
			s = ''
			for j in range(i + 1):
				s += str(ans[i][j]) + ' '
			print(s)
main()


def check(i, j, n):
	if i >= 0 and i < n and (j >= 0) and (j < n):
		return True
	return False
n = int(input())
l = list(map(int, input().split()))
a = [[-1 for j in range(n)] for i in range(n)]
flag = True
for i in range(n):
	num = l[i] - 1
	a[i][i] = l[i]
	(k, m) = (i, i)
	for j in range(num):
		flag1 = False
		if check(k, m - 1, n):
			if a[k][m - 1] == -1:
				a[k][m - 1] = l[i]
				m -= 1
				flag1 = True
		if not flag1:
			if check(k + 1, m, n):
				if a[k + 1][m] == -1:
					a[k + 1][m] = l[i]
					k += 1
					flag1 = True
		if not flag1:
			if check(k - 1, m, n):
				if a[k - 1][m] == -1:
					a[k - 1][m] = l[i]
					k -= 1
					flag1 = True
		if not flag1:
			if check(k, m + 1, n):
				if a[k][m + 1] == -1:
					a[k][m + 1] = l[i]
					m += 1
					flag1 = True
		if not flag1:
			flag = False
			break
if not flag:
	print(-1)
else:
	for i in range(n):
		for j in range(i + 1):
			print(a[i][j], end=' ')
		print()


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

def main():
	(n,) = readline()
	p = list(readline())
	ans = [[None] * i + [pi] for (i, pi) in enumerate(p)]
	for (i, pi) in enumerate(p):
		(x, y) = (i, i)
		for __ in range(pi - 1):
			if y and ans[x][y - 1] is None:
				y -= 1
			else:
				x += 1
			assert ans[x][y] is None
			ans[x][y] = pi
	for row in ans:
		print(*row)
main()


n = int(input())
p = list(map(int, input().split()))
board = []
for i in range(n):
	board.append([0 for i in range(n)])
for i in range(n):
	board[i][i] = p[i]
	px = i
	py = i
	for j in range(p[i] - 1):
		if py == 0:
			px += 1
		elif board[px][py - 1] == 0:
			py -= 1
		else:
			px += 1
		if px >= n or py < 0:
			print(-1)
			exit()
		board[px][py] = p[i]
for i in range(n):
	print(*board[i][0:i + 1])


def findsol(mapp, n):
	for j in range(n - 1, -1, -1):
		put(mapp, n, j, mapp[j][j])
	return mapp

def put(mapp, n, j, val):
	step = [(1, 0), (0, -1)]
	(cy, cx) = (j, j)
	for i in range(val - 1):
		for (sy, sx) in step:
			(ny, nx) = (cy + sy, cx + sx)
			if valid(ny, nx, mapp, n):
				mapp[ny][nx] = val
				(cy, cx) = (ny, nx)
				break

def print_map(mapp, n):
	for i in range(n):
		print(' '.join([str(each) if each != 0 else ' ' for each in mapp[i]]))

def valid(ny, nx, mapp, n):
	return 0 <= ny and ny < n and (0 <= nx) and (nx < n) and (mapp[ny][nx] == 0)
n = int(input())
diag = list(map(int, input().split()))
mapp = {i: [0 for j in range(n)] for i in range(n)}
for i in range(n):
	mapp[i][i] = diag[i]
re = findsol(mapp, n)
print_map(re, n)


n = int(input())
arr = list(map(int, input().split()))
array = []
for i in range(n):
	array.append([])
	for j in range(n):
		array[i].append(0)
for i in range(n):
	array[i][i] = arr[i]
	count = arr[i] - 1
	x = i
	y = i
	while count > 0:
		if x > 0 and array[y][max(x - 1, 0)] == 0:
			array[y][x - 1] = arr[i]
			x -= 1
			count -= 1
		else:
			array[y + 1][x] = arr[i]
			y += 1
			count -= 1
for i in array:
	for j in i:
		if j != 0:
			print(j, end=' ')
	print('')


from collections import Counter as cc
from copy import deepcopy as dc
import random
import math
MAX_SIZE = 1e+18
try:
	n = int(input())
	a = list(map(int, input().split()))
	mat = [[0 for i in range(n)] for j in range(n)]
	for i in range(n):
		mat[i][i] = a[i]
	flag = 0
	for i in range(n):
		(k, j, l) = (a[i] - 1, i, i)
		while k > 0:
			if j - 1 >= 0 and mat[l][j - 1] == 0:
				mat[l][j - 1] = a[i]
				k -= 1
				j -= 1
			elif l + 1 < n and mat[l + 1][j] == 0:
				mat[l + 1][j] = a[i]
				l += 1
				k -= 1
			else:
				flag = 1
				break
		if flag == 1:
			break
	if flag == 1:
		print(-1)
	else:
		for i in range(n):
			print(*mat[i][:i + 1])
except EOFError as e:
	pass


n = int(input())
A = [[0] * n for _ in range(n)]

def search(i, j, c, v):
	if c == 0 or i < 0 or i >= n or (j < 0) or (j >= n) or (j > i) or (A[i][j] != 0):
		return c
	A[i][j] = v
	c = search(i - 1, j, c - 1, v)
	c = search(i, j - 1, c, v)
	c = search(i + 1, j, c, v)
	c = search(i, j + 1, c, v)
	return c
for (i, v) in enumerate(map(int, input().split())):
	rem = search(i, i, v, v)
	if rem > 0:
		print(-1)
		exit()
for i in range(n):
	print(' '.join(map(str, A[i][:i + 1])))


n = int(input())
p_list = [int(tt) for tt in input().split()]

def getResult(n, p_list):
	res = [[0] * n for _ in range(n)]
	for i in range(n):
		res[i][i] = p_list[i]
	for i in range(n - 1, -1, -1):
		v = p_list[i]
		row = i
		col = i
		count = 1
		while count < v:
			if row + 1 < n and res[row + 1][col] == 0:
				res[row + 1][col] = v
				row += 1
			elif col > 0:
				res[row][col - 1] = v
				col -= 1
			else:
				return False
			count += 1
	return res
res = getResult(n, p_list)
if res:
	for i in range(n):
		temp = [str(k) for k in res[i][:i + 1]]
		print(' '.join(temp))
else:
	print(-1)


n = int(input())
p = list(map(int, input().split()))
l = []
for i in range(1, n + 1):
	l.append([None] * i)
for i in range(n):
	x = i
	y = i
	num = p[i]
	for j in range(num):
		l[y][x] = num
		if x > 0 and l[y][x - 1] is None:
			x = x - 1
		else:
			y = y + 1
for i in range(n):
	print(*l[i])


n = int(input())
res = [[0] * (k + 1) for k in range(n)]
p = list(map(int, input().split()))
for i in range(n):
	res[i][i] = p[i]
for k in range(n - 1):
	found1 = 0
	for i in range(n - k):
		if res[i + k][i] == k + 1:
			found1 = 1
			continue
		if not found1:
			res[i + 1 + k][i] = res[i + k][i]
		else:
			res[i + k][i - 1] = res[i + k][i]
for i in range(n):
	print(*res[i])


n = int(input())
diag = [int(i) for i in input().strip().split()]
list_n = [[0] * n for i in range(n)]
for i in range(n):
	list_n[i][i] = diag[i]
for i in range(n):
	row = i
	col = i - 1
	val = list_n[i][i]
	while val - 1 != 0:
		if col >= 0 and list_n[row][col] == 0:
			list_n[row][col] = list_n[i][i]
			val -= 1
			col -= 1
		elif col < 0 or list_n[row][col] != 0:
			col += 1
			row += 1
for i in range(n):
	print(' '.join(map(str, list_n[i][0:i + 1])))


def inputi():
	return int(input())

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

def inputls():
	return list(map(str, input().split(' ')))

def print_list(lista):
	s = ''
	for i in lista[:-1]:
		if i != None:
			s += str(i) + ' '
	if lista[-1] != None:
		s += str(lista[-1])
	return s

def llenar(ans, row, column, cnt, value):
	if cnt == 1:
		return 0
	if ans[row][max(column - 1, 0)] == None:
		ans[row][max(column - 1, 0)] = value
		return llenar(ans, row, max(column - 1, 0), cnt - 1, value)
	elif ans[min(row + 1, len(ans) - 1)][column] == None:
		ans[min(row + 1, len(ans) - 1)][column] = value
		return llenar(ans, min(row + 1, len(ans) - 1), column, cnt - 1, value)
	else:
		return -1

def solve():
	n = inputi()
	diagonal = inputli()
	ans = [[None] * n for i in range(n)]
	for i in range(n):
		ans[i][i] = diagonal[i]
	for (idx, x) in enumerate(diagonal):
		auxiliar = llenar(ans, idx, idx, x, x)
		if auxiliar == -1:
			break
	if ans == -1:
		print(-1)
	else:
		for i in range(n):
			print(print_list(ans[i]))
	return 0
solve()


n = int(input())
p = [int(s) for s in input().split()]
diags = [p]
for di in range(1, n):
	skipped = False
	diags.append([])
	for i in range(n - di):
		if diags[di - 1][i] == di:
			skipped = True
		if skipped:
			diags[-1].append(diags[di - 1][i + 1])
		else:
			diags[-1].append(diags[di - 1][i])
for row in range(n):
	print(' '.join([str(diags[row - col][col]) for col in range(row + 1)]))


import bisect
import collections
import functools
import itertools
import math
import heapq
import random
import string

def repeat(_func=None, *, times=1):

	def decorator(func):

		@functools.wraps(func)
		def wrapper(*args, **kwargs):
			for _ in range(times):
				func(*args, **kwargs)
		return wrapper
	if _func is None:
		return decorator
	else:
		return decorator(_func)

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def getint():
	return int(input())

def getmatrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def display_matrix(mat):
	for i in range(len(mat)):
		print(mat[i])
MOD = 1000000007

def main():
	n = getint()
	mat = [[0] * n for _ in range(n)]
	arr = l_unpack()
	for i in range(n):
		mat[i][i] = arr[i]
	hmap = {x: x - 1 for x in arr}

	def isvalid(x, y):
		return 0 <= x < n and 0 <= y < n
	for diag in range(n):
		for p in range(n - diag):
			(x, y) = (diag + p, p)
			if not isvalid(x, y):
				break
			val = mat[x][y]
			if hmap[val] == 0:
				continue
			((lx, ly), (dx, dy)) = ((x, y - 1), (x + 1, y))
			if isvalid(lx, ly) and mat[lx][ly] == 0:
				mat[lx][ly] = val
				hmap[mat[x][y]] -= 1
			elif isvalid(dx, dy) and mat[dx][dy] == 0:
				mat[dx][dy] = val
				hmap[mat[x][y]] -= 1
			else:
				print(-1)
				return
	if sum(hmap.values()):
		print(-1)
		return
	for i in range(n):
		print(*mat[i][:i + 1])
main()


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	plst = list(map(int, input().split()))
	ans = [[-1] * n for _ in range(n)]

	def nex(ii, jj):
		if jj == 0:
			return (ii + 1, jj)
		elif ans[ii][jj - 1] == -1:
			return (ii, jj - 1)
		else:
			return (ii + 1, jj)
	for (i, p) in enumerate(plst):
		ans[i][i] = p
		(ii, jj) = (i, i)
		for _ in range(p - 1):
			while ans[ii][jj] != -1:
				(ii, jj) = nex(ii, jj)
			ans[ii][jj] = p
	for i in range(n):
		print(*ans[i][:i + 1])
for _ in range(1):
	main()


import os
from sys import stdin

def solve(tc):
	N = int(stdin.readline().strip())
	seq = list(map(int, stdin.readline().split()))
	grid = [[0 for i in range(N)] for j in range(N)]
	for i in range(N):
		(y, x) = (i, i)
		for j in range(seq[i]):
			grid[y][x] = seq[i]
			if x > 0 and grid[y][x - 1] == 0:
				x -= 1
				continue
			y += 1
	for i in range(N):
		print(' '.join(map(str, grid[i][:i + 1])))
tcs = 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


import math
from collections import defaultdict

def r():
	return int(input())

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

def rl():
	return list(map(int, input().split()))
n = r()
a = rl()
ans = []
for i in range(n):
	ans.append([' '] * n)
for i in range(n):
	ans[i][i] = a[i]
for i in range(n):
	puts = a[i] - 1
	down = i
	left = i
	while puts > 0:
		if left - 1 > -1 and left - 1 < n and (ans[down][left - 1] == ' '):
			ans[down][left - 1] = a[i]
			left -= 1
		else:
			ans[down + 1][left] = a[i]
			down += 1
		puts -= 1
for i in range(n):
	print(*ans[i])


D = [*map(int, [*open(0)][1].split())]
n = len(D)
r = range
g = [(y + 1) * [0] for y in r(n)]
for d in r(n):
	for i in r(n - d):
		g[d + i][i] = D[i]
	D.remove(d + 1)
for i in r(n):
	print(*g[i])


n = int(input())
p = list(map(int, input().split()))
ans = [[0] * (i + 1) for i in range(n)]
for i in range(n):
	ans[i][i] = p[i]
for i in range(n):
	num = p[i] - 1
	k = i
	ind = i
	while num:
		if k - 1 >= 0 and ans[ind][k - 1] == 0:
			k -= 1
		else:
			ind += 1
		num -= 1
		ans[ind][k] = ans[i][i]
for i in ans:
	print(*i)


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

def answer(n, permutation):
	if n == 1:
		return [[1]]
	perm2 = []
	for i in permutation:
		if i > 1:
			perm2.append(i - 1)
	arr = answer(n - 1, perm2)
	for i in range(n - 1):
		for j in range(i + 1):
			arr[i][j] += 1
	arr.append(permutation)
	return arr

def final(n, permutation):
	arr = answer(n, permutation)
	arr.reverse()
	a = [[' ' for j in range(n)] for i in range(n)]
	for i in range(n):
		for j in range(n - i):
			a[i + j][i] = arr[j][i]
	return a
arr = final(n, temp)
for i in arr:
	for j in i:
		print(j, end=' ')
	print('')


n = int(input())
(*p,) = map(int, input().split())
mtx = [[0] * n for _ in ' ' * n]
for i in range(n):
	(x, y) = (i, i)
	color = p[i]
	mtx[i][i] = color
	for j in range(p[i] - 1):
		if x > 0 and mtx[y][x - 1] == 0:
			x -= 1
		elif y < n - 1 and mtx[y + 1][x] == 0:
			y += 1
		else:
			print(-1)
			break
		mtx[y][x] = color
	else:
		continue
	break
else:
	for (i, row) in enumerate(mtx):
		print(*row[:i + 1])


import sys
sys.setrecursionlimit(150000)
n = int(input())
arr = list(map(int, input().split()))
matrix = [[0 for j in range(n)] for i in range(n)]
direc = [[0, -1], [1, 0], [0, 1], [-1, 0]]

def dfs(i, j, num, fre, d):
	if fre[0] == 0:
		return
	if i < j or i >= n or j < 0 or (j >= n):
		return
	if matrix[i][j] > 0:
		return
	fre[0] -= 1
	matrix[i][j] = num
	for diff in range(4):
		newd = (d - 1 + diff) % 4
		newi = i + direc[newd][0]
		newj = j + direc[newd][1]
		dfs(newi, newj, num, fre, newd)
matrix = [[0 for j in range(n)] for i in range(n)]
flag = True
fre = [0]
for i in range(n):
	fre[0] = arr[i]
	dfs(i, i, arr[i], fre, 1)
	if fre[0] > 0:
		flag = False
		break
if flag:
	for (i, ele) in enumerate(matrix):
		print(' '.join(map(str, ele[:i + 1])))
else:
	print(-1)


n = int(input())
l = [*map(int, input().split())]
a = [[0] * i for i in range(1, n + 1)]
for i in reversed(range(n)):
	p = i
	q = i
	for j in range(l[i]):
		if p != n - 1:
			if a[p + 1][q] == 0:
				a[p][q] = l[i]
				p += 1
			else:
				a[p][q] = l[i]
				q -= 1
		else:
			a[p][q] = l[i]
			q -= 1
for i in range(n):
	print(*a[i])


n = int(input())
l = [*map(int, input().split())]
ans = [[] for i in range(n)]
flag = True
for i in range(n):
	for j in range(i):
		ans[i] += [0]
	ans[i] += [l[i]]
	for j in range(i + 1, n):
		ans[i] += [-1]
for k in range(n):
	j = i = k
	x = l[k] - 1
	while x > 0:
		if i > 0 and ans[i - 1][j] == 0:
			i -= 1
			ans[i][j] = l[k]
		elif j > 0 and ans[i][j - 1] == 0:
			j -= 1
			ans[i][j] = l[k]
		elif i < n and ans[i + 1][j] == 0:
			i += 1
			ans[i][j] = l[k]
		elif j < n and ans[i][j + 1] == 0:
			j += 1
			ans[i][j] = l[k]
		else:
			break
		x -= 1
	if x > 0:
		flag = False
		print(-1)
if flag:
	for i in range(n):
		print(*ans[i][:i + 1])


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = [[None] * (i + 1) for i in range(n)]
	i = 0
	for v in map(int, input().split()):
		a[i][i] = v
		x = i
		y = i
		for j in range(v - 1):
			if y > 0 and a[x][y - 1] is None:
				y -= 1
				a[x][y] = v
			elif x + 1 < n and a[x + 1][y] is None:
				x += 1
				a[x][y] = v
			else:
				print(-1)
				return
		i += 1
	for i in range(n):
		print(' '.join(map(str, a[i])))
solve()


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd
import bisect
import sys
import copy

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 = int(input())
a = get_array()
ans = [[None for j in range(i + 1)] for i in range(n)]
for i in range(n):
	to_move = a[i] - 1
	ans[i][i] = a[i]
	if to_move:
		if i > 0 and ans[i][i - 1] == None:
			(i1, j1) = (i, max(i - 1, 0))
		else:
			i1 = i + 1
			j1 = i
	while to_move:
		if ans[i1][j1] == None:
			while True:
				ans[i1][j1] = a[i]
				to_move -= 1
				if to_move and j1 - 1 >= 0 and (ans[i1][j1 - 1] == None):
					j1 -= 1
				else:
					break
		if to_move:
			if i1 < n - 1:
				i1 += 1
			else:
				j1 += 1
				break
	if to_move:
		while to_move and j1 < n and (ans[i1][j1] == None):
			ans[i1][j1] = a[i]
			to_move -= 1
			j1 += 1
for i in range(n):
	print(*ans[i])


n = int(input())
myOut = [[0] * i for i in range(1, n + 1)]
diagonal = list(map(int, input().split()))
for i in range(n - 1, -1, -1):
	p = i
	q = i
	for j in range(diagonal[i]):
		myOut[p][q] = diagonal[i]
		if p == n - 1:
			q -= 1
		elif myOut[p + 1][q] == 0:
			p += 1
		else:
			q -= 1
for i in range(n):
	print(*myOut[i])


n = int(input())
s = [int(i) for i in input().split()]
q = {}
for i in range(n):
	q[i + 1] = i
ans = []
for i in range(n):
	ans.append([0] * (i + 1))
for i in range((n + 1) // 2):
	m = i
	j = i
	ans[i][i] = s[i]
	if n % 2 == 1 and i != n // 2 or n % 2 == 0:
		ans[-1 - i][-1] = s[-1 - i]
	while q[s[i]]:
		while j > 0 and (not ans[m][j - 1]) and q[s[i]]:
			j -= 1
			ans[m][j] = s[i]
			q[s[i]] -= 1
		while m + 1 < n and (not ans[m + 1][j]) and q[s[i]]:
			m += 1
			ans[m][j] = s[i]
			q[s[i]] -= 1
			if j > 0 and (not ans[m][j - 1]):
				break
	m = n - 1 - i
	j = n - 1 - i
	while q[s[-1 - i]]:
		while q[s[-i - 1]] and m + 1 < n and (not ans[m + 1][j]):
			m += 1
			ans[m][j] += s[-i - 1]
			q[s[-i - 1]] -= 1
		while q[s[-i - 1]] and j > 0 and (not ans[m][j - 1]):
			j -= 1
			ans[m][j] = s[-i - 1]
			q[s[-i - 1]] -= 1
			if m + 1 < n and (not ans[m + 1][j]):
				break
for i in ans:
	print(*i)


import sys
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
depth = 1000005
mod = 1000000007
sys.setrecursionlimit(depth)
from math import inf, gcd, log
from collections import defaultdict

def valid(x, y):
	if x < 0 or x >= n:
		return False
	if y < 0 or y >= n:
		return False
	if m[x][y] != 0:
		return False
	return True

def dfs(x, y, cnt, val):
	if cnt == 0:
		return
	m[x][y] = val
	if valid(x, y - 1):
		dfs(x, y - 1, cnt - 1, val)
	else:
		dfs(x + 1, y, cnt - 1, val)
n = int(input())
m = [[0 for _ in range(n)] for _ in range(n)]
a = list(map(int, input().split()))
for i in range(n):
	m[i][i] = a[i]
for i in range(n):
	dfs(i, i, a[i], a[i])
for i in range(n):
	for j in range(i + 1):
		print(m[i][j], end=' ')
	print()


def main():
	n = int(input())
	P = [int(x) for x in input().split()]
	sol = [[0] * (i + 1) for i in range(n)]
	for (i, p) in enumerate(P):
		sol[i][i] = p
		row = i
		col = i
		for _ in range(p - 1):
			if col > 0 and sol[row][col - 1] == 0:
				col -= 1
			elif row < n - 1 and sol[row + 1][col] == 0:
				row += 1
			else:
				print(-1)
				return
			sol[row][col] = p
	for s in sol:
		print(' '.join((str(x) for x in s)))
main()


n = int(input())
p = map(int, input().split())
b = [[-1] + [0] * i + [next(p)] + [-1] for i in range(n)] + [[-1] * (n + 1)]
wrong = False
for k in range(n):
	pk = b[k][k + 1]
	(x, y) = (k, k + 1)
	for i in range(1, pk):
		if b[x - 1][y] == 0:
			b[x - 1][y] = pk
			x -= 1
		elif b[x][y - 1] == 0:
			b[x][y - 1] = pk
			y -= 1
		elif b[x + 1][y] == 0:
			b[x + 1][y] = pk
			x += 1
		else:
			wrong = True
			break
	if wrong:
		break
if wrong:
	print(-1)
else:
	for l in b[:-1]:
		print(' '.join(map(str, l[1:-1])))


def start(a, count, num, curx, cury):
	if count == 0:
		return
	if curx == 0 or (curx > 0 and a[cury][curx] != 0):
		a[cury][curx] = num
		count -= 1
		start(a, count, num, curx, cury + 1)
	else:
		a[cury][curx] = num
		count -= 1
		if a[cury][curx - 1] != 0:
			start(a, count, num, curx, cury + 1)
		else:
			start(a, count, num, curx - 1, cury)
n = int(input())
b = list(map(int, input().split()))
a = []
for i in range(n):
	a.append([0] * n)
for i in range(len(a)):
	start(a, b[i], b[i], i, i)
for i in range(len(a)):
	for j in range(i + 1):
		print(a[i][j], end=' ')
	print()


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby

def go_left(h, v, e, l, fail):
	if l == 0:
		return False
	h -= 1
	arr[v][h] = e
	l -= 1
	if h >= 1 and arr[v][h - 1] == 0:
		return go_left(h, v, e, l, fail)
	elif v + 1 <= n - 1 and arr[v + 1][h] == 0:
		return go_down(h, v, e, l, fail)
	else:
		fail = 1

def go_down(h, v, e, l, fail):
	if l == 0:
		return False
	v += 1
	arr[v][h] = e
	l -= 1
	if h >= 1 and arr[v][h - 1] == 0:
		return go_left(h, v, e, l, fail)
	elif v + 1 <= n - 1 and arr[v + 1][h] == 0:
		return go_down(h, v, e, l, fail)
	else:
		fail = 1
for _ in range(1):
	n = II()
	a = LI()
	fail = 0
	arr = [0] * n
	for i in range(n):
		arr[i] = [0] * (i + 1)
	for i in range(n):
		e = a[i]
		arr[i][i] = e
		h = i
		v = i
		if h >= 1 and arr[v][h - 1] == 0:
			go_left(h, v, e, e - 1, fail)
		else:
			go_down(h, v, e, e - 1, fail)
	if fail == 1:
		print(-1)
	else:
		for i in range(n):
			print(*arr[i])


from math import *
from collections import defaultdict as dt
from sys import stdin
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int, stdin.readline().split())
L = lambda : list(map(int, stdin.readline().split()))
mod = 1000000009
inf = 100000000000000000000
ss = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	n = I()
	a = L()
	b = [[0 for j in range(i + 1)] for i in range(n)]
	for i in range(n):
		j = k = i
		x = y = a[i]
		while x:
			if j < 0 or b[k][j] != 0:
				j = j + 1
				k = k + 1
			b[k][j] = y
			x = x - 1
			j = j - 1
	for i in b:
		print(*i)
tt = 1
for _ in range(tt):
	solve()


import sys
input = sys.stdin.readline
n = int(input())
P = list(map(int, input().split()))
ANS = [[-1] * n for i in range(n)]
Q = []
for i in range(n):
	ANS[i][i] = P[i]
	if P[i] - 1 > 0:
		Q.append((i, i, P[i] - 1))
while Q:
	NQ = []
	for i in range(len(Q)):
		(x, y, c) = Q[i]
		if y == 0 or ANS[x][y - 1] != -1:
			ANS[x + 1][y] = ANS[x][y]
			if c - 1 > 0:
				NQ.append((x + 1, y, c - 1))
		elif x == n - 1 or ANS[x + 1][y] != -1:
			ANS[x][y - 1] = ANS[x][y]
			if c - 1 > 0:
				NQ.append((x, y - 1, c - 1))
		else:
			NQ.append((x, y, c))
	Q = NQ
	NQ = []
	for i in range(len(Q) - 1, -1, -1):
		(x, y, c) = Q[i]
		if y == 0 or ANS[x][y - 1] != -1:
			ANS[x + 1][y] = ANS[x][y]
			if c - 1 > 0:
				NQ.append((x + 1, y, c - 1))
		elif x == n - 1 or ANS[x + 1][y] != -1:
			ANS[x][y - 1] = ANS[x][y]
			if c - 1 > 0:
				NQ.append((x, y - 1, c - 1))
		else:
			NQ.append((x, y, c))
	Q = NQ
for i in range(n):
	print(*ANS[i][:i + 1])


import sys
import os.path
if os.path.exists('input_file.txt'):
	sys.stdin = open('input_file.txt', 'r')
	sys.stdout = open('output_file.txt', 'w')
mod = 1000000007

def factorial(a):
	ans = 1
	for i in range(1, a + 1):
		ans = ans * i % mod
	return ans
n = int(input())
a = list(map(int, input().split()))
r = 0
j = 0
i = 0
f = 0
l = [[-1 for i in range(nn)] for nn in range(1, n + 1)]
while r < n:
	i = r
	j = i
	for jj in range(a[r]):
		if a[r] == 1:
			l[i][i] = 1
			break
		elif l[r][r] == -1:
			l[r][r] = a[r]
		elif r == 0:
			l[jj][r] = a[r]
		elif i - 1 >= 0 and l[j][i - 1] == -1:
			i -= 1
			l[j][i] = a[r]
		else:
			j += 1
			l[j][i] = a[r]
	r += 1
for i in l:
	for ii in i:
		print(ii, end=' ')
	print()


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

def li():
	return [int(i) for i in input().split()]
for t in range(1):
	n = ii()
	p = li()
	ans = [[-1 for j in range(n)] for i in range(n)]
	for index in range(n):
		x = p[index]
		i = index
		j = index
		while x > 0:
			ans[i][j] = p[index]
			if j != 0:
				if ans[i][j - 1] == -1:
					j = j - 1
				else:
					i += 1
			else:
				i += 1
			x -= 1
	for i in range(n):
		print(*ans[i][:i + 1])


n = int(input())
p = list(map(int, input().split()))
ans = [[None for j in range(i + 1)] for i in range(n)]
for i in range(n):
	pi = p[i]
	size_i = p[i]
	(x, y) = (i, i)
	while size_i > 0:
		ans[x][y] = pi
		size_i -= 1
		if y >= 1 and ans[x][y - 1] is None:
			y = y - 1
		else:
			x = x + 1
for i in range(n):
	print(*ans[i])


from sys import stdin, stdout
import math

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

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

def li():
	return list(mi())

def si():
	return stdin.readline()
n = ii()
inp = li()
ans = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
	val = inp[i]
	r = i
	c = i
	ans[r][c] = val
	for j in range(1, val):
		if c - 1 >= 0 and ans[r][c - 1] == 0:
			c = c - 1
		else:
			r = r + 1
		ans[r][c] = val
for i in range(n):
	print(*ans[i][:i + 1])


from collections import deque, Counter
from math import sqrt, ceil, factorial
from sys import stdin, stdout
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float('inf')
ans_ = []

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

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

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

def st():
	return input().strip()
ans = []

def solve():
	n = inp()
	arr = read()
	mat = [[0] * (n + 2) for i in range(n + 2)]
	for i in range(n):
		x = y = i + 1
		for j in range(arr[i]):
			mat[x][y] = arr[i]
			if y > 1 and (not mat[x][y - 1]):
				y -= 1
			else:
				x += 1
	for i in range(n):
		ans.append(mat[i + 1][1:i + 2])
solve()
for i in ans:
	print(*i)


def f(previ, prevj, x):
	if (prevj == 0 and previ < n - 1) and mx[previ + 1][prevj] == -1:
		mx[previ + 1][prevj] = x
		return (previ + 1, prevj)
	if prevj > 0 and mx[previ][prevj - 1] == -1:
		mx[previ][prevj - 1] = x
		return (previ, prevj - 1)
	if previ < n - 1 and mx[previ + 1][prevj] == -1:
		mx[previ + 1][prevj] = x
		return (previ + 1, prevj)
	if previ > 0 and mx[previ - 1][prevj] == -1:
		mx[previ - 1][prevj] = x
		return (previ - 1, prevj)
	if prevj < x and mx[previ][prevj + 1] == -1:
		mx[previ][prevj + 1] = x
		return (previ, prevj + 1)
	return (-1, -1)
n = int(input())
l = list(map(int, input().split()))
mx = [[-1 for i in range(n)] for j in range(n)]
for i in range(n):
	mx[i][i] = l[i]
for i in range(n):
	prevj = i
	previ = i
	flag = 0
	for j in range(l[i] - 1):
		(previ, prevj) = f(previ, prevj, l[i])
		if previ == -1 and prevj == -1:
			flag = 1
			break
		mx[previ][prevj] = l[i]
	if flag == 1:
		break
if flag:
	print(-1)
else:
	for i in range(n):
		temp = []
		for j in range(i + 1):
			temp.append(mx[i][j])
		print(*temp)


import os, sys, math
from io import BytesIO, IOBase
from collections import defaultdict, deque, OrderedDict
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(input())

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

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

def Sn():
	return input().strip()
BUFSIZE = 8192

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def solve():
	n = I()
	l = list(In())
	ans = [[-1] * n for i in range(n)]
	for i in range(n):
		q = deque([(i, i)])
		cnt = l[i]
		while q:
			(x, y) = q.popleft()
			ans[x][y] = l[i]
			cnt -= 1
			if cnt == 0:
				break
			if y - 1 >= 0 and ans[x][y - 1] == -1:
				q.append((x, y - 1))
			elif x + 1 < n and ans[x + 1][y] == -1:
				q.append((x + 1, y))
			elif y + 1 < n and ans[x][y + 1] == -1:
				q.append((x, y + 1))
	for i in range(n):
		for j in range(i + 1):
			print(ans[i][j], end=' ')
		print()
	pass

def main():
	T = 1
	for i in range(T):
		solve()
M = 998244353
P = 1000000007

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


def show(lis):
	ln = len(lis)
	for i in range(ln):
		li = lis[i][:i + 1]
		print(*li)

def solve(n, d):
	m = [[0] * n for i in range(n)]
	for (i, it) in enumerate(d):
		m[i][i] = it
	for i in range(n):
		row = set()
		(cx, cy) = (i, i)
		cur = m[i][i]
		todo = m[i][i] - 1
		while todo and cx < n and (cy < n):
			if cy > 0 and m[cx][cy - 1] == 0:
				todo -= 1
				cy -= 1
			elif cx < n - 1 and m[cx + 1][cy] == 0:
				todo -= 1
				cx += 1
			m[cx][cy] = cur
			if cy == 0:
				row.add(cx)
		rows = list(row)
		rows.sort()
		for cx in rows:
			if todo == 0:
				break
			cy = 0
			while m[cx][cy] == cur:
				cy += 1
			while cy <= cx and m[cx][cy] == cur and todo:
				todo -= 1
				m[cx][cy] = cur
		if todo:
			print(-1)
			return
	show(m)
n = int(input())
d = list(map(int, input().split()))
solve(n, d)


n = int(input())
mat = [[0] * n for _ in range(n)]
for (i, v) in enumerate(map(int, input().split())):
	(x, y, c) = (i, i, 1)
	mat[x][y] = v
	flag = True
	while flag and c < v:
		flag = False
		if y > 0 and mat[x][y - 1] == 0:
			y -= 1
			mat[x][y] = v
			flag = True
		elif x < n - 1 and mat[x + 1][y] == 0:
			x += 1
			mat[x][y] = v
			flag = True
		c += 1
for i in range(n):
	for j in range(i):
		if mat[i][j] == 0:
			mat[i][j] = mat[n - 1][n - 1]
for i in range(n):
	for j in range(i + 1):
		print(mat[i][j], end=' ')
	print()


n = int(input())
P = list(map(int, input().split()))
A = []
for i in range(n):
	A.append([-1] * n)
for i in range(n):
	A[i][i] = P[i]
	cnt = P[i] - 1
	j = i - 1
	k = i
	while cnt > 0:
		if j > 0 and A[k][j] == -1:
			A[k][j] = P[i]
			j -= 1
			cnt -= 1
		elif j == 0 and A[k][j] == -1:
			A[k][j] = P[i]
			k += 1
			cnt -= 1
		else:
			j += 1
			k += 1
for i in range(n):
	for j in range(i + 1):
		print(A[i][j], end=' ')
	print('')


def fill(i, j, val, cnt, n):
	if cnt[0] == 0:
		return
	if j < 0:
		return
	if i >= n:
		return
	if i == j:
		fill(i, j - 1, val, cnt, n)
		fill(i + 1, j, val, cnt, n)
	else:
		if ans[i][j] != 0:
			return
		ans[i][j] = val
		cnt[0] -= 1
		fill(i, j - 1, val, cnt, n)
		fill(i + 1, j, val, cnt, n)
n = int(input())
arr = list(map(int, input().split()))
ans = [[0 for j in range(i)] for i in range(1, n + 1)]
for i in range(n):
	ans[i][i] = arr[i]
	fill(i, i, arr[i], [arr[i] - 1], n)
for x in ans:
	print(*x)


from sys import stdin, stdout
input = stdin.readline

def f():
	global mat, val, i
	x = i
	y = i
	for k in range(val - 1):
		if x != 0 and mat[x - 1][y] == -1 and (y <= x - 1):
			mat[x - 1][y] = val
			x -= 1
		elif y != 0 and mat[x][y - 1] == -1 and (y - 1 <= x):
			mat[x][y - 1] = val
			y -= 1
		elif x != n - 1 and mat[x + 1][y] == -1 and (y <= x + 1):
			mat[x + 1][y] = val
			x += 1
		elif y != n - 1 and mat[x][y + 1] == -1 and (y + 1 <= x):
			mat[x][y + 1] = val
			y += 1
		else:
			return False
	return True
t = 1
for _ in range(t):
	n = int(input())
	p = [int(x) for x in input().split()]
	mat = [[-1 for i in range(n)] for j in range(n)]
	ans = 0
	for i in range(n):
		val = p[i]
		mat[i][i] = val
		if not f():
			ans = 1
			break
	if ans:
		print(-1)
		continue
	for i in range(n):
		for j in range(i + 1):
			stdout.write(str(mat[i][j]) + ' ')
		stdout.write('\n')


n = int(input())
arr = []
diag = [int(x) for x in input().split()]
for i in range(n):
	temp = [0 for x in range(i + 1)]
	temp[i] = diag[i]
	arr.append(temp)
for i in range(n):
	c = diag[i]
	val = c
	arr[i][i] = 0
	j = i
	temp = i
	while c > 0:
		while j > -1 and c > 0:
			if arr[temp][j] != 0:
				break
			arr[temp][j] = val
			c -= 1
			j -= 1
		j += 1
		temp += 1
for i in range(n):
	print(*arr[i])


def valuePlacer(i, j, val, count):
	if count:
		if j - 1 >= 0 and matrix[i][j - 1] == 0:
			matrix[i][j - 1] = val
			count -= 1
			valuePlacer(i, j - 1, val, count)
		elif i + 1 < n and matrix[i + 1][j] == 0:
			matrix[i + 1][j] = val
			count -= 1
			valuePlacer(i + 1, j, val, count)
n = int(input())
matrix = [[0 for j in range(n)] for i in range(n)]
val = list(map(int, input().split()))
for i in range(n):
	matrix[i][i] = val[i]
for i in range(n):
	valuePlacer(i, i, matrix[i][i], matrix[i][i] - 1)
for i in matrix:
	for j in i:
		if j == 0:
			break
		print(j, end=' ')
	print()


def solve(i, j, n, arr, val, c):
	while c > 0:
		if j - 1 >= 0:
			if arr[i][j - 1] == 0:
				arr[i][j - 1] = val
				j -= 1
				c -= 1
			else:
				arr[i + 1][j] = val
				i += 1
				c -= 1
		else:
			arr[i + 1][j] = val
			i += 1
			c -= 1
n = int(input())
per = [int(x) for x in input().split()]
arr = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
	arr[i][i] = per[i]
for i in range(n):
	(x, y) = (i, i)
	val = arr[x][y]
	count = val - 1
	solve(x, y, n, arr, val, count)
for ele in arr:
	for e in ele:
		if e == 0:
			print(' ', end='')
		else:
			print(e, end=' ')
	print()


n = int(input())
a = list(map(int, input().split()))
s = []
for jj in range(n):
	s.append([0] * n)
for jj in range(n):
	(r, c) = (jj, jj)
	for kk in range(a[jj]):
		s[r][c] = a[jj]
		if c > 0:
			if not s[r][c - 1]:
				c -= 1
			else:
				r += 1
		else:
			r += 1
for (kk, jj) in enumerate(s):
	print(*jj[:kk + 1])


def main():
	n = int(input())
	p = list(map(int, input().split()))
	m = [[0] * n for i in range(n)]
	for i in range(n):
		pi = p[i]
		(x, y) = (i, i)
		m[x][y] = pi
		for j in range(p[i] - 1):
			if m[x][y - 1] == 0 and y - 1 >= 0:
				y -= 1
			elif m[x + 1][y] == 0 and x + 1 < n:
				x += 1
			else:
				ans = -1
				print(ans)
				exit()
			m[x][y] = pi
	for i in range(n):
		for j in range(i + 1):
			print(m[i][j], end=' ')
		print()
main()


from bisect import bisect, bisect_left
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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 RL():
	return map(int, sys.stdin.readline().split())

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

def N():
	return int(input())

def A(n):
	return [0] * n

def AI(n, x):
	return [x] * n

def A2(n, m):
	return [[0] * m for i in range(n)]

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

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
mod = 10 ** 9 + 7
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

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

def floorsum(a, b, c, n):
	if a == 0:
		return b // c * (n + 1)
	if a >= c or b >= c:
		return floorsum(a % c, b % c, c, n) + b // c * (n + 1) + a // c * n * (n + 1) // 2
	m = (a * n + b) // c
	return n * m - floorsum(c, c - b - 1, a, m - 1)

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class ST:

	def __init__(self, arr):
		n = len(arr)
		mx = n.bit_length()
		self.st = [[0] * mx for i in range(n)]
		for i in range(n):
			self.st[i][0] = arr[i]
		for j in range(1, mx):
			for i in range(n - (1 << j) + 1):
				self.st[i][j] = max(self.st[i][j - 1], self.st[i + (1 << j - 1)][j - 1])

	def query(self, l, r):
		if l > r:
			return -inf
		s = (r + 1 - l).bit_length() - 1
		return max(self.st[l][s], self.st[r - (1 << s) + 1][s])

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] > self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return flag

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def bell(s, g):
	dis = AI(n, inf)
	dis[s] = 0
	for i in range(n - 1):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
	change = A(n)
	for i in range(n):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
				change[v] = 1
	return dis

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

def lis(nums):
	res = []
	for k in nums:
		i = bisect.bisect_left(res, k)
		if i == len(res):
			res.append(k)
		else:
			res[i] = k
	return len(res)

def RP(nums):
	n = len(nums)
	s = set(nums)
	d = {}
	for (i, k) in enumerate(sorted(s), 1):
		d[k] = i
	bi = BIT([0] * (len(s) + 1))
	ans = 0
	for i in range(n - 1, -1, -1):
		ans += bi.query(d[nums[i]] - 1)
		bi.update(d[nums[i]], 1)
	return ans

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j, n, m):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res

@bootstrap
def gdfs(r, p):
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None
t = 1
for i in range(t):
	n = N()
	p = RLL()
	ans = []
	for i in range(1, n + 1):
		ans.append(A(i))
		ans[-1][-1] = p[i - 1]
	for i in range(n - 1, -1, -1):
		k = p[i] - 1
		(ci, cj) = (i, i)
		while k:
			if ci + 1 < n and ans[ci + 1][cj] == 0:
				ci = ci + 1
				ans[ci][cj] = p[i]
				k -= 1
			else:
				cj -= 1
				ans[ci][cj] = p[i]
				k -= 1
	for x in ans:
		print(*x)


from math import inf
n = int(input())
chessboard = [[inf] * (i + 1) for i in range(0, n + 1)]
permutation = list(map(int, input().split()))
for i in range(1, n + 1):
	chessboard[i][i] = permutation[i - 1]

def DFS(chessboard, x):
	positions = [(x, x)]
	size = 1
	while len(positions) > 0 and size < chessboard[x][x]:
		(i, j) = positions[-1]
		if i > 1 and j <= i - 1 and (chessboard[i - 1][j] == inf):
			positions.append((i - 1, j))
			chessboard[i - 1][j] = chessboard[x][x]
			size += 1
		elif j > 1 and chessboard[i][j - 1] == inf:
			positions.append((i, j - 1))
			chessboard[i][j - 1] = chessboard[x][x]
			size += 1
		elif i < n and chessboard[i + 1][j] == inf:
			positions.append((i + 1, j))
			chessboard[i + 1][j] = chessboard[x][x]
			size += 1
		elif j + 1 <= i and chessboard[i][j + 1] == inf:
			positions.append((i, j + 1))
			chessboard[i][j + 1] = chessboard[x][x]
			size += 1
		else:
			positions.pop()
	if size < chessboard[x][x]:
		return False
	if x == len(permutation):
		return True
	if x < len(permutation):
		return DFS(chessboard, x + 1)
if DFS(chessboard, 1):
	for i in range(1, n + 1):
		for j in range(1, i + 1):
			print(chessboard[i][j], end=' ')
		print()
else:
	print(-1)


def Solve():
	n = int(input())
	A = list(map(int, input().split()))
	a = [i for i in range(n + 1)]
	ans = []
	for i in range(n):
		ans.append([0 for i in range(n)])
	for i in range(n):
		ans[i][i] = A[i]
		a[i + 1] -= 1
	for i in range(1, n + 1):
		k = A[i - 1]
		(p, q) = (i - 1, i - 1)
		while a[k] > 0:
			if q > 0 and ans[p][q - 1] == 0:
				q -= 1
				ans[p][q] = k
			else:
				p += 1
				ans[p][q] = k
			a[k] -= 1
	for i in range(n):
		for j in range(i + 1):
			print(ans[i][j], end=' ')
		print()
Solve()


n = int(input())
diag = tuple(map(int, input().split()))
li = [[0] * n for _ in range(n)]
for i in range(n):
	li[i][i] = diag[i]
is_failed = False
for i in range(n - 1, -1, -1):
	region_num = diag[i]
	x = y = i
	for _ in range(region_num - 1):
		(nx, ny) = (x + 1, y)
		if 0 <= nx < n and 0 <= ny <= i and (li[nx][ny] == 0):
			li[nx][ny] = region_num
			(x, y) = (nx, ny)
			continue
		(nx, ny) = (x, y - 1)
		if 0 <= nx < n and 0 <= ny <= i and (li[nx][ny] == 0):
			li[nx][ny] = region_num
			(x, y) = (nx, ny)
			continue
		(nx, ny) = (x - 1, y)
		if 0 <= nx < n and 0 <= ny <= i and (li[nx][ny] == 0):
			li[nx][ny] = region_num
			(x, y) = (nx, ny)
			continue
		(nx, ny) = (x, y + 1)
		if 0 <= nx < n and 0 <= ny <= i and (li[nx][ny] == 0):
			li[nx][ny] = region_num
			(x, y) = (nx, ny)
			continue
		is_failed = True
		break
	if is_failed:
		break
if is_failed:
	print(-1)
else:
	for i in range(n):
		print(*li[i][:i + 1])


n = int(input())
l = list(map(int, input().split()))
ans = [[0] * n for i in range(n)]
for i in range(n):
	v = l[i]
	c = v
	k = i
	j = i
	f = 0
	while c > 0:
		if j >= 0 and ans[k][j] == 0:
			ans[k][j] = v
			j -= 1
			c -= 1
			f = 1
		else:
			if f == 1:
				j += 1
			k += 1
			f = 0
for i in range(n):
	for j in range(i + 1):
		print(ans[i][j], end=' ')
	print()


n = int(input())
A = list(map(int, input().split()))
B = []
B = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
	B[i][i] = A[i]
for i in range(n):
	c = i
	r = i
	u = A[i] - 1
	while u > 0:
		if r > 0 and B[c][r - 1] == 0 and (u > 0):
			B[c][r - 1] = A[i]
			r -= 1
			u -= 1
		elif c < n - 1 and B[c + 1][r] == 0 and (u > 0):
			B[c + 1][r] = A[i]
			c += 1
			u -= 1
		elif r < n - 1 and B[c][r + 1] == 0 and (u > 0):
			B[c][r + 1] = A[i]
			r += 1
			u -= 1
for i in range(n):
	for j in range(i + 1):
		print(B[i][j], end=' ')
	print()


n = int(input())
p = list(map(int, input().split()))
result = []
for i in range(n):
	result.append([0] * n)
for c in range(n):
	(x, y) = (c, c)
	num = p[c]
	while num > 0:
		while y >= 0 and result[x][y] == 0 and (num > 0):
			result[x][y] = p[c]
			y -= 1
			num -= 1
		if num > 0:
			y += 1
			x += 1
for r in result:
	row = [str(x) for x in r if x != 0]
	print(' '.join(row))


n = int(input())
(*arr,) = map(int, input().split())
ans = [[0 for j in range(i)] for i in range(1, n + 1)]
for i in range(n):
	ans[i][i] = arr[i]
	x = y = i
	while arr[i] > 1:
		if y - 1 >= 0 and ans[x][y - 1] == 0:
			y -= 1
		else:
			x += 1
		ans[x][y] = ans[i][i]
		arr[i] -= 1
for x in ans:
	print(*x)


n = int(input())
sol = [[]]
for i in range(n):
	sol.append([0 for j in range(i + 2)])
i = 0
for x in input().split():
	i += 1
	sol[i][-1] = int(x)
for start in range(1, n + 1):
	count = sol[start][-1] - 1
	r = start
	c = start
	while count != 0:
		if c - 1 > 0 and sol[r][c - 1] == 0:
			c -= 1
			count -= 1
			sol[r][c] = sol[start][-1]
		else:
			r += 1
			count -= 1
			sol[r][c] = sol[start][-1]
	start += 1
for l in sol[1:]:
	print(*l[1:])


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

def fill(A, i, j, with_num, count):
	if with_num == count:
		return
	if A[i][j] == 0:
		A[i][j] = with_num
		count += 1
	if j > 0 and A[i][j - 1] == 0:
		fill(A, i, j - 1, with_num, count)
	elif i < len(A) - 1 and A[i + 1][j] == 0:
		fill(A, i + 1, j, with_num, count)
n = int(input())
diag = read_ints()
A = [[0] * n for _ in range(n)]
for (i, n) in enumerate(diag):
	fill(A, i, i, n, 0)
for row in A:
	print(*[el for el in row if el])


def ALL_MIGHT(graph, i, j, n):
	if i >= 0 and i < n and (j >= 0) and (j < n) and (graph[i][j] == 0):
		return True
	else:
		return False

def PLUS_ULTRA(graph, num, x, i, j, n):
	if num == 1:
		return
	if ALL_MIGHT(graph, i + 1, j, n) == True:
		graph[i + 1][j] = x
		num -= 1
		PLUS_ULTRA(graph, num, x, i + 1, j, n)
	elif ALL_MIGHT(graph, i, j - 1, n) == True:
		graph[i][j - 1] = x
		num -= 1
		PLUS_ULTRA(graph, num, x, i, j - 1, n)
	else:
		return
n = int(input())
perm = list(map(int, input().split()))
ans = []
for i in range(n):
	tmp = []
	for j in range(i):
		tmp.append(0)
	tmp.append(perm[i])
	ans.append(tmp)
for i in range(n - 1, -1, -1):
	PLUS_ULTRA(ans, perm[i], perm[i], i, i, n)
ver = False
for i in range(len(ans)):
	for j in range(len(ans[i])):
		if ans[i][j] == 0:
			ver = True
			break
if ver == False:
	for i in range(len(ans)):
		print(*ans[i])
else:
	print(-1)


import sys, random
n = int(input())
d = list(map(int, input().split()))
p = [[0] * n for i in range(n)]
for i in range(n):
	p[i][i] = d[i]
for i in range(n - 1, -1, -1):
	val = p[i][i]
	kol = val - 1
	j = i
	while kol > 0:
		if i + 1 < n and p[i + 1][j] == 0:
			p[i + 1][j] = val
			i += 1
			kol -= 1
		else:
			p[i][j - 1] = val
			j -= 1
			kol -= 1
for i in range(n):
	for j in range(i + 1):
		print(p[i][j], end=' ')
	print()


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
n = I()
a = [[0] * n for i in range(n)]
for (i, j) in enumerate(R()):
	a[i][i] = j
for i in range(n):
	(x, y) = (i, i)
	for j in range(a[i][i] - 1):
		if y > 0 and (not a[x][y - 1]):
			a[x][y - 1] = a[i][i]
			y -= 1
		else:
			a[x + 1][y] = a[i][i]
			x += 1
for i in range(n):
	print(*a[i][:i + 1])


n = int(input())
l = list(map(int, input().split()))
k = []
for i in range(n):
	k.append([-1] * (i + 1))
for i in range(n):
	k[i][i] = l[i]
for i in range(n):
	a = i
	b = i
	g = l[i] - 1
	while g > 0:
		if b > 0 and k[a][b - 1] == -1:
			k[a][b - 1] = l[i]
			g -= 1
			b -= 1
		else:
			k[a + 1][b] = l[i]
			a += 1
			g -= 1
for x in k:
	print(*(i for i in x))


import os
import sys
from io import BytesIO, IOBase

def main():
	import bisect
	import math
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	inf = 1e+17
	mod = 10 ** 9 + 7
	Max = 10 ** 6
	primes = []
	prime = [True for i in range(Max + 1)]
	p = 2
	while p * p <= Max + 1:
		if prime[p] == True:
			for i in range(p * p, Max + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, Max + 1):
		if prime[p]:
			primes.append(p)

	def factorial(n):
		f = 1
		for i in range(1, n + 1):
			f = f * i % mod
		return f

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

	def solve(n, arr):
		grid = []
		for i in range(n):
			row = []
			for j in range(i):
				row.append(0)
			row.append(arr[i])
			grid.append(row)
		for j in range(n - 1, -1, -1):
			num = grid[j][j]
			put = num - 1
			r = j
			c = j
			while put > 0:
				if r + 1 < n:
					if grid[r + 1][c] == 0:
						grid[r + 1][c] = num
						put -= 1
						r += 1
					elif c - 1 >= 0:
						if grid[r][c - 1] == 0:
							grid[r][c - 1] = num
							put -= 1
							c -= 1
						else:
							return [[-1]]
					else:
						return [[-1]]
				elif c - 1 >= 0:
					if grid[r][c - 1] == 0:
						grid[r][c - 1] = num
						put -= 1
						c -= 1
					elif r + 1 < n:
						if grid[r + 1][c] == 0:
							grid[r + 1][c] = num
							put -= 1
							r += 1
						else:
							return [[-1]]
					else:
						return [[-1]]
		return grid
		pass
	t = 1
	ans = []
	for _ in range(t):
		n = int(input())
		arr = [int(x) for x in input().split()]
		ans.append(solve(n, arr))
	for j in range(len(ans)):
		if ans[j] == [[-1]]:
			print(-1)
		else:
			for row in ans[j]:
				print(' '.join(list(map(str, row))))
	pass
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')
main()


import collections
import itertools
from functools import reduce
mod = 10 ** 9 + 7

def permutationbysum():
	for _ in range(int(input())):
		(num, l, r, achieve) = map(int, input().split())
		k = r - l + 1
		if k * (k + 1) // 2 <= achieve <= k * (num * 2 + 1 - k) // 2:
			outpos = r % num
			inpos = l - 1
			ans = [0] * num
			for i in range(num, 0, -1):
				if achieve - i > 0 or (achieve - i == 0 and inpos == r - 1):
					achieve -= i
					ans[inpos] = i
					inpos += 1
				else:
					ans[outpos] = i
					outpos += 1
					outpos %= num
			print(*ans)
		else:
			print(-1)

def peaks():
	for _ in range(int(input())):
		(num, peak) = map(int, input().split())
		pos = 1
		rpos = num
		ans = []
		now = 0
		if num == 1:
			if not peak:
				print(1)
			else:
				print(-1)
			continue
		if num == 2:
			if peak:
				print(-1)
			else:
				print(1, 2)
			continue
		added = 0
		while rpos + 1 != pos:
			if not peak:
				while pos <= rpos:
					ans.append(pos)
					pos += 1
				break
			if not now:
				ans.append(pos)
				pos += 1
			else:
				ans.append(rpos)
				rpos -= 1
				if num - added != 1:
					peak -= 1
			added += 1
			now = 1 - now
		if peak:
			print(-1)
			continue
		print(*ans)
import sys
input = sys.stdin.readline

def addone():
	for _ in range(int(input())):
		(num, changes) = input().split()
		l = collections.deque(sorted([int(i) for i in num]))
		perm = collections.deque()
		changes = int(changes)
		cd = 0
		ans = len(num)
		while True:
			nextnum = l.pop()
			while perm and perm[-1] == nextnum:
				l.append(perm.pop())
			c = 10 - nextnum - cd
			changes -= c
			cd += c
			if changes >= 0:
				if not c:
					perm.appendleft(1 - cd)
					l.appendleft(-cd)
				else:
					l.appendleft(1 - cd)
					l.appendleft(-cd)
				ans += 1
			else:
				break
		print(ans % 1000000007)
import math

def andsequences():

	def mapping(num):
		nonlocal mnum
		nonlocal c
		num = int(num)
		if num < mnum:
			mnum = num
			c = 1
		elif num == mnum:
			c += 1
		return num
	mod = 1000000007
	for _ in range(int(input())):
		mnum = float('inf')
		c = 0
		num = int(input())
		l = list(map(mapping, input().split()))
		for i in l:
			if mnum & i != mnum:
				print(0)
				break
		else:
			if c == 1:
				print(0)
			else:
				print(math.factorial(num - 2) * (c - 1) * c % mod)

def numberdigit():
	n = 10 ** 5 * 2
	l = [0] * 11
	mod = 10 ** 9 + 7
	l[0] = l[1] = l[2] = l[3] = l[4] = l[5] = l[6] = l[7] = l[8] = 2
	l[9] = 3
	l[10] = 4
	for i in range(11, n):
		l.append((l[i - 10] + l[i - 9]) % mod)
	for _ in range(int(input())):
		(num, c) = input().split()
		c = int(c)
		ans = 0
		for i in num:
			i = int(i)
			if 10 - i > c:
				ans += 1
			else:
				ans += l[c - (10 - i)]
		print(ans % mod)

def mushroom():
	(people, t1, t2, percent) = map(int, input().split())
	l = []
	percent = 1 - percent * 0.01
	for i in range(1, people + 1):
		(s, s1) = map(int, input().split())
		l.append([i, max(s * t1 * percent + s1 * t2, s1 * t1 * percent + s * t2)])
	l.sort(key=lambda x: x[1], reverse=True)
	for i in l:
		i[1] = '{:.2f}'.format(i[1])
		print(*i)

def escape():
	prins = int(input())
	dra = int(input())
	start = int(input())
	pack = int(input())
	c = int(input())
	speeddiff = dra - prins
	if speeddiff <= 0:
		return 0
	pd = start * prins
	ans = 0
	while pd < c:
		hs = pd / speeddiff
		pd += prins * hs
		if pd >= c:
			break
		time = pd / dra
		time += pack
		pd += prins * time
		ans += 1
	return ans

def perm():

	def high(n, k):
		return k * (2 * n - k + 1) // 2

	def low(k):
		return k * (k + 1) // 2
	for _ in range(int(input())):
		(num, lef, rig, s) = map(int, input().split())
		k = rig - lef + 1
		(rig, lef) = (rig - 1, lef - 1)
		if not high(num, k) >= s >= low(k):
			print(-1)
			continue
		l = [0] * num
		lp = lef
		rp = lef - 1
		for i in range(num, 0, -1):
			if high(i, k) >= s and s - i >= low(k - 1) and k:
				l[lp] = i
				lp += 1
				s -= i
				k -= 1
			else:
				l[rp] = i
				rp -= 1
		if k:
			print(-1)
		else:
			print(*l)

def newcom():
	for _ in range(int(input())):
		(days, price) = map(int, input().split())
		dl = input().split()
		worth = input().split()
		worth.append(0)
		ans = float('inf')
		req = 0
		left = 0
		for i in range(days):
			a = int(dl[i])
			w = int(worth[i])
			ans = min(ans, req + max(0, price - left + a - 1) // a)
			ns = max(0, w - left + a - 1) // a
			req += ns + 1
			left += a * ns - w
		print(ans)

def perfectsq():
	for _ in range(int(input())):
		n = input()
		for i in input().split():
			sq = math.sqrt(int(i))
			if sq != int(sq):
				print('YES')
				break
		else:
			print('NO')

def and0big():
	for _ in range(int(input())):
		(l, k) = map(int, input().split())
		print(l ** k % mod)
import math

def mod1p():
	n = int(input())
	ans = dict()
	p = 1
	for i in range(1, n):
		if math.gcd(i, n) == 1:
			ans[str(i)] = True
			p = p * i % n
	if p == 1:
		print(len(ans))
		print(' '.join(ans.keys()))
	else:
		ans.pop(str(p))
		print(len(ans))
		print(' '.join(ans.keys()))

def shorttask():
	num = 10000100
	l = [-1] * (num + 2)
	s = [-1] * (num + 2)
	l[1] = 1
	for i in range(2, int(math.sqrt(num + 1)) + 2):
		if l[i] == -1:
			l[i] = i
			for x in range(i * i, num + 1, i):
				if l[x] == -1:
					l[x] = i
	s[1] = 1
	for i in range(2, num + 1):
		if l[i] == -1:
			l[i] = i
			s[i] = i + 1
		else:
			i1 = i
			s[i] = 1
			while i1 % l[i] == 0:
				i1 //= l[i]
				s[i] = s[i] * l[i] + 1
			s[i] *= s[i1]
	ans = [-1] * (num + 1)
	for i in range(num, 0, -1):
		if s[i] < num:
			ans[s[i]] = i
	for _ in range(int(input())):
		print(ans[int(input())])

def review():
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		for i in input().split():
			i = int(i)
			if i == 1 or i == 3:
				ans += 1
		print(ans)

def GCDleng():
	po10 = [0] * 11
	po10[1] = 1
	for i in range(2, 11):
		po10[i] = po10[i - 1] * 10
	for _ in range(int(input())):
		(n, n1, res) = map(int, input().split())
		print(po10[n], po10[n1] + po10[res])

def anothercarddeck():
	(n, q) = map(int, input().split())
	l = input().split()
	d = {l[i]: i for i in range(n - 1, -1, -1)}
	ans = []
	for i in input().split():
		now = d[i]
		ans.append(now + 1)
		for key in d:
			if d[key] < now:
				d[key] += 1
		d[i] = 0
	print(*ans)

def mincoststring():
	(n, letters) = map(int, input().split())
	l = [chr(i + 97) for i in range(letters)]
	ans = []
	real = letters - 1
	if not n:
		print(*ans, sep='')
		return
	if n == 1:
		print(*ans, sep='', end='')
		print(l[1 % (real + 1)])
		return
	while n:
		for i in range(len(l)):
			for i1 in range(i, len(l)):
				if i1 != real:
					ans.append(l[i1])
					ans.append(l[i])
					n -= 2
				else:
					ans.append(l[i1])
					n -= 1
				if not n:
					print(*ans, sep='')
					return
				if n == 1:
					print(*ans, sep='', end='')
					print(l[(i1 + 1) % (real + 1)])
					return
	print(*ans)

def mincost2():
	(n, letters) = map(int, input().split())
	l = [chr(i + 97) for i in range(letters)]
	comb = []
	if letters == 1 or n == 1:
		print('a' * n)
		return
	for i in range(letters):
		for i1 in range(i, letters):
			comb.append(l[i1] + l[i])
	lc = len(comb)
	while True:
		for i in range(lc):
			if ord(comb[i][0]) - 97 == letters - 1:
				n -= 1
				print(comb[i][0], end='')
			else:
				n -= 2
				print(comb[i], end='')
			if n == 1:
				pos = ord(comb[i][0]) - 97 + 1
				print(l[pos % letters])
				return
			if not n:
				return

def Tittat():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		l = list(map(int, input().split()))
		for i in range(n):
			if not k:
				break
			while k and l[i]:
				l[i] -= 1
				l[-1] += 1
				k -= 1
		print(*l)

def xorq2():
	for _ in range(int(input())):
		n = int(input())
		s = 0
		num = -1
		nc = 0
		c = 0
		for i in input().split():
			i = int(i)
			s ^= i
			c += 1
			if num == -1 and s == i:
				num = s
				s = 0
				nc += c
				c = 0
			if num != -1 and (s == num or not s):
				s = 0
				nc += c
				c = 0
		print(['NO', 'YES'][nc == n])

def xorq2re():
	n = int(input())
	s = input().split()
	xor = 0
	for i in range(n):
		s[i] = int(s[i])
		xor ^= s[i]
	if not xor:
		print('YES')
	else:
		new = 0
		ans = 0
		for i in s:
			new ^= i
			if new == xor:
				new = 0
				ans += 1
		print(['NO', 'YES'][ans > 1])
import sys
sys.setrecursionlimit(2300)

def q3partition():

	def partition():
		if tol % 2:
			return 0
		up = tol
		rec = [[False] * (up + 2) for _ in range(n + 1)]
		rec[0][0] = True
		for i in range(1, n + 1):
			v = l[i - 1]
			for j in range(up + 1):
				if rec[i - 1][j]:
					if v + j <= up:
						rec[i][j + v] = True
					rec[i][j] = True
		return rec[n][tol // 2]

	def ints(x):
		nonlocal tol
		nonlocal gcf
		x = int(x)
		tol += x
		gcf = math.gcd(gcf, x) if gcf != float('inf') else x
		return x
	n = int(input())
	tol = 0
	gcf = float('inf')
	l = list(map(ints, input().split()))
	if partition():
		pos = 1
		for i in l:
			if i // gcf % 2:
				print(1)
				print(pos)
				return
			pos += 1
	else:
		print(0)

def permu(n, r):
	return math.factorial(n) // math.factorial(n - r)

def comb(n, r):
	return math.factorial(n) // math.factorial(r) * math.factorial(n - r)

def calc():
	n = int(input())
	ans = permu(n, n)
	for i in range(1, n + 1):
		ans -= comb(n, i)
	print(ans)

def order():
	for _ in range(int(input())):
		n = int(input())
		odd = []
		even = []
		for i in input().split():
			i = int(i)
			if i % 2:
				odd.append(i)
			else:
				even.append(i)
		print(*odd + even)

def TMTdoc():
	n = int(input())
	l = input().rstrip()
	tts = 0
	tms = 0
	for i in l:
		if i == 'T':
			tts += 1
		else:
			tms += 1
	if tms * 2 == tts:
		nowts = 0
		nowms = 0
		for i in l:
			if i == 'T':
				nowts += 1
			else:
				nowms += 1
				if nowts >= nowms and tms - nowms + 1 <= tts - nowts:
					continue
				return 'NO'
	else:
		return 'NO'
	return 'YES'

def relayrace():

	def solve(n):
		if n:
			s = -1
		else:
			s = 1
		nowmax = -float('inf')
		nowmin = -nowmax
		ans = 0
		for (i, v) in sorted(l, key=lambda x: (x[1], s * int(x[0])), reverse=True):
			i = int(i)
			if i > nowmax:
				nowmax = i
			if i < nowmin:
				nowmin = i
			ans += v * (nowmax - nowmin)
		return ans
	n = int(input())
	l = -1
	ans = 0
	for i in sorted(input().split(), key=lambda x: int(x)):
		if l == -1:
			l = int(i)
		else:
			ans += int(i) - l
	return ans

def relayraces():
	n = int(input())
	l = sorted(map(int, input().split()))
	minv = float('INF')
	minpos = 0
	for i in range(len(l)):
		if i > 0 and 0 <= l[i] - l[i - 1] <= minv:
			minv = l[i] - l[i - 1]
			minpos = i
		if i < n - 1 and l[i + 1] - l[i] <= minv:
			minv = l[i + 1] - l[i]
			minpos = i
	lpos = minpos - 1
	rpos = minpos + 1
	ans = 0
	while lpos >= 0 and rpos < n:
		diffl = -(l[lpos] - l[minpos])
		diffr = l[rpos] - l[minpos]
		if diffl < diffr:
			minpos = lpos
			lpos -= 1
			ans += diffl
		else:
			minpos = rpos
			rpos += 1
			ans += diffr
	if lpos < 0:
		m = l[0]
		for i in range(rpos, n):
			ans += l[i] - m
	else:
		h = l[-1]
		for i in range(minpos, -1, -1):
			ans += h - l[i]
	return ans

def relayracess():

	def recur(l, r):
		if l == r:
			return 0
		if d[l, r] != -1:
			return d[l, r]
		ans = nums[r] - nums[l] + min(recur(l + 1, r), recur(l, r - 1))
		d[l, r] = ans
		return ans
	d = collections.defaultdict(lambda : -1)
	n = int(input())
	nums = sorted(map(int, input().split()))
	return recur(0, n - 1)

def relayracesss():
	n = int(input())
	l = sorted(map(int, input().split()))
	dp = [[0] * n for _ in range(n)]
	for i in range(n - 2, -1, -1):
		for i1 in range(i + 1, n):
			dp[i][i1] = l[i1] - l[i] + min(dp[i + 1][i1], dp[i][i1 - 1])
	return dp[0][n - 1]

def relayracessss():
	n = int(input())
	l = sorted(map(int, input().split()))
	dp = [0] * n
	for le in range(n - 2, -1, -1):
		for ri in range(le + 1, n):
			dp[ri] = l[ri] - l[le] + min(dp[ri], dp[ri - 1])
	return dp[-1]

def binli():
	n = int(input())
	n2 = n * 2
	s = input().rstrip()
	s1 = input().rstrip()
	s2 = input().rstrip()
	posl = [0, 0, 0]
	ans = ''
	while max(posl) < n2:
		l = [[], []]
		l[int(s[posl[0]])].append(0)
		l[int(s1[posl[1]])].append(1)
		l[int(s2[posl[2]])].append(2)
		if len(l[0]) >= 2:
			for i in l[0]:
				posl[i] += 1
			ans += '0'
		else:
			for i in l[1]:
				posl[i] += 1
			ans += '1'
	if posl[0] == n2:
		if posl[1] >= posl[2]:
			ans += s1[posl[1]:]
		else:
			ans += s2[posl[2]:]
	elif posl[1] == n2:
		if posl[0] >= posl[2]:
			ans += s[posl[0]:]
		else:
			ans += s2[posl[2]:]
	elif posl[0] >= posl[1]:
		ans += s[posl[0]:]
	else:
		ans += s1[posl[1]:]
	print(ans)

def almostsort():
	(n, k) = map(int, input().split())
	ul = 2 ** (n - 1)
	if k > ul:
		return [-1]
	permen = []
	bi = bin(k - 1)[2:]
	if bi == '0':
		return range(1, n + 1)
	pos = n - len(bi)
	ans = list(range(1, pos))
	for i in bi:
		permen.append(pos)
		if not int(i):
			ans += permen[::-1]
			permen = []
		pos += 1
	permen.append(n)
	ans += permen[::-1]
	return ans

def q1_2050():
	for i in range(int(input())):
		s = int(input())
		if s % 2050:
			print(-1)
		else:
			ab = 2050
			while ab <= s:
				ab *= 10
			ab //= 10
			c = 0
			while s and s != 1:
				c += s // ab
				s = s % ab
				while s != 1 and s and (s < ab):
					ab //= 10
			print(c)

def q2jog():
	(n, m) = map(int, input().split())
	sortbyval = []
	rowsv = [collections.defaultdict(int) for _ in range(n)]
	for row in range(n):
		for i in input().split():
			i = int(i)
			sortbyval.append([i, row])
			rowsv[row][i] += 1
	sortbyval.sort(key=lambda x: x[0])
	larl = []
	for i in range(0, n * m, m):
		larl.append(sortbyval[i:i + m])
	ans = [[0] * m for _ in range(n)]
	person = 0
	for i in larl:
		for (v, pos) in i:
			ans[pos][person] = v
			rowsv[pos][v] -= 1
			person += 1
			if person == m:
				break
		else:
			continue
		break
	for r in range(n):
		for c in range(m):
			if not ans[r][c]:
				for key in list(rowsv[r].keys()):
					if not rowsv[r][key]:
						rowsv[r].pop(key)
						continue
					rowsv[r][key] -= 1
					ans[r][c] = key
					break
	for i in ans:
		print(*i)

def q3fillomino(n, inp):

	def gorow():
		nonlocal nowp
		nonlocal col
		nonlocal totake
		t = 0
		if nowp and col < n and totake and (not l[col][nowp - 1]):
			for back in range(nowp, -1, -1):
				if l[col][back]:
					nowp += 1
					col += 1
					return t
				if not totake:
					return t
				l[col][back] = i
				totake -= 1
				nowp -= 1
				t = 1
			nowp += 1
			col += 1
		return t
	l = [[0] * i for i in range(1, n + 1)]
	p = 0
	for i in inp:
		totake = int(i)
		nowp = p
		col = p
		while col < n:
			if not totake:
				break
			for _ in range(n - p):
				if not gorow():
					break
			if not totake or col == n or nowp == n:
				break
			l[col][nowp] = i
			totake -= 1
			col += 1
		p += 1
	for i in l:
		print(*i)

def main():
	q3fillomino(int(input()), input().split())
main()


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [[0] * n for i in range(n)]
	for i in range(n):
		ans[i][i] = arr[i]
	for i in range(n):
		x = arr[i]
		(ci, cj) = (i, i)
		for j in range(1, x):
			if cj and ans[ci][cj - 1] == 0:
				cj -= 1
				ans[ci][cj] = x
			else:
				ci += 1
				ans[ci][cj] = x
	for i in range(n):
		print(*ans[i][:i + 1])
solve()


def Solve(P, N, M):
	for (idx, Row) in enumerate(M):
		Row[-1] = P[idx]
		Count = P[idx] - 1
		(row, column) = (idx, idx)
		while Count:
			if M[row][max(0, column - 1)] == 0:
				M[row][column - 1] = P[idx]
				column -= 1
				Count -= 1
			elif M[min(row + 1, N - 1)][column] == 0:
				M[row + 1][column] = P[idx]
				row += 1
				Count -= 1
			else:
				return False
	return M
N = int(input())
P = list(map(int, input().split()))
M = [[0] * (i + 1) for i in range(N)]
ans = Solve(P, N, M)
if not ans:
	print(-1)
else:
	for i in ans:
		print(*i)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	R = N
	C = N
	grid = [[-1 for c in range(C)] for r in range(R)]
	for i in range(N):
		(r, c) = (i, i)
		grid[r][c] = A[i]
		for j in range(A[i] - 1):
			for (dr, dc) in [(0, -1), (1, 0)]:
				nr = r + dr
				nc = c + dc
				if 0 <= nr < R and 0 <= nc < C and (grid[nr][nc] == -1):
					r = nr
					c = nc
					grid[r][c] = A[i]
					break
			else:
				assert False
	return '\n'.join((' '.join((str(x) for x in row if x != -1)) for row in grid))
DEBUG = False
if DEBUG:
	import random
	random.seed(0)
	for _ in range(100):
		N = random.randint(1, 10)
		A = list(range(1, N + 1))
		random.shuffle(A)
		print('tc' + str(_), N, A)
		ans = solve(N, A)
	exit()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = 1
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	if n == 1:
		return 0
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [digit[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [digit[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add_edge(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n, mod=0):
		self.BIT = [0] * (n + 1)
		self.num = n
		self.mod = mod

	def query(self, idx):
		res_sum = 0
		mod = self.mod
		while idx > 0:
			res_sum += self.BIT[idx]
			if mod:
				res_sum %= mod
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		mod = self.mod
		while idx <= self.num:
			self.BIT[idx] += x
			if mod:
				self.BIT[idx] %= mod
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class Matrix:
	mod = 10 ** 9 + 7

	def set_mod(m):
		Matrix.mod = m

	def __init__(self, L):
		self.row = len(L)
		self.column = len(L[0])
		self._matrix = L
		for i in range(self.row):
			for j in range(self.column):
				self._matridigit[i][j] %= Matrix.mod

	def __getitem__(self, item):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		return self._matridigit[i][j]

	def __setitem__(self, item, val):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		self._matridigit[i][j] = val

	def __add__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matridigit[i][j] + other._matridigit[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __sub__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matridigit[i][j] - other._matridigit[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __mul__(self, other):
		if type(other) != int:
			if self.column != other.row:
				raise SizeError('sizes of matrixes are different')
			res = [[0 for j in range(other.column)] for i in range(self.row)]
			for i in range(self.row):
				for j in range(other.column):
					temp = 0
					for k in range(self.column):
						temp += self._matridigit[i][k] * other._matrix[k][j]
					res[i][j] = temp % Matrix.mod
			return Matrix(res)
		else:
			n = other
			res = [[n * self._matridigit[i][j] % Matrix.mod for j in range(self.column)] for i in range(self.row)]
			return Matrix(res)

	def __pow__(self, m):
		if self.column != self.row:
			raise MatrixPowError('the size of row must be the same as that of column')
		n = self.row
		res = Matrix([[int(i == j) for i in range(n)] for j in range(n)])
		while m:
			if m % 2 == 1:
				res = res * self
			self = self * self
			m //= 2
		return res

	def __str__(self):
		res = []
		for i in range(self.row):
			for j in range(self.column):
				res.append(str(self._matridigit[i][j]))
				res.append(' ')
			res.append('\n')
		res = res[:len(res) - 1]
		return ''.join(res)
import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import gcd, log
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
n = int(input())
if 0:
	p = [i + 1 for i in range(n)]
	random.shuffle(p)
else:
	p = li()
ans = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
	need = p[i]
	stack = [(i, i, 1, 0)]
	while stack:
		(px, py, dx, dy) = stack.pop()
		if need:
			ans[px][py] = p[i]
			need -= 1
		else:
			break
		(ldx, ldy) = (-dy, dx)
		if 0 <= px + ldx < n and 0 <= py + ldy < n and (not ans[px + ldx][py + ldy]):
			stack.append((px + ldx, py + ldy, ldx, ldy))
		if 0 <= px + dx < n and 0 <= py + dy < n and (not ans[px + dx][py + dy]):
			stack.append((px + dx, py + dy, dx, dy))
		(rdx, rdy) = (dy, -dx)
		if 0 <= px + rdx < n and 0 <= py + rdy < n and (not ans[px + rdx][py + rdy]):
			stack.append((px + rdx, py + rdy, rdx, rdy))
for i in range(n):
	print(*ans[i][:i + 1])


n = int(input())
array = list(map(int, input().split()))
board = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
	board[i][i] = array[i]
for i in range(n - 1, -1, -1):
	val = board[i][i]
	count = val
	(x, y) = (i, i)
	while count:
		board[x][y] = val
		if x < n - 1 and board[x + 1][y] == 0:
			x += 1
		else:
			y -= 1
		count -= 1
for i in range(n):
	for j in range(i + 1):
		print(board[i][j], end=' ')
	print('')


n = int(input())
a = list(map(int, input().split()))
dp = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	dp[i][i] = a[i]
for i in range(1, n):
	flag = True
	for j in range(n - i):
		if flag:
			if dp[i + j - 1][j] != 1:
				dp[i + j][j] = dp[i + j - 1][j] - 1
			else:
				flag = False
				dp[i + j][j] = dp[i + j][j + 1] - 1
		else:
			dp[i + j][j] = dp[i + j][j + 1] - 1
k = 1
for i in range(1, n):
	for j in range(n - i):
		dp[i + j][j] += k
	k += 1
for i in range(n):
	for j in range(n):
		if dp[i][j]:
			print(dp[i][j], end=' ')
	print()


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)

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

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict
import math
n = I()
s = lint()
l = [[0] * n for i in range(n)]
for i in range(n):
	r = s[i]
	num = r
	k = i
	j = i
	while k < n and num > 0:
		while j >= 0 and num > 0:
			if l[k][j] != 0:
				j += 1
				break
			l[k][j] = r
			num -= 1
			if j == 0:
				break
			else:
				j -= 1
		k += 1
for i in range(n):
	for j in range(n):
		if l[i][j] == 0:
			break
		else:
			print(l[i][j], end=' ')
	print()


n = int(input())
d = [int(aa) for aa in input().split()]
a = [[0 for i in range(n)] for j in range(n)]
for k in range(n):
	j = k
	i = k
	a[i][j] = d[k]
	c = d[i] - 1
	while c > 0:
		if i >= 0 and j - 1 >= 0 and (a[i][j - 1] == 0):
			a[i][j - 1] = d[k]
			c -= 1
			j -= 1
		else:
			a[i + 1][j] = d[k]
			c -= 1
			i += 1
for i in range(n):
	for j in range(i + 1):
		if i != j:
			print(a[i][j], end=' ')
		if i == j:
			print(a[i][j])


def main():
	n = int(input())
	p = list(map(int, input().split()))
	board = []
	for i in range(n):
		board.append([])
		for j in range(i):
			board[-1].append(0)
		board[-1].append(p[i])
	for i in range(n - 1, -1, -1):
		color = p[i]
		remaining = color - 1
		pos = [i, i]
		while remaining:
			if pos[0] + 1 != n:
				if board[pos[0] + 1][pos[1]] == 0:
					board[pos[0] + 1][pos[1]] = color
					pos[0] += 1
					remaining -= 1
					continue
			board[pos[0]][pos[1] - 1] = color
			pos[1] -= 1
			remaining -= 1
	for i in range(n):
		print(*board[i])
main()


import sys
n = int(input())
arr = list(map(int, input().split()))
if n == 1:
	print(1)
	sys.exit()
ans = [[-1 for i in range(n)] for j in range(n)]
for i in range(n):
	ans[i][i] = arr[i]
r = ans[0][0] - 1
for i in range(1, r + 1):
	ans[i][0] = arr[0]
for i in range(1, n):
	r = i
	c = i
	for j in range(1, arr[i]):
		if c >= 1 and ans[r][c - 1] == -1:
			ans[r][c - 1] = arr[i]
			c -= 1
		elif r + 1 <= n - 1 and ans[r + 1][c] == -1:
			ans[r + 1][c] = arr[i]
			r += 1
		else:
			print(-1)
			sys.exit()
for i in range(n):
	for j in ans[i]:
		if j != -1:
			print(j, end=' ')
	print()


n = int(input())
dia = list(map(int, input().split()))
temp = [0] * n
final = [list(temp) for _ in range(n)]
for i in range(n):
	k = dia[i]
	(x, y) = (i, i)
	while y > -1 and x < n:
		if k == 0:
			break
		if final[x][y] == 0:
			final[x][y] = dia[i]
			if y > 0:
				if final[x][y - 1] == 0:
					y -= 1
			k -= 1
		else:
			x += 1
for i in range(n):
	print(*final[i][:i + 1])


from sys import stdin
input = stdin.buffer.readline
n = int(input())
arr = [int(x) for x in input().split()]
dp = [[-1 for i in range(n)] for j in range(n)]
for i in range(n):
	dp[i][i] = arr[i]
vis = [1] * (n + 1)
for i in range(n):
	x = dp[i][i]
	j = i
	k = i
	while vis[x] < x:
		if k - 1 >= 0 and dp[j][k - 1] == -1:
			dp[j][k - 1] = x
			vis[x] = vis[x] + 1
			k = k - 1
		elif j + 1 < n and dp[j + 1][k] == -1:
			dp[j + 1][k] = x
			vis[x] = vis[x] + 1
			j = j + 1
for i in range(n):
	print(*dp[i][:i + 1])


n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
	l.append([0] * (i + 1))
for x in range(n):
	i = j = x
	c = a[x]
	while c > 0:
		l[i][j] = a[x]
		if j > 0 and l[i][j - 1] == 0:
			j -= 1
		else:
			i += 1
		c -= 1
for y in range(n):
	print(*l[y])


def main():
	N = int(input())
	P = list(map(int, input().split()))
	ans = [[None for j in range(N)] for i in range(N)]
	for i in range(N):
		ans[i][i] = P[i]
		r = i
		c = i
		for j in range(P[i] - 1):
			if c > 0 and (not ans[r][c - 1]):
				c -= 1
			else:
				r += 1
			ans[r][c] = P[i]
	for row in ans:
		for col in row:
			if not col:
				continue
			print(col, end=' ')
		print()
main()


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import itertools
import bisect
import heapq

def main():
	pass
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 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 primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

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 maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	for i in range(2, n + 1):
		if primes[i]:
			for j in range(i + i, n + 1, i):
				primes[j] = False
	p = []
	for i in range(0, n + 1):
		if primes[i]:
			p.append(i)
	return p

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

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s

def rec(i, j, num, cnt):
	if cnt == 0:
		return mat
	if j == 0 or mat[i][j - 1] != -1:
		mat[i + 1][j] = num
		cnt -= 1
		rec(i + 1, j, num, cnt)
	else:
		mat[i][j - 1] = num
		cnt -= 1
		rec(i, j - 1, num, cnt)
n = int(input())
l = list(map(int, input().split()))
mat = [[-1] * (i + 1) for i in range(0, n)]
for i in range(0, n):
	mat[i][i] = l[i]
for i in range(0, n):
	rec(i, i, mat[i][i], mat[i][i] - 1)
for i in mat:
	print(*i)


import sys, heapq, math
from collections import defaultdict, deque
input = sys.stdin.readline

def solve(row, col, val):
	for i in range(val - 1):
		if col - 1 >= 0 and grid[row][col - 1] == -1:
			grid[row][col - 1] = val
			col -= 1
		else:
			grid[row + 1][col] = val
			row += 1
n = int(input())
l = list(map(int, input().split()))
grid = [[-1 for _ in range(n)] for _ in range(n)]
for i in range(n):
	grid[i][i] = l[i]
for i in range(n):
	solve(i, i, grid[i][i])
for i in range(n):
	for j in range(i + 1):
		print(grid[i][j], end=' ')
	print()


n = int(input())
l = list(map(int, input().split()))
mat = [[0] * i for i in range(1, n + 1)]
for i in range(n):
	(ox, oy) = (i, i)
	m = l[i]
	c = m
	mat[ox][oy] = m
	c -= 1
	x = ox
	y = oy
	while c > 0:
		if y - 1 >= 0 and mat[x][y - 1] == 0:
			mat[x][y - 1] = m
			y -= 1
		elif x + 1 <= n - 1 and mat[x + 1][y] == 0:
			mat[x + 1][y] = m
			x += 1
		else:
			ox += 1
			x = ox
			y = oy
			mat[x][y] = m
		c -= 1
for i in range(n):
	for j in range(i + 1):
		print(mat[i][j], end=' ')
	print()


n = int(input())
inp = input().split()
arr = []
for i in inp:
	arr.append(int(i))
dp = [[0 for i in range(n)] for i in range(n)]
i = 0
while i < n:
	dp[i][i] = arr[i]
	i += 1
k = 0
ind = True
while k < n and ind == True:
	p = arr[k]
	count = p - 1
	x = k
	y = k
	while count:
		if y - 1 >= 0 and dp[x][y - 1] == 0:
			dp[x][y - 1] = p
			y -= 1
			count -= 1
		elif x + 1 < n and dp[x + 1][y] == 0:
			dp[x + 1][y] = p
			count -= 1
			x += 1
		else:
			ind = False
			break
	k += 1
if ind == True:
	k = 0
	while k < n:
		m = 0
		while m <= k:
			print(dp[k][m], end=' ')
			m += 1
		print()
		k += 1
else:
	print(-1)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

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

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	b = list(map(int, input().split()))
	a = [[-1] * n for i in range(n)]
	for i in range(n):
		a[i][i] = b[i]
	prefer = [(1, 0), (0, -1), (-1, 0), (0, 1)]
	pos = True
	j = n - 1
	while j >= 0:
		cur = (j, j)
		for i in range(a[j][j] - 1):
			found = False
			for (p, q) in prefer:
				(x, y) = cur
				if 0 <= x + p < n and 0 <= y + q < n and (a[x + p][y + q] == -1):
					found = True
					a[x + p][y + q] = a[j][j]
					cur = (x + p, y + q)
					break
			if not found:
				pos = False
				break
		if not pos:
			break
		j -= 1
	if not pos:
		print(-1)
		continue
	for i in range(n):
		print(*a[i][:i + 1])


n = int(input())
l = list(map(int, input().split()))
ans = [[0] * n for i in range(n)]
for i in range(n):
	ans[i][i] = l[i]
for i in range(n):
	row = i
	col = i - 1
	val = ans[i][i]
	while val != 1:
		if col >= 0 and ans[row][col] == 0:
			ans[row][col] = ans[i][i]
			col -= 1
			val -= 1
		elif col < 0 or ans[row][col] != 0:
			col += 1
			row += 1
for i in range(n):
	print(' '.join(map(str, ans[i][0:i + 1])))


import sys

def input():
	return sys.stdin.readline().rstrip()

def slv():
	n = int(input())
	perm = list(map(int, input().split()))
	perms = []
	for i in range(n):
		if i == 0:
			perms.append(perm)
		else:
			perms.append([0] * (n - i))
	ADDITION = [0] * (n + 1)
	for i in range(n):
		if i == 0:
			for elem in perms[i]:
				ADDITION[elem] += 1
			continue
		else:
			for (idx, v) in enumerate(perms[i - 1]):
				if ADDITION[v] == v:
					continue
				else:
					l = idx - 1
					r = idx
					if l >= 0 and perms[i][l] == 0:
						perms[i][l] = v
						ADDITION[v] += 1
						continue
					else:
						assert perms[i][r] == 0
						perms[i][r] = v
						ADDITION[v] += 1
	ans = [[] for i in range(n)]
	for i in range(n):
		for j in range(i, n):
			ans[j].append(perms[i][j - i])
	for i in range(n):
		ans[i].reverse()
		print(*ans[i])
	return

def main():
	t = 1
	for i in range(t):
		slv()
	return
main()


n = int(input())
gr = []
a = list(map(int, input().split()))
for i in range(n):
	t = [''] * n
	t[i] = a[i]
	gr.append(t)
for i in range(n):
	(x, y) = (i, i)
	d = 0
	while d != a[i] - 1:
		if x > 0 and gr[y][x - 1] == '':
			gr[y][x - 1] = a[i]
			x -= 1
			d += 1
		elif y < n - 1 and gr[y + 1][x] == '':
			gr[y + 1][x] = a[i]
			y += 1
			d += 1
		else:
			print(-1)
			exit()
for a in gr:
	print(*a)


a = int(input())
z = list(map(int, input().split()))
fin = [[0 for i in range(a)] for i in range(a)]
glag = 0
for i in range(len(z)):
	cnt = 0
	x = i
	y = i
	fin[x][y] = z[i]
	cnt += 1
	flag = 0
	t1 = 0
	while cnt < z[i]:
		if x == 0 and y == len(z) - 1:
			flag = 1
			break
		if x == 0 and fin[y + 1][x] != 0:
			flag = 1
			break
		if y == len(z) - 1 and fin[y][x - 1] != 0:
			flag = 1
			break
		if t1 == 0:
			x -= 1
			if x < 0:
				x += 1
				t1 = 1
				continue
			if fin[y][x] != 0:
				t1 = 1
				x += 1
				continue
			fin[y][x] = z[i]
			cnt += 1
			continue
		if t1 == 1:
			y += 1
			if y == len(z):
				t1 = 0
				y -= 1
				continue
			if fin[y][x] != 0:
				t1 = 0
				y -= 1
				continue
			fin[y][x] = z[i]
			t1 = 0
			cnt += 1
			continue
		flag = 1
		break
	if flag == 1:
		glag = 1
		break
if glag == 1:
	print(-1)
	exit(0)
for i in range(len(z)):
	for j in range(i + 1):
		print(fin[i][j], end=' ')
	print(' ')


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 = int(input())
l = list(map(int, input().split()))
l1 = [[0] * n for i in range(n)]
for i in range(n):
	c = l[i]
	x = i
	y = x
	while c:
		for j in range(y, -1, -1):
			if l1[x][j]:
				j += 1
				break
			if not c:
				break
			l1[x][j] = l[i]
			c -= 1
		y = j
		x += 1
l2 = []
for i in l1:
	l3 = []
	for j in i:
		if j == 0:
			break
		l3.append(j)
	l2.append(l3)
for i in l2:
	print(*i)


import os
import sys
from collections import Counter
from io import BytesIO, IOBase
from math import gcd, inf, sqrt, ceil, floor

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

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

def getFactorization(x):
	ret = set()
	while x != 1:
		ret.add(spf[x])
		x = x // spf[x]
	return ret

def printDivisors(n):
	i = 2
	z = [1, n]
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				z.append(i)
			else:
				z.append(i)
				z.append(n // i)
		i = i + 1
	return z

def create(n, x, f):
	pq = len(bin(n)[2:])
	if f == 0:
		tt = min
	else:
		tt = max
	dp = [[inf] * n for _ in range(pq)]
	dp[0] = x
	for i in range(1, pq):
		for j in range(n - (1 << i) + 1):
			dp[i][j] = tt(dp[i - 1][j], dp[i - 1][j + (1 << i - 1)])
	return dp

def enquiry(l, r, dp, f):
	if l > r:
		return inf if not f else -inf
	if f == 1:
		tt = max
	else:
		tt = min
	pq1 = len(bin(r - l + 1)[2:]) - 1
	return tt(dp[pq1][l], dp[pq1][r - (1 << pq1) + 1])

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	x = []
	for i in range(2, n + 1):
		if prime[i]:
			x.append(i)
	return x

def main():
	if True:
		n = int(input())
		a = [int(X) for X in input().split()]
		matx = [[0 for i in range(n)] for j in range(n)]
		an = 1
		for i in range(n):
			matx[i][i] = a[i]
		for j in range(n):
			pp = 1
			xx = [j, j]
			while pp < a[j]:
				if xx[1] > 0 and matx[xx[0]][xx[1] - 1] == 0:
					xx[1] -= 1
					matx[xx[0]][xx[1]] = a[j]
					pp += 1
				elif xx[0] + 1 < n and matx[xx[0] + 1][xx[1]] == 0:
					xx[0] += 1
					matx[xx[0]][xx[1]] = a[j]
					pp += 1
				else:
					an = -1
					break
		if an == 1:
			for j in range(n):
				print(*matx[j][:j + 1])
		else:
			print(-1)
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')
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

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

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

def modInverse(b):
	g = gcd(b, mod)
	if g != 1:
		return -1
	else:
		return pow(b, mod - 2, mod)

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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	n = int(inp())
	a = lis()
	g = [[-1] * n for i in range(n)]
	for i in range(n):
		currx = i
		curry = i
		g[currx][curry] = a[i]
		cnt = 1
		while cnt != a[i]:
			while curry - 1 >= 0 and g[currx][curry - 1] == -1 and (cnt != a[i]):
				curry -= 1
				g[currx][curry] = a[i]
				cnt += 1
			if cnt != a[i]:
				currx += 1
				g[currx][curry] = a[i]
				cnt += 1
	for i in range(n):
		print(' '.join((str(g[i][j]) for j in range(i + 1))))
testcase(1)


n = int(input())
a = [int(i) for i in input().split()]
m = []
f = 1
for i in range(n):
	m += [[-1] * n]
for i in range(n - 1, -1, -1):
	l = a[i]
	b = a[i]
	(x, y) = (i, i)
	for j in range(a[i]):
		m[x][y] = b
		if j == a[i]:
			break
		if x + 1 >= y and x + 1 < n and (m[x + 1][y] == -1):
			x += 1
		elif x >= y + 1 and y + 1 < n and (m[x][y + 1] == -1):
			y += 1
		elif y - 1 >= 0 and m[x][y - 1] == -1 and (x >= y - 1):
			y -= 1
		elif x - 1 >= 0 and m[x - 1][y] == -1 and (x - 1 >= y):
			x -= 1
		elif j != a[i] - 1:
			f = 0
			break
	if not f:
		break
if not f:
	print(-1)
else:
	for i in range(n):
		print(*m[i][:i + 1])


from sys import stdin
input = stdin.readline
n = int(input())
p = list(map(int, input().split()))
ans = [[0] * i for i in range(1, n + 1)]
use = [[0] * i for i in range(1, n + 1)]
for i in range(n):
	y = i
	x = i
	ans[y][x] = p[i]
	use[y][x] = True
	res = p[i] - 1
	while res > 0:
		if x > 0 and (not use[y][x - 1]):
			ans[y][x - 1] = p[i]
			use[y][x - 1] = True
			res -= 1
			x -= 1
		elif y + 1 < n and (not use[y + 1][x]):
			ans[y + 1][x] = p[i]
			use[y + 1][x] = True
			res -= 1
			y += 1
for i in range(n):
	print(*ans[i])


import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue
import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [[0 for i in range(n)] for j in range(n)]
	for i in range(n):
		ans[i][i] = a[i]
	for i in range(n):
		lp = a.index(i + 1)
		a.pop(lp)
		for j in range(n - i - 1):
			ans[i + 1 + j][j] = a[j]
	for i in range(n):
		for j in range(n):
			if ans[i][j] != 0:
				print(ans[i][j], end=' ')
		print()


import math

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

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

def I():
	return int(input())

def S():
	return input()

def twoD(row):
	return [L() for i in range(row)]

def fill(val, size):
	return [val] * size

def strToList(s):
	return [s[i] for i in range(len(s))]

def printList(a):
	[print(i, end=' ') for i in a]
	print()

def binary(a):
	return bin(a)[2:]

def decimal(s):
	a = 0
	n = len(s)
	for i in range(n - 1, -1, -1):
		a += int(s[i]) * 2 ** (n - 1 - i)
	return a

def google(a, b):
	print('')

def show(x):
	for i in x:
		for j in i:
			print(j, end=' ')
		print()
n = I()
x = L()
a = [['' for i in range(n)] for j in range(n)]
for i in range(n):
	a[i][i] = x[i]
for k in range(n):
	i = k
	j = k - 1
	l = a[k][k] - 1
	while l:
		if j < 0 or a[i][j] != '':
			i += 1
			j += 1
		else:
			a[i][j] = a[k][k]
			j -= 1
			l -= 1
show(a)


import os, 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))
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *
from collections import deque as dq
n = ii1()
arr = iia()
dp = [[None] * n for i in range(n)]
for i in range(n):
	dp[i][i] = arr[i] - 1

def trav(i, j, rem, val):
	if rem == 0:
		return
	if j - 1 >= 0 and dp[i][j - 1] == None:
		dp[i][j - 1] = val
		trav(i, j - 1, rem - 1, val)
	elif i + 1 >= 0 and dp[i + 1][j] == None:
		dp[i + 1][j] = val
		trav(i + 1, j, rem - 1, val)
	else:
		return
for i in range(n):
	trav(i, i, arr[i] - 1, arr[i] - 1)
flag = True
for i in range(n):
	for j in range(i + 1):
		if dp[i][j] == None:
			flag = False
		else:
			dp[i][j] += 1
if flag:
	for i in range(n):
		print(*dp[i][:i + 1])
else:
	print(-1)


from collections import deque, Counter
from collections import defaultdict as dfd
from bisect import bisect, bisect_left
from math import sqrt, gcd, ceil, factorial
from heapq import heapify, heappush, heappop
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float('inf')
ans_ = []

def nin():
	return int(input())

def ninf():
	return int(file.readline())

def st():
	return input().strip()

def stf():
	return file.readline().strip()

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

def readf():
	return list(map(int, file.readline().strip().split()))

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

def readffl():
	return list(map(float, file.readline().strip().split()))

def solve():
	n = nin()
	arr = read()
	mat = [[0] * n for i in range(n)]
	for i in range(n):
		x = y = i
		for j in range(arr[i]):
			mat[x][y] = arr[i]
			if y == 0 or mat[x][y - 1]:
				x += 1
			else:
				y -= 1
	for i in range(n):
		ans_.append(mat[i][:i + 1])
solve()
for i in ans_:
	print(*i)


n = int(input())
arr = list(map(int, input().split()))
mat = [[-1 for x in range(n)] for x in range(n)]
for i in range(n - 1, -1, -1):
	num = arr[i]
	x = i
	y = i
	for i in range(num):
		mat[x][y] = num
		if x != n - 1:
			if mat[x + 1][y] == -1:
				x = x + 1
				y = y
			else:
				x = x
				y = y - 1
		else:
			x = x
			y = y - 1
for i in range(n):
	for j in range(i + 1):
		print(mat[i][j], end=' ')
	print()


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	stairs = [[0] * i for i in range(1, n + 1)]

	def free(x, y):
		return 0 <= x <= n - 1 and 0 <= y < x and (stairs[x][y] == 0)
	for (i, num) in enumerate(l):
		left = num
		first = True
		stack = [(i, i)]
		while left and stack:
			(x, y) = stack.pop()
			if first:
				first = False
			elif not free(x, y):
				continue
			stairs[x][y] = num
			stack.append((x - 1, y))
			stack.append((x, y + 1))
			stack.append((x + 1, y))
			stack.append((x, y - 1))
			left -= 1
		if left:
			print(-1)
			for level in stairs:
				print(*level)
			return
	for level in stairs:
		print(*level)
solve()


n = int(input())
arr = list(map(int, input().split()))
ans = []
for i in range(n):
	ans.append([0] * i + [arr[i]])
for i in range(n):
	num = arr[i] - 1
	(x, y) = (i, i)
	while num > 0:
		if 0 <= y - 1 < i:
			if ans[x][y - 1] == 0:
				ans[x][y - 1] = arr[i]
				y = y - 1
				num = num - 1
			elif i <= x + 1 < n:
				if ans[x + 1][y] == 0:
					ans[x + 1][y] = arr[i]
					x = x + 1
					num = num - 1
		elif i <= x + 1 < n:
			if ans[x + 1][y] == 0:
				ans[x + 1][y] = arr[i]
				x = x + 1
				num = num - 1
for ar in ans:
	print(*ar)


n = int(input())
diagonal = list(map(int, input().split()))
matrix = [[None for _ in range(n)] for _ in range(n)]
for i in range(n):
	matrix[i][i] = diagonal[i]
cur = 1
row = 0
while row < n:
	flag = True
	for i in range(n - row):
		temp = matrix[row + i][i]
		if temp == cur:
			flag = False
			continue
		if flag:
			matrix[row + i + 1][i] = temp
		else:
			matrix[row + i][i - 1] = temp
	row += 1
	cur += 1
for i in range(n):
	print(*matrix[i][:i + 1])


import sys, os.path

def valid(x, y, n):
	if x < 0 or y < 0:
		return False
	if x >= n or y >= n:
		return False
	if grid[x][y] != -1:
		return False
	return True

def dfs(x, y, dig, n):
	if cnt[0] == 0:
		return
	if valid(x, y, n):
		grid[x][y] = dig
		cnt[0] -= 1
	for i in range(3):
		nx = x + dx[i]
		ny = y + dy[i]
		if valid(nx, ny, n):
			dfs(nx, ny, dig, n)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
dx = [0, 1, -1]
dy = [-1, 0, 0]
n = int(input())
a = list(map(int, input().split()))
cnt = [0]
grid = [[-1 for j in range(n)] for i in range(n)]
for i in range(n):
	grid[i][i] = a[i]
for i in range(n):
	cnt[0] = a[i] - 1
	dfs(i, i, a[i], n)
for i in range(n):
	temp = []
	for j in range(i + 1):
		temp.append(grid[i][j])
	print(*temp)


n = int(input())
l = list(map(int, input().split()))
gr = [[-1] * n for _ in range(n)]
for i in range(n):
	(p1, p2) = (i, i)
	L = l[i]
	while l[i] > 0:
		gr[p1][p2] = L
		l[i] -= 1
		if p2 - 1 >= 0 and gr[p1][p2 - 1] == -1:
			p2 -= 1
		else:
			p1 += 1
for i in range(n):
	for j in range(n):
		if j <= i:
			print(gr[i][j], end=' ')
	print()


n = int(input())
P = list(map(int, input().split()))
result = [[0] * n for i in range(n)]
directions = [(-1, 0), (0, -1), (1, 0), (0, 1)]
directions.reverse()
for i in range(n):
	regionIndex = P[i]
	result[i][i] = regionIndex
	count = regionIndex
	regionStack = [(i, i)]
	while count:
		(x, y) = regionStack.pop()
		result[x][y] = regionIndex
		count -= 1
		for (dx, dy) in directions:
			nx = x + dx
			ny = y + dy
			if 0 <= nx < n and 0 <= ny < n and (nx >= ny) and (result[nx][ny] == 0):
				regionStack.append((nx, ny))
for i in range(n):
	print(*result[i][:i + 1])


def get_input(first=False):
	l = [int(e) for e in input().split()]
	if first:
		return l[0]
	return l

def next_diagonal(diag, n):
	k = n - len(diag) + 1
	diag.pop(diag.index(k))
	return diag

def fill_sol(sol, diag, n):
	o = n - len(diag)
	for (i, d) in enumerate(diag):
		sol[i + o][i] = d
n = get_input(True)
diag = get_input()
sol = [[None] * i for i in range(1, n + 1)]
fill_sol(sol, diag, n)
for _ in range(n - 1):
	diag = next_diagonal(diag, n)
	fill_sol(sol, diag, n)
for b in sol:
	print(*b)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
bo = []
for i in range(n):
	temp = [0 for _ in range(i)]
	temp.append(a[i])
	bo.append(temp)
flag = 1
for i in range(n):
	key = bo[i][i]
	(posi, posj) = (i, i)
	count = 1
	while count < key:
		if posj - 1 >= 0 and bo[posi][posj - 1] == 0:
			bo[posi][posj - 1] = key
			posj -= 1
			count += 1
		elif posi + 1 < n and bo[posi + 1][posj] == 0:
			bo[posi + 1][posj] = key
			posi += 1
			count += 1
		else:
			flag = 0
			print(-1)
if flag:
	for i in range(n):
		print(*bo[i])


n = int(input())
diag = list(map(int, input().split()))
dep = [(-1, 0), (0, -1), (1, 0)]
rep = [[0 for i in range(j + 1)] for j in range(n)]

def valid(i, j):
	if j > i:
		return False
	if i < 0 or j < 0:
		return False
	if rep[i][j] > 0:
		return False
	return True
possible = True
for i in range(n):
	x = diag[i]
	rep[i][i] = x
	(k, l) = (i, i)
	for _ in range(x - 1):
		found = False
		for (dk, dl) in dep:
			if valid(k + dk, l + dl):
				found = True
				k = k + dk
				l = l + dl
				rep[k][l] = x
			if found:
				break
		if not found:
			possible = False
			break
	if not possible:
		break
if possible:
	for repi in rep:
		print(*repi)
else:
	print(-1)


def is_left_possible(x, y, g):
	if y == 0:
		return False
	if g[x][y - 1] == ' ':
		return True
	return False
n = int(input())
grid = []
for i in range(n):
	grid.append([' ' for e in range(n)])
a = list(map(int, input().split()))
for i in range(n):
	ele = a[i]
	left = ele
	grid[i][i] = str(ele)
	left -= 1
	(x, y) = (i, i)
	while left:
		if is_left_possible(x, y, grid):
			y -= 1
		else:
			x += 1
		grid[x][y] = str(ele)
		left -= 1
for i in range(n):
	print(*grid[i])