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):
class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+1)
        for i, c in enumerate(s[:self.index]):
            out[i] = Node(parent+c, self.index)
        out[i+1] = Node(parent+s[self.index], self.index+1)
        return out

def main():
    n = int(input())
    root = Node("a", 1)
    children = [root]
    for _ in range(n-1):
        parents, children = children, []
        for parent in parents:
            children.extend(parent.get_children())
    for child in children:
        print(child.string)

if __name__ == "__main__":
    s = "abcdefghij"
    main()

Solution (Python):
class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        s = "abcdefghij"
        parent = self.string
        out = [None]*(self.index+1)
        for i, c in enumerate(s[:self.index]):
            out[i] = Node(parent+c, self.index)
        out[i+1] = Node(parent+s[self.index], self.index+1)
        return out

def main():
    n = int(input())
    root = Node("a", 1)
    children = [root]
    for _ in range(n-1):
        parents, children = children, []
        for parent in parents:
            children.extend(parent.get_children())
    for child in children:
        print(child.string)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
s = "abcdefghij"

class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+1)
        for i, c in enumerate(s[:self.index]):
            out[i] = Node(parent+c, self.index)
        out[i+1] = Node(parent+s[self.index], self.index+1)
        return out

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

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


A='abcdefghijklmnopqrstuvwxyz'
P=['a']
X=[[] for _ in range(n)]
X[0].append('a')
for i in range(n-1):
    P.append(A[i+1])
    for j in range(len(X[i])):
        flag=False
        for k in range(len(P)):
            X[i+1].append(X[i][j]+P[k])
            if not P[k] in X[i][j]:
                flag=True
            if flag:
                break
Y=X[n-1]
for i in range(len(Y)):
    print(Y[i])

Solution (Python):
n = int(input())
s = "abcdefghij"

class Node:

    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+2)
        for i, c in enumerate(s[:self.index+1], 1):
            out[i] = Node(parent+c, max(i, self.index))
        return out[1:]

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Solution (Python):
n = int(input())
s = "abcdefghij"

class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+1)
        for i, c in enumerate(s[:self.index+1], 1):
            out[i-1] = Node(parent+c, max(i, self.index))
        return out

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Solution (Python):
n = int(input())
s = "abcdefghij"

class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+2)
        for i, c in enumerate(s[:self.index+1], 1):
            out[i] = Node(parent+c, max(i, self.index))
        return out[1:]

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Solution (Python):
n = int(input())
s = "abcdefghij"

class Node:
    def __init__(self, string, index):
        self.children = []
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        for i, c in enumerate(s[:self.index+1], 1):
            self.children.append(Node(parent+c, max(i, self.index)))
        return self.children

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Solution (Python):
n = int(input())
s = "abcdefghij"

class Node:
    def __init__(self, string, index):
        self.children = []
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        for i, c in enumerate(s[:self.index+1]):
            self.children.append(Node(parent+c, max(self.index, i+1)))
        return self.children

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Solution (Python):
n = int(input())
s = "abcdefghij"

class Node:
    def __init__(self, string, index):
        self.children = []
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        for i, c in enumerate(s[:self.index+1]):
            self.children.append(Node(parent+c, self.index if self.index>i else i+1))
        return self.children

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Solution (Python):
n = int(input())
s = set(list("abcdefghijk"))

class Node:
    def __init__(self, char, parents):
        self.children = []
        self.string = parents+char
        self.charset = set(self.string)

    def get_children(self):
        parents = self.string
        for c in sorted(list(self.charset|set(min(s-self.charset)))):
            self.children.append(Node(c, parents))
        return self.children

root = Node("a", "")
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Solution (Python):

n = int(input())

alphas = "abcdefghij"
init_str = ""

def standard(moji, x):
    
    if len(moji) == n:
        print(moji)
    else:
        for j in range(x+1):
            if j == x:
                
                standard(moji + alphas[j], x + 1)
            else:
                
                standard(moji + alphas[j], x)


standard(init_str, 0)

Solution (Python):

import sys
sys.setrecursionlimit(4100000)
n=int(input())
def dfs(s, mx):
    if len(s)==n:
        print(s)
        return 0
    for i in range(ord('a'), mx+2):
        t=str(s)
        moji=str(chr(i))
        t+=moji
        dfs(t, max(mx, i))
dfs('',ord('a')-1)

Solution (Python):
N = int(input())
strlist = 'abcdefghij'

def dfs(s, i):
  if len(s) == N:
    print(s)
  else:
    for j in range(i+1):
      t = s + strlist[j]
      if j == i:
        dfs(t, i+1)
      else:
        dfs(t, i)

dfs('', 0)

Solution (Python):
N = int(input())
strlist = 'abcdefghij'

ans = [['a']]
for i in range(1, N):
  ans.append([])
  for s in ans[i-1]:
    n = ord(max(s)) - 96
    for j in range(n+1):
      ans[i].append(s+strlist[j])

print(*ans[-1], sep='\n')

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

N = int(input())

s = [[] for _ in range(N)]
a_ord = ord("a")

for i in range(N):
    if i == 0:
        s[0].append("a")
        continue
    for j in s[i - 1]:
        j_max_ord = max([ord(x) for x in j])
        for k in range(a_ord, j_max_ord + 2):
            s[i].append(j + chr(k))

ans = s[-1]
ans.sort()

for i in ans:
    print(i)

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


ans = [['a']]
for i in range(1, N):
  ans.append([])
  for s in ans[i-1]:
    n = len(set(s))
    for j in range(n+1):
      ans[i].append(s+strlist[j])


print(*ans[-1], sep='\n')

Solution (Python):
string=['a','b','c','d','e','f','g','h','i','j']
N=int(input())
res=[]
def dfs(ss):
  if len(ss)==N:
    ss=''.join(ss)
    res.append(ss)
  else:
    for i in range(string.index(max(ss))+2):
      a=ss+[string[i]]
      dfs(a)
  return res
ans=dfs(['a'])
for i in range(len(ans)):
  print(ans[i])

Solution (Python):


min_char = "abcdefghij"

def dtype_tree(tree, max, num):
    for i in range(max+1):
        tgt_tree = [i]
        if num > 0:
            new_max = max
            if new_max < i+1:
                new_max = i+1
            new_tree = dtype_tree([], new_max, num-1)
            tgt_tree.append(new_tree)

        if tree == None:
            tree = tgt_tree
        else:
            tree.append(tgt_tree)
    return tree

def print_tree(tree, prefix):
    new_prefix = prefix
    if len(tree) == 1:
        print(prefix + min_char[tree[0]])
    else:
        for elem in tree:
            if type(elem) != list:
                new_prefix += min_char[elem]

            else:
                print_tree(elem, new_prefix)

    return


def abc_XXX(num):
    tree = dtype_tree(None, 0, num-1)

    print_tree(tree, "")
    return



if(__name__ == '__main__'):
    
    n = int(input())
    
    abc_XXX(n)

Solution (Python):
string=['a','b','c','d','e','f','g','h','i','j']
N=int(input())
res=[]
def dfs(ss):
  if len(ss)==N:
    ss=''.join(ss)
    res.append(ss)
  else:
    for i in range(string.index(max(ss))+2):
      a=ss+[string[i]]
      dfs(a)
  return res
ans=dfs(['a'])
for i in range(len(ans)):
  print(ans[i])

Solution (Python):
abc = "abcdefghij"

N = int(input())

def dfs(S, i):
    if len(S) == N:
        return S

    return "\n".join([dfs(S + c, i) for c in abc[:i]] + [dfs(S + abc[i], i + 1)])

print(dfs("a", 1))

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

def main():

    S = ["a"]
    N = int(input())
    m = 97

    def add_str(S,m):
        if len(S)==N:
            print("".join(S))
        else:
            for j in range(97,m+2):
                add_str(S+[chr(j)], max(m,j))

    add_str(S,m)

if __name__ == '__main__':
    main()

Solution (Python):

from math import ceil
from math import floor
from math import sqrt

def next(c):
    return chr(ord(c)+1)

def step(N, pred, c, cur_max): 
    cur_max = chr(max(ord(c), ord(cur_max)))
    if N == 1:
        return [pred + c]
    else:
        ret = []
        for elem in range(ord('a'), ord(cur_max)+2):
            ret = ret + step(N-1, pred + c, chr(elem), cur_max)
        
        return ret

if __name__ == '__main__':
    input_line = 1
    for i in range(input_line):
        s = input().rstrip().split(' ')
        a = int(s[0])
        ret = step(a, "", 'a', 'a')
        for elem in ret:
            print(elem)

Solution (Python):
def mm(a):
  x = 0
  for i in range(0,len(a)):
    if x < ord(a[i]):
      x = ord(a[i])

  return x

n = int(input())
ans = ["a"]
 
for i in range(0,len(ans)):
  while len(ans[i]) < n:
    k = mm(ans[i])
    for j in range(97,k+2):
      ans.append(ans[i] + chr(j))
    del ans[i]
 
sorted(ans)
for i in range(0,len(ans)):
  print(ans[i])

Solution (Python):
cdict = "abcdefghijk"

N = int(input())

def str_func( s , num ):
  if( len(s) == N ):
    print(s)
    return
  else:
    for i in range( num ):
      if( i==num-1):
        str_func( s+cdict[i], num+1)
      else:
        str_func( s+cdict[i], num)
        
str_func( "", 1 )

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

def dfs(s, count):
    if len(s) == n:
        print(s)
        return

    for z in range(count + 1):
        dfs(s + a[z], count + 1 if z == count else count)


dfs("", 0)

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

Solution (Python):
N = int(input())
if N == 1:
    for i0 in range(1):
        print(chr(i0+97), sep='')
if N == 2:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            print(chr(i0+97), chr(i1+97), sep='')
if N == 3:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                print(chr(i0+97), chr(i1+97), chr(i2+97), sep='')
if N == 4:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), sep='')
if N == 5:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), sep='')
if N == 6:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        for i5 in range(max(i0, i1, i2, i3, i4) + 2):
                            print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), chr(i5+97), sep='')
if N == 7:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        for i5 in range(max(i0, i1, i2, i3, i4) + 2):
                            for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
                                print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), chr(i5+97), chr(i6+97), sep='')
if N == 8:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        for i5 in range(max(i0, i1, i2, i3, i4) + 2):
                            for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
                                for i7 in range(max(i0, i1, i2, i3, i4, i5, i6) + 2):
                                    print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), chr(i5+97), chr(i6+97), chr(i7+97), sep='')
if N == 9:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        for i5 in range(max(i0, i1, i2, i3, i4) + 2):
                            for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
                                for i7 in range(max(i0, i1, i2, i3, i4, i5, i6) + 2):
                                    for i8 in range(max(i0, i1, i2, i3, i4, i5, i6, i7) + 2):
                                        print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), chr(i5+97), chr(i6+97), chr(i7+97), chr(i8+97), sep='')
if N == 10:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        for i5 in range(max(i0, i1, i2, i3, i4) + 2):
                            for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
                                for i7 in range(max(i0, i1, i2, i3, i4, i5, i6) + 2):
                                    for i8 in range(max(i0, i1, i2, i3, i4, i5, i6, i7) + 2):
                                        for i9 in range(max(i0, i1, i2, i3, i4, i5, i6, i7, i8) + 2):
                                            print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), chr(i5+97), chr(i6+97), chr(i7+97), chr(i8+97), chr(i9+97), sep='')

Solution (Python):
a='a'
exec('a=[s+chr(c)for s in a for c in range(97,ord(max(s))+2)];'*~-int(input()))
print(*a)

Solution (Python):
import sys
sys.setrecursionlimit(20000000)
n = int(input())

def dfs(num, l):
    if num == 0:
        return l
    l_new = []
    for s, set_size in l:
        for i in range(set_size+1):
            s_size = set_size if i < set_size else set_size + 1
            l_new.append((s + chr(ord('a') + i), s_size))
    return dfs(num-1, l_new)


ans = dfs(n-1, [("a", 1)])
ans = list(map(lambda x: x[0], ans))
ans.sort()
print("\n".join(ans))

Solution (Python):
chars = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
N = int(input())

def solve(s = "", used = 0, depth = 0):
  if len(s) == N:
    print(s)
    return
  
  for i in range(min(used + 2, depth + 1)):
    
    
    solve(s + chars[i], max(used, i), depth + 1)

solve()

Solution (Python):
import collections
N = int(input())
stack = collections.deque("a")
charset = [chr(ord("a") + i) for i in range(26)]
ans = []
while stack:
    s = stack.pop()
    if len(s) == N:
        ans.append(s)
        continue
    my_max = 0
    for s_s in s:
        my_max = max(my_max, charset.index(s_s))
    for i in range(my_max + 2):
        stack.append(s + charset[i])
[print(a) for a in sorted(ans)]

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


def dfs(s, mx):
    if len(s) == n:
        print(s)
        return

    for c in range(ord('a'), mx + 1 + 1):
        dfs(s + chr(c), max(mx, c))


dfs("", ord('a') - 1)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)


N = int(input())
ans = []
a = ord('a')


def f(c, A):
    global N, a
    if 0 not in A:
        ans.append(''.join(A))
        return
    B = list(A)
    idx = B.index(0)
    B[idx] = c
    if 0 not in B:
        ans.append(''.join(B))
        return

    for i in range(2 ** (B.count(0)) - 1, -1, -1):
        k = i
        C = B[:]
        idx = C.index(0)
        while k > 0:
            if k & 1 == 1:
                C[idx] = c
            if 0 in C[idx + 1:]:
                idx = C.index(0, idx + 1)
            k >>= 1
        f(chr(ord(c) + 1), tuple(C))



A = [0] * N
f('a', tuple(A))
ans = list(ans)
ans.sort()
print(*ans, sep='\n')

Solution (Python):
n=int(input())-1
l=[[] for _ in range(10)]
l[0].append('a')
for i in range(n):
  for w in l[i]:
    s = sorted(set(w))
    for c in s:
      l[i+1].append(w+c)
    l[i+1].append(w+chr(ord(s[-1])+1))  
print(*l[n],sep='\n')

Solution (Python):
al=[chr(ord('a') + i) for i in range(26)]
def dfs(N, f):
    if len(f) == N:
        return f
    else:
        result = ""
        f_index = [al.index(i) for i in f]
        for i in range(max(f_index) +1 + 1):
            result +=dfs(N,  f + al[i])
        return result

N = int(input())
ans = dfs(N, 'a')
for i in range(int(len(ans) / N)):
    print(ans[N*i : N * (i+1)])

Solution (Python):
import copy

n = int(input())

ary_list = []
def f(ary, max_num):
    if len(ary) == n:
        ary_list.append(ary)
        return
    for i in range(max_num + 2):
        next_ary = copy.copy(ary)
        next_ary.append(i)
        f(next_ary, max_num + (1 if i == max_num + 1 else 0))

f([], -1)

str_list = []
for i in range(len(ary_list)):
    for j in range(n):
        ary_list[i][j] = chr(97 + ary_list[i][j])
    str_list.append("".join(ary_list[i]))

str_list = sorted(str_list)

for s in str_list:
    print(s)

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

def dfs(s, count):
    if len(s) == n:
        print(s)
        return

    for z in range(count + 1):
        dfs(s + a[z], count + 1 if z == count else count)


dfs("", 0)

Solution (Python):
def d_string_equivalence():
    from string import ascii_lowercase
    N = int(input())
    ans = []

    def dfs(string, can_use):
        if len(string) == N:
            ans.append(string)
            return None
        for ch in ascii_lowercase[:can_use + 1]:
            if ch == ascii_lowercase[can_use]:
                
                dfs(string + ch, can_use + 1)
            else:
                
                dfs(string + ch, can_use)
    dfs('', 0)  
    return '\n'.join(ans)

print(d_string_equivalence())

Solution (Python):
def rec(w, x, n):
    if len(w) == n:
        return print(w)
    else:
        for i in range(x + 1):
            rec(w + chr(ord('a') + i), x + 1 if i == x else x, n)


n = int(input())
rec("", 0, n)

Solution (Python):
from string import ascii_lowercase as alphabets


N = int(input())


def dfs(s, used):
    if len(s) == N:
        print(s)
        return
    for i in range(used+2):
        t = s
        t += alphabets[i]
        dfs(t, max(used, i))


dfs("a", 0)

Solution (Python):
from itertools import combinations_with_replacement, combinations

N = int(input())

alphabets = [chr(i) for i in range(97, 97+26)]

def dfs(S, i):
    if len(S) == N:
        yield ''.join(S)
        return

    for j in range(i):
        for w in dfs(S + [alphabets[j]], i): 
            yield w

    for w in dfs(S + [alphabets[i]], i + 1):
        yield w

for w in dfs([], 0):
    print(w)

Solution (Python):
from collections import deque
N = int(input())

alphabet = "abcdefghij"
visited = 1
st = deque([("a", visited)])

while len(st) > 0:
    str, visited = st.popleft()

    if len(str) == N:
        print(str)
    else:
        
        for x in alphabet[0 : visited]:
            st.append((str + x, visited))
        
        
        st.append((str + alphabet[visited], visited + 1))

Solution (Python):
from collections import deque
N = int(input())

alphabet = "abcdefghij"
visited = 1
st = deque([["a", visited]])

while len(st) > 0:
    str, visited = st.popleft()

    if len(str) == N:
        print(str)
    else:
        
        for x in alphabet[0 : visited]:
            st.append([str + x, visited])
        
        
        st.append([str + alphabet[visited], visited + 1])

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

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

todo = ['a']
while len(todo)>0:
    p = todo.pop(-1)
    l = len(p)
    cou = len(set(p))
    if l < n:
        for i in range(cou+1):
            todo.append(p+d[i])
    else:
        ans.append(p)


print('\n'.join(sorted(set(ans))))

Solution (Python):
from collections import deque

def bfs(i):
    q = deque()
    q.append(["a"])
    while q:
        p = q.popleft()
        l = len(p)
        if l == i:
            print("".join(p))
        if not len(p) == i:
            for j in range(l + 1):
                if j >= 1:
                    if alph[j - 1] in p:
                        q.append(p + [alph[j]])
                else:
                    q.append(p + ["a"])
        
alph = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
n = int(input())
bfs(n)

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

alphas = "abcdefghij"
init_str = ""

def standard(moji, i):
    if len(moji) == n:
        print(moji)
    else:
        for j in range(i):
            if j == i - 1:
                standard(moji + alphas[j], i + 1)
            else:
                standard(moji + alphas[j], i)
                

standard(init_str, 1)

Solution (Python):
n=int(input())
o=ord('a')

def dfs(s,m):
    if len(s)==n:
        print(s)
    else:
        for i in range(m+1):
            dfs(s+chr(o+i),max(m,i+1))
dfs("",0)

Solution (Python):
def dfs(word, i):
    if len(word) == n:
        print(word)
    else:
        if i == 0:
            dfs('a', 1)
        else:
            for j in range(len(set(word)) + 1):
                dfs(word + chr(97 + j), j + 1)


if __name__ == "__main__":
    n = int(input())

    dfs('', 0)

Solution (Python):
N = int(input())
str = "abcdefghijklmnopqrstuvwxyz"
def dfs(s,mx):
    if len(s) == N:
        print(s)
    else:
        for c in str[:mx+1]:
            if c == str[mx]: dfs(s+c, mx+1)
            else: dfs(s+c, mx)
dfs("", 0)

Solution (Python):
def dfs(s, mx, N):
    if len(s) == N:
        print s
    else:
        for ch in range(ord('a'), ord(mx) + 1):
            if chr(ch) == mx:
                dfs(s + chr(ch), chr(ord(mx) + 1), N)
            else:
                dfs(s + chr(ch), mx, N)

def solve2():
    N = int(raw_input())
    dfs('', 'a', N)

if __name__ == '__main__':
    solve2()

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

N = int(input())

ans = ['a']
alph = list(string.ascii_lowercase[:10])
l = 1

while l < N:
    ans2 = []
    for value in ans:
        for letter in alph:
            ans2.append(value + letter)
            if letter not in value:
                break
    l += 1
    ans = ans2
    
for value in sorted(ans):
    print(value)

Solution (Python):









n = int(input())

strlist = "abcdefghij"

def dfs(s,num):
    if len(s) >= n:
        print(s)
        return
    elif num ==0:
        dfs("a",1)
    else:
        for i in range(num):
            dfs(s+strlist[i],num)
        dfs(s+strlist[num],num+1)

dfs("",0)

Solution (Python):
"""
N = 2, 3, 4,...と実験していくと何となく再帰的な構造が見える。
ここで文字列の末尾に再帰構造を見出そうとするときれいにいかず失敗する。
（例）
    N = 3                   N = 4
    a---a---a               a---a---a---a
    '   '---b               '   '   '---b
    '---b---a               '   '---b---a
        '---b               '       '---b
        '---c               '       '---c
                            '---b---a---a
                                '   '---b
                                '   '---c
                                '---b---a
                                '   '---b
                                '   '---c
                                '---c---a
                                    '---b
                                    '---c
                                    '---d

正しくは先頭から再帰構造を見出すべき（数学的帰納法を先頭にかけるのと似た感じ。。。）
するとN=4の場合の樹形図の左から３列目まではN=3と全く同じ形なことに気づく。

よって左から木を生やしていき、（根から葉まで使われた文字数）＋１が新しい葉として生じる。

ここで実際に木を構成するのは面倒そうなので、実装時にはNの各値に対して
（根から葉までの文字列＋使われた最後位の文字）の組をリストに格納する。
（例）N=4なら
    [("aaaa", "a"), ("aaab", "b"), ("aaba", "b"), ("aabb", "b"), ("aabc", "c"), ("abaa", "b"),...]
各組をpopleftすれば、それから新しい文字列（新しい葉）が構成可能。
"""

from collections import deque

N = int(input())
leaf = deque([("a", "a")])
newleaf = []
for _ in range(N - 1):
    while leaf:
        string, maxchar = leaf.popleft()
        maxnum = ord(maxchar) 
        for i in range(97, maxnum + 2):
            newleaf.append((string + chr(i), chr(max(maxnum, i))))
    leaf = deque(newleaf)
    newleaf = []

for s in leaf:
    print(s[0])

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


def f(L, m):
    l = len(L)
    if l == N:
        print(''.join(list(map(lambda i: chr(i + 96), L))))
        return
    for d in range(1, min(l + 1, m + 1) + 1):
        f(L + [d], max(m, d))


f([1], 1)

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

N = int(input())

if N == 1:
    print('a')
    exit()
if N == 2:
    print('aa')
    print('ab')
    exit()

ans = ['aaa', 'aab', 'aba', 'abb', 'abc']
alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
length = 3

while length < N:
    ans2 = []
    for value in ans:
        for letter in alph:
            ans2.append(value + letter)
            if letter not in value:
                break
    length += 1
    ans = copy.deepcopy(sorted(ans2))

for value in ans:
    print(value)

Solution (Python):
from collections import deque
N=int(input())
if N==1:
    print("a")
    exit()
X=[chr(i+97) for i in range(N)]
q=deque(["a"])
while(len(q)>0):
    r=q.popleft()
    k=len(set(r))
    for i in range(k+1):
        p=r+X[i]
        if len(p)==N:
            print(p)
        else:
            q.append(p)

Solution (Python):
n=int(input())
def dfs(s,st):
  if len(s)==n:
    return print(s)
  else:
    for i in range(ord('a'),ord(st)+1):
      if i==ord(st):
        dfs(s+chr(i),chr(ord(st)+1))
      else:
        dfs(s+chr(i),chr(ord(st)))
dfs('','a')

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


def f(L):
    l = len(L)
    if l == N:
        print(''.join(list(map(lambda i: chr(i + 96), L))))
        return
    for d in range(1, min(l, max(L)) + 2):
        f(L + [d])


f([1])

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


def dfs(s, mx):
    if len(s) == n:
        print(s)
        return
    for i in range(ord('a'), ord(mx) + 2):
        dfs(s + chr(i), max(mx, chr(i)))


dfs('a', 'a')

Solution (Python):










n = int(input())



def dfs(s, var):
    if len(s) == n:
        print(s)
    else:
        for i in range(var):
            dfs(s+chr(ord('a')+i), var)

        dfs(s+chr(ord('a')+var), var+1)

dfs('a',1)

Solution (Python):
n=int(input())
def cur(x):
    if len(x)==n:
        s="".join([chr( ord("a")+x[i]) for i in range(n)])
        print(s)

    else:
         for i in range(max(x)+2):
             cur(x+[i])

cur([0])

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

abc = list('abcdefghij')


def solve(ans):
    if len(ans) == n:
        print(*ans, sep='')
    else:
        idx = max([abc.index(ans[i]) for i in range(len(ans))])
        for i in range(idx+2):
            nans = ans + [abc[i]]
            solve(nans)


solve(['a'])

Solution (Python):
n=int(input())
def cur(x):
    if len(x)==n:
        s="".join([chr( ord("a")+x[i]) for i in range(n)])
        print(s)

    else:
         for i in range(max(x)+2):
             cur(x+[i])

cur([0])

Solution (Python):
def dfs(n, s, types):
    if(n==1):
        for i in range(types):
            c = chr(97+i)
            print(s+c)
    else:
        for i in range(types):
            c = chr(97+i)
            if(i==types-1):
                dfs(n-1, s+c, types+1)
            else:
                dfs(n-1, s+c, types)

N = int(input())
dfs(N, '', 1)