Problem:
 Score : 400 points    Problem Statement In this problem, we only consider strings consisting of lowercase English letters.  Strings s and t are said to be isomorphic when the following conditions are satisfied:   |s| = |t| holds.  For every pair i, j , one of the following holds:  s_i = s_j and t_i = t_j .  s_i \neq s_j and t_i \neq t_j .     For example, abcac and zyxzx are isomorphic, while abcac and ppppp are not.  A string s is said to be in normal form when the following condition is satisfied:   For every string t that is isomorphic to s , s \leq t holds. Here \leq denotes lexicographic comparison.   For example, abcac is in normal form, but zyxzx is not since it is isomorphic to abcac , which is lexicographically smaller than zyxzx .  You are given an integer N .
Print all strings of length N that are in normal form, in lexicographically ascending order.      Constraints  1 \leq N \leq 10  All values in input are integers.         Input Input is given from Standard Input in the following format:  N       Output Assume that there are K strings of length N that are in normal form: w_1, \ldots, w_K in lexicographical order.
Output should be in the following format:  w_1  :  w_K         Sample Input 1 1      Sample Output 1 a       Sample Input 2 2      Sample Output 2 aa
ab

Solution (Python):


from sys import stdin
import numpy as np


    

N = int(input())


def append_str(W, N):
    w_new = []
    for w in W:
        kind = len(set(w))
        for i in range(kind+1):
            w_new.append(w+alphabets[i])
    return w_new
    

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


for n in range(N):
    if n == 0:
        w = [seed]
    else:
        w = append_str(w, n+1)
    
for buf in w:
    print(buf)

Solution (Python):
N=int(input())
A=["a","b","c","d","e","f","g","h","i","j"]
L=[{}for i in range(N+1)]
L[1]["a"]=1


for i in range(2,N+1):
    for j,k in L[i-1].items():
        for l in range(k+1):
            L[i][j+A[l]]=max(l+1,k)

ans=L[N].keys()
ans=list(ans)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)

N = 0


def dfs(S, M):
    if len(S) == N:
        print(S)
        return
    for c in range(ord('a'), M + 1):
        dfs(S + chr(c), max(M, c + 1))


def solve():
    global N
    N = Scanner.int()
    dfs('', ord('a'))


def main():
    
    solve()


if __name__ == "__main__":
    main()

Solution (Python):


def dfs(s: str, m: int):
    global n
    if len(s) == n:
        print(s)
    else:
        for c in range(ord('a'), m + 1):
            dfs(s + chr(c), m + 1 if c == m else m)


n = int(input())
dfs('', ord('a'))

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

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

Solution (Python):
def f(num,N,S):
    alphabet = ["a","b","c","d","e","f","g","h","i","j"]
    if N == num:
        for i in S:
          print(i)
        return
    else:
        tmp = []
        length = len(S)
        for i in S:
            ttmp = sorted(list(i))
            for j in range(alphabet.index(ttmp[-1])+2):
                tmp.append(i+alphabet[j])
        f(num+1,N,tmp)
 
N = int(input())
f(1,N,["a"])

Solution (Python):
def f(num,N,S):
    alphabet = ["a","b","c","d","e","f","g","h","i","j"]
    if N == num:
        for i in range(len(S)):
            print(S[i])
        return
    else:
        tmp = []
        length = len(S)
        for i in S:
            ttmp = sorted(list(i))
            for j in range(alphabet.index(ttmp[-1])+2):
                tmp.append(i+alphabet[j])
        f(num+1,N,tmp)
 
N = int(input())
f(1,N,["a"])

Solution (Python):
from collections import deque

def dfs(q):
    if len(q)==N:
        print(''.join(q))
        return
    
    for i in range(min(26, ord(max(q))-ord('a')+2)):
        q.append(alpha[i])
        dfs(q)
        q.pop()
    
N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
dfs(deque(['a']))

Solution (Python):

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

n=int(input())
dfs('','a')

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

def dfs(i,c,d):
	if i==n:
		ans.append(c)
		return
	for j in range(0,d+1):
		dfs(i+1,c+chr(97+j),d+(j==d))

dfs(0,"",0)

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

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

s = ['a']*(n)


def dfs(x,alp):
    if x == n:
        print(''.join(s))
        return
    
    for i in range(alp+1):
        
        s[x] = chr(i+ord("a"))
        dfs(x+1,max(i+1,alp))
        


dfs(0,0)

Solution (Python):
from itertools import combinations
def g(i):
    return chr(i+96)
def f(n,i):
    global Ind
    if n==0:
        B.append("".join(A))
        return
    if n==1:
        j = Ind.pop()
        A[j] = g(i)
        B.append("".join(A))
        A[j]=0
        Ind.append(j)
        Ind = sorted(Ind)
        return
    j0 = Ind.pop(0)
    Ind1 = Ind[:]
    A[j0] = g(i)
    for k in range(n):
        for x in combinations(Ind1,n-1-k):
            tmp = []
            for j in range(n-1-k):
                A[x[j]] = g(i)
                tmp.append(x[j])
            for j in tmp:
                Ind.remove(j)
            f(k,i+1)
            for j in tmp:
                A[j] = 0
                Ind.append(j)
            Ind = sorted(Ind)
    Ind.append(j0)
    Ind = sorted(Ind)
    
N = int(input())
A = [0 for _ in range(N)]
Ind = list(range(N))
B = []
f(N,1)
B = sorted(B)
for b in B:
    print(b)

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

N = int(input())

chars = "abcdefghij"

queue = deque()
queue.append(('a', 1))

ans = []

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):
n = int(input())

ansl = []
def dfs(s, max_s):
    if len(s) == n:
        ansl.append(s)
        return
    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    for i in range(max_s+1):
        dfs(s+ascii_lowercase[i], max(i+1, max_s))

dfs("", 0)
for a in ansl:
    print(a)

Solution (Python):
"""
DFSを実装する.再帰を計算する必要があるので，関数の定義が必要
a - a -a
      -b
  - b -a
      -b
      -c
"""
N=int(input())
a_uni = ord('a')
z_uni = ord('z')
def dfs(s,maximum_uni):
    if len(s)==N:
        print(s)
        return None
    for i in range(a_uni,(maximum_uni+1)+1):
        maximum_uni = max(maximum_uni,i)
        dfs(s+chr(i),maximum_uni)
dfs('a',a_uni)

Solution (Python):

N = int(input())

arrays = list("abcdefghij")
pat_dic = {i:arrays[i] for i in range(N)}
par_patterns = list(range(10))

patterns = par_patterns[:N]
def next_search(arr,N):
    tmp = arr.copy()
    if len(tmp) == N:
        print(''.join([pat_dic[tmp[i]] for i in range(N)]))
        return None
    for st in patterns:
        if max([0]+tmp)+1 < st:
            continue
        tmp.append(st)
        if tmp[0] != 0:
            continue

        next_search(tmp, N)
        tmp = arr.copy()

next_search([], N)

Solution (Python):
N = int(input())
seed = "a"
alpha = "abcdefghij"


def dfs(string, mx_ind):
    if len(string) == N:
        print(string)
    else:
        for i in range(mx_ind + 1):
            dfs(string + alpha[i], mx_ind + 1 if i == mx_ind else mx_ind)


dfs("", 0)

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

l=["a"]

a=ord("a")

for i in range(N-1):
    la=[]
    for j in l:
        b=ord(max(j))
        for k in range(a,b+2):
            la.append(j+chr(k))
    l=la

for i in l:
    print(i)

Solution (Python):
n=int(input());s=['a']
while len(s)>0:
  t=s.pop(-1)
  if len(t)==n:print(t)
  else:
    a=max(ord(i)for i in t)
    for a in range(a+1,96,-1):s.append(t+chr(a))

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

num_to_alp = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e', 5:'f', 6:'g', 7:'h', 8:'i', 9:'j'}
alp_to_num = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9}
words = deque([[0]])

def next_letters(x):
    letters = deque([])
    for i in range(x + 2):
        letters.append(i)
    return letters

while len(words[0]) < n:
    word = words.popleft()
    letters = next_letters(max(word))
    for l in letters:
        l = [l]
        words.append(word + l)

for word in words:
    word = [num_to_alp[i] for i in word]
    print(''.join(word))

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())
import copy
ans = [[0]]
for i in range(n-1):
    x = len(ans)
    for j in range(x):
        mx = max(ans[j])
        for k in range(mx+2):
            tmp = ans[j].copy()
            tmp.append(k)
            ans.append(tmp)
    ans = [s for s in ans if len(s)==i+2]
for s in ans:
    tmp = ""
    for i in s:
        tmp += chr(ord("a")+ i)
    print(tmp)

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



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

strs = ["a"]
cnt = 1
while cnt < N:
    tmps = []
    for s in strs:
        for i,d in enumerate(dic[::-1]):
            if d in s:
                ind = len(dic)-i-1
                break
        
        for i in range(ind+2):
            tmps.append(s+dic[i])
    cnt += 1
    strs = tmps[:]
for s in strs:
    print(s)

Solution (Python):
str = 'abcdefghijklmnop'
def bt(n,m,s):
  if n == 0:
    print(s)
    return
  for c in range(m):
    bt(n-1,m,s+str[c])
  
  bt(n-1,m+1,s+str[m])
n = int(input())
bt(n,0,'')

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):
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):
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):
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 examA():
    L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K = I()

    ans = L[K-1]
    print(ans)
    return

def examB():
    H, W = LI()
    if H==1 or W==1:
        print(1)
        return
    ans = H*W//2 + (H*W)%2
    print(ans)
    return

def examC():
    a,b,c = LI()
    if c-(a+b)<=0:
        print("No")
        return
    judge = (c-a-b)**2-4*a*b
    if judge>0:
        print("Yes")
    else:
        print("No")
    return

def examD():
    def bfs(N):
        W = [0]*(5*10**6)
        L = [""]*(5*10**6)
        que = deque()
        que.append(0)
        L[0] = "a"
        W[0] = 0
        flag = True
        ne = 0
        while(flag):
            now = que.popleft()
            nowW = W[now]
            if len(L[now])==N:
                flag = False
                break
            for i in range(W[now]+2):
                ne += 1
                W[ne] = max(nowW,i)
                que.append(ne)
                L[ne] = L[now] + alphabet[i]
        return L
    N = I()
    D = bfs(N)
    for ans in D:
        if not ans:
            break
        if len(ans)<N:
            continue
        print(ans)
    return

def examD2():
    N = I()
    def dfs(n,s,i):
        if len(s)==n:
            return
        for k in range(i+1):
            if len(s)==n-1:
                print(s+alphabet[k])
            dfs(n,s+alphabet[k],max(i,k+1))
        return
    dfs(N,"",0)
    return

def examE():
    def LCS_R(S,T):
        N = len(S); M = len(T)
        dp = [[inf] * (M + 1) for _ in range(N + 1)]
        dp_S = [[""] * (M + 1) for _ in range(N + 1)]
        dp[0][0] = 0
        for i in range(N):
            for j in range(M):
                if S[i] == T[j] or S[i] == "?" or T[j] == "?":
                    dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + 1)
                    if dp[i + 1][j + 1]==dp[i][j] + 1:
                        cur = S[i]
                        if S[i] == "?" or T[j] == "?":
                            cur = "?"
                        dp_S[i+1][j+1] = dp_S[i][j] + cur
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]+1)
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)
                if dp[i + 1][j] == dp[i][j] + 1:
                    dp_S[i + 1][j] = dp_S[i][j] + S[i]
                if dp[i][j + 1] == dp[i][j] + 1:
                    dp_S[i][j + 1] = dp_S[i][j] + T[j]
        dp[N][M] = min(dp[N][M], dp[N-1][M] + 1)
        dp[N][M] = min(dp[N][M], dp[N][M-1] + 1)
        if dp[N][M] == dp[N-1][M] + 1:
            dp_S[N][M] = dp_S[N-1][M] + S[N-1]
        if dp[N][M] == dp[N][M-1] + 1:
            dp_S[N][M] = dp_S[N][M-1] + T[M-1]

        i = N; j = M
        rep = []
        while i > 0 and j > 0:
            if dp[i][j] == dp[i - 1][j]:
                rep.append(S[i-1])
                i -= 1
            elif dp[i][j] == dp[i][j - 1]:
                rep.append(T[j-1])
                j -= 1
            else:
                rep.append(S[i - 1])
                i -= 1
                j -= 1

        return dp,dp_S

    A = SI()
    B = SI()
    C = SI()

    a1,d1 = LCS_R(A,B)
    a2,d2 = LCS_R(B,C)
    a3,d3 = LCS_R(C,A)


    S1,d1 = LCS_R(d1[-1][-1],C)
    S2,d2 = LCS_R(d2[-1][-1],A)
    S3,d3 = LCS_R(d3[-1][-1],B)

    ans = min(S1[-1][-1],S2[-1][-1],S3[-1][-1])
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examD2()

"""

"""

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):
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):
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):
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):
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):
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):
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):
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):
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):
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):
n = int(input())
alphabets = 'abcdefghijkl'
norms = [['a']]
for i in range(1,n):
  rtn = []
  for norm in norms[-1]:
    n_ch = len(set(norm))
    for j in range(n_ch+1):
      rtn.append(norm+alphabets[j])
  norms.append(rtn)
  
for norm in norms[-1]:
  print(norm)

Solution (Python):
N = int(input())
S = "abcdefghijklmn"
Q = [(1,1,"a")]
A = []
while Q:
    q = Q.pop(-1)
    if q[0]==N:
        A.append(q[2])
        continue
    for i in range(q[1]+1):
        Q.append((q[0]+1,max(q[1],i+1),q[2]+S[i]))
for a in sorted(A):print(a)

Solution (Python):
n=int(input())
def make(floor,kind,name): 
    if floor==n+1: 
        print(name)
        return
    num=min(floor,kind+1)
    for i in range(num):
        use=0 
        if kind-1<i:
            use=1
        make(floor+1,kind+use,name+chr(i+97))
make(1,0,"")

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

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

for num in range(n-1):
    x = []
    for i in range(len(w)):
        x.append(w[i] + 'a')
        for num in range(num+1):
            if al[num] in w[i]:
                x.append(w[i] + al[num+1])
    w = x

for _ in range(len(w)):
    print(w[_])

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


def f(n, lst):
    if n == N:
        print(''.join(map(str, [chr(s + 97) for s in lst])))
    else:
        for i in range(max(lst) + 2):
            f(n + 1, lst + [i])


f(1, [0])

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

tank = []
tank.append(['a'])
for i in range(n):
    tmp_tank = []
    for w in tank[i]:
        tmp_max = max(list(w))
        nxt_max = chr(ord(tmp_max)+1)
        for i in range(ord('a'), ord(nxt_max)+1):
            tmp_tank.append(w+chr(i))
    tank.append(tmp_tank)

for w in tank[n-1]:
    print(w)

Solution (Python):
def dfs(a='', b='a'):
	if len(a) == N:
		print(a)
	else:
		i = '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())

before = ["0"]
for i in range(n-1):
    next = []
    for elem in before:
        m = 1
        for j in range(len(elem)):
            m = max(m, int(elem[j])+1)
        for j in range(m+1):
            next.append(elem+str(j))
    before = next[:]

before.sort()
d = {"0":"a", "1":"b", "2":"c", "3":"d", "4":"e", "5":"f", "6":"g", "7":"h", "8":"i", "9":"j"}
for elem in before:
    ans = []
    for i in range(len(elem)):
        ans.append(d[elem[i]])
    print("".join(ans))

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

def rec(s, mx, l):
    if l >= n:
        print("".join([chr(ord("a") + x) for x in s]))
        return
    for x in range(mx+2):
        rec(s+[x], max(mx, x), l+1)

rec([0], 0, 1)

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


n = int(input())
dfs('', ord('a') - 1)

Solution (Python):
n = int(input())
alphabet = list("abcdefghij"[:n])


def print_string(string="", depth=1):
    if len(string) == n:
        print(string)
    else:
        for i in range(depth):
            if i+1 == depth:
                print_string(string+alphabet[i], depth=depth+1)
            else:
                print_string(string+alphabet[i], depth=depth)
                
print_string()

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

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

Solution (Python):
N = int( input() )
alphabets = "abcdefghij"[ :N ]
types= ["a"]

for _ in range(N-1):
  for j in range(len(types)):
    target=types.pop(0)
    
    for k in range(len(set(target))+1):
      types.append(target+alphabets[k])
    
types.sort()
for each in types:
  print(each)

Solution (Python):
n = int(input())
dic_a = {str(k):v for k,v in zip(range(10),'abcdefghij')}

def main(s):
    if len(s) < n:
        for ss in range(int(max(s))+2):
            main(s+str(ss))
    else:
        print(''.join([dic_a[x] for x in s]))
            
main('0')

Solution (Python):
def main():
    number = int(input())
    queue = ["a"]
    for i in range(number - 1):
        now_queue = []
        for now in queue:
            limit = ord(max(now)) + 2
            for j in range(ord("a"), limit):
                now_queue.append(now + chr(j))
        queue = now_queue
    for q in queue:
        print(q)


if __name__ == '__main__':
    main()

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

Solution (Python):
alphabetlist=['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=int(input())
S=[0 for i in range(0,N)]
string=''
for i in range(0,N):
    string+='a'
print(string)
digit=N-1
while True:
    if digit!=0:
        if S[digit]==max(S[0:digit])+1:
            digit-=1
        else:
            S[digit]+=1
            for j in range(digit+1,N):
                S[j]=0
            digit=N-1
            if S[0]==1:
                break
            string=[0 for i in range(0,N)]
            for i in range(0,N):
                string[i]=alphabetlist[S[i]]
            print(''.join(string))
    else:
        break

Solution (Python):


n=int(input())
def dfs(s):
    if len(s)==n:
        print(s)
    else:
        for i in range(ord("a"),ord(max(s))+1+1): 
            dfs(s+chr(i))
dfs("a")

Solution (Python):


n=int(input())
alps=[chr(ord("a")+x) for x in range(26)]
def dfs(s,mx):
    if len(s)==n:
        print(s)
    else:
        for i in range(mx+1):
            if (i==mx):
                dfs(s+alps[i],mx+1)
            else:
                dfs(s+alps[i],mx)
                
                
dfs("",0)