Problem:
Score : 400 points

Problem Statement

In this problem, we only consider strings consisting of lowercase English letters.

Strings s and t are said to be isomorphic when the following conditions are satisfied:

|s| = |t| holds.

For every pair i, j, one of the following holds:

s_i = s_j and t_i = t_j.

s_i \neq s_j and t_i \neq t_j.

For example, abcac and zyxzx are isomorphic, while abcac and ppppp are not.

A string s is said to be in normal form when the following condition is satisfied:

For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.

For example, abcac is in normal form, but zyxzx is not since it is isomorphic to abcac, which is lexicographically smaller than zyxzx.

You are given an integer N.
Print all strings of length N that are in normal form, in lexicographically ascending order.

Constraints

1 \leq N \leq 10

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Assume that there are K strings of length N that are in normal form: w_1, \ldots, w_K in lexicographical order.
Output should be in the following format:

w_1
:
w_K

Sample Input 1

1

Sample Output 1

a

Sample Input 2

2

Sample Output 2

aa
ab

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=1000000007;
constexpr ll mod=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll n;
V<string> s;
void dfs(string str,int cnt,char bfo){
    if(cnt==n){
        s.emplace_back(str);
        return ;
    }
    char d=char((bfo-'a'+1)+'a');
    //cout<<d<<endl;
    str.push_back('a');
    for(char i='a';i<=d;i++){
        str[cnt]=i;
        dfs(str,cnt+1,i);
    }
}
int main(){
cin>>n;
if(n<3)return 0;
string t="a";
dfs(t,1,'a');
sort(all(s));
int cnt=1;
V<pair<string,int>> dat;
for(int i=0;i<s.size();i++){
    V<int> c(n,0);
    cnt=1;string p={};
    for(int j=0;j<n;j++){
        if(c[s[i][j]-'a']==0)c[s[i][j]-'a']=cnt++;
        p.push_back(char(c[s[i][j]-'a']+'0'));
    }
    dat.emplace_back(p,i);
}
sort(all(dat));
string bfo="**";
V<string> ans;
for(int i=0;i<dat.size();i++){
    if(bfo!=dat[i].fi){ans.emplace_back(s[dat[i].se]);bfo=dat[i].fi;}
}
sort(all(ans));
for(string &str:ans){
    cout<<str<<"\n";
}
}