from itertools import permutations string,n = input(“Enter string and size”).split() print(*[''.join(i) for i in permutations(sorted(string),int(n))],sep=' ')