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):
tt=[]
ss=[[]]
nn=[]
def ylist(n,nn,ss,s,nstate,tt):
    if n<=1:
        tt.append(s)
        return 
    n=n-1
    for i in range(0,nstate):
        s1=s+[nn[i]]
        ss.append(s1)
        ylist(n,nn,ss,s1,nstate,tt)
    nstate=nstate+1
    s1=s+[nn[nstate-1]]
    ss.append(s1)
    ylist(n,nn,ss,s1,nstate,tt)
    return

n=int(input())  


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

nstate=1    
s=["a"]
ss=[]
tt=[]
ylist(n, nn, ss, s, nstate,tt)
for t in tt:
    t2=""
    for ts in t  :
        t2=t2+ts
    print(t2)

Solution (Python):
def f(n, count=0, i=0, s=""):
    global ans
    if count == n:
        ans.append(s)
        return
    if i == 0:
        f(n, count + 1, i=i+1, s=s+"a")
    else:
        for j in range(i + 1):
            f(n, count + 1, i=max(i, j + 1), s=s+chr(ord("a") + j))

import sys
sys.setrecursionlimit(10000)
n = int(input())
ans = []
f(n)
ans.sort()
for i in ans:
    print(i)

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


def DFS(N, S):
    if len(S) == N:
        print(S)
    else:
        if S:
            next_max_chr = ord(max(S)) + 1
        else:
            next_max_chr = ord("a")
        for i in range(0, next_max_chr - ord("a") + 1):
            DFS(N, S + chr(ord("a") + i))


DFS(N, "")

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


def DFS(N, S):
    if len(S) == N:
        print(S)
    else:
        next_chrs = []
        if S:
            next_max_chr = ord(max(S)) + 1
        else:
            next_max_chr = ord("a")
        for i in range(0, next_max_chr - ord("a") + 1):
            DFS(N, "".join([S, chr(ord("a") + i)]))


DFS(N, "")

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


def DFS(N, S):
    if len(S) == N:
        print(S)
    else:
        next_chrs = []
        if S:
            next_max_chr = ord(max(S)) + 1
        else:
            next_max_chr = ord("a")
        for i in range(0, next_max_chr - ord("a") + 1):
            DFS(N, "".join([S, chr(ord("a") + i)]))


DFS(N, "")

Solution (Python):
def main():
  a='a'
  for _ in~-int(input())*a:
    a=(s+chr(c)for s in a for c in range(97,ord(max(s))+2))
  print('\n'.join(a))
main()

Solution (Python):
def main():
  a='a'
  for _ in~-int(input())*a:
    a=[s+chr(c)for s in a for c in range(97,ord(max(s))+2)]
  print('\n'.join(a))
main()

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

n = int(input())

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


mx = ord('a')
dfs('a', mx)

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

answer = [(97, 'a')]
for _ in range(N - 1):
    new_answer = []
    for i, j in answer:
        for k in range(97, i + 1):
            new_answer.append((i, j + chr(k)))
        new_answer.append((i+1,j+chr(i+1)))
    answer = new_answer[:]

answer = [j for _, j in answer]
answer.sort()
print('\n'.join(answer))

Solution (Python):
def f(n, count=0, i=0, lst=[]):
    global ans
    if count == n:
        s = ""
        for j in range(count):
            s += chr(ord("a") + lst[j])
        ans.append(s)
        return
    if i == 0:
        lst.append(i)
        f(n, count + 1, i=i+1, lst=lst)
    else:
        for j in range(i + 1):
            f(n, count + 1, i=max(i, j + 1), lst=lst+[j])

import sys
sys.setrecursionlimit(10000)
n = int(input())
ans = []
f(n)
ans.sort()
for i in ans:
    print(i)

Solution (Python):
import sys
sys.setrecursionlimit(10**5)
def dfs(s, mx):
  if len(s)==N:
    print(s)
  else:
    for i in range(mx+1):
      if i<mx:
        dfs(s+chr(ord('a')+i),mx)
      else:
        dfs(s+chr(ord('a')+i), mx+1)

N = int(input())
dfs("",0)

Solution (Python):
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)))}

R = ['a']
for i in range(1, N):
    next_r = []
    for r in R:
        max_s = max(r)
        for x in X[:first_presence[max_s] + 2]:
            next_r.append(r + x)
    R = next_r

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

Solution (Python):
N = int(input())
cur = [('a', 0)]
for _ in range(N-1):
    new = []
    for s, c in cur:
        for i in range(c + 2):
            new.append((s + chr(ord('a') + i), max(i, c)))
    cur = new
for s, c in cur:
    print(s)

Solution (Python):
def d(s,n):
 if len(s)==n:return print(s)
 for i in range(97,ord(max(s))+2):d(s+chr(i),n)
d("a",int(input()))

Solution (Python):
import sys
sys.setrecursionlimit(100000)

def dfs(s, mx):
    if len(s) == N:
        print(s)
        return 0
    for c in range(ord("a"), mx + 2):
        t = s
        t += chr(c)
        dfs(t, max(mx, c))

N = int(input())
dfs("", ord("a") - 1)

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()

def dfs(s, limit):
    if len(s) == N:
        print(s)
    else:
        for i in range(limit+2):
            x = chr(i + ord('a'))
            dfs(s + x, max(limit, i))

dfs('a', 0)

Solution (Python):
n=int(input())
dic={0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',8:'i',9:'j'} 

ans=[['a',1]]
for i in range(1,n):
 tmp=[]
 for prev,val in ans:
   for j in range(val+1): 
    
     if j!=val: 
        
       tmp.append([prev+dic[j],val])
     else: 
      
       tmp.append([prev+dic[j],val+1])
 ans=tmp
ans=sorted(ans,key=lambda x:x[0]) 

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

Solution (Python):
n=int(input())
def d(s):
  if len(s)==n:print(s)
  else:
    for i in range(97,ord(max(s))+2):d(s+chr(i))
d("a")

Solution (Python):
n=int(input())
def d(s):
    if len(s)==n:
        print(s)
    else:
        for i in range(97,ord(max(s))+2):
            d(s+chr(i))
d("a")

Solution (Python):


def dfs(string,n):
    if len(string)==n:
        print(string)
    else:
        s=string
        for i in range(97,max([ord(j)for j in string])+2):
            dfs(string+chr(i),n)
        

dfs("a",int(input()))

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

n = int(input())

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


mx = ord('a')
dfs('a', mx)

Solution (Python):
N = int(input())
ans_list = ["a"]
alphabet = [chr(ord("a") + i) for i in range(N)]

for i in range(N - 1):
    ans_list = [ ans + x for ans in ans_list for x in alphabet[:len(set(ans)) + 1]]

for ans in ans_list:
    print(ans)

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

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

scripts = [[] for i in range(N)]
scripts[0] = ["a"]

for i in range(N-1) :
  for ii in range(N-1) :
    if(len(scripts[N-ii-1]) > 0) :
      scripts[N-ii-1] = [str1+str2 for str1 in scripts[N-ii-1] for str2 in alphabets[0:N-ii]]
    scripts[N-ii-1].extend([str1+alphabets[N-ii-1] for str1 in scripts[N-ii-2]])
  scripts[0] = [scripts[0][0]+alphabets[0]]
  
scripts_flatten = []
for i in range(N) :
  scripts_flatten.extend(scripts[i])
scripts_flatten.sort()
for string in scripts_flatten :
  print(string)

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

q = ['a']
for i in range(n-1):
    nq=[]
    for j in q:
        stop=ord(max(j))+2

        for k in range(ord('a'),stop):
            nq.append(j+chr(k))
        q=nq

for i in q:
    print(i)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()

S = [[0]]
ans = []
while S:
    v = S.pop()
    if len(v) == N:
        ans.append(v)
        continue
    else:
        for u in range(max(v)+2):
            S.append(v+[u])

for i,a in enumerate(ans):
    a = list(map(lambda x: chr(x+ord('a')),a))
    ans[i] = ''.join(a)

ans.sort()

for a in ans:
    print(a)

Solution (Python):
def f(word,n):
    if len(word)==N:return print(word)
    else:
        for i in range(n+1):
            f(word+chr(97+i),n+1 if i==n else n)


N=int(input())
f("",0)

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = [[0]]
limit = 0
for i in range(N-1):
    B = []
    for j in range(limit + 2):
        for x in A:
            if max(x) + 1 < j:
                continue
            y = x + [j]
            B.append(y)
    A = B
    limit += 1

A = [tuple(x) for x in A]
A = sorted(set(A))
for x in A:
    x = [chr(y + ord('a')) for y in x]
    print(''.join(x))

Solution (Python):
N = int(input())
def DFS(s, mx):
    if len(s) == N:
        print(s)
        return
    c = 'a'
    while c <= chr(ord(mx)+1):
        t = s + c
        DFS(t, chr(max(ord(c), ord(mx))))
        c = chr(ord(c) + 1)
DFS("", chr(ord('a')-1))

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
def f(s, last):
    if len(s) == n:
        print(s)
    else:
        for i in range(97, last + 2):
            f(s + chr(i), last + 1 if i == last + 1 else last)


f('', 96)

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

def dfs(s, m):
    
    if len(s) == n:
        print(s)
    else:
        for i in range(m + 1 - a):
            dfs(s + chr(a + i), m + 1 if i == m - a else m)

dfs("", a)

Solution (Python):
from collections import deque, defaultdict, Counter
from math import ceil, floor
from string import ascii_lowercase as AL
import sys
def input():
    return sys.stdin.readline().strip()







def dfs(s, mx, N):
    
    if len(s) == N:
        print(s)
    else:
        for ch in AL:
            if ord(ch) <= ord(mx):
                next_ch = chr(ord(ch) + 1) if ch == mx else mx
                dfs(s + ch, next_ch, N)

N = int(input())
dfs("", 'a', N)

Solution (Python):
n = int(input())
ans = []

def dfs( s , mx ):
    if len(s) == n:
        ans.append(s)
        return
    else:
        for j in range(mx+1):
            t = chr(j + 97)
            mx2 = ord(max(s+t)) - 96
            dfs( s+t , mx2 )
            
dfs('a' , 1)

for i in ans:
    print(i)

Solution (Python):
from collections import deque

q = deque()

q.append('a')

n = int(input())

ans_list = []
flag = 0

if n != 1:
    while flag == 0:
        s = q.pop()
        if len(s) > n:
            flag = 1
        a = list(s)
        x = chr(ord('a')-1)
        a = map(ord,a)
        max_a = max(a)
        while ord(x) != max_a+1:
            x = chr(ord(x)+1)
            y = s + x
            q.appendleft(y)
            if len(y) == n:
                ans_list.append(y)
else:
    ans_list = ['a']

ans_list = sorted(ans_list)

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

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

A = "abcdefghij"
N = 0
def dfs(s, lim):
    global N
    if len(s) == N:
        print("".join(s))
        
        return
    for i in range(lim): 
        s.append(A[i])
        dfs(s, len(set(s)) + 1)
        s.pop()
    
    
    
    

def main():
    global N
    N = int(input().strip())
    dfs([], 1)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A = ['a']
S = 'abcdefghij'
for _ in range(n-1):
    A = [ a + s for a in A for s in S[:len(set(a)) + 1]]
print('\n'.join(A))

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

N = int(input())

chars = "abcdefghij"
queue = deque()
queue.append(("a", 1))

while queue:
    s, num = queue.popleft()
    if len(s) == N:
        print(s)
    else:
        for i in range(num+1):
            ss = s + chars[i] 
            if i == num:
                queue.append((ss, num+1))
            else:
                queue.append((ss, num))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    if n == 1:
        return "a"
    r = []
    def f(t, k):
        u = chr(ord(k)+1)
        lf = len(t) == n - 1
        for c in string.ascii_lowercase:
            if c > u:
                break
            if lf:
                r.append(JA(t+[c], ""))
            else:
                if c > k:
                    f(t+[c], c)
                else:
                    f(t+[c], k)
    f(['a'], 'a')

    return JA(r, "\n")


print(main())

Solution (Python):
def string_equivalence(n):
    ans = [[]]
    s = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
    for _ in range(n):
        tmp = []
        for a in ans:
            for i in range(len(set(a))+1):
                a_tmp = []
                a_tmp.extend(a)
                a_tmp.append(s[i])
                tmp.append(a_tmp)
        ans = tmp
    for ans_s in ans:
        print(''.join(ans_s))

n = int(input())
string_equivalence(n)

Solution (Python):
def dfs(a='', b=chr(ord('a'))):
	if len(a) == N:
		print(a)
	else:
		i = chr(ord('a'))
		while i < b:
			dfs(a + i, b)
			i = chr(ord(i) + 1)
		dfs(a + b, chr(ord(b) + 1))

N = int(input())
dfs()

Solution (Python):
n = int(input())
A = 'a'
S = 'abcdefghij'
for _ in range(n-1):
    A = [ a + s for a in A for s in S[:len(set(a)) + 1]]
print('\n'.join(A))

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


if __name__ == "__main__":
    N = int(input())
    al = [chr(ord('a') + i) for i in range(26)]

    def dfs(s, mx):
        if (len(s) == N):
            print(s)
        else:
            for c in al:
                if c == chr(ord(mx) + 1):
                    break
                nmx = chr(ord(mx) + 1) if (c == mx) else mx  
                dfs(s + c, nmx)

    dfs('', 'a')

Solution (Python):
from collections import defaultdict, deque

def dfs(q, M, d):
    if d==N:
        res = []

        for qi in q:
            res.append(dic[qi])
        
        print(''.join(res))
        return
        
    for i in range(M+1):
        q.append(i)
        dfs(q, M, d+1)
        q.pop()
    
    q.append(M+1)
    dfs(q, M+1, d+1)
    q.pop()

N = int(input())
dic = defaultdict(int)
c = 0

for a in 'abcdefghijklmnopqrstuvwxyz':
    dic[c] = a
    c += 1

dfs(deque([0]), 0, 1)

Solution (Python):
n = int(input())
A = 'a'
S ='abcdefghij'
for _ in range(n-1):
    A = [a + s for a in A for s in S[:len(set(a))+1]]
print(*A, sep='\n')

Solution (Python):
n = int(input())
A = ['a']
S = 'abcdefghij'
for _ in range(n-1):
    A = [ a + s for a in A for s in S[:len(set(a)) + 1]]
print('\n'.join(A))

Solution (Python):
n = int(input())
A = ['a']
S = 'abcdefghij'
for _ in range(n-1):
    B = []
    for a in A:
        for s in S[:len(set(a)) + 1]:
            B.append(a + s)
    A = B[::]
print('\n'.join(A))

Solution (Python):
import sys

sys.setrecursionlimit(100000)


def dfs(s, mx):
    if len(s) == N:
        print(s)
        return 0
    for c in range(ord("a"), mx + 2):
        t = s
        t += chr(c)
        dfs(t, max(mx, c))


N = int(input())
dfs("", ord("a") - 1)

Solution (Python):
N=int(input())
import itertools
L=[N-i for i in range(N,0,-1) for j in range(i)]
a=[0]*N
stop=[i for i in range(N)]
dict=[chr(ord('a')+i) for i in range(N)]
def content(a):
  ans=''
  for i in a:
    ans+=dict[i]
  return ans
print(content(a))
def saiki(a,p):
  nowp=N-1
  nowv=max(a)+1
  x=a[:]
  
  while nowp>p:
    
    if nowp==N-1:
      for X in range(nowv+1):
        a[nowp]=X
        print(content(a))
        
    else:
      for X in range(1,nowv+1):
        a[nowp]=X
        a=saiki(a,nowp)
    a[nowp]=0
    nowp-=1
  return x
P=N-1
if N>1:
  a[-1]+=1
  print(content(a))
while P>0:
  a=saiki(a,P)
  P-=1
  a=[0]*N
  a[P]=1

Solution (Python):



import sys
sys.setrecursionlimit(10**8)
N=int(input())
abc=list("abcdefghij")
def dfs(s,v):
    global N
    for i in range(v+2):
        ns=s+abc[i]
        if len(ns)<N :
            if i!=v+1:
                dfs(ns,v)
            else:
                dfs(ns,v+1)
        if len(ns)==N:
            print("".join(ns))
if N==1:
    print("a")
else:
    dfs("a",0)

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

for _ in range(n - 1):
    A = {a + s for a in A for s in a + chr(ord(max(a)) + 1)}
    


print(*sorted(A), sep='\n')

Solution (Python):


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

    N = int(input())
    d = deque(['a'])
    while len(d[0])<N:
        s = d.popleft()
        diff = ord(max(s)) - ord('a')
        for i in range(diff+2):
            x = ord('a')
            d.append(s+chr(x+i))
    while len(d)!=0:
        print(d.popleft())

if __name__ == '__main__':
    main()

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


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

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

ans = ["a"]

for i in range(n-1):
    old = ans
    ans = []
    for t in old:
        k = len(set(list(t)))
        for j in range(k+1):
            ans.append(t+chr(97+j))

print("\n".join(ans))

Solution (Python):
def saiki(s, n, m):
  if n == 0:
    print(s)
    return
  
  a = ord('a')
  c = ord(m) + 2
  
  
  for i in range(a, c):
    saiki(s+chr(i), n-1, chr(max(i, ord(m))))
    
n = int(input())

saiki('a',n-1, 'a')

Solution (Python):
N=int(input())
from collections import deque
q=deque([["a",1]])
while q:
  ch,most=q.popleft()
  if len(ch)==N:
    print(ch)
    continue
  for i in range(ord("a"),ord("a")+most):
    q.append([ch+chr(i),most])
  q.append([ch+chr(ord("a")+most),most+1])

Solution (Python):
def main():
    from collections import deque
    from operator import itemgetter
    from string import ascii_lowercase

    N = int(input())

    deq = deque(), deque()
    curr = 0
    deq[curr].append(('a', 0))  
    for _ in range(N - 1):
        while deq[curr]:
            word, largest_char_index = deq[curr].popleft()
            for add_char_index in range(largest_char_index + 1 + 1):
                new_word = word + ascii_lowercase[add_char_index]
                deq[curr ^ 1].append(
                    (new_word, max(largest_char_index, add_char_index)))
        curr ^= 1

    print(*map(itemgetter(0), deq[curr]), sep='\n')


if __name__ == '__main__':
    main()

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

eng = "abcdefghijklmnopqrstuvwxyz"

def range_dic(inp_dic):
    ans_dic = {}
    for key, value in inp_dic.items():
        for i in range(30):
            if i <= key:
                w = eng[i]
                _value = [v + w for v in  value]
                if not key in ans_dic:
                    ans_dic[key] = []
                ans_dic[key].extend(_value)
            elif i == key + 1:
                w = eng[i]
                _value = [v + w for v in  value]
                if not i in ans_dic:
                    ans_dic[i] = []
                ans_dic[i].extend(_value)
    return ans_dic


inp_dic = {0: ["a"]}

for i in range(N-1):
    inp_dic = range_dic(inp_dic)
results = []
for words in inp_dic.values():
    results.extend(list(words))

results.sort()
for result in results:
    print(result)

Solution (Python):

N = int(input())
def dfs(s, l, char_num):
    if l == N:
        print(s)
    else:
        for i in range(char_num+1):
            ns = s+chr(97+i)
            dfs(ns, l+1, len(set(ns)))

dfs('a',1, 1)

Solution (Python):


import sys
sys.setrecursionlimit(300000)


def solve(N: int):
    def _convert(cur):
        ret = [''] * N
        for i, pos in enumerate(cur):
            c = chr(ord('a') + i)
            for p in pos:
                ret[p] = c
        ret = ''.join(ret)
        return ret
    def rec(idx, cur):
        if idx == N:
            ret = _convert(cur)
            return [ret]
        ret = []
        for c in cur:
            c.append(idx)
            tmp = rec(idx + 1, cur)
            ret += tmp
            c.pop()
        cur.append([idx])
        ret += rec(idx + 1, cur)
        cur.pop()

        return ret
    ret = rec(0, [])
    for r in ret:
        print(r)
    
    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):
n = int(input())

def dfs(s, mx):
    """
    :param s: 今の文字
    :param mx: 今までで最大の文字
    :return:
    """
    if len(s) == n:
        print(s)
        return
    for c in range(ord('a'), ord(mx) + 1 + 1):
        t = s
        t += chr(c)
        mx = chr(max(ord(mx), c))
        dfs(t, mx)

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

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

def dfs(n,i,s,ans):
    if n == N:
        ans.append(s)
        return
    
    for j in range(i+1):
        tmp = s + chr(j + 97)
        max_j = ord(max(tmp)) - 96
        dfs(n+1,max_j,tmp,ans) 
    

def main():
    ans = []
    dfs(1,1,'a',ans)
    ans.sort()
    for a in ans:
        print(a)


    


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
def dfs(x):
    if len(x) == n:
        print(''.join(map(lambda i: chr(ord('a') + i - 1), x)))
        return
    for i in range(max(x)+1):
        y = x.copy()
        y.append(i+1)
        dfs(y)
dfs([1])

Solution (Python):
n = int(input())
ans = []
def dfs(x):
    if len(x) == n:
        print(''.join(map(lambda i: chr(ord('a') + i - 1), x)))
        return
    for i in range(max(x)+1):
        y = x.copy()
        y.append(i+1)
        dfs(y)
dfs([1])

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

ans = []
def dfs(x):
    if len(x) == n:
        ans.append(x)
        return
    for i in range(max(x)+1):
        y = x.copy()
        y.append(i+1)
        dfs(y)
dfs([1])


for ai in ans:
    print(''.join(map(lambda x: chr(ord('a') + x - 1), ai)))

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

ans = []
def dfs(x):
    if len(x) == n:
        ans.append(x)
        return
    for i in range(0, max(x)+1):
        y = x.copy()
        y.append(i+1)
        dfs(y)
dfs([1])


r = ['a','b','c','d','e','f','g','h','i','j']
for ai in ans:
    print(''.join(map(lambda x: str(r[x-1]), ai)))

Solution (Python):
N=int(input())
ABC=["a","b","c","d","e","f","g","h","i","j"]
def dfs(n,s):
  if len(s)==N:
    print(s)
    return
  
  for i in range(n+1):
    _s=s+ABC[i]
    dfs(max(n,i+1),_s)
    
dfs(0,"")

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


l = list('' for _ in range(n))

def dfs(i, mx):
    if i == n:
        
        print(''.join(l))
        return
    
    for j in range(mx + 1):
        
        l[i] = chr(ord('a') + j)
        
        dfs(i+1, max(j + 1, mx))

dfs(0, 0)

Solution (Python):
import sys
import re

l = sys.stdin.readline()
l = int(l)
out = []
def x(stri,l,depth):
  str = 'abcdefghij'
  use = 0
  for i in range(0,l-depth+1):
    if( use == 1):
      break
    cdepth = depth
    cstri = stri
    if ( str[i] not in cstri):
      use = 1
    cstri += str[i] 
    cdepth -= 1
    if( cdepth == 0):
	out.append(cstri)
    else:
	x(cstri,l,cdepth)


stri = 'a'
if( l == 1):
 print stri
 exit(0)
x(stri,l,l-1)

count = 0
for i in out:
  print i


sys.stdout.flush()

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()


l=['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']


n=I()

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

  for i in range(x+1):
    _s=s+l[i]
    dfs(max(x,i+1),_s)

def main():
  dfs(0,'')

main()

Solution (Python):

class Solution:

    def solve(self, N: int):

        def dfs(prev_str: str, max_search_char: str):
            if len(prev_str) == N:
                print(prev_str)
                return
            else:

                for i in range(ord('a'), ord(max_search_char) + 1):
                    c = chr(i)
                    if i == ord(max_search_char):
                        dfs(prev_str + c, chr(i+1))
                    else:
                        dfs(prev_str + c, max_search_char)

        dfs('', 'a')


if __name__ == '__main__':

    
    N = int(input())
    
    solution = Solution()
    answer = solution.solve(N)

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

def it(i,n):
    if i == N:
        yield [None]*N
    else:
        for x in range(n):
            for d in it(i+1,n):
                d[i] = x
                yield d
        for d in it(i+1,n+1):
            d[i] = n
            yield d

print(*(''.join(chr(x+ord('a')) for x in d) for d in it(0,0)), sep='\n')

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

def it(remain,n):
    if remain == 0:
        yield []
    else:
        for x in range(n+1):
            for d in it(remain-1,max(x+1,n)):
                d.append(x)
                yield d


print(*(''.join(chr(x+ord('a')) for x in reversed(d)) for d in it(N,0)), sep='\n')

Solution (Python):
n = int(input())
L = []
def f(s, m):
    if len(s) == n:
        L.append(s)
        return
    for i in range(97, m+2):
        f(s + chr(i), max(i, m))
f("a", 97)
for l in L:
    print(l)

Solution (Python):
def rec(pos, used, s):
    if pos == n:
        print(s)
        return
    for i in range(used):
        rec(pos + 1, used, s + chr(ord('a') + i))
    rec(pos + 1, used + 1, s + chr(ord('a') + used))

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

Solution (Python):
def dfs(s, mx):
    if len(s) == n:
        print(s)
        return
    for c in a[:mx]:
        dfs(s+c, mx)
    dfs(s+a[mx], mx+1)

n = int(input())
a = "abcdefghij"
dfs("", 0)

Solution (Python):

import itertools


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

    if N==1:
        print("a")
        return

    anss = []

    def _dfs(d, _max, ans):
        if d==N:
            anss.append(ans)
            return

        for i in range(ord("a"), _max+2):
            _dfs(d+1, max(_max, i), ans+chr(i))

    _dfs(1, ord("a"), "a")

    anss.sort()

    for ans in anss:
        print(ans)


if __name__ == "__main__":
    solve()

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):
def main():
    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

    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()