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

    ans = []

    def fanc(i, s):
        if len(s) == n:
            ans.append(s)
        else:
            for x in range(i + 2):
                
                fanc(max([x, i]), s + chr(97 + x))
                

    fanc(0, "a")
    ans.sort()
    for i in ans:
        print(i)

    
main()

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

res = []

def f(n, m):
    if n == 0:
        print("".join(res))
        return
    for i in range(m):
        res.append(chr(97+i))
        f(n-1, m)
        res.pop()
    else:
        res.append(chr(97+m))
        f(n-1, m+1)
        res.pop()

f(N, 0)

Solution (Python):
n = int(input())
lets = [chr(i) for i in range(ord("a"), ord("a") + n)]
d = {e: i for i, e in enumerate(lets)}

s = ["a"]
for i in range(1, n):
    nxt = []
    for e in s:
        mx = 0
        for l in e:
            mx = max(mx, d[l])
        for j in range(mx + 2):
            nxt.append(e + lets[j])
    s = nxt

print(*s, sep="\n")

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

d = {1:["a"], 2:["aa", "ab"]}
for i in range(3, N+1):
    d[i] = []
    for base in d[i-1]:
        max_c = ord(max(base)) + 1
        for j in range(ord("a"), max_c+1):
            cand = base
            cand += chr(j)
            d[i].append(cand)

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

Solution (Python):
n = int(input())
alp='abcdefghij'
ansls=[list() for _ in range(n)]
ansls[0]=[('a',1)]
for i in range(1,n):
    for s,c in ansls[i-1]:
        for j in range(c+1):
            aps = s + alp[j]
            if j==c:
                c+=1
            ansls[i].append((aps,c))

ansls[-1].sort(key=lambda x:x[0])
for s,c in ansls[-1]:
    print(s)

Solution (Python):
N = int(input())
alph = list("abcdefghij")
ans = []

if N == 1: print("a")
def roop(root,use):
    if len(root) != N:
        for i in range(use+1):
            ans = root + alph[i]
            roop(ans,max(i+1,use))
            if len(ans) == N:
                print(ans)

roop("a",1)

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

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int, ins()))
def lin(): return list(input())
def iin(): return map(int, ins())

import copy
n = ii()
dic = {1: ['a']}
dic.update({i+2:[] for i in range(9)})
def getnext(dic):
    tmp = {i+1:[] for i in range(10)}
    for i, v in dic.items():
        for j in v:
            for k in range(i+1):
                if i == k:
                    tmp[i+1].append(j+chr(k+0x61))
                else:
                    tmp[i].append(j+chr(k+0x61))
    return tmp
for i in range(n-1):
    dic = getnext(dic)
tmp = []
for i in range(10):
    tmp += dic[i+1]
tmp.sort()
for i in tmp:
    print(i)

Solution (Python):
N = int(input())
dp = []
AL = 'abcdefghijklmn'
dp.append(['a'])
if N == 1:
    print('a')
else:
    for i in range(2, N+1):
        tmp = []
        for l in dp[-1]:  
            n = len(set(l))
            for i in range(n+1):
                tmp.append(l + AL[i])
        dp.append(tmp)

    for s in dp[N-1]:
        print(s)

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

l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
standard = list([] for i in range(n))

for i in range(n):
    if i == 0:
        standard[0].append(['a', 0])
    else:
        for w in standard[i-1]:
            for j in range(w[1]+1):
                standard[i].append([w[0]+l[j], w[1]])
            standard[i].append([w[0]+l[w[1]+1], w[1]+1])

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

Solution (Python):


N = int(input())

ans = []
chars = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
def func(N, s):
    if len(s) == N:
        ans.append(s)
        return

    if len(s) == 0:
        size = 1
    else:
        size = 0
        for c in s:
            size = max(size, ord(c) - 95)
    for c in chars[:size]:
        func(N, s+c)

func(N,"")

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

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

n = int(input())

def rec(s, kind):
    if len(s) == n:
        print(s)
        return
    for i in range(kind+1):
        end = chr(ord('a')+i)
        if i < kind:
            rec(s+end, kind)
        else:
            rec(s+end, kind+1) 

rec('a', 1)

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

ans_list = [['a',0]]

for i in range(1,N):
    pre_ans_list = ans_list.copy()
    ans_list = []
    for word_info in pre_ans_list:
        word = word_info[0]
        max_word = word_info[1] 
        postfix = alphabets[:min(i,max_word+1)+1]
        for j,p in enumerate(postfix):
            ans_list.append([word+p,max(j,max_word)])
for a in ans_list:
    print(a[0])

Solution (Python):
from functools import reduce
n = int(input())

alphabet = "abcdefghij"

cur = [[] for _ in range(10)]
nxt = [[] for _ in range(10)]

cur[0] = ["a"]
for _ in range(1, n):
	for i in range(10):
		for x in cur[i]:
			nxt[i].extend([x + alphabet[j] for j in range(i + 1)])
			nxt[i + 1].append(x + alphabet[i + 1])
	cur = nxt.copy()
	nxt = [[] for _ in range(10)]
ans = reduce(lambda a, b: a + b, cur)
ans.sort()
print(*ans, sep = "\n")

Solution (Python):
import sys
from string import ascii_lowercase

alphs = list(ascii_lowercase)

n = int(sys.stdin.readline().rstrip())

def main():
    cur = ['a']
    for _ in range(n-1):
        nex = []
        for s in cur:
            i = 0
            for c in s:
                i = max(i, ord(c) - 97)
            for al in alphs[:i+2]:
                nex.append(s + al)
        cur = nex
    return sorted(cur)

if __name__ == "__main__":
    ans = main()
    print(*ans, sep='\n')

Solution (Python):
from string import ascii_lowercase


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


def solve(n):
    if n == 1:
        return [["a"]]

    tmp = solve(n - 1)

    lower = list(ascii_lowercase)
    ret = []
    for t in tmp:
        m_t = max(t)
        for i in range(lower.index(m_t) + 2):
            ret.append(t + [lower[i]])
    return ret


N = int(input())
ans = solve(N)
for a in ans:
    print("".join(a))

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

q = ['a']
for i in range(N - 1):
    nq = []
    for s in q:
        stop = ord(max(s)) + 2
        for i in range(ord('a'), stop):
            nq.append(s + chr(i))
    q = nq
for s in q:
    print(s)

Solution (Python):
from string import ascii_lowercase

def resolve():
    n = int(input())
    l = [[0]]
    for i in range(1, n):
        ll = []
        for j in l:
            for k in range(max(j) + 2):
                ll.append(j + [k])
        l = ll
    for i in l:
        print("".join([ascii_lowercase[x] for x in i]))

if __name__ == '__main__':
    resolve()

Solution (Python):
s="abcdefghij"
n=int(input())
ans=["a"]
for i in range(2,n+1):
    temp=[]
    lookup=s[:i]
    for j in ans:
        for k in lookup:
            temp.append(j+k)
            if k not in j:
                break
    ans=temp
for i in ans:
    print(i)

Solution (Python):
words = "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 ".split()

def calcMax(current, i):
    maxC = -1
    for c in range(N):
        if(c != N - i):
            maxC = max(maxC, current[c])
    return maxC

def seek(current):
    for i in range(1, N):
        if(current[-i] <= max(current[:-i])):
            current[-i] += 1
            for j in range(i-1):
                current[N-1-j] = 0
            return True, current
    return False, current

def convert(ans):
    ansStr = ""
    for a in ans:
        ansStr += words[a]
    return ansStr

N = int(input())

ans = [0] * N

print(convert(ans))
flag, ans = seek(ans)
while(flag == True):
    print(convert(ans))
    flag, ans = seek(ans)

Solution (Python):
import sys

N=int(input())
if N==1:
  print("a")
  sys.exit()
  
old_list=[[0]]
for i in range(1,N):
  new_list=[]
  for l in old_list:
    maxl=max(l)
    for k in range(maxl+2):
      new_list.append(l+[k])
  old_list=new_list
    

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

for ll in old_list:
  
  str_list=[]
  for elm in ll:
    str_list.append(llist[elm])
  print("".join(str_list))

Solution (Python):
N = int(input())
alpha = "abcdefghijklmnopqrstuvwxyz"

dp = [-1]*N
dp[0] = 1


ans = []


def solve(x, n, l):  
    if l == N:
        ans.append(x)
    else:
        for i in range(n):
            j = n
            if i == n-1:
                j += 1
            solve(x + alpha[i], j, l+1)


solve("", 1, 0)
ans.sort()
for x in ans:
    print(x)

Solution (Python):

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline




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


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

res=[]
def search(seq,k,n):
    global N
    
    if k==N+1:

        tmp=[ascii_lowercase[s-1] for s in seq[1:]]
        res.append("".join(tmp))
        return 
    
    seq[k]=n
    search(seq,k+1,n+1)
    
    for l in range(1,n):
        seq[k] = l
        search(seq, k+1,n)
    

N=int(input())
seq=[-1]*(N+1)
seq[1]=1
search(seq,2,2)


res=sorted(res)

for rr in res:
    print(rr)

Solution (Python):
import collections
import copy
n=int(input())
l=['a']
c=[chr(i) for i in range(97, 97+26)]
for i in range(n-1):
  L=[]
  for j in range(len(l)):
    C=collections.Counter(l[j])
    for k in range(len(C.values())+1):
      L.append(l[j]+c[k])
  l=copy.copy(L)
l.sort()
for i in range(len(l)):
  print(l[i])

Solution (Python):
import sys, math
input = sys.stdin.readline
N = int(input())

dic = 'abcdefghijklmnopqrstuvwxyz'

def f(n, i, s):
  if n == 1:
    print(s)
    return
  for j in range(i+1):
    f(n-1, i, s + dic[j])
  if i+1 < 25:
  	f(n-1, i+1, s + dic[i+1])

f(N, 0, 'a')

Solution (Python):
N = int(input())
s = 'a'
ans = []
alpha = [chr(ord('a') + j) for j in range(10)]

def dfs(S):
  if len(S)==N:
    ans.append(S)
    
    return None
  lis = alpha[:max([alpha.index(s) for s in S])+2]
  
  for t in lis:
    T = S+t
    dfs(T)
    
dfs('a')
print(*ans, sep='\n')

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

al = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
ss = ["a"]
if n == 1:
    print("a")
else:
    for k in range(2, n+1):
        ssn = []
        for s in ss:
            for i in range(k):
                if i > 0:
                    if al[i - 1] not in s:
                        break
                sx = s + al[i]
                if k == n:
                    print(sx)
                ssn.append(sx)
        ss = ssn

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

def ww(s, sn, ans,n):
    global N 
    if n == N:
        ans.append(s)
        return 0
    n += 1
    for i in range(sn+1):
        if i == sn:  
            ww(s+chr(ord("a")+i), sn+1, ans, n)
        else:
            ww(s+chr(ord("a")+i), sn, ans, n)
ans = []
ww("a", 1, ans, 1)

ans.sort()

for i in ans:
    print(i)

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


from itertools import product
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

def dfs(ans, i):
    if len(ans) == n:
        print("".join(ans))
        return
    for j in range(i+1):
        dfs(ans+ascii_lowercase[j], max(j+1, i))

dfs("", 0)

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

ans = [["a"]]

def s_func(x):
    m = -1
    for i in range(len(x)):
        m = max(m, ord(x[i]))
    ret = [chr(i) for i in range(97,m+2)]
    return ret

for i in range(N-1):
    new = []
    for j in range(len(ans[i])):
        s_list = s_func(ans[i][j])
        for s in s_list:
            new.append(ans[i][j] + s)
    ans.append(new)
ans[N-1].sort()
for a in ans[N-1]:
    print(a)

Solution (Python):
from collections import deque

N = int(input())

queue = deque()
queue.append((0,))
while queue:
    s = queue.popleft()
    if len(s) == N:
        print(''.join('abcdefghij'[i] for i in s))
        continue
    for i in range(max(s) + 2):
        queue.append(s + (i,))

Solution (Python):
def solve(li):
    if len(li) == n:
        ans.append(li)
        return
    tmp = max(li)
    for i in range(1, tmp + 2):
        solve(li + [i])

ans = []
n = int(input())
solve([1])
res = []
alph = "abcdefghijklmnopq"

for ptn in ans:
    for i in range(n):
        ptn[i] = alph[ptn[i] - 1]
    res.append("".join(ptn))
res = sorted(res)
for i in res:
    print(i)

Solution (Python):
import bisect
import math

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % mod) % mod
    return CONV()


def getStan(n,prevAlpha):
    if n==0:
        return [""]
    if n==1:
        return [[p] for p in range(prevAlpha+2)]
    else:
        ret = []
        for p in range(prevAlpha+1):
            gs = getStan(n-1, prevAlpha)
            ret += [[p]+g for g in gs]
        gs = getStan(n-1, prevAlpha+1)
        ret+=[[prevAlpha+1]+g for g in gs]
        return ret

def main():
    N = iRaw()
    s = "a"*N
    base = ord("a")
    lastS = [chr(ord("a")+n) for n in range(N)]
    gs = getStan(N-1,0)
    for g in gs:
        print ("".join(["a"]+[chr(c+base) for c in g]))

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
def fac(N):
    if N == 1:
        return [['a']]
    li = []
    for x in fac(N-1):
        n = len(set(x))
        for i in range(n+1):
            li.append(x+[chr(97+i)])
    return li
for x in fac(N):
    print(''.join(x))

Solution (Python):

import sys
S = ['a','b','c','d','e','f','g','h','i','j']
def getResult(current:str,remain:int,used:int):
    if remain==0:
        print(current)
    else:
        for i in range(used):
            getResult(current+S[i],remain-1,used)
        getResult(current+S[used],remain-1,used+1)

def solve(N: int):
    getResult(S[0],N-1,1)
    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):
chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
n = int(input())
seq = [97 for i in range(n)]
i = n - 1
print('a' * n)
while i > 0:
    if seq[i] <= max(seq[:i]):
        seq[i] += 1
        i = n - 1
        print(''.join(map(chr, seq)))
    else:
        seq[i] = 97
        i -= 1

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import copy
import queue

def main():
    mod=10**9+7
    N=I()
    q=queue.Queue()
    q.put("a")
    ans=[]
    
    
    while True:
        s=q.get()
        if len(s)==N:
            q.put(s)
            break
        s2=list(copy.deepcopy(s))
        s2.sort()
        big=ord(s2[-1])-97
        for i in range(big+2):
            q.put(s+chr(i+97))
            
    while not q.empty():
        s=q.get()
        ans.append(s)  
    
    ans.sort()
    
    for i in range(len(ans)):
        print(ans[i])

main()

Solution (Python):
import copy
def make(n, data):
    out = []
    
    key = data[1]
    for i in range(key + 1):
        
        out.append([data[0] + chr(ord("a") + i), max(key, i + 1)])
    return out

n = int(input())
ans = [["a", 1]]
for i in range(1, n):
    tmp = []

    for j in range(len(ans)):
        tmp += make(i + 1, ans[j])
            
    if len(tmp) >= 1:
        ans = copy.deepcopy(tmp)
    

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

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

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

alp = "abcdefghijklmnopqrstuvwxyz"

def next(s,n):
    if n==0:
        print(s)
        return
    val = len(set(s)) 
    for i in range(val+1):
        next(s + alp[i],n-1)

s="a"
next(s,n-1)

Solution (Python):
al=[chr(ord('a') + i) for i in range(26)]
N=int(input())
ans=[[] for _ in range(N)]
ans[0].append("a")

if N==1:
  print("a")
else:
  for i in range(1,N):    
    for item in ans[i-1]:
      lis=list(item)
      st=set(lis)
      for j in range(len(st)+1):
        ans[i].append(item +chr(ord('a') + j))
  for answer in ans[-1]:
    print(answer)

Solution (Python):


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

     ans = list()
     for i in range(n):
          ans = solve(ans)
     
     print('\n'.join(ans))

def solve(l):
     ret = list()
     if len(l) == 0:
          return ['a']

     for i in l:
          num = len(set(i))
          for n in range(num + 1):
               s = i + chr(ord('a') + n)
               ret.append(s)
     
     return ret

if __name__ == "__main__":
    main()

Solution (Python):
import string

n = int(input())

Ans = [[] for _ in range(n+1)]
Ans[1].append('a')
Strs = [x for x in string.ascii_lowercase]

for i in range(1,n):
    for ans in Ans[i]:
        Use_str = [x for x in ans]
        Use_str = set(Use_str)
        for moji in Use_str:
            add = ans + moji
            Ans[i+1].append(add)
        add = ans + Strs[len(Use_str)]
        Ans[i+1].append(add)

Answer = sorted(Ans[n])
for ans in Answer:
    print(ans)

Solution (Python):
N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'

def src(s):
  i = 0
  while s != alpha[i]:
    i += 1
  return i
def super_troop(n):
  if n == 1:
    return ['a']
  else:
    L = super_troop(n-1)
    LL = []
    for i in L:
      S = [j for j in i]
      S.sort(reverse=True)
      for k in range(src(S[0])+2):
        LL.append(i + alpha[k])
    return LL
X = super_troop(N)
X.sort()
for i in range(len(X)):
  print(X[i])

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

strings = ["a"]

for i in range(n-1):
    newstrings = []
    for s in strings:
        mx = ord('a')
        for char in s:
            mx = max(mx, ord(char))
        
        for c in range(ord('a'),mx+2):
            newstrings.append(s+chr(c))
    
    strings = newstrings

for s in strings:
    print(s)

Solution (Python):


iim = lambda: map(int, input().rstrip().split())
from collections import deque

def resolve():
    N = int(input())
    S = "abcdefghij"

    q = deque([("", 0, 0)])
    ans = []
    while q:
        
        s1, i1, i2 = q.popleft()
        

        if i1 == N:
            ans.append(s1)
            continue
        for i in range(i2):
            q.append((s1+S[i], i1+1, i2))
        q.append((s1+S[i2], i1+1, i2+1))

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


if __name__ == "__main__":
    resolve()

Solution (Python):

def main():
    N = int(input())
    li = 'abcdefghijklmnopqrstuvwxyz'

    def condition(t,char):
        nonlocal li
        if li.index(sorted(t)[-1]) + 1 >= li.index(char):
            return True
        else:
            return False
    def f(k):
        nonlocal li
        if k == 1:
            return ['a']
        else:
            temp = f(k-1)
            return [t+char for t in temp for char in li[:k] if condition(t, char)]

    result = f(N)
    for t in sorted(result):
        print(t)

if __name__ == '__main__':
    main()

Solution (Python):
ans = []
alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
k = int(input())
l = ['']*k
def recur(l, ind, newChar):
    if ind == k:
        ans.append(''.join(l))
        return
    for i in range(newChar):
        l[ind] = alp[i]
        recur(l, ind+1, newChar)
    l[ind] = alp[newChar]
    recur(l, ind+1, newChar+1)

recur(l,0,0)
for a in ans:
    print(a)

Solution (Python):



def ri():
    return int(input())

def rl():
    return list(input().split())

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

words = set()
alp = list("abcdefghij")
def dfs(n, s):
    if len(s) == n:
        return
    for i in range(0, len(s)):
        for c in alp:
            if ord(c)>ord(s[i])+1:
                break
            ns = s[:i+1]+c+s[i+1:]
            if ns in words:
                continue
            words.add(ns)
            dfs(n, ns)

def main():
    n = ri()
    if n == 1:
        print("a")
        return
    dfs(n, 'a')
    for w in sorted(words):
        if len(w) == n:
            print(w)



if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque

S = "abcdefghij"
N = int(input())
d = deque([("a", 1, 1)])
while(len(d)>0):
    tmp = d.pop()
    if tmp[1] < N:
        for i in range(tmp[2] + 1):
            tmp2 = (tmp[0] + S[i], tmp[1] + 1, max(tmp[2], i + 1))
            d.appendleft(tmp2)
    else:
        print(tmp[0])

Solution (Python):



n = int(input())

s_new = 'a'
kind_new = [1]
litter =["a","b","c","d","e","f","g","h","i","j"]


for i in range(n-1):
    s_old = s_new
    kind_old = kind_new
    s_new = []
    kind_new=[]
    for j in range(len(s_old)):
        for k in range(kind_old[j]+1):
            s_new.append(s_old[j]+litter[k])
            if k > kind_old[j]-1:
            	kind_new.append(kind_old[j]+1)
            else:
            	kind_new.append(kind_old[j])

for s in s_new:
	print(s)

Solution (Python):

def normal_form(n, base='', e=1, l='abcdefghij'):
    if n == 1:
        for i in range(e):
            print(base + l[i])
        return
    
    for i in range(e-1):
        normal_form(n-1, base + l[i], e)
    normal_form(n-1, base + l[e-1], e+1)


n = int(input())
normal_form(n)

Solution (Python):



import sys
sys.setrecursionlimit(10000000)



def pin(type=int):
    return map(type,input().rstrip().split())
"""
def resolve():
    a,b,c=pin()
    from math import sqrt
    cond =(c-a-b)>sqrt(a*b)*2
    print(["No","Yes"][cond])
"""
def resolve():
    N,=pin()
    from collections import deque
    from collections import Counter
    ans=deque([["a",1]])
    L=1
    abc="abcdefghij"
    
    if N>1:
        for i in range(2,N+1):
            while(len(ans[0][0])<N):
                temp=ans.popleft() 
                string,types=temp
                for y in range(types+1):
                    temp2=string
                    temp2+=abc[y]
                    count=Counter(temp2)
                    
                    ans.append([temp2,len(count)])
                    
    for A in ans:
        print(A[0])
"""


"""
"""
お前カッコ閉じるの忘れてるだろ
"""
if __name__=="__main__":resolve()

Solution (Python):
N = int(input())
char = ["a","b","c","d","e","f","g","h","i","j"]
pre = [("",0)]
for i in range(N):
    nx = []
    for s,cnt in pre:
        for c in char[:cnt]:
            nx.append((s+c,cnt))
        c = char[cnt]
        nx.append((s+c,cnt+1))
    pre = nx

for s,_ in pre:
    print(s)

Solution (Python):
import sys,collections as cl,bisect as bs,math
from decimal import *
getcontext().prec = 50
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

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

po = cl.deque([["",-1],["",0]])
co = 0
fl = False
while True:
    kkk = po.popleft()
    if kkk[1] == -1:
        if len(po) == 0:
            exit()
        co += 1
        if co == n:
            fl = True
        po.append(["",-1])
    else:
        if fl:
            for i in range(kkk[1]+1):
                print(kkk[0]+abc[i])
        else:
            for i in range(kkk[1]+1):
                if i == kkk[1]:
                    po.append([kkk[0]+abc[i],kkk[1]+1])
                else:
                    po.append([kkk[0]+abc[i],kkk[1]])

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 + 2):
            new_answer.append((max(k, i), j + chr(k)))
    answer = new_answer[:]

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

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())


def makeS(len, n, k, res):
    
    ans = []
    if len == n:
        return [res]

    for i in range(k + 1):
        s = chr(97+i)
        if i == k:
            l = makeS(len, n + 1, k + 1, res + s)
        else:
            l = makeS(len, n + 1, k, res + s)

        ans += l

    return ans


ans = makeS(N, 0, 0, "")

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

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

def go(s):
   global n
   if len(s)==n:
       print(s)
       return
   l=max(s)
   for i in range(ord('a'),ord(l)+1):
       go(s+chr(i))
   if l < 'z':
       go(s + chr(ord(l) + 1))

go("a")

Solution (Python):
def dfs(n, i, s, maxi):
    global ans
    maxi = max(i, maxi)
    s += chr(i)
    if n == N:
        ans += [s]
        return
    for ii in range(97, maxi+2):
        dfs(n+1, ii, s, maxi)

N = int(input())
i = 97
ans = []
dfs(1, 97, '', 97)
ans = sorted(ans)
for a in ans:
    print(a)

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

N = int(input())

def rec(i, m, ar) :
  if i == N :
    print(''.join(chr(s + 97) for s in ar))
    return 
  for j in range(min(m + 1, N)) :
    rec(i + 1, max(m, j + 1), ar + [j])


rec(0, 0, [])

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

def f(i, s, n):
	if i==n:
		print(s)
		return
	x=len(set(s))
	for j in range(x+1):
		f(i+1, s+chr(j+97), n)
		
f(0,"",n)

Solution (Python):
from collections import deque
n = int(input())
l = ["a","b","c","d","e","f","g","h","i","j","k"]
ansl = []
d = deque()
ans = "a"
d.append([ans,0])
while len(d):
    now,m = d.pop()
    
    if len(now) == n:
        ansl.append(now)
    else:
        for i in range(m+2):
            if i == m+1:
                d.append([now+l[i],m+1])
            else:
                d.append([now+l[i],m])
ansl.sort()
for i in ansl:
    print(i)

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

def main():
    n = int(input())
    S = [[] for _ in range(n)]
    S[0] = ['a']
    
    dic = {i:j for i,j in zip(range(10),'abcdefghij')}
    for i in range(1,n):
        for st in S[i-1]:
            kind = 1
            while dic[kind] in st:
                kind += 1
            for j in range(kind+1):
                S[i].append(st+ dic[j])
    print(*S[-1],sep='\n')

if __name__=='__main__':
    main()

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

ws = [['a']]
for level in range(1, n):
    ws.append([])
    for front_w in ws[level - 1]:
        max_c = max(front_w)
        ws[level] += ([front_w + chr(c) for c in range(ord('a'), ord(max_c) + 2)])

print('\n'.join(ws[-1]))

Solution (Python):
n=int(input())
li=["a"]
alpha=["a","b","c","d","e","f","g","h","i","j"]
if n==1:
    print("a")
    exit()
else:
    for i in range(n-1):
        ans=[]
        for j in range(len(li)):
            for k in range(len(set(li[j]))+1):
                ans.append(li[j]+alpha[k])
        li=ans
for i in range(len(ans)):
    print(ans[i])

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


def l(i):
    return chr(i + 96)


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


f(1, [])

Solution (Python):
n = int(input())
fac = [1]
for d in range(1,11):
  fac.append(fac[-1]*d)

l = fac[n]
fac2 = []
for d in range(n):
  fac2.append(fac[n]//fac[d+1])
for i in range(l):
  tmp = []
  cum = []
  for d in range(n):
    j = i//(fac2[d])%(d+1)
    tmp.append(j)
    if not cum:
      cum = [0]
    else:
      if j > cum[-1] + 1:
        break
      cum.append(max(cum[-1],j))
  
  
  
    
      
  else:
    ans = ''
    for d in range(n):
      ans += chr(tmp[d]+97)
    print(ans)

Solution (Python):

import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()

    def f(s,v):
        if len(s) == N:
            print(s)
            return
        for i in range(v):
            f(s+chr(ord('a')+i),v)
        f(s+chr(ord('a')+v),v+1)
    f('a',1)



        


if __name__ == '__main__':
    main()