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


n = int(input())

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

if n == 2:
    print('aa')
    print('ab')
    exit()

words = 'abcdefghijklm'
ans = [['', -1]]

for i in range(1, n+1):
    usable = list(words[:i])
    news = []
    for candidate, limit in ans:
        for num, word in enumerate(usable):
            if num > limit + 1:
                break
            new = candidate + word
            news.append([new, max(limit, num)])
    ans = news

result = [word for word, limit in ans]
result.sort()
for res in result:
    print(res)

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

ALP = "abcdefghij"

result = []

def mx(s):
    m = 0
    for i in s:
        if m < int(i):
            m = int(i)
    return m

def add(res):
    res_c = []
    for r in res:
        m = mx(r)
        for i in range(1, m + 2):
            res_c.append(r + str(i))
    return res_c

for n in range(N):
    if n == 0:
        result.append("1")
    else:
        result = add(result)

v = []
for i in range(1, N + 1):
    v = []
    for j in result:
        a = j.replace(str(i), ALP[i - 1])
        v.append(a)
    result = v

for r in result:
    if r == 'abcdefghia0':
        print('abcdefghij')
    else:
        print(r)

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

alphabet = "abcdefghijk"

ans = [[] for _ in range(11)]
ans[1].append([0, "a"])

for i in range(n):
    for j, r in ans[i]:
        for k, t in enumerate(alphabet[:j+2]):
            if k == j+1:
                ans[i+1].append([j+1, r+t])
                continue
            ans[i+1].append([j, r+t])

for t in ans[n]:
    print(t[1])

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

list = [['a', 0]]
if N > 1:
    for n in range(N -1):
        new_list = []
        for i in range(len(list)):
            old_string = list[i][0]
            max_num = list[i][1]
            for j in range(max_num + 1):
                new_string = old_string + L[j]
                new_list.append([new_string, max_num])
            new_string = old_string + L[max_num + 1]
            new_list.append([new_string, max_num + 1])
        list = new_list
for i in range(len(list)):
    print(list[i][0])

Solution (Python):
alpha_small_ = [chr(i) for i in range(97, 97+26)] 

n = int(input())
ans = []
def solve(now,i):
    if len(now) == n:
        ans.append(now)
        return
    for j in range(i+1):
        solve(now+alpha_small_[j],max(i,j+1))

solve("a",1)


for x in sorted(ans):
    print(x)

Solution (Python):

def get_normal_form(seq_type):
    curr_char = ord('a')
    return "".join([chr(curr_char + int(i)) for i in seq_type])


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

    def rec(category, acc, result):
        if len(acc) == n:
            result.append(acc)
            return result

        for c in range(category):
            result = rec(category, acc + str(c), result)
        result = rec(category + 1, acc + str(category), result)

        return result

    result = rec(1, "0", [])
    result.sort()
    for r in result:
        print(get_normal_form(r))


if __name__ == "__main__":
    submit()

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

Char = [chr(97 + i) for i in range(N+10)]

ans = ["a"]
for i in range(N - 1):
    tmp = []
    for a in ans:
        rng = ord(max(a)) - 97
        for c in Char[: rng + 2]:
            tmp.append(a + c)
    ans = tmp

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

Solution (Python):
n=int(input())
ans=[]
def rec(i,s):
    if i == n:
        ans.append(s)
        return True
    else:
        if len(set(s)) == 1:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
        if len(set(s)) == 2:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
        if len(set(s)) == 3:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
        if len(set(s)) == 4:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
        if len(set(s)) == 5:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
            rec(i+1,s+"f")
        if len(set(s)) == 6:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
            rec(i+1,s+"f")
            rec(i+1,s+"g")
        if len(set(s)) == 7:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
            rec(i+1,s+"f")
            rec(i+1,s+"g")
            rec(i+1,s+"h")
        if len(set(s)) == 8:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
            rec(i+1,s+"f")
            rec(i+1,s+"g")
            rec(i+1,s+"h")
            rec(i+1,s+"i")
        if len(set(s)) == 9:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
            rec(i+1,s+"f")
            rec(i+1,s+"g")
            rec(i+1,s+"h")
            rec(i+1,s+"i")
            rec(i+1,s+"j")
rec(1,"a")
print("\n".join(ans))

Solution (Python):
import string
import itertools

alphabets = string.ascii_lowercase

N = int(input())

res = []


def f(s):
    return max([ord(t) - ord("a") for t in s])


def bfs(s, d):
    if d == N - 1:
        res.append(s)
        return

    for i in range(f(s) + 2):
        bfs(s + alphabets[i], d + 1)


bfs("a", 0)

res = sorted(res)
print("\n".join(res))

Solution (Python):
import string

def generate(n, res, cur = None, alphabet = None):
    if cur is None:
        cur = []
    if alphabet is None:
        alphabet = list(string.ascii_lowercase)[::-1]
    if n == 0:
        res.append(''.join(cur))
        return
    for i in range(len(cur)):
        cur.append(cur[i])
        generate(n - 1, res, cur, alphabet)
        cur.pop()
    cur.append(alphabet.pop())
    generate(n - 1, res, cur, alphabet)
    alphabet.append(cur.pop())

res = []
generate(int(input()), res=res)
res = sorted(set(res))
for row in res:
    print(row)

Solution (Python):
N = int(input())
W = 'abcdefghij'
ans = set()

for i in range(1,N+1):
  if i == 1:
    ans.add('a')
  else:
    tmp = set()
    for a in ans:
      index = W.index(sorted(list(a))[-1])
      for i in range(index+2):
        tmp.add(a+W[i])
    ans = tmp
    
for a in sorted(ans):
  print(a)

Solution (Python):
al = list("abcdefghij")
n = int(input())
w = [0 for i in range(n)]
w[-1] = -1
la = list(range(n))
while (w != la):
  w[-1] += 1
  for i in range(n-1):
    i = n-i-1
    z = False
    for j in range(n):
      if i != j and w[j] == w[i]:
        z = True
    if (not z) and (not (w[i]-1 in w)):
      w[i] = 0
      w[i-1] += 1
  c = [al[w[i]] for i in range(n)]
  print("".join(c))

Solution (Python):
def solve():
    N = int(raw_input())
    ret = [('a', 'a')]
    for i in range (2, N+1):
        tmp = []
        for stri in ret:
            for j in range(ord('a'), ord(stri[1]) + 1):
                tmp.append((stri[0] + chr(j), stri[1]))
            tmp.append((stri[0] + chr(ord(stri[1]) + 1), chr(ord(stri[1]) + 1)))
        ret = tmp
    for stri in ret:
        print stri[0]

if __name__ == '__main__':
    solve()

Solution (Python):
def main(n):
    if n == 1:
        return ['a']
    else:
        ans = []
        for a in main(n-1):
            b = '`'
            while b <= max(a):
                b = chr(ord(b) + 1)
                ans.append(a + str(b))
        return ans
N = int(input())
L = main(N)
for i in L:
    print(i)

Solution (Python):
length = int(input())
nums = []
def num_to_abc(n):
    return chr(ord("a") + n)

def f(level,already):
    if level >= length:
        nums.append(already)
        return
    else:
        for i in range(0, max(already) + 2):
            f(level + 1, already + [i])

f(1,[0])
for n in nums:
    print("".join(list(map(num_to_abc, n))))

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

def func(length):
    if length == 1:
        return ["a"]
    else:
        output = []
        for s in func(length-1):
            for i in range(len(set(list(s)))+1):
                output.append(s + l[i])
        return output

ans = func(N)
ans.sort()
for a in ans:
    print(a)

Solution (Python):
import numpy as np

n = int(input())

answers = [[[] for i in range(n)] for j in range(n)]
answers[0][0] = "a"
alphabets = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
if n == 1:
    print("a")
else:
    for i in range(n-1):
        for j in range(n):
            b_ans = answers[i][j]
            for one_ans in b_ans:
                for k in range(j+1):
                    answers[i+1][j].append(one_ans + alphabets[k])
                answers[i+1][j+1].append(one_ans + alphabets[j+1])
    all_answers = []
    for i in range(n):
        for single_ans in answers[n-1][i]:
            all_answers.append(single_ans)
    ans = sorted(all_answers)
    for print_ans in ans:
        print(print_ans)

Solution (Python):
import collections
N = int(input())
ans1 = ["a"]
ans2 = ["aa", "ab"]
ans3 = []
ans4 = []
ans5 = []
ans6 = []
ans7 = []
ans8 = []
ans9 = []
ans10 = []
def count(s):
    return(len(collections.Counter(s)))
    
for x in ans2:
    for i in range(count(x)+1):
        ans3.append(x+chr(97+i))
for x in ans3:
    for i in range(count(x)+1):
        ans4.append(x+chr(97+i))
for x in ans4:
    for i in range(count(x)+1):
        ans5.append(x+chr(97+i))         
for x in ans5:
    for i in range(count(x)+1):
        ans6.append(x+chr(97+i)) 
for x in ans6:
    for i in range(count(x)+1):
        ans7.append(x+chr(97+i)) 
for x in ans7:
    for i in range(count(x)+1):
        ans8.append(x+chr(97+i)) 
for x in ans8:
    for i in range(count(x)+1):
        ans9.append(x+chr(97+i)) 
for x in ans9:
    for i in range(count(x)+1):
        ans10.append(x+chr(97+i)) 

ans=[ans1, ans2, ans3, ans4, ans5, ans6, ans7, ans8, ans9, ans10]
for x in ans[N-1]:
    print(x)

Solution (Python):


from copy import deepcopy

N = int(input())


w = []
























def rec(word):
    
    
    
    

    appeared = []
    for c in word:
        if c not in appeared:
            appeared.append(c)

    length = len(word)

    if length == N:
        w.append(word)
        return None

    last = appeared[-1]
    appeared.append(chr(ord(last) + 1))
    for tail in appeared:
        rec(word + tail)


rec("a")

for word in sorted(w):
    print(word)

Solution (Python):
def main():
    N = int(input())
    string = [chr(i) for i in range(97, 97+26)]
    ans = [[] for _ in range(10)]
    ans[0].append('a')
    for i in range(9):
        for s in ans[i]:
            n = len(set(s))
            for j in range(n+1):
                ans[i+1].append(''.join([s, string[j]]))
    print('\n'.join(ans[N-1]))

main()

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()
L = [[[0]]]
for i in range(1, n):
    new_L = []
    for each_type in L:
        new_L += [each_type + [[i]]]
        for j in range(len(each_type)):
            new_type = deepcopy(each_type)
            new_type[j] += [i]
            new_L += [new_type]
    L = new_L


ans = []
for t in L:
    a = [''] * n
    cnt = 97
    for k in t:
        for l in k:
            a[l] = chr(cnt)
        cnt += 1
    ans += [''.join(a)]


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

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

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

prev = ["a"]

for i in range(1, N):
    temp = []
    for item in prev:
        item_list = []
        for j in range(len(item)):
            item_list.append(item[j])
        num_char = len(set(item_list))
        for j in range(num_char+1):
            temp.append(item+char_list[j])

    prev = temp


print ' '.join(map(str, prev))

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
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()

G = []

def dfs(n, string, next_usable):
    if n == 0:
        G.append(string)
        return
    for char in next_usable:
        new_string = string + char
        if char == next_usable[-1]:
            added_char = chr(ord(char) + 1)
            next_usable += added_char
        dfs(n-1, new_string, next_usable)

def main():
    N = I()
    string = 'a'
    dfs(N, '', 'a')
    for string in G:
        print(string)


main()

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

	lst = [['a',1]]

	for i in range(2,N+1):
		anslst = []
		for j in range(len(lst)):
			s = lst[j][0]
			n = lst[j][1]
			for l in range(n+1):
				ss = s
				if l == n:
					n += 1
				ss = ss + alp[l]
				anslst.append([ss,n])

		lst = anslst

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

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

from collections import deque

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

def gcd(n,m):
    while m:
        n,m = m, n%m
    return n

def lcm(n,m):
    return n*m//gcd(n,m)

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

    
    

    pp = "a"

    vQ = deque([])
    vQ_app = vQ.append

    vQ_app(pp)
    while vQ:
        pp = vQ.popleft()
        if len(pp)>=N: break
        ma = max(ord(s) for s in pp)
        for i in range(ord('a'), ma+2):
            vQ_app(pp + chr(i))

    
    
    vQ.appendleft("a" * N)

    res = vQ
    print(*sorted(res), sep="\n")

main()

Solution (Python):
from itertools import combinations_with_replacement
from itertools import combinations
N = int(input())

alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
cand = {"a"}
for i in range(N-1):
    nex_cand = set()
    for c in cand:
        for j in range(i+2):
            a = alpha[j]
            if all(v in c for v in alpha[:j]):
                nex_cand.add(c+a)
    cand = nex_cand

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

Solution (Python):
ans =["a"]
n =int(input())
for i in range(1,n):
  plus=[]
  for s in ans:
    nn=0
    for h in range(len(s)):
      nn=max(nn,ord(s[h]))
    num=nn-ord("a")+1
    for j in range(num+1):
      plus.append(s+chr(ord("a")+j))
  ans = plus
ans.sort()
for ss in ans:print(ss)

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

a = ord('a')
reprs = [('a', a)]
for i in range(1, n):
    tmprep = []
    for r, l in reprs:
        for j in range(l-a+2):
            tmprep.append((r+chr(a+j), max(l, a+j)))
    reprs = tmprep



for r, l in reprs:
    print(r)

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

ans = ["a"]
for n in range(N - 1):
    nex = []
    for v in ans:
        for i in range(ord("a"), max(ord(s) for s in v) + 2):
            nex.append(v + chr(i))
    ans = nex[:]
        
print(*sorted(ans), sep="\n")

Solution (Python):
N=int(input())
alpha=["a","b","c","d","e","f","g","h","i","j","k","l"]
now=["a"]
next_list=[]
for _ in range(N-1):
    for check in now:
        count = len(set(check))

        
        for add in range(count+1):
            next_list.append(check + alpha[add])

    now = next_list[:]
    next_list=[]

for a in now:
    print(a)

Solution (Python):
n = int(input())
cands = set([])

def dfs(s,l,k):
  if l == n:
    cands.add(s)
  else:
    for i in range(k):
      dfs(s+chr(97+i), l+1,k)
    dfs(s+chr(97+k),l+1,k+1)

dfs('',0,0)
ans = list(cands)
ans.sort()
for a in ans:
  print(a)

Solution (Python):
N = int(input())
lst = [{'s': 'a', 'c': 1}]
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
for n in range(N - 1):
    new_lst = []
    for x in lst:
        for c in range(x['c'] + 1):
            new_s = x['s'] + alphabet[c]
            if c == x['c']:
                new_c = c + 1
            else:
                new_c = x['c']
            new_lst.append({'s': new_s, 'c': new_c})
    lst = new_lst
for x in lst:
    print(x['s'])

Solution (Python):
N=int(input())
global key
key="abcdefghij"
def normal(N):
    if N==1:
        return ["a"]
    else:
        new=[]
        lis=normal(N-1)
        for s in lis:
            i=0
            while key[i] in s:
                new.append(s+key[i])
                i+=1
            new.append(s+key[i])
    return new
lis=normal(N)
for s in lis:
    print(s)

Solution (Python):
import itertools

n = int(input())

alpha_list = ['a','b','c','d','e','f','g','h','i','j']
string_list = []
count = 0

def extend(string,count,n):
    if len(string) >= n:
        string_list.append(string)
        return True
    else:
        for i in range(count+1):
            sc = string
            sc += alpha_list[i]
            if i == count:
                count += 1
            extend(sc,count,n)
    
extend('',count,n)

string_list.sort()
for s in string_list:
    print(s)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



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

def mm(sl, i, m):
	if len(sl)==i:
		print(''.join(sl))
		return
	for j in range(m+1):
		sl[i]=ll[j]
		mm(sl, i+1, m)
	sl[i]=ll[m+1]
	mm(sl, i+1, m+1)
	

def main():
	n = int(input())
	sl=['a']*n
	mm(sl, 1, 0)
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):

N = int(input())
a = [chr(i) for i in range(97, 97+26)]
ret = []
def backtrack(N,s,i):
    
    if N == 1:
        ret.extend([s+c for c in a[:i+1]])
        return
    for j in range(i+1):
        
        if j == i:
            backtrack(N-1,s+a[j],i+1)
        else:
            backtrack(N-1,s+a[j],i)
backtrack(N,"",0)
for s in ret:
  print(s)

Solution (Python):
chars = 'abcdefghij'

n = int(input())

def f(gen):
    for x,s in gen:
        for i in range(x+1):
            yield (max(x,i+1), s + chars[i])

gen = [(0, "")]
for _ in range(n):
    gen = f(gen)

for __, s in gen:
    print(s)

Solution (Python):
import copy
from functools import reduce
alphabet = " abcdefghij"
def dfs(n, arr, cur):
  if cur == n:
    return print(reduce(lambda x, y:x+y, map(lambda x:alphabet[x], arr)))
  else:
    i = 1
    while i <= max(arr)+1:
      tmp = copy.copy(arr)
      tmp[cur] = i
      dfs(n, tmp, cur+1)
      i += 1

N = int(input())
dfs(N, [0]*N, 0)

Solution (Python):
chr='abcdefghijklmnopqrstuvwxyz'
a=[0]*int(input())
while 1:
  print(''.join(chr[i]for i in a))
  if a==list(range(len(a))):break
  a[-1]+=1
  i=-1
  while a[i]-max(a[:i]+[0])>1:
    a[i]=0
    i-=1
    a[i]+=1

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

def printStrAsList(strAsList):
  result = ''
  for chrItem in strAsList:
    result += chr(97 + chrItem)
  print(result)

def printList(strAsList):
  loopTimes = max(strAsList) + 1
  isLastChr = len(strAsList) == n-1
  for i in range(loopTimes + 1):
    if isLastChr:
      printStrAsList(strAsList + [i])
    else:
      printList(strAsList + [i])

if n == 1:
  print('a')
else:
  printList([0])

Solution (Python):

def print_rec(now_moji, tsugi, nokori):
    if nokori == 0:
        print(now_moji)
    else:
        for i in range(tsugi + 1):
            tsugi_moji = now_moji + chr(i + 97)
            if i == tsugi:
                print_rec(tsugi_moji, tsugi + 1, nokori - 1)
            else:
                print_rec(tsugi_moji, tsugi, nokori - 1)


n = int(input())
if n == 1:
    print("a")
else:
    print_rec("a", 1, n - 1)

Solution (Python):
alf = 'abcdefghijklmnopqrstuvwxyz'
d = {c:i+1 for i,c in enumerate(alf)}
d['z']=25
def dfs(n):
    lst = []
    lst.append([['a'],0])
    while lst:
        a,mx = lst.pop()
        if len(a) == n:
            print(''.join(a))
            continue
        for i in range(min(mx+1,25)+1)[::-1]:
            lst.append([a + [alf[i]], max(i,mx)])

n= int(input())
dfs(n)

Solution (Python):
abc = 'abcdefghij'
answer = []
n = int(input())
for bits in range(2 ** (n - 1)):
    cur_height = 1
    heights = []
    isfree = []
    for _ in range(n - 1):
        if bits % 2 == 1:
            cur_height += 1
            heights.append(cur_height)
            isfree.append(False)
        else:
            heights.append(cur_height)
            isfree.append(True)
        bits //= 2
    results = [[0]]
    for i in range(n - 1):
        new_results = []
        for result in results:
            if isfree[i]:
                for j in range(heights[i]):
                    new_results.append(result + [j])
            else:
                new_results.append(result + [heights[i] - 1])
        results = new_results
    for result in results:
        abcresult = (abc[i] for i in result)
        answer.append(''.join(abcresult))
answer.sort()
for a in answer:
    print(a)

Solution (Python):
n = int(input())
s = "abcdefghij"
a = [[] for i in range(10)]
a[0] = [[0]]
def add_word(n):
    temp = a[n-1]
    for i in range(len(temp)):
        for j in range(len(set(temp[i])) + 1):
            a[n].append(temp[i] + [j])
for i in range(1,n):
    add_word(i)

for i in a[n-1]:
    ans = ""
    for j in i:
        ans += s[j]
    print(ans)

Solution (Python):

a = int(input())

l = 1
cur_ret = [[0]]
while l < a:
    new_ret = []
    na = new_ret.append
    for i in cur_ret:
        k = max(i) + 2
        for j in range(k):
            na(i+[j])
    cur_ret = new_ret
    l+=1

def format(x):
    x = list(map(lambda x : chr(x+97),x))
    return "".join(x)

cur_ret = list(map(format,cur_ret))
cur_ret.sort()
for i in cur_ret:
    print(i)

Solution (Python):
import sys
sys.setrecursionlimit(5000000)
N = int(input())
ans = []


def func(s):
    if len(s) == N:
        ans.append(s)
    else:
        for i in range(ord(max(s))-95):
            func(s+chr(97+i))

func('a')
for a in sorted(ans):
    print(a)

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:
        flag = False
        for letter in alph:
            if flag:
                break
            ans2.append(value + letter)
            if letter not in value:
                flag = True
    length += 1
    ans = copy.deepcopy(sorted(ans2))

for value in ans:
    print(value)

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

combi = [[0]]
for i in range(1, n):
    new = []
    for item in combi:
        for t in range(0, max(item) + 2):
            new.append(item + [t])
    combi = new

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

for i in combi:
    print("".join([dicter[j] for j in i]))

Solution (Python):
n=int(input())
a='abcdefghij'
ans=[['']]
for i in range(n):
    s=ans[-1][::]
    l=len(s)
    t=[]
    for j in range(i+1):
        for k in range(l):
            if j>0:
                if a[j-1] not in s[k]:
                    continue
            t.append(s[k]+a[j])
    ans.append(t)
t=sorted(ans[-1])
for s in t:
    print(s)

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

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

def moji(mes, layer, lim):
    if(layer==n):
        print(mes)
        return
    for i in range(lim+1):
        moji(mes+l[i], layer+1, max(lim,i+1))
    return

moji("", 0, 0)

Solution (Python):
n = int(input())
alp = [chr(i) for i in range(97, 97+26)]
 
def update(a, m):
    a_new = []
    m_new = []
    for val_a, val_m in zip(a,m):
        for i in range(val_m + 2):
            a_new += [val_a + alp[i]]
            m_new += [max(val_m, i)]
    return a_new, m_new
 
a = ['a']
m = [0]
 
for i in range(n-1):
  a, m = update(a,m)
 
for v in a:
  print(v)

Solution (Python):
A=[]
B=["a"]
N=int(input())
if N>1:
 for i in range(N-1):
  A=B
  B=[]
  C=len(A)
  for j in range(C):
   F=len(A[j])
   D=0
   for f in range(F):
    D=max(ord(A[j][f])-95,D)
   for k in range(D):
    E=A[j]+chr(97+k)
    B.append(E)
for i in range(len(B)):
 print(B[i])

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

moji = ["a","b","c","d","e","f","g","h","i","j"]
start = ["a"]
ll = [[] for i in range(11)] 

def syurui(l):
    return len(set(l))

ll[1].append(["a"])

for i in range(2,N+1):
    for j in range(len(ll[i-1])):
        for k in range(syurui(ll[i-1][j])+1):
            tmp = copy.copy(ll[i-1][j])
            ll[i-1][j].append(moji[k])
            ll[i].append(ll[i-1][j])
            ll[i-1][j] = tmp

for i in range(len(ll[N])):
    kotae ="".join(ll[N][i])
    print(kotae)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
ans = []
def bfs(s,tmp):
    if len(s)==n:
        ans.append(s)
        return
    for i in range(ord('a'),ord('a')+tmp+1):
        if i==ord('a')+tmp:
            bfs(s+chr(i),tmp+1)
        else:
            bfs(s+chr(i),tmp)
bfs('a',1)
print(*ans,sep='\n')

Solution (Python):



def plse1(s, i):
    if i == 0:
        return s
    m = max(s[:i])
    if s[i] > m:
        s = plse1(s, i - 1)
        s[i] = 0
    else:
        s[i] += 1
    return s


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

s = [0] * n
while True:
    string = ''
    for i in range(n):
        string += ss[s[i]]
    print(string)
    s = plse1(s, n - 1)
    if s == [0] * n:
        break

Solution (Python):
import copy

n = int(input())
lst = ['a']
alphabet = 'abcdefghij'

for i in range(n - 1):
  new_list = []
  for word in lst:
    ch = ''
    for k in alphabet:
      ch = k
      if k in word:
        new_list.append(word + k)
      else:
        break
    new_list.append(word + k)
  lst = copy.copy(new_list)

for word in lst:
  print(word)

Solution (Python):
n=int(input())
tmp=[['1',set({1})]]
for i in range(1,n):
  tmp2=[]
  for s,c in tmp:
    for j in range(len(c)+1):
      tmp2.append([s+str((j+1)%10),c|set({j+1})])
  tmp=tmp2
ans=[]
dic={'1':'a','2':'b','3':'c','4':'d','5':'e','6':'f','7':'g','8':'h','9':'i','0':'j'}
for s,c in tmp:
  ts=''
  for tc in s:
    ts+=dic[tc]
  ans.append(ts)
ans=sorted(ans)
for s in ans:
  print(s)

Solution (Python):

N = int(input())
S = "abcdefghij"
ans = [""]
for k in range(N):
    n = []
    for e in ans:
        for f in S[:len(set(str(x) for x in e))+1]:
            n.append(e+f)
    ans = n
ans = sorted(ans)
for e in ans:
    print(e)

Solution (Python):
from collections import deque
N = int(input())
alpha = ['a','b','c','d','e','f','g','h','i','j']
ans = []

stack = deque(['a'])

while stack:
    if len(stack[-1]) == N:
        break
    s = stack.pop()
    s_list = sorted(list(s))
    index = alpha.index(s_list[-1])
    for i in range(index+2):
        stack.appendleft(s+alpha[i])
    

stack.reverse()
for j in range(len(stack)):
    print(stack[j])

Solution (Python):
import sys


sys.setrecursionlimit(10 ** 7)

from string import ascii_lowercase

d = dict(zip(ascii_lowercase, range(26)))

N = int(input())

def nexts(s, n, maxnum):
    if n == N:
        print(s)
        return
    for i in range(maxnum+1):
        nexts(s + ascii_lowercase[i], n+1, max(maxnum,i+1))

nexts('a', 1, 1)

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

t = []
c = 'abcdefghij'

def f(s, d, m):
  if d == 0:
    t.append(s)
    return
  
  for k in range(m+1):
    f(s*10 + k, d-1, m+1 if k==m else m)
    
f(0, n, 0)

for i in t:
  x = []
  for j in range(n):
    x.append(c[i // 10**(n-j-1) % 10])
  print(''.join(x))

Solution (Python):
N = int(input())
al = [chr(ord('a') + i) for i in range(26)]
li = ['a']
for i in range(1,N):
    k = []
    li = set(li)
    for s in li:
        count = len(set(list(s)))
        for m in range(count+1):
            nk = s+al[m]
            k.append(nk)
    li = k
n = len(li)
li.sort()
for i in range(n):
    print(li[i])

Solution (Python):
import sys


def chr2idx(c):
    return ord(c)-ord("a")
def idx2chr(x):
    return chr(ord("a")+x)

N=int(input())
ar=[["a","a"]]
if N==1:
    print("a")
    sys.exit()

for i in range(N-1):
    new_ar=[]
    L=len(ar)
    for j in range(L):
        lastchr=chr2idx(ar[j][1])
        for k in range(lastchr+1):
            new_ar+=[[ar[j][0]+idx2chr(k),idx2chr(lastchr)]]
        new_ar+=[[ar[j][0]+idx2chr(lastchr+1),idx2chr(lastchr+1)]]

    ar=new_ar[:]

L=len(ar)
for i in range(L):
    print(ar[i][0])

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

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

res = [['a']]

def calc(prev_list):
    new_list = []
    for i in prev_list:
        for j in range(len(set(i))+1):
            new_list.append(i+[zls[j]])
    return new_list

for i in range(N-1):
    res = calc(res)

for i in res:
    print(''.join(i))