Skip to content
UPEEC

All Permutations

Medium#recursion#backtracking· solved by 0 · time limit 2.0 s

Print every distinct permutation of the string in lexicographic (dictionary) order.

Input

One lowercase word.

Output

One permutation per line.

Constraints

1 to 7 letters.

Sample 1

Input

abc

Output

abc
acb
bac
bca
cab
cba

Sample 2

Input

aab

Output

aab
aba
baa

Sign in or join free to run and submit your solution.