def print_data():
for i in data:
print(f"{i:>5}", end="")
print()
def f(i):
if i == n:
return
data[0], data[i] = data[i], data[0]
data[1:] = sorted(data[1:])
print_data()
for x in range(1, len(data)):
for y in range(x + 1, len(data)):
data[x], data[y] = data[y], data[x]
print_data()
data.sort()
f(i + 1)
n = int(input())
data = [i for i in range(1, n+1)]
f(0)