https://www.acmicpc.net/problem/10974
import itertools n = int(input()) arr = [] for i in range(n): arr.append(i+1) res = itertools.permutations(arr, n) for i in list(res): for j in i: print(j, end=" ") print()