#include <bits/stdc++.h>
using namespace std;
void phoneKeypad(string s,string input)
{ if(input.compare(s)==0)
{return;
}
cout<<input<<endl;
next_permutation(input.begin(),input.end());
return phoneKeypad(s,input);
}
int main()
{
string input;
cin >> input;
string s=input;
sort(s.begin(),s.end());
next_permutation(input.begin(),input.end());
phoneKeypad(s,input);
return 0;
}