Олимпиадный тренинг

Задача 27024. password output


Задача

Темы: Перестановки
Once, at a computer science lesson, Lesha Vasilyev was given a special task with permutations for Damir. 
Lesha really liked this idea, so he took the laptop from the shelf, turned it on and noticed that Anton Vitalyevich had changed his passwords.
Lesha knows that the password contains all the characters of the maximum lexicographic string S, but he does not have much time to search, the tasks must be submitted in 40 minutes!
Help Lesha and write a program that can display all password options for the string S.
Passwords are displayed in alphabetical order.

Enter Output
lesha
ahs
ash
has
hsa
sah
sha


(с) Alexander Mamaev