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 (Python):
from collections import deque,Counter
n=int(input())
abc="abcdefghijklmnopqrstuvwxyz"
arr=deque()
def dfs(string,cnt):
    if cnt==n+1:
        arr.append(string)
        return 0
    l=len(list(set(list(string))))
    for i in abc[:l+1]:
        dfs(string+i,cnt+1)

dfs("",1)
arr=sorted(list(arr))
for i in arr:
    print(i)

Solution (Python):
import sys
import re
input = sys.stdin.readline

N = int(input())

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
ans = []
for i in range(N):
    if not i:
        ans.append(['a'])
    else:
        l = []
        p = []
        for x in ans[-1]:
            m = max([alpha.index(a) for a in x])
            l.extend([x + a for a in alpha[:m + 2]])

        ans.append(l)

for x in ans[N - 1]:
    print(x)

Solution (Python):
N = int(input())
D = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Ans = [["a"]]
for i in range(1, 10):
    before = Ans[i - 1]
    
    next = []
    for j in before:
        L = set(list(j))
        
        for k in range(len(L) + 1):
            
            next.append(j + D[k])
    Ans.append(next)

print(*Ans[N - 1], sep="\n")

Solution (Python):
N = int(input())

alph = [chr(ord('a') + i)  for i in range(N)]
S = ""
ans = []



def add_s(S, j):

    if len(S) == N:
        ans.append(S)
        print(S)
        return

    for s in range(j+2):
        S += alph[s]
        if s == j+1:
            add_s(S, j+1)
        else:
            add_s(S, j)
        S = S[:-1]

add_s("a", 0)

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
n=int(input())
al=[chr(ord('a') + i) for i in range(15)]
def dfs(c,i):
    if i==n:
        print(c)
        return
    p=0
    for k in c:
        p=max(p,ord(k))
    for k in range(p-ord('a')+2):
        dfs(c+al[k],i+1)
dfs("a",1)

Solution (Python):
def solve(x):
    if len(x) == n:
        ans.append(x)
        return 0
    syurui = len(set(x))
    for i in range(syurui + 1):
        solve(x + chr(97 + i))


n = int(input())

a = "a"

ans = []

solve(a)

ans = sorted(ans)

print(*ans)

Solution (Python):
import collections
def f(l):
    res=[]
    l,res=res,l
    for i in range(len(res)):
        c=collections.Counter(res[i])
        for j in range(len(c)+1):
            l.append(res[i]+chr(97+j))
    return l

n=int(input())
if n==1:
    print("a")
else:
    ans=["a"]
    i=1
    while i<n:
        ans=f(ans)
        i+=1
    for i in range(len(ans)):
        print(ans[i])

Solution (Python):
N=input()
A="abcdefghij"

S=["a"]
for n in range(2,N+1):
    temp=[]
    for s in S:
        max_s=max(s)
        ind_max_s=A.index(max_s)
        for i in range(ind_max_s+2):
            temp.append(s+A[i])
    S=temp

S.sort()
for x in S:
    print x

Solution (Python):
n = int(input())
l = ["a","b","c","d","e","f","g","h","i","j"]
i = 0
def st(s,n,k,m):
  if k == n:
    print(s)
    return
  for i in range(m):
    st(s+l[i],n,k+1,m)
  st(s+l[m],n,k+1,m+1)
st("a",n,1,1)

Solution (Python):
n = int(input())
list_abc = ['a','b','c','d','e','f','g','h','i','j']

list_old0 = [0]
list_old1 = [[0,0],[0,1]]
list_old = [[0,0],[0,1]]
if n>2:
    m = n
else:
    m = 3

for i in range(2,m):
    list_new=[]
    for k in list_old:
        
        for j in range(i+1):
            
            b=k.copy()
            
            
            if max(k)+1<j:
                continue
            b.append(j)
            list_new.append(b)
    
    list_old = list_new

if n==1:
    print('a')
elif n==2:
    print('aa')
    print('ab')
else:
    for l in list_old:
        for y in l:
            print(list_abc[y],end='')
        print()

Solution (Python):
n=int(input())
s="abcdefghijklmno"
end=[0,1,2,3,4,5,6,7,8,9,10,11,12,13]
lim=0
res=[0]*n
for i in res:
  print(s[i],end="")
print("")

while res!=end[:n]:
  res[(n-1)]=res[(n-1)]+1
  for i in range(n-1):
    if res[n-i-1]>(max(res[:(n-i-1)])+1):
      res[n-i-1]=0
      res[n-i-2]=res[n-i-2]+1
  for i in res:
    print(s[i],end="")
  print("")

Solution (Python):
N = int(input())
ans = ['a']
moji = ['a','b','c','d','e','f','g','h','i','j']
count = 1
while count < N:
    tmp = []
    for i in ans:
        for k in range(len(set(list(i)))+1):
            tmp.append(i+moji[k])
    count += 1
    ans = tmp
ans.sort()
for i in ans:
    print(i)

Solution (Python):
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
alphabets = string.ascii_lowercase

N = int(input())
ans = [["a", 0]]
for i in range(1, N):
    ans2 = copy.deepcopy(ans)
    ans = []
    for l in ans2:
        for k in range(int(l[1]) + 2):
            ans.append([l[0] + alphabets[k], max(l[1], k)])
for i in ans:
    print(i[0])

Solution (Python):
N = int(input())
alp = lambda c: chr(c+96)
def num(L,key):
    if len(L) == N:
        ans = [alp(a) for a in L]
        print(''.join(ans))
    else:
        for k in range(1,key+1):
            l = L + [k]
            num(l,key)
        l = L + [key+1]
        num(l, key+1)

init =[1]
num(init,1)

Solution (Python):
w = []
N = int(input())


def addchar(s):
    if(len(s) < N):
        x = len(set(s))+1
        for i in range(x):
            t = s + chr(ord("a")+i)
            addchar(t)
    else:
        w.append(s)

addchar("a")
for i in w:
  print(i)

Solution (Python):
n = int(input())
words = ['a', 'b', 'c', 'd', 'e', 'f','g','h', 'i', 'j']
ans = [[] for _ in range(n)]
ans[0].append(["a", 1])
for i in range(n - 1):
    for ai in ans[i]:
        for j in range(ai[1]):
            ans[i + 1].append([ai[0] + words[j], ai[1]])
        ans[i + 1].append([ai[0] + words[ai[1]], ai[1] + 1])

for a in ans[n - 1]:
    print(a[0])

Solution (Python):

import sys
import numpy as np

al = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

def solve(N: int):
    
    def p_out(ppp):
        print("".join([al[p] for p in ppp]))

    def rec_ad(token, ttl):

        if ttl != 0:
            for k in range(max(token)+2):
                rec_ad(token + [k], ttl - 1)
        else :
            p_out(token)

    rec_ad([0], N-1)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    solve(N)

if __name__ == '__main__':
    main()

Solution (Python):
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


def f(s, m, n):
    if(len(s) == n):
        print(s)
        return
    for i in range(m):
        
        f(s+chr(i+ord('a')), m if i < m-1 else (m+1), n)


n = int(input())
dump(n)
ans = set()


f('a', 2, n)

Solution (Python):

"""
Created on Sat Mar 14 20:59:48 2020

@author: Kanaru Sato
"""

dict = list("abcdefghijklmnopqrstuvwxyz")

def gen(n):
    if n == 1:
        return ["a"]
    else:
        rvalue = []
        for s in gen(n-1):
            max = 0
            for i in range(len(s)):
                num = dict.index(s[i])
                if num >= max:
                    max = num
            for i in range(max+2):
                rvalue.append(s+dict[i])
        return rvalue

n = int(input())
l = gen(n)
ans = sorted(l)

for i in range(len(ans)):
    print(ans[i])

Solution (Python):
K = int(input())
word_dic = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10}
l_word = ["a","b","c","d","e","f","g","h","i","j"]
L = ["a"]
if K == 1:
  print("a")
else:
  for i in range(K-1):
    M = []
    for x in L:
      k_x = 0
      for y in list(x):
        if k_x < word_dic[y]:
          k_x = word_dic[y]
      for j in range(k_x+1):
        M.append(x + l_word[j])
    L = M[:]
  else:
    for x in L:
      print(x)

Solution (Python):
n = int(input())

chars = [
    'a',
    'b',
    'c',
    'd',
    'e',
    'f',
    'g',
    'h',
    'i',
    'j']

def f(i):
    if i == 1:
        return [chars[i - 1]]
    else:
        temp = f(i - 1)
        e = []
        for j in temp:
            w = min([len(set(j)) + 1, i - 1])
            for c in range(w):
                e.append(j + chars[c])
        e.append(''.join(chars[0:i]))
        return e

    
result = f(n)
result = sorted(result)
for i in result:
    print(i)

Solution (Python):
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
from decimal import *








N=int(input())
lst=[i for i in range(1,N)]
lst2=[[] for i in range(N)]
lst2[0].append([0])

for l in lst:
    for l2 in lst2[l-1]:
        for i in range(max(l2)+2):
            lst2[l].append(l2+[i])

lst2=lst2[-1]
lst2=sorted(["".join([chr(m+ord("a"))for m in l]) for l in lst2 ])
for i in lst2:
    print(i)

Solution (Python):
def main():
    n = int(input())

    chars_list = [
        ['a'],
        ['aa', 'ab'],
        ['aaa', 'aab', 'aba', 'abb', 'abc'],
        ['aaaa', 'aaab', 'aaba', 'aabb', 'aabc', 'abaa', 'abab', 'abac', 'abba', 'abbb', 'abbc', 'abca', 'abcb', 'abcc', 'abcd']
    ]
    a = 'abcdefghijkl'

    if n <= 4:
        for s in chars_list[n-1]:
            print(s)
    else:
        while n - 4 > 0:
            appends_list = []
            for char in chars_list[-1]:
                for alphabet in a:
                    appends_list.append(char+alphabet)
                    if alphabet not in char:
                        break
            chars_list.append(appends_list)
            n -= 1

        for s in chars_list[-1]:
            print(s)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
def print_from_l(l):
    print(''.join(map(lambda s:chr(97+s), l)))
def g(l):
    if len(l) == n:
        print_from_l(l)
    else:
        for i in range(max(l)+2):
            g(l + [i])
g([0])

Solution (Python):
n = int(input())
a = [0]*n

def print_str():
    for i in reversed(a):
        print(chr(97+i), end='')
    print()

print_str()
while True:
    for i in range(n-1):
        if a[i] <= max(a[i+1:]):
            a[i] += 1
            for j in range(i):
                a[j] = 0
            print_str()
            break
    else:
        break

Solution (Python):
from copy import deepcopy
def f(num,N,S):
    alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t"]
    if N == num:
        S.sort()
        for i in range(len(S)):
            print(S[i])
        return
    else:
        tmp = []
        length = len(S)
        for i in range(length):
            ttmp = list(S[i])
            ttmp.sort()
            tttmp = alphabet.index(ttmp[-1])
            for j in range(tttmp+2):
                tmp.append(S[i]+alphabet[j])
                    
        S = deepcopy(tmp)
        S.sort()
        f(num+1,N,S)

N = int(input())
f(1,N,["a"])

Solution (Python):
n = int(input())
num_list = [97] * n
target = n - 1
tmp_target = n - 1
max_num = 97
if n==1:
    print('a')
while tmp_target > 0:
    print("".join(list(map(chr, num_list))))
    if max(num_list[0:target:]) >= num_list[target]:
        num_list[target] += 1
    else:
        num_list[target] = 97
        tmp_target = target - 1
        while tmp_target > 0:
            if max(num_list[0:tmp_target:]) >= num_list[tmp_target]:
                num_list[tmp_target] += 1
                break
            else:
                num_list[tmp_target] = 97
                tmp_target -= 1

Solution (Python):
def continuous(string):
    numbers = [ord(c) - 97 for c in list(string)]
    largest = max(numbers)
    flag = True
    for i in range(1, largest+1):
        if i not in numbers:
            flag = False
            break
    return flag
  
  
def solve(N):
    if N == 1:
        return "a"
    else:
        tmp = solve(N-1)
        tmp_top = ["a" + t for t in tmp]
        tmp_bottom = [t + alphabet for t in tmp for alphabet in ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"][:N]]
        tmp_bottom = [t for t in tmp_bottom if continuous(t)]
        tmp = sorted(list(set(tmp_top + tmp_bottom)))
        return tmp
      
      
N = int(input())
res = solve(N)
for s in res:
    print(s)

Solution (Python):
import sys


def main():
    N = int(input())

    use = ["a"]
    if N == 1:
        print("a")
        exit()
    for i in range(1,N):
        ans = []
        for st in use:
            c = 0
            for t in st:
                c = max(c,ord(t)-ord("a"))
            for j in range(c+2):
                s = chr(97+j)
                if i == N-1:
                    print(st+s)
                else:
                    ans.append(st+s)
        use = ans
   
if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = "abcdefghijklmmopkrstuvwxyz"


def solve(s, m):
    if len(s) == n:
        print(s)
        return
    for v in a:
        if ord(v)-m <= 1:
            solve(s+v, max(m, ord(v)))


solve("a", ord("a"))

Solution (Python):
n=int(input())
char=[chr(i) for i in range(97, 97+26)]

ans=["a"]
before=0

for i in range(2,n+1):
    for c in range(len(ans)):
        From=char.index(sorted(list(ans[c]))[-1])
        for m in range(From+2):
            ans.append(ans[c]+char[m])
    
    
b=[]

for g in range(len(ans)):
    if len(ans[g])==n:
        b.append(ans[g])

b.sort()

for i in range(len(b)):
    print(b[i])

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    
    def rec(n, maxchr, ans):
        if n==N-1:
            print(ans)
        else:
            for i in range(maxchr+1):
                
                rec(n+1, maxchr, ans+chr(i+97))
            rec(n+1, maxchr+1, ans+chr(maxchr+98))

    rec(0, 0, 'a')

if __name__ == '__main__':
    resolve()

Solution (Python):
import itertools

bells = [[], [[0]]] + [None for i in range(9)]
bell_n = [1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975]

def search(n):
    ret = []
    ret.append( [ 0 for _ in range(n) ] )
    for k in range(1,n):
        for bi in bells[k]:
            for ids in itertools.combinations(range(1,n), k):
                st = [0 for _ in range(n)]
                for i, id in enumerate(ids):
                    st[id] = bi[i] + 1
                ret.append(st)
    return ret

for i in range(2, 11):
    bells[i] = search(i)
    assert bell_n[i] == len(bells[i])

N = int(input())
table = "abcdefghij"
outs = []
for bi in bells[N]:
    out = ""
    for b in bi:
        out += table[b]
    outs.append(out)

print("\n".join(sorted(outs)))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

n = int(input())
ans = []

if n == 1:
    print('a')
    exit()

@lru_cache(None)
def rec(before, depth, MAX):
    for i in range(MAX-ord('a') +2):
        tmp = before + chr(ord('a') + i)
        if len(tmp) >= n:
            ans.append(tmp)
        else:
            MAX = max(MAX, ord(tmp[-1]) )
            rec(tmp, depth+1, MAX)


rec('a',1, ord('a'))

ans.sort()

print(*ans, sep ='\n')

Solution (Python):
n = int(input())
al = [chr(i) for i in range(97,97+26)]

dpn = ['a']
dpp = []
if n == 1:
    print('a')
    exit()
for i in range(1,n):
    for j in dpn:
        for k in al[:max(list(map(ord,list(j))))-97+2]:
            if i != n-1:
                dpp.append(j + k)
            else:
                print(j+k)
    if i != n-1:
        dpn = dpp
        dpp = []

Solution (Python):

from collections import deque
import copy
str_list_befor = ['0', '1', '2','3','4','5', '6', '7','8','9']
str_list_after = ['a', 'b', 'c','d','e','f', 'g', 'h','i','j']

n = int(input())

dq = deque()
dq.append([0])
if n > 1:
    for i in range(n-1):
        
        for j in range(len(dq)):
            
            prv = dq.popleft()
            for j in range(max(prv)+2):
                tmp = copy.copy(prv)
                tmp.append(j)
                
                dq.append(tmp)
            

for i in range(len(dq)):
    result = ""
    tmp_r = dq.popleft()
    result = "".join(map(str, tmp_r))
    for j in range(len(str_list_befor)):
        result = result.replace(str_list_befor[j], str_list_after[j])

    print(result)

Solution (Python):
import math

N = int(input())
ZL = [[] for _ in range(N)]
ZL[0].append([0])
for i in range(1, N):
    for szl in ZL[i - 1]:
        n1 = max(szl)
        for j in range(n1 + 2):
            ZL[i].append(szl + [j])


def func(i):
    if i == 0:
        return "a"
    if i == 1:
        return "b"
    if i == 2:
        return "c"
    if i == 3:
        return "d"
    if i == 4:
        return "e"
    if i == 5:
        return "f"
    if i == 6:
        return "g"
    if i == 7:
        return "h"
    if i == 8:
        return "i"
    if i == 9:
        return "j"


L = ZL[N - 1]
for sl in L:
    for i in range(N):
        sl[i] = func(sl[i])
L.sort()
for sl in L:
    print("".join(map(str, sl)))

Solution (Python):
N = int(input())
az = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
def norm(n, in_list):
	out_list = []
	for line in in_list:
		for i in range(len(set(line))+1):
			new_line = line + az[i]
			out_list.append(new_line)
	return out_list
init_line = ['a']
for _ in range(N-1):
	init_line = norm(1, init_line)
for line in init_line:
	print(line)

Solution (Python):
n = int(input())
s = 'a'

def func(s, count, cc):
    if count == n:
        print(s)
        return
    for i in range(min(count, cc) + 1):
        func(s + chr(ord('a') + i), count + 1, max(i+1, cc))

func(s, 1, 1)

Solution (Python):
import collections


def main():
    n = int(input())
    
    
    
    
    

    ret = [[] for _ in range(10)]
    ret[0] = ["a"]

    alp = "abcdefghijklmnopqrstuvwxyz"

    if n == 1:
        print(ret[n-1][0])
        return

    ind = 1
    while ind < n:
        tmp_len = len(ret[ind-1])
        for j, _r in enumerate(ret[ind-1]):
            alphabet_num = len(collections.Counter(_r))
            for k in range(alphabet_num+1):
                ret[ind].append(_r+alp[k])
        ind += 1


    for r in ret[n-1]:
        print(r)
    return


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
al = [chr(i + 97) for i in range(N)]
def sol(S):
    if len(S) == N:
        print(S)
        return
    for i in range(len(set(S)) + 1):
        sol(S + al[i])
sol('')

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

ans = set()
def rec(i, S):
    if S in ans:
        return
    if i == N:
        ans.add(S)
        return
    for c in S:
        rec(i+1, S+c)
    if i == 0:
        rec(i+1, 'a')
    else:
        li = sorted(S)
        rec(i+1, S+chr(ord(li[-1])+1))
rec(0, '')
ans = sorted(ans)
[print(s) for s in ans]

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    m='abcdefghijklmnopqrstuvwxyz'
    m=list(m)
    n=int(input())
    ans=[[] for _ in range(n)]
    ans[0].append(['0','0'])
    for i in range(1,n):
        for j,mj in ans[i-1]:
            for k in range(i+1):
                if k<=int(mj)+1:
                    ans[i].append([j+str(k),str(max(int(mj),k))])
    p=[]
    for i,mi in ans[n-1]:
        s=''
        for j in range(len(i)):
            s+=m[int(i[j])]
        p.append(s)
    p.sort()
    for i in p:
        print(i)
        
if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque

N = int(input())

l = deque(['a'])

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

for i in range(1, N):
    
    len_l = len(l)
    for k in range(len_l):
        x = l.popleft()
        for j in range(len(set(x))+1):
            
            l.append(x+alpha[j])
            



for i in l:
    print(i)

Solution (Python):
n = int(input())
r = ['a']
for _ in range(n - 1):
  r = [s + c for s in r for c in set(s) | {chr(ord(max(s)) + 1)}]
print(*sorted(r), sep='\n')

Solution (Python):
n=int(input())

tree = [[0,1]]
for _ in range(n-1):
    tree = [ t+[i]  for t in tree for i in range(1,max(t)+2) ]
for t in tree:
    print( "".join([chr(ord("a")+tt-1) for tt in t[1:] ] ) )

Solution (Python):
n = int(input())

tank = []
res = ["a"]

for le in range(1,n):
    tank = res
    res = []
    for i in range(len(tank)):
        tmp = "a"
        for j in range(le):
            res.append(tank[i] + tank[i][j])
            if tank[i][j] > tmp:
                tmp = tank[i][j]
        res.append(tank[i] + chr(ord(tmp)+1))
    res = list(set(res))
res.sort()

for e in res:
    print(e)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd

sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    ans = [0 for _ in range(n)]
    ans[0] = 'a'
    ANS = []
    for n1 in range(0,n):
        for e1 in combinations(range(1,n),n1):
            for e in e1:
                ans[e] = 'a'
            list1 = deque()
            for i in range(1,n):
                if i not in e1:
                    list1.append(i)
            if list1:
                index = list1.popleft()
                ans[index] = 'b'
            if not list1:
                ANS.append(''.join(ans))
            for n2 in range(0,n-n1-1):
                for e2 in combinations(list1,n2):
                    for e in e2:
                        ans[e] = 'b'
                    list2 = deque()
                    for i in list1:
                        if i not in e2:
                            list2.append(i)
                    if list2:
                        index = list2.popleft()
                        ans[index] = 'c'
                    if not list2:
                        ANS.append(''.join(ans))
                    for n3 in range(0,n-n1-n2-2):
                        for e3 in combinations(list2,n3):
                            for e in e3:
                                ans[e] = 'c'
                            list3 = deque()
                            for i in list2:
                                if i not in e3:
                                    list3.append(i)
                            if list3:
                                index = list3.popleft()
                                ans[index] = 'd'
                            if not list3:
                                ANS.append(''.join(ans))
                            for n4 in range(0,n-n1-n2-n3-3):
                                for e4 in combinations(list3,n4):
                                    for e in e4:
                                        ans[e] = 'd'
                                    list4 = deque()
                                    for i in list3:
                                        if i not in e4:
                                            list4.append(i)
                                    if list4:
                                        index = list4.popleft()
                                        ans[index] = 'e'
                                    if not list4:
                                        ANS.append(''.join(ans))
                                    for n5 in range(0,n-n1-n2-n3-n4-4):
                                        for e5 in combinations(list4,n5):
                                            for e in e5:
                                                ans[e] = 'e'
                                            list5 = deque()
                                            for i in list4:
                                                if i not in e5:
                                                    list5.append(i)
                                            if list5:
                                                index = list5.popleft()
                                                ans[index] = 'f'
                                            if not list5:
                                                ANS.append(''.join(ans))
                                            for n6 in range(0,n-n1-n2-n3-n4-n5-5):
                                                for e6 in combinations(list5,n6):
                                                    for e in e6:
                                                        ans[e] = 'f'
                                                    list6 = deque()
                                                    for i in list5:
                                                        if i not in e6:
                                                            list6.append(i)
                                                    if list6:
                                                        index = list6.popleft()
                                                        ans[index] = 'g'
                                                    if not list6:
                                                        ANS.append(''.join(ans))
                                                    for n7 in range(0,n-n1-n2-n3-n4-n5-n6-6):  
                                                        for e7 in combinations(list6,n7):
                                                            for e in e7:
                                                                ans[e] = 'g'
                                                            list7 = deque()
                                                            for i in list6:
                                                                if i not in e7:
                                                                    list7.append(i)
                                                            if list7:
                                                                index = list7.popleft()
                                                                ans[index] = 'h'
                                                            if not list7:
                                                                ANS.append(''.join(ans))
                                                            for n8 in range(0,n-n1-n2-n3-n4-n5-n6-n7-7):  
                                                                for e8 in combinations(list7,n8):
                                                                    for e in e8:
                                                                        ans[e] = 'h'
                                                                    list8 = deque()
                                                                    for i in list7:
                                                                        if i not in e8:
                                                                            list8.append(i)
                                                                    if list8:
                                                                        index = list8.popleft()
                                                                        ans[index] = 'i'
                                                                    if not list8:
                                                                        ANS.append(''.join(ans))
                                                                    for n9 in range(0,n-n1-n2-n3-n4-n5-n6-n7-n8-8):  
                                                                        for e9 in combinations(list8,n9):
                                                                            for e in e9:
                                                                                ans[e] = 'i'
                                                                            list9 = deque()
                                                                            for i in list8:
                                                                                if i not in e9:
                                                                                    list9.append(i)
                                                                            if list9:
                                                                                index = list9.popleft()
                                                                                ans[index] = 'j'
                                                                            ANS.append(''.join(ans))
    ANS = list(set(ANS))
    ANS.sort()
    for i in range(len(ANS)):
        print(ANS[i])
        
if __name__ == "__main__":
    main()

Solution (Python):

import sys

sys.setrecursionlimit(10 ** 5)
to = "abcdefghij"


def dfs(s):
    if len(s) == n:
        print(s)
        return
    m = max(ord(c) - ord("a") for c in s) + 1
    for i in range(m + 1):
        dfs(s + to[i])


n = int(input())
dfs("a")

Solution (Python):
from itertools import product
N = int(input())
X = [chr(ord('a') + i) for i in range(N)]
first_presence = {x: i for x, i in zip(X, list(range(N)))}

ans = ['a']
R = ['a']

for i in range(1, N):
    nr = []
    for r in R:
        mr = max(r)
        for x in X:
            nr.append(r + x)
            if mr == x:
                break
        nr.append(r + chr(ord(mr) + 1))
    R = nr

ans = list(set(R))
ans.sort()
print(*ans, sep="\n")