# Problemrosalind练习题十八
# A permutation of length n is an ordering of the positive integers {1,2,…,n}. For example, π=(5,3,2,1,4) is a permutation of length 5.
# Given: A positive integer n≤7.
# Return: The total number of permutations of length n, followed by a list of all such permutations (in any order).
# Sample Dataset
# 3
# Sample Output
# 6
# 1 2 3
# 1 3 2
# 2 1 3
# 2 3 1
# 3 1 2
# 3 2 1
# 这个题目的目的是输出长度为n的排列的个数以及所有排列。
import itertools
n = 3 # 读取输入n
perms = list(itertools.permutations(range(1, n+1))) # 求出所有排列
print(len(perms)) # 输出排列个数
for perm in perms: # 输出每个排列
print(" ".join(str(x) for x in perm))