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)

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>

#define SIZE 100005
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
using namespace std;


int main()
{	
	
	ll N;
	scanf("%lld", &N);
	char S[11]={'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'};
	char ans[100];
	ll nowmax1=0, nowmax2=0, nowmax3=0, nowmax4=0, nowmax5=0, nowmax6=0, nowmax7=0, nowmax8=0, nowmax9=0, nowmax10=0;
	for(ll a1=0;a1<=0;a1++)
	{	nowmax1=a1+1;
	if(N>=2){
		for(ll a2=0;a2<=nowmax1;a2++)
		{	nowmax2=max(a2+1, nowmax1);
	if(N>=3){
		for(ll a3=0;a3<=nowmax2;a3++)
		{	nowmax3=max(a3+1, nowmax2);
	if(N>=4){
		for(ll a4=0;a4<=nowmax3;a4++)
		{	nowmax4=max(a4+1, nowmax3);
	if(N>=5){
		for(ll a5=0;a5<=nowmax4;a5++)
		{	nowmax5=max(a5+1, nowmax4);
	if(N>=6){
		for(ll a6=0;a6<=nowmax5;a6++)
		{	nowmax6=max(a6+1, nowmax5);
	if(N>=7){
		for(ll a7=0;a7<=nowmax6;a7++)
		{	nowmax7=max(a7+1, nowmax6);
	if(N>=8){
		for(ll a8=0;a8<=nowmax7;a8++)
		{	nowmax8=max(a8+1, nowmax7);
	if(N>=9){
		for(ll a9=0;a9<=nowmax8;a9++)
		{	nowmax9=max(a9+1, nowmax8);
	if(N>=10){
		for(ll a10=0;a10<=nowmax9;a10++)
		{	nowmax10=max(a10+1, nowmax9);
			ans[0]=S[a1];
			ans[1]=S[a2];
			ans[2]=S[a3];
			ans[3]=S[a4];
			ans[4]=S[a5];
			ans[5]=S[a6];
			ans[6]=S[a7];
			ans[7]=S[a8];
			ans[8]=S[a9];
			ans[9]=S[a10];
			
			printf("%s \n", ans);
			
		}
		}
		else
		{
			ans[0]=S[a1];
			ans[1]=S[a2];
			ans[2]=S[a3];
			ans[3]=S[a4];
			ans[4]=S[a5];
			ans[5]=S[a6];
			ans[6]=S[a7];
			ans[7]=S[a8];
			ans[8]=S[a9];
			printf("%s \n", ans);
		}
			}
		}
		else
		{
			ans[0]=S[a1];
			ans[1]=S[a2];
			ans[2]=S[a3];
			ans[3]=S[a4];
			ans[4]=S[a5];
			ans[5]=S[a6];
			ans[6]=S[a7];
			ans[7]=S[a8];
			
			printf("%s \n", ans);
		}	}
		}
		else
		{
			ans[0]=S[a1];
			ans[1]=S[a2];
			ans[2]=S[a3];
			ans[3]=S[a4];
			ans[4]=S[a5];
			ans[5]=S[a6];
			ans[6]=S[a7];
			printf("%s \n", ans);
		}	}
		}
		else
		{
			ans[0]=S[a1];
			ans[1]=S[a2];
			ans[2]=S[a3];
			ans[3]=S[a4];
			ans[4]=S[a5];
			ans[5]=S[a5];
			printf("%s \n", ans);
		}	}
		}
		else
		{
			ans[0]=S[a1];
			ans[1]=S[a2];
			ans[2]=S[a3];
			ans[3]=S[a4];
			ans[4]=S[a5];
			printf("%s \n", ans);
		}	}
		}
		else
		{
			ans[0]=S[a1];
			ans[1]=S[a2];
			ans[2]=S[a3];
			ans[3]=S[a4];
			printf("%s \n", ans);
		}	}
		}
		else
		{
			ans[0]=S[a1];
			ans[1]=S[a2];
			ans[2]=S[a3];
			printf("%s \n", ans);
		}
		}
		}
		else
		{
			ans[0]=S[a1];
			ans[1]=S[a2];
			printf("%s \n", ans);
		}
		
		}
		}
		else
		{
			ans[0]=S[a1];
			printf("%s \n", ans);
		}
		}

		
		
}