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.IO;
using System.Linq;

namespace AtCoderPractice
{
    class Program
    {
        const string AZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        const string az = "abcdefghijklmnopqrstuvwxyz";
        static void Main(string[] args)
        {
            var r = "";
            var count = 0;

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 処理
            var v = StandardInputToInt();






            var nums = Enumerable.Range(1, v).ToArray();
            var combinations = Combination.Enumerate(nums, v, withRepetition: true).Where(n => n.First() == 1);

            int i = 1;
            foreach (var elem in combinations)
            {
                string s = string.Join("", elem.Select(x => az[x- 1]).ToArray()) ;
                Console.WriteLine("{0}", s);
            }


            //Console.WriteLine($"{r}");

            // 処理終了1
            Console.Out.Flush();
            Console.ReadKey();

            return;


        }


        public static class Combination
        {
            public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition)
            {
                if (k == 1)
                {
                    foreach (var item in items)
                        yield return new T[] { item };
                    yield break;
                }
                foreach (var item in items)
                {
                    var leftside = new T[] { item };

                    // item よりも前のものを除く （順列と組み合わせの違い)
                    // 重複を許さないので、unusedから item そのものも取り除く
                    var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

                    foreach (var rightside in Enumerate(unused, k - 1, withRepetition))
                    {
                        yield return leftside.Concat(rightside).ToArray();
                    }
                }
            }
        }



        // x - a number, from which we need to calculate the square root
        // epsilon - an accuracy of calculation of the root from our number.
        // The result of the calculations will differ from an actual value
        // of the root on less than epslion.
        public static decimal Sqrt(decimal x, decimal epsilon = 0.0M)
        {
            if (x < 0) throw new OverflowException("Cannot calculate square root from a negative number");

            decimal current = (decimal)Math.Sqrt((double)x), previous;
            do
            {
                previous = current;
                if (previous == 0.0M) return 0;
                current = (previous + x / previous) / 2;
            }
            while (Math.Abs(previous - current) > epsilon);
            return current;
        }


        #region 標準処理ライブラリ
        /// <summary>
        /// 半角スペース区切りの標準入力を文字列のIListに変換します。
        /// </summary>
        /// <returns></returns>
        static public IList<string> StandardInputToStrings()
        {
            return Console.ReadLine().Split(' ').ToList();
        }

        /// <summary>
        /// stringを取得
        /// </summary>
        /// <returns></returns>
        static public string StandardInputToString()
        {
            return Console.ReadLine();
        }

        /// <summary>
        /// 半角スペース区切りの標準入力を文字列のIListに変換します。複数行に対応。
        /// </summary>
        /// <returns></returns>
        static public IList<IList<string>> MultipleStandardInputToStrings()
        {
            string line;
            var r = new List<List<string>>();
            do
            {
                line = Console.ReadLine();
                r.Add(line.Split(' ').ToList());
                line = Console.ReadLine();
            } while (line == null);

            return (IList<IList<string>>)r;
        }

        /// <summary>
        /// 半角スペース区切りの標準入力を数値のIListに変換します。
        /// </summary>
        /// <returns></returns>
        static public IList<long> StandardInputToLongs()
        {
            return Console.ReadLine().Split(' ').Select(n => long.Parse(n)).ToList();
        }
        /// <summary>
        /// 半角スペース区切りの標準入力を数値のIListに変換します。
        /// </summary>
        /// <returns></returns>
        static public long StandardInputToLong()
        {
            return long.Parse(Console.ReadLine());
        }

        /// <summary>
        /// 半角スペース区切りの標準入力を文字列のIListに変換します。複数行に対応。
        /// </summary>
        /// <returns></returns>
        static public IList<IList<long>> MultipleStandardInputToLongs()
        {
            string line;
            var r = new List<List<long>>();
            do
            {
                line = Console.ReadLine();
                r.Add(line.Split(' ').Select(n => long.Parse(n)).ToList());
                line = Console.ReadLine();
            } while (line == null);

            return (IList<IList<long>>)r;
        }

        /// <summary>
        /// 半角スペース区切りの標準入力を数値のIListに変換します。
        /// </summary>
        /// <returns></returns>
        static public IList<int> StandardInputToInts()
        {
            return Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
        }
        /// <summary>
        /// 半角スペース区切りの標準入力を数値のIListに変換します。
        /// </summary>
        /// <returns></returns>
        static public int StandardInputToInt()
        {
            return int.Parse(Console.ReadLine());
        }

        /// <summary>
        /// 半角スペース区切りの標準入力を文字列のIListに変換します。複数行に対応。
        /// </summary>
        /// <returns></returns>
        static public IList<IList<int>> MultipleStandardInputToInts()
        {
            string line;
            var r = new List<List<int>>();
            do
            {
                line = Console.ReadLine();
                r.Add(line.Split(' ').Select(n => int.Parse(n)).ToList());
                line = Console.ReadLine();
            } while (line == null);

            return (IList<IList<int>>)r;
        }
    }






    public static class AtCoderResultExtentions
    {
        static public string AsDelimitedResult<T>(this IList<T> ie, string delimitter = " ")
        {
            return string.Join(delimitter, ie);
        }
    }
    #endregion


    #region List拡張
    public static class IListExtensions
    {
        public static IList<T> Swap<T>(this IList<T> ie, int indexA, int indexB)
        {
            var temp = ie[indexA];
            ie[indexA] = ie[indexB];
            ie[indexB] = temp;
            return ie;
        }
    }
    #endregion
}