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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public class Node
	{
		public char Chara{get;set;}
		
		public List<Node> Children{get;set;}
	}
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		
		var k = new List<string>();
		var par = new Node(){Chara='a', Children=new List<Node>()};
		BFS(par, 0, n);
		
		var ms = new Stack<char>();
		WriteDown(par, ms, n);
		
	}
	
	static void BFS(Node parent, int deep, int max)
	{
		if(deep==max-1)
			return;
		for(int i = 0; i <= deep+1; i++)
		{
			var m = new Node(){Chara=(char)('a'+i), Children=new List<Node>()};
			parent.Children.Add(m);
			BFS(m, deep+1, max);
		}
	}
	
	
	static void WriteDown(Node parent, Stack<char> stack, int max)
	{
		if(parent == null)
			return;
		
		stack.Push(parent.Chara);
		foreach(var n in parent.Children)
		{
			WriteDown(n, stack, max);
		}
		if(stack.Count == max)
		{
			var c = stack.ToArray();
			Array.Reverse(c);
		var t = new string(c);
		
		Console.WriteLine(t);
		}
		stack.Pop();
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}