#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int n,m;
scanf("%d",&m);
string ch;
cin >> ch;
sort(ch.begin(),ch.end());
n=0;
do
{
cout << ch <<endl;
n++;
}while(next_permutation(ch.begin(),ch.end()));
cout <<n;
return 0;
}
"next_permutation" is very cool