fork(1) download
  1. # your code goes here
  2. import sys
  3. from itertools import permutations
  4.  
  5. def perm(string:str, num:int):
  6. npr = list(permutations(string,len(string)))
  7. try:
  8. return "".join(npr[num-1])
  9. except:
  10. return "No permutation"
  11.  
  12. while strings := sys.stdin.readline():
  13. try:
  14. string, num = strings.split()
  15. print(f"{string} {num} = {perm(string,int(num))}")
  16. except:
  17. break
Success #stdin #stdout 0.63s 507668KB
stdin
ghekqsaswl 277
stdout
ghekqsaswl 277 = ghekaswqsl