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):
import sys
input = sys.stdin.readline

n = int(input())

a_ord = ord('a')

s = ["a"]

ans = []

def dfs(s):
    max_ord = a_ord
    for i in s:
        max_ord = max(max_ord, ord(i))
    for i in range(a_ord, max_ord + 2):
        t = s[:]
        t.append(chr(i))
        if len(t) == n:
            ans.append("".join(t))
        else:
            dfs(t)
if n == 1:
    print('a')
else:
    dfs(s)
    ans.sort()
    for w in ans:
        print(w)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())





q = deque()
s = "a"
q.append(s)

while q:
    t = q.popleft()
    if len(t)==n:
        print(t)
    else:
        c = max(t)
        for j in range(97,ord(c)+2):
            nt = copy(t)
            nc = chr(j)
            nt += nc
            q.append(nt)

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

def dfs(str):
    if len(str) == N:
        print(*str, sep="")
        return

    M = max(str)

    for i in range(ord(M) - ord("a") + 2):
        char = alpha[i]
        str.append(char)
        dfs(str)
        str.pop()

alpha = 'abcdefghijklmnopqrstuvwxyz'
s = deque(["a"])
dfs(s)

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

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

lst = ['a']
for i in range(n-1):
    new_lst = []
    for string in lst:
        num = ord(sorted(string)[-1])
        for j in range(ord('a'), num+2):
            new_lst.append(string+chr(j))
    lst = new_lst

for string in lst:
    print(string)

Solution (Python):
N=int(input())
alp=["a","b","c","d","e","f","g","h","i","j"]
alp=alp[:N]
ans=[]
def dfs(now):
    
    if len(now)==N:
        ans.append(now)
        return
    for i,s in enumerate(alp):
        if len(set(now))>=i:
            next_s=now+s
            dfs(next_s)
dfs("a")
ans=sorted(ans)
for a in ans:
    print(a)

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

def dfs(now):
    if len(now)==N:
        print(''.join(now))
        return
    
    M = max(now)
    
    for i in range(ord(M)-ord('a')+2):
        now.append(alpha[i])
        dfs(now)
        now.pop()

N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
dfs(deque(['a']))

Solution (Python):
def saiki(n,A):

    if n == N:
        A.sort()
        for i in A:
            print(i)
        return

    alpha = list("abcdefghijklmnopqr")

    tmp = []

    for i in A:
        a = alpha.index(sorted(list(i))[-1])
        for j in range(a+2):
            tmp.append(i+alpha[j])
    
    saiki(n+1,tmp)

N = int(input())

saiki(1,["a"])

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


def get_range(s):
    start = ord("a")
    end = ord(max(s))
    return [chr(c) for c in range(start, end + 2)]


def pana(s):
    if len(s) == N:
        ans.append(s)
        return
    for t in get_range(s):
        pana(s + t)
    return


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

Solution (Python):
t="abcdefghijklmnopqrstuvwxyz"
n=int(input())
ans=[]
def dfs(s):
  global ans
  if len(s)==n:
    ans.append(s)
    return 
  for i in range(len(set(s))+1):dfs(s+t[i])
  return
dfs("")
ans.sort()
for i in ans:print(i)

Solution (Python):
from collections import deque
 
n = int(input())
 
def dfs(n):
  stack = deque()
  stack.append("a")
  while stack:
    q = stack.popleft()
    if len(q) == n:
      ans.append(q) 
    if len(q) < n:
      for i in range(ord("a"), ord(max(q)) + 2):
        stack.append(q + chr(i))
    
    
ans = []
dfs(n)
 
print("\n".join(ans))

Solution (Python):
from collections import deque
N = int(input())
que = deque(['a'])

while len(que) > 0:
    s = que.popleft()
    if len(s) == N:
        print(s)
    else:
        for i in range(ord(sorted(s)[-1]) - 95):
            que.append(s + chr(97 + i))

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

def standard_string(N, st):
    if len(st) == N:
        print(st)
    elif st == "":
        standard_string(N, "a")
    else:
        for i in range(97, ord(max(st))+ 2):
            st += chr(i)
            standard_string(N, st)
            st = st[:-1]
standard_string(N, "")

Solution (Python):
a = int(input())
S = 'abcdefghij'

def dfs(s,c):
    if c == a:
        ans.append(s)
        return 
    for i in S[:c+1]:
        if i in s:dfs(s+i,c+1)
        else:
            dfs(s+i,c+1)
            return 
ans = []

dfs("",0)

for i in ans:
    print(i)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
a = int(input())
S = 'abcdefghij'

def dfs(s,c):
    if c == a:
        ans.append(s)
        return 
    for i in S[:c+1]:
        if i in s:dfs(s+i,c+1)
        else:
            dfs(s+i,c+1)
            return 
ans = []

dfs("",0)

for i in ans:
    print(i)

Solution (Python):
n = int(input())
a = ["a","b","c","d","e","f","g","h","i","j"]
def dfs(s):
  m = len(s)
  if m == n:
    ans = ""
    for i in range(n):
      ans += a[int(s[i])]
    print(ans)
  else:
    for i in range(int(max(list(s)))+2):
      dfs(s+str(i))

dfs("0")

Solution (Python):

n = int(input())

stack = [["",0] for i in range(10**6*4)]
stack[0] = ["a",1]
pos = 0    
while(pos>=0):
    if(len(stack[pos][0]) == n):
        print(stack[pos][0])
        pos-=1
    else:
        
        nowstr = stack[pos][0]
        nowlen = stack[pos][1]
        
        pos-=1
        for ii in range(nowlen+1):
            i = nowlen-ii
            pos+=1
            stack[pos][0] = nowstr+chr(ord('a')+i)
            if(i == nowlen):
                stack[pos][1] = nowlen+1
            else:
                stack[pos][1] = nowlen

Solution (Python):

N = int(input())

def dfs(x):
    if len(x) == N:
        s = "".join(chr(v + ord("a")) for v in x)
        print(s)
        return

    val = max(x)
    for i in range(val + 2):
        x.append(i)
        dfs(x)
        x.pop()

dfs([0])

Solution (Python):
from string import ascii_lowercase

n = int(input())

def f(l):
    if len(l)==n:
        print("".join([ascii_lowercase[i] for i in l]))
        return
    
    for i in range(max(l)+2):
        f(l+[i])

f([0])

Solution (Python):
n = map(int, raw_input().split(' '))[0]

def dfs(i, mx, n, cur = []):
	if i==n:
		print ''.join(cur)
		return
	for v in range(0, mx + 1): dfs(i + 1, mx + (1 if v == mx else 0), n , cur + [chr(v+ ord('a'))])

dfs(0,0,n)

Solution (Python):

n = map(int, raw_input().split(' '))[0]


def dfs(i, mx, n, res, cur = []):
	if i==n:
		res.append(''.join(cur[::]))
		return


	for v in range(0, mx + 1):
		dfs(i + 1, mx + (1 if v == mx else 0), n , res, cur + [chr(v+ ord('a'))])

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

Solution (Python):


import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    def dfs(S, available):
        if len(S) == n:
            print("".join(S))
            return

        for i in range(available + 1):
            S.append(chr(97 + i))
            dfs(S, max(available, i + 1))
            S.pop()

    dfs([], 0)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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

        for i in range(num + 1):
            t = s + chr(97 + i)
            dfs(t, max(num, i + 1))

    dfs("", 0)


if __name__ == '__main__':
    resolve()

Solution (Python):
def solve():
    N = int(input())
    dfs("", 0, N)

def dfs(cur, n_type, N):
    if len(cur) == N:
        print(cur)
        return
    
    for offset in range(n_type+1):
        next_chr = chr(ord('a') + offset)
        next_n_type = n_type + 1 if offset==n_type else n_type
        dfs(cur+next_chr, next_n_type, N)
    
    return
if __name__ == '__main__':
    solve()

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

alphabets = [chr(ord('a') + x) for x in range(26)]

ans = []


def dfs(d, i_max, S):
    if d == N-1:
        ans.append(S)
        return
    for i in range(i_max+2):
        dfs(d+1, max(i_max, i), S + alphabets[i])


dfs(0, 0, "a")
print(*ans, sep='\n')

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
strlist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def dfs(n, before):
    lensetbefore = len(set(before))
    if n == 1:
        print(before)
    if n > 1:
        for s in strlist[:lensetbefore+1]:
            dfs(n-1, before+s)

def main():
    N = int(input())
    dfs(N, 'a')


if __name__ == "__main__":
    main()

Solution (Python):


from collections import deque


N = int(input())

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

def dfs(a_list, a_len):
    if a_len==N:
        print("".join(a_list))
        return
    else:
        biggest = 97
        count = len(set(a_list)) 
        for c in range(biggest, biggest + count + 1):
            ch = chr(c)
            a_list.append(ch)
            dfs(a_list, a_len+1)
            a_list.pop()


a_nums = deque([])


dfs(a_nums, 0)

Solution (Python):

n = int(input())
def dfs(cnt,s):
    if cnt == n:
        print(s)
        return
    biggest = 'a'
    c = 0
    while c < len(s):
        if s[c] == biggest:
            biggest = chr(ord(biggest)+1)
            c += 1
        else:
            c += 1
    
    for i in range(0,ord(biggest) - ord('a')+1):
        sc = chr(ord('a') + i)
        
        s += sc
        dfs(cnt + 1, s)
        s = s[:-1]

dfs(0,"")

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


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

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


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

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

from collections import deque

option=deque()
option.append("a")
ans=[]

while option:
    s=option.pop()
    if len(s)==n:
        ans.append(s)
        continue
    maxi=0
    for i in s:
        maxi=max(maxi,ord(i))
        
    for i in range(97,maxi+2):
        new_s=s+chr(i)
        if new_s not in option and len(new_s)<=n:
            option.append(new_s)

ans=sorted(ans)
for i in ans:
    print(i)

Solution (Python):
n = int(input())
def dfs(s):
  if len(s) == n:
    print(s)
  else:
    max_list = []
    for _ in s:
      max_list.append(ord(_))
    for i in range(ord("a"),max(max_list) + 2):
      s = s + chr(i)
      dfs(s)
      s = s[:len(s) - 1]
      
dfs("a")

Solution (Python):
from collections import deque

n = int(input())

def dfs(n):
  stack = deque()
  stack.append("a")
  while stack:
    q = stack.popleft()
    if len(q) == n:
      ans.append(q) 
    if len(q) < n:
      for i in range(ord("a"), ord(max(q)) + 2):
        stack.append(q + chr(i))
    
ans = []
dfs(n)

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

Solution (Python):
n=int(input())
from collections import deque
def dfs():
  todo=deque([[1]])
  ret=[]
  while len(todo)>0:
    t=todo.popleft()
    if len(t)==n:
      ret.append(t)
    else:
      l=max(t)+1
      for i in range(l):
        tc=t.copy()
        tc.append(i+1)
        todo.append(tc)
  return ret
a=dfs()
n2a = lambda c: chr(c+64).lower()
for ai in a:
  
  print(''.join(map(n2a,ai)))

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


def read():
    N = int(input().strip())
    return N,

def standalize(N):

    q = list()
    alphabets = "abcdefghijklmnopqrstuvwxyz"
    
    s = []

    def dfs(i):
        """i種類の文字から選んで、sの末尾に追加する
        """
        if len(s) == N:
            q.append(''.join(s))
        else:
            for j, a in enumerate(alphabets[:i-1]):
                s.append(a)
                dfs(i)
                s.pop()
            a = alphabets[i-1]
            s.append(a)
            dfs(i+1)
            s.pop()
    
    dfs(1)
    return q

def solve(N):
    for s in standalize(N):
        print(s)

if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % outputs)

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


def read():
    N = int(input().strip())
    return N,

def standalize(N):

    q = list()
    alphabets = "abcdefghijklmnopqrstuvwxyz"
    
    def dfs(i, s=[]):
        """i種類の文字から選んで、sの末尾に追加する
        """
        if len(s) == N:
            q.append(''.join(s))
        else:
            for j, a in enumerate(alphabets[:i-1]):
                dfs(i, s + [a])
            a = alphabets[i-1]
            dfs(i+1, s + [a])
    
    dfs(2, s=['a'])
    return q

def solve(N):
    for s in standalize(N):
        print(s)

if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % outputs)

Solution (Python):
n=int(input())
l=[['a1']]+[[] for _ in range(9)]
for i in range(9):
  for b in l[i]:
    t=b[-1]
    for p in range(int(t)):
      l[i+1].append(b[:-1]+chr(97+p)+t)
    l[i+1].append(b[:-1]+chr(97+int(t))+str(int(t)+1))
for i in l[n-1]:
  if len(i)==12:
    print(i[:-2])
  else:
    print(i[:-1])

Solution (Python):
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

N = int(input())
ans = []
def dfs(i,standard):
    if i == N:
        ans.append(standard)
        return
    before_M = max(ord(s) for s in standard)
    for j in range(97,before_M + 2):
        dfs(i + 1,standard + chr(j))
dfs(1,'a')
print('\n'.join(ans))

Solution (Python):
def main():
    from string import ascii_lowercase

    N = int(input())

    ans = []

    def dfs(s='a', ma='a'):
        if len(s) == N:
            ans.append(s)
            return

        for c in ascii_lowercase:
            dfs(s + c, max(c, ma))
            if c > ma: break

    dfs()

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
n = int(input())

def dfs(s):
    if len(s) == n:
        print(s)
    else:
        for x in map(chr, range(97, ord(max(s))+2)):
            dfs(s+x)


dfs("a")

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
n = int(input())
ls = []


def dfs(s):
    if len(s) == n:
        ls.append(s)
        return 0
    else:
        for x in map(chr, range(97, ord(max(s))+2)):
            dfs(s+x)


dfs("a")
ls.sort()
for x in ls:
    print(x)

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

d = 'abcdefghijklm'


def conv(s):
    s = list(map(lambda x: d[x], s))
    return ''.join(s)


def dfs(s, k):
    if len(s) == n:
        print(s)
    else:
        for i in range(k):
            dfs(s+d[i], k)
        dfs(s+d[k], k+1)


dfs('a', 1)

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

d = 'abcdefghijklm'


def conv(s):
    s = list(map(lambda x: d[x], s))
    return ''.join(s)


def dfs(s):
    if len(s) == n:
        print(conv(s))
    else:
        mx = max(s)+1
        for i in range(mx+1):
            dfs(s+[i])


dfs([0])

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

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

from collections import deque
from collections import Counter
abc="abcdefghijklmnopqrstuvwxyz"
ans=["a"]

for i in range(1,N):
    d=deque(ans)
    ans=[]
    while d:
        temp=d.popleft()
        temp2=list(temp)
        cnt=Counter(temp2)
        L=len(cnt)
        for j in range(L+1):
            ans.append(temp+abc[j])

for a in ans:
    print(a)

Solution (Python):
n = int(input())
a = ["a","b","c","d","e","f","g","h","i","j"]
def dfs(s, max_x, LEN):
  if LEN == n:
    print(s)
  else:
    for c in a[:a.index(max_x)+2]:
      dfs(s+c, max(max_x,c), LEN+1)
dfs("a", "a", 1)

Solution (Python):
s="abcdefghij"
n=int(input())
ans=[["a",1]]
c=1
while(c<n):
    an=[]
    for i in ans:
        lim=min(i[1]+1,10)
        for j in range(lim):
            if (j==i[1]) and (j!=10):
                an.append([i[0]+s[j],i[1]+1])
            else:
                an.append([i[0]+s[j],i[1]])
    ans=an
    c+=1
for i in ans:
    print(i[0])

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
if __name__ == '__main__':
    def solve(s, a):
        if len(s) == n:
            print(s)
        else:
            for c in range(ord("a"), a + 1):
                if c == a:
                    solve(s + chr(c), a + 1)
                else:
                    solve(s + chr(c), a)
    n = int(input())
    solve("", ord("a"))

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

def dfs(s, mx):
    if len(s) == N:
        print(s)
    else:
        for c in range(ord("a"),mx+1):
            if c == mx:
                dfs(s+chr(c),mx+1)
            else:
                dfs(s+chr(c),mx)

dfs("",ord("a"))

Solution (Python):
def p(S):
    str = ""
    for s in S:
        str += chr(ord("a")+int(s))
    print(str)

N = int(input())
S = [0]*N

def up(i):
    if i == 0:
        return True
    S[i] += 1
    if S[i] == max(S[:i]) + 2:
        S[i] = 0
        return up(i-1)
    return False

while True:
    p(S)
    if up(N-1):
        break

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

def getlist():
	return list(map(int, input().split()))


def main():
	N = int(input())
	ansL = [[] for i in range(10)]
	ansL[0].append(["a", 1])
	for i in range(N - 1):
		n = len(ansL[i])
		for j in range(n):
			for k in range(ansL[i][j][1]):
				ansL[i + 1].append([ansL[i][j][0] + chr(97 + k), ansL[i][j][1]])
			ansL[i + 1].append([ansL[i][j][0] + chr(97 + ansL[i][j][1]), ansL[i][j][1] + 1])

	n = len(ansL[N - 1])
	for i in range(n):
		print(ansL[N - 1][i][0])
	



if __name__ == '__main__':
	main()

Solution (Python):
N=int(input())
A=["a"]
if N==1:
    print("a")
    exit()
else:
    S="abcdefghijklmn"
    slist=list(S) 
    for i in range(2,N+1):
        temp=[[] for _ in range(N)]
        for j in range(i-1):
            for w in A[j]:
                for u in slist[:j+1]:
                    temp[j].append(w+u)
                temp[j+1].append(w+slist[j+1])
        A=temp
    B=[]    
    for j in range(N):
        for t in A[j]:
            B.append(t)
    B.sort()
    for i in range(len(B)):
        print(B[i])

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    if N==1:
        print('a')
    else:
        q = ['a']
        for _ in range(N - 1):
            nq = []
            for j in q:
                for k in range(ord('a'), ord(max(j)) + 2):
                    nq.append(j + chr(k))
            q=nq

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

resolve()

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


def dfs(n, s):
    if len(s) == n:
        print(s)
        return
    cnt = len(set(s))
    cnt += 1

    for a in alpha[:cnt]:
        ns = s + a
        dfs(n, ns)


dfs(N, "")

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

from collections import deque

q = deque()

q.append('a')

while True:
    str = q.popleft()
    temp_lst = list(str) + [chr(ord('a') + len(set(str)))]
    temp_lst = list(set(temp_lst))
    temp_lst.sort()
    for c in temp_lst:
        q.append(str + c)
    if len(str) < N:
        continue
    elif len(str) == N:
        print(str)
    else:
        break

Solution (Python):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


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

    que = queue.Queue()
    que.put(('a', ord('a')))

    while not que.empty():
        res, m = que.get()
        if len(res) < N:
            for i in range(ord('a'), min(ord('z'), m + 1) + 1):
                que.put((res + chr(i), max(m, i)))
        elif len(res) == N:
            print(res)
        else:
            break


if __name__ == '__main__':
    main()

Solution (Python):
def num_to_str(n):
    return chr(97 + n)

def str_to_num(s):
    return ord(s) - 97

def dfs(s,m,n,N,ans):
    if n == N:
        ans.append(s)
        return
    for i in range(m+2):
        dfs(s+num_to_str(i),max(m,i),n+1,N,ans)

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


if __name__ == "__main__":
    main()

Solution (Python):
def ST(A,k):
    
    
    OP = []
    for a in A:
        max_cord = 0
        for i in range(len(a)):
            max_cord = max(ord(a[i]),max_cord)
        for i in range(97,max_cord+2):
            OP.append(a+chr(i))
    return OP

N = int(input())

n,A = 1,["a"]
while n < N:
    A = ST(A,n)
    n += 1

A.sort()
for i in range(len(A)):
    print(A[i])

Solution (Python):
n=int(input())
s='abcdefghij'
def f(string):
  r=[]
  for i in range(len(string)):
    m=0
    for j in string[i]:
      if ord(j)-97 > m:
        m=ord(j)-97
    for j in range(m+2):
      r.append(string[i] + s[j])
  return r
string=['a']
for i in range(n-1):
  string=f(string)
for a in string:
  print(a)

Solution (Python):
import string

alphabet = string.ascii_lowercase

n = int(input())

def DFS(before,keta):
    num = 0
    if keta == n:
        print(before)
        return
    for i in before:
        num = max(num,alphabet.index(i))
    num += 1
    for j in range(num+1):
        DFS(before+alphabet[j],keta+1)

DFS("a",1)

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

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

dfs('', ord('a'))

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

if N == 1:
	print('a')
	sys.exit()
else:
	ans = []
	def solve(s,m):
		if len(s) == N:
			ans.append(s)
			return 
		for n in range(97, m+2):
			solve(s + chr(n), max(n,m))
	solve('a',97)
	for a in ans:
		print(a)

Solution (Python):
def main():
    from string import ascii_lowercase
    dic = {i: s for i, s in enumerate(ascii_lowercase)}
    N = int(input())
    ans = []

    def dfs(s, mx):
        if len(s) == N:
            ans.append(s)
            return
        else:
            for i in range(mx+2):
                mx = max(mx, i)
                dfs(s + dic[i], mx)
    dfs("a", 0)
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from string import ascii_lowercase
    dic = {i: s for i, s in enumerate(ascii_lowercase)}
    N = int(input())
    ans = []

    def dfs(s, mx):
        if len(s) == N:
            ans.append(s)
            return
        else:
            for i in range(mx+2):
                v = s + dic[i]
                mx = max(mx, i)
                dfs(v, mx)
    dfs("a", 0)
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from string import ascii_lowercase
    dic = {i: s for i, s in enumerate(ascii_lowercase)}
    N = int(input())
    ans = []

    def dfs(s, mx):
        if len(s) == N:
            print(s)
            return
        else:
            for i in range(mx+2):
                v = s + dic[i]
                mx = max(mx, i)
                dfs(v, mx)
    dfs("a", 0)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from string import ascii_lowercase
    dic = {s: i for i, s in enumerate(ascii_lowercase)}
    rdic = {i: s for i, s in enumerate(ascii_lowercase)}
    N = int(input())
    ans = []

    def dfs(n, s):
        if N < n:
            return
        elif n == N:
            ans.append(s)
            return
        else:
            for i in range(max([dic[c] for c in s])+2):
                v = s + rdic[i]
                dfs(n+1, v)
    dfs(1, "a")
    ans.sort()
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(read())


def check(s):
    if len(s) == n:
        print(s)
    else:
        for i in range(97, ord(max(s)) + 2):
            check(s + chr(i))


check('a')

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

def dfs(s, mx):
    if len(s) == N:
        print(s)
    else:
        c = 'a'
        while ord(c) <= ord(mx):
            if c == mx:
                dfs(s + c, chr(ord(mx) + 1))
            else:
                dfs(s + c, mx)
            c = chr(ord(c) + 1)

dfs('', 'a')

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

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

q=deque(['a'])

for i in range(n-1):
    qi_ans=[]
    while(len(q)>0):
        qi=q.popleft()
        qiword_maxind=0
        for j in range(len(qi)):
            qi_ans.append(qi+qi[j])
            qij_ind=alpha.index(qi[j])
            if(qiword_maxind<qij_ind):
                qiword_maxind=qij_ind
        else:
            qi_ans.append(qi+alpha[qiword_maxind+1])
    qi_ans=sorted(list(set(qi_ans)))

    q.extend(qi_ans)

lenq=len(q)
for i in range(lenq):
    print(q.popleft())

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

alp = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8, "i":9, "j":10}
alp2 = "abcdefghij"

def solve(N):
    ans = []
    if N == 1:
        ans.append("a")
    else:
        pre = solve(N-1)
        for i in range(len(pre)):
            tmp = sorted(pre[i])
            num = alp[tmp[len(tmp)-1]]
            for j in range(num+1):
                ans.append(pre[i]+alp2[j])
    return ans
            

f_ans = solve(N)
f_ans.sort()

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

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

ss = ['a']
for i in range(1, N):
    tmp = []
    
    for s in ss:
        newc = ord(max(s)) + 1
        for j in range(ord('a'), newc+1):
            tmp.append(s + chr(j))
    ss = tmp

for s in sorted(ss):
    print(s)

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

Solution (Python):
N=int(input())
A=["a"]
S="abcdefghijklmn"
for i 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, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = "abcdefghijk"


ans = 0

def dfs(a, mx):
    
    
    
    if len(a) == N:
        print(a)
        return
    for c in range(len(S[:mx+2])):
        t = a
        t += S[:mx+2][c]
        dfs(t, max(c, mx))

dfs("", -1)

Solution (Python):

N=int(input())

l0=['a']
l1=[]
li=[0]
li1=[]
alp=[chr(i) for i in range(97, 97+26)]

for i in range(1,N):
    for j, l in enumerate(l0):
        ind=0
        while ind<=li[j]+1:
            l1.append(l+alp[ind])
            if ind==li[j]+1: li1.append(li[j]+1)
            else: li1.append(li[j])
            ind+=1
    l0=l1.copy()
    l1=[]
    li=li1.copy()
    li1=[]

for l in l0:
    print(l)

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

def dfs(s, mx):
    if (len(s) == N):
        print(s)
        return
    for i in range(mx + 1):
        dfs(s + chr(97 + i), mx + (i == mx))

dfs('', 0)

Solution (Python):
from collections import deque

N = int(input())
d = {i:[] for i in range(1, N+1)}
q = deque([(1, "a")])

while q:
    pos, s = q.popleft()
    if pos == N+1:
        break
    d[pos].append(s)
    size = len(set(s))
    for i in range(size+1):
        q.append((pos+1, s+chr(97+i)))

for i in d[N]:
    print(i)

Solution (Python):
from collections import deque

d = {i:[] for i in range(1, 11)}
q = deque([(1, "a")])
while q:
    pos, s = q.popleft()
    if pos == 11:
        break
    d[pos].append(s)
    size = len(set(s))
    for i in range(size+1):
        q.append((pos+1, s+chr(97+i)))

N = int(input())
for i in d[N]:
    print(i)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

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

def dfs(arr, max_val):
    if len(arr) == n:
        ans.append(arr)
        return
    for i in range(max_val + 2):
        next_arr = arr[:]
        next_arr.append(i)
        dfs(next_arr, max(max_val, i))

dfs([0], 0)

ans.sort()
orda = ord("a")
for line in ans:
    print("".join([chr(orda + item) for item in line]))