n = int(input())
arr = sorted(range(1, n + 1))
nums = [0] * n
undo = [True] * n
def dp(i):
if i >= n:
print(' '.join([str(itm) for itm in nums]))
return
j = 0
while j < n:
if undo[j]:
undo[j] = False
nums[i] = arr[j]
dp(i + 1)
undo[j] = True
while j < n - 1 and arr[j] == arr[j + 1]: j += 1 # 本次递归num[i] 对于未使用的同值 只使用头一个
j += 1
dp(0)