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



Sample input:
1


Sample output:
a

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from itertools import permutations
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    l=[[] for _ in range(N+1)]
    l[0]=[('a',ord('a'))]
    for i in range(N-1):
        for a,z in l[i]:
            for j in range(ord('a'),z+2):
                l[i+1].append((a+chr(j),max(z,j)))
    l.sort()
    for a,z in l[N]:
        print(''.join(a))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

myList = [[0, "a"]]

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

if N == 1:
    print("a")
else:
    for indx in range(1,N):
        newMyList = []
        for strItem in myList:
            for addIndx in range(strItem[0] + 2):
                newNum = max(addIndx, strItem[0])
                newMyList.append([newNum, strItem[1] + alfList[addIndx]])
        myList = newMyList
    
    for indx in range(len(myList)):
        print(myList[indx][1])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
n=INT()
a=["a" for i in range(n)]
def f(num):
    global n,a
    if num==n:
        print("".join([str(n) for n in a]))
        return
    elif num==1:
        a[num]="a"
        f(num+1)
        a[num]="b"
        f(num+1)
    else:
        a[num]="a"
        f(num+1)
        a[num]="b"
        f(num+1)
        try:
            if a.index("b")<num:
                a[num]="c"
                f(num+1)
            if a.index("c")<num:
                a[num]="d"
                f(num+1)
            if a.index("d")<num:
                a[num]="e"
                f(num+1)
            if a.index("e")<num:
                a[num]="f"
                f(num+1)
            if a.index("f")<num:
                a[num]="g"
                f(num+1)
            if a.index("g")<num:
                a[num]="h"
                f(num+1)
            if a.index("h")<num:
                a[num]="i"
                f(num+1)
            if a.index("i")<num:
                a[num]="j"
                f(num+1)
        except:
            pass
f(1)

Submission status: Accepted

Solution code:
n = int(input())

base = ['a' for i in range(n)]

end = ['z' for i in range(n)]

def sorted_k_partitions(seq, k):
    n = len(seq)
    groups = []  # a list of lists, currently empty

    def generate_partitions(i):
        if i >= n:
            yield list(map(tuple, groups))
        else:
            if n - i > k - len(groups):
                for group in groups:
                    group.append(seq[i])
                    yield from generate_partitions(i + 1)
                    group.pop()

            if len(groups) < k:
                groups.append([seq[i]])
                yield from generate_partitions(i + 1)
                groups.pop()

    result = generate_partitions(0)

    # Sort the parts in each partition in shortlex order
    result = [sorted(ps, key = lambda p: (len(p), p)) for ps in result]
    # Sort partitions by the length of each part, then lexicographically.
    result = sorted(result, key = lambda ps: tuple(map(len, ps)) + (ps,))

    return result

seq = [i+1 for i in range(n)]

# print(seq)

res = []

for k in seq:
    for groups in sorted_k_partitions(seq, k):
        temp = ['a' for i in range(n)]
        tmp = []
        tmp = list(groups)
        tmp.sort()
        # print(tmp)
        counter = 0
        for t in tmp:
            for e in t:
                temp[e-1] = chr(ord('a') + counter)
            counter += 1
        # print('after')
        # print(temp)
        res.append(''.join(temp))

res.sort()

for r in res:
    print(r)

Submission status: Accepted

Solution code:
N = int(input())

alphabets = list('Zabcdefghijklmn')
s = ['a']
ss = []
for i in range(2, N + 1):
    subset = alphabets[1:i + 1]
    for j in range(len(s)):
        for k in subset:
            ss.append(s[j] + k)
            if s[j].find(k) == -1:
                break
    # print('s, ss', s, ss)
    s = ss
    ss = []
print(*s, sep='\n')
# for i in s:
#     print(i)

Submission status: Accepted

Solution code:
from string import ascii_lowercase as alps

n = int(input())

def solve(x=n, c=0, l=[]):
    if x == 0:
        print(''.join(alps[i-1] for i in l))
        return

    x -= 1

    for nc in range(1, c + 1):
        solve(x, c, l + [nc])

    solve(x, c+1, l + [c+1])

solve()

Submission status: Accepted

Solution code:
n = int(input())


A = ['a']

for i in range(n-1):
    B = A[i:]
    for j in B:
        for i in range(ord("a"), ord(max(j)) + 2):
            A.append("".join(j) + chr(i))
A = sorted(A)
for i in A:
    if len(i) == n:
        print(i)

Submission status: Accepted

Solution code:
N = int(input())

s = set()

def solve(n):
    global s

    if n == N:
        return

    if len(s) == 0:
        s.add('a')
        solve(n+1)
    else:
        new_s = set()
        for v in s:
            xc = chr(ord(max(v))+1)
            for vc in v:
                new_s.add(v + vc)
                new_s.add(v + xc)
        s = new_s
        solve(n+1)

solve(0)
ans = sorted(s)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
K = int(input())-1
al = [chr(i) for i in range(97, 97+26)]
S_arr = [al[0]]
for i in range(K):
  new_S_arr = []
  for S in S_arr:
    for j in range(len(set(list(S)))+1):
      new_S_arr.append(S + al[j])
  S_arr = new_S_arr

for S in S_arr:
  print(S)

Submission status: Accepted

Solution code:
n = int(input())
a = [ [] for _ in range(11) ]
a[0].append("a")

alp = "abcdefghijklmn"
for i in range(1, 10):
    for aa in a[i-1]:
        for c in alp[:i+1]:
            max_e = max( [ord(x) for x in aa] )
            if max_e+1 < ord(c): break
            a[i].append(aa+c)

for ans in a[n-1]:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ch = ['a','b','c','d','e','f','g','h','i','j']
def l (num,s):
    global n
    global ch
    if num == n:
        return s
    new = []
    for i in s:
        x = len(set(i)) +1
        for j in range(x):
            p = i + ch[j]
            new.append(p)
    return num+1,new
dt = (1,['a'])
for k in range(n):
    dt = l(dt[0],dt[1])
for z in dt:
    print(z)

Submission status: Accepted

Solution code:
n = int(input())

def plus(s):
  m = max(s)
  ret = []
  for i in range(ord(m)-97+2):
    ret.append(s+chr(i+97))
  return ret

s = 'a'
ws = [[] for i in range(10+1)]
ws[0].append(s)
for i in range(1,10+1):  
  for s in ws[i-1]:
    ws[i].extend(plus(s))     
    
for s in ws[n-1]:
  print(s)

Submission status: Accepted

Solution code:
n=int(input())

stack=['a']
alpahbet=[chr(i) for i in range(97, 97+26)]

if n==1:
    print('a')
else:
    cnt=1
    
    while cnt<n:
        nextstack=[]

        while len(stack):
            curs=stack.pop()
            pat=set()
            for c in alpahbet:
                ret=0
                for j in range(cnt):
                    if curs[j]==c:
                        ret=ret*2
                    else:
                        ret=ret*2+1
                
                if ret in pat:
                    continue

                pat.add(ret) 
                nextstack.append(curs+c)
        
        stack=sorted(nextstack)
        cnt+=1
    
    for s in stack:
        print(s)

Submission status: Accepted

Solution code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()

alpha =list("abcdefghij")

def dfs(string, counter, N):
    if N==counter:
        lists.append(string)
        return 
    
    for i in range(counter):
        if i==0:
            dfs(string + alpha[i], counter+1, N)
        elif alpha[i-1] in string:
            dfs(string + alpha[i], counter+1, N)

lists = []

dfs("a", 2, N+1)

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

Submission status: Accepted

Solution code:
import sys


def I(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LMI(): return list(map(int, sys.stdin.readline().split()))


MOD = 10 ** 9 + 7

s = 'abcdefghijklmnop'
N = I()

for c1 in range(1):
    if N == 1:
        print(s[c1])
        continue
    for c2 in range(2):
        if N == 2:
            print(s[c1]+s[c2])
            continue
        for c3 in range(max(c1, c2) + 2):
            if N == 3:
                print(s[c1] + s[c2] + s[c3])
                continue
            for c4 in range(max(c1, c2, c3) + 2):
                if N == 4:
                    print(s[c1] + s[c2] + s[c3] + s[c4])
                    continue
                for c5 in range(max(c1, c2, c3, c4) + 2):
                    if N == 5:
                        print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] )
                        continue
                    for c6 in range(max(c1, c2, c3, c4, c5) + 2):
                        if N == 6:
                            print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6])
                            continue
                        for c7 in range(max(c1, c2, c3, c4, c5, c6) + 2):
                            if N == 7:
                                print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6] + s[c7] )
                                continue
                            for c8 in range(max(c1, c2, c3, c4, c5, c6, c7) + 2):
                                if N == 8:
                                    print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6] + s[c7] + s[c8])
                                    continue
                                for c9 in range(max(c1, c2, c3, c4, c5, c6, c7, c8) + 2):
                                    if N == 9:
                                        print(s[c1]+s[c2]+s[c3]+s[c4]+s[c5]+s[c6]+s[c7]+s[c8]+s[c9])
                                        continue
                                    for c10 in range(max(c1, c2, c3, c4, c5, c6, c7, c8, c9) + 2):
                                        print(s[c1]+s[c2]+s[c3]+s[c4]+s[c5]+s[c6]+s[c7]+s[c8]+s[c9]+s[c10])

Submission status: Accepted

Solution code:
N = int(input())
al = "abcdefghijklmnopqrstuvwxyz"
atoi = {s:i for i, s in enumerate(al)}
itoa = {i:s for i, s in enumerate(al)}

l = []
def func(s, i):
    if i == N:
        print(s)
        l.append(s)
        return
    # if al[:i] == s:
    #     for c in al[:i+1]:
    #         func(s + c, i+1)
    # else:
    #     for c in al:
    #         func(s + c, i+1 )

    # if i == N - 1:
    maxi = max([atoi[c] for c in s])
    for c in al[:maxi+2]:
        func(s+c, i+1)
    # else:
    #     for c in al[:i+1]:
    #         func(s+c, i+1) 

func("a", 1)

Submission status: Accepted

Solution code:
N = int(input())

cset = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
sset = ['a'] * N
def rec(di, usedci):
    if di >= len(sset):
        print(''.join(sset))
        return
    for i in range(usedci+1):
        sset[di] = cset[i]
        rec(di+1, usedci)
    sset[di] = cset[usedci+1]
    rec(di+1, usedci+1)

rec(1, 0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import deque, defaultdict
import bisect
from math import factorial, sqrt

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

def generate_valid_strings(base):
    result = set()
    candidates = set(list(base))

    for c in candidates:
        string = base + c
        result.add(string)

    for c in ALPHABETS:
        if c not in candidates:
            string = base + c
            result.add(string)
            break

    return result


def main():
    #a, b, c = map(int, input().split())
    N = int(input())

    all_strings = defaultdict(set)

    x = 'a'
    all_strings[1].add(x)
    for i in range(1, N):
        new_strings = set()
        prev_strings = all_strings[i]
        for string in prev_strings:
            new_strings |= generate_valid_strings(string)
        all_strings[i+1] = new_strings

    result = sorted(all_strings[N])
    for string in result:
        print(string)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque,Counter
n=int(input())
abc="abcdefghijklmnopqrstuvwxyz"
arr=deque()
def dfs(string,cnt):
    if cnt==n+1:
        arr.append(string)
        return 0
    l=len(list(set(list(string))))
    for i in abc[:l+1]:
        dfs(string+i,cnt+1)

dfs("",1)
arr=sorted(list(arr))
for i in arr:
    print(i)

Submission status: Accepted

Solution code:
import sys
import re
input = sys.stdin.readline

N = int(input())

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
ans = []
for i in range(N):
    if not i:
        ans.append(['a'])
    else:
        l = []
        p = []
        for x in ans[-1]:
            m = max([alpha.index(a) for a in x])
            l.extend([x + a for a in alpha[:m + 2]])

        ans.append(l)

for x in ans[N - 1]:
    print(x)

Submission status: Accepted

Solution code:
N = int(input())
D = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Ans = [["a"]]
for i in range(1, 10):
    before = Ans[i - 1]
    # print(before)
    next = []
    for j in before:
        L = set(list(j))
        # print(L)
        for k in range(len(L) + 1):
            # print(j)
            next.append(j + D[k])
    Ans.append(next)
# print(Ans)
print(*Ans[N - 1], sep="\n")

Submission status: Accepted

Solution code:
N = int(input())

alph = [chr(ord('a') + i)  for i in range(N)]
S = ""
ans = []


# i文字目に何を入れるか　j種類使っている状態
def add_s(S, j):

    if len(S) == N:
        ans.append(S)
        print(S)
        return

    for s in range(j+2):
        S += alph[s]
        if s == j+1:
            add_s(S, j+1)
        else:
            add_s(S, j)
        S = S[:-1]

add_s("a", 0)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
n=int(input())
al=[chr(ord('a') + i) for i in range(15)]
def dfs(c,i):
    if i==n:
        print(c)
        return
    p=0
    for k in c:
        p=max(p,ord(k))
    for k in range(p-ord('a')+2):
        dfs(c+al[k],i+1)
dfs("a",1)

Submission status: Accepted

Solution code:
def solve(x):
    if len(x) == n:
        ans.append(x)
        return 0
    syurui = len(set(x))
    for i in range(syurui + 1):
        solve(x + chr(97 + i))


n = int(input())

a = "a"

ans = []

solve(a)

ans = sorted(ans)

print(*ans)

Submission status: Accepted

Solution code:
import collections
def f(l):
    res=[]
    l,res=res,l
    for i in range(len(res)):
        c=collections.Counter(res[i])
        for j in range(len(c)+1):
            l.append(res[i]+chr(97+j))
    return l

n=int(input())
if n==1:
    print("a")
else:
    ans=["a"]
    i=1
    while i<n:
        ans=f(ans)
        i+=1
    for i in range(len(ans)):
        print(ans[i])

Submission status: Accepted

Solution code:
N=input()
A="abcdefghij"

S=["a"]
for n in range(2,N+1):
    temp=[]
    for s in S:
        max_s=max(s)
        ind_max_s=A.index(max_s)
        for i in range(ind_max_s+2):
            temp.append(s+A[i])
    S=temp

S.sort()
for x in S:
    print x

Submission status: Accepted

Solution code:
n = int(input())
l = ["a","b","c","d","e","f","g","h","i","j"]
i = 0
def st(s,n,k,m):
  if k == n:
    print(s)
    return
  for i in range(m):
    st(s+l[i],n,k+1,m)
  st(s+l[m],n,k+1,m+1)
st("a",n,1,1)

Submission status: Accepted

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

list_old0 = [0]
list_old1 = [[0,0],[0,1]]
list_old = [[0,0],[0,1]]
if n>2:
    m = n
else:
    m = 3

for i in range(2,m):
    list_new=[]
    for k in list_old:
        #print('b')
        for j in range(i+1):
            #print('c')
            b=k.copy()
            #print(b)
            #print(f'j{j}')
            if max(k)+1<j:
                continue
            b.append(j)
            list_new.append(b)
    #print(list_new)
    list_old = list_new

if n==1:
    print('a')
elif n==2:
    print('aa')
    print('ab')
else:
    for l in list_old:
        for y in l:
            print(list_abc[y],end='')
        print()

Submission status: Accepted

Solution code:
n=int(input())
s="abcdefghijklmno"
end=[0,1,2,3,4,5,6,7,8,9,10,11,12,13]
lim=0
res=[0]*n
for i in res:
  print(s[i],end="")
print("")

while res!=end[:n]:
  res[(n-1)]=res[(n-1)]+1
  for i in range(n-1):
    if res[n-i-1]>(max(res[:(n-i-1)])+1):
      res[n-i-1]=0
      res[n-i-2]=res[n-i-2]+1
  for i in res:
    print(s[i],end="")
  print("")

Submission status: Accepted

Solution code:
N = int(input())
ans = ['a']
moji = ['a','b','c','d','e','f','g','h','i','j']
count = 1
while count < N:
    tmp = []
    for i in ans:
        for k in range(len(set(list(i)))+1):
            tmp.append(i+moji[k])
    count += 1
    ans = tmp
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
alphabets = string.ascii_lowercase

N = int(input())
ans = [["a", 0]]
for i in range(1, N):
    ans2 = copy.deepcopy(ans)
    ans = []
    for l in ans2:
        for k in range(int(l[1]) + 2):
            ans.append([l[0] + alphabets[k], max(l[1], k)])
for i in ans:
    print(i[0])

Submission status: Accepted

Solution code:
N = int(input())
alp = lambda c: chr(c+96)
def num(L,key):
    if len(L) == N:
        ans = [alp(a) for a in L]
        print(''.join(ans))
    else:
        for k in range(1,key+1):
            l = L + [k]
            num(l,key)
        l = L + [key+1]
        num(l, key+1)

init =[1]
num(init,1)

Submission status: Accepted

Solution code:
w = []
N = int(input())


def addchar(s):
    if(len(s) < N):
        x = len(set(s))+1
        for i in range(x):
            t = s + chr(ord("a")+i)
            addchar(t)
    else:
        w.append(s)

addchar("a")
for i in w:
  print(i)

Submission status: Accepted

Solution code:
n = int(input())
words = ['a', 'b', 'c', 'd', 'e', 'f','g','h', 'i', 'j']
ans = [[] for _ in range(n)]
ans[0].append(["a", 1])
for i in range(n - 1):
    for ai in ans[i]:
        for j in range(ai[1]):
            ans[i + 1].append([ai[0] + words[j], ai[1]])
        ans[i + 1].append([ai[0] + words[ai[1]], ai[1] + 1])

for a in ans[n - 1]:
    print(a[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

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

def solve(N: int):
    
    def p_out(ppp):
        print("".join([al[p] for p in ppp]))

    def rec_ad(token, ttl):

        if ttl != 0:
            for k in range(max(token)+2):
                rec_ad(token + [k], ttl - 1)
        else :
            p_out(token)

    rec_ad([0], N-1)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


def f(s, m, n):
    if(len(s) == n):
        print(s)
        return
    for i in range(m):
        # dump(i)
        f(s+chr(i+ord('a')), m if i < m-1 else (m+1), n)


n = int(input())
dump(n)
ans = set()
# for si in f('a', 2, n):
#    pass  # print(si)
f('a', 2, n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 14 20:59:48 2020

@author: Kanaru Sato
"""

dict = list("abcdefghijklmnopqrstuvwxyz")

def gen(n):
    if n == 1:
        return ["a"]
    else:
        rvalue = []
        for s in gen(n-1):
            max = 0
            for i in range(len(s)):
                num = dict.index(s[i])
                if num >= max:
                    max = num
            for i in range(max+2):
                rvalue.append(s+dict[i])
        return rvalue

n = int(input())
l = gen(n)
ans = sorted(l)

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

Submission status: Accepted

Solution code:
K = int(input())
word_dic = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10}
l_word = ["a","b","c","d","e","f","g","h","i","j"]
L = ["a"]
if K == 1:
  print("a")
else:
  for i in range(K-1):
    M = []
    for x in L:
      k_x = 0
      for y in list(x):
        if k_x < word_dic[y]:
          k_x = word_dic[y]
      for j in range(k_x+1):
        M.append(x + l_word[j])
    L = M[:]
  else:
    for x in L:
      print(x)

Submission status: Accepted

Solution code:
n = int(input())

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

def f(i):
    if i == 1:
        return [chars[i - 1]]
    else:
        temp = f(i - 1)
        e = []
        for j in temp:
            w = min([len(set(j)) + 1, i - 1])
            for c in range(w):
                e.append(j + chars[c])
        e.append(''.join(chars[0:i]))
        return e

    
result = f(n)
result = sorted(result)
for i in result:
    print(i)

Submission status: Accepted

Solution code:
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
from decimal import *
#input = sys.stdin.readline


#N=int(input())

#A=list(map(int,input().split()))
#XY=[list(map(int,input().split())) for i in range(N)]

N=int(input())
lst=[i for i in range(1,N)]
lst2=[[] for i in range(N)]
lst2[0].append([0])

for l in lst:
    for l2 in lst2[l-1]:
        for i in range(max(l2)+2):
            lst2[l].append(l2+[i])

lst2=lst2[-1]
lst2=sorted(["".join([chr(m+ord("a"))for m in l]) for l in lst2 ])
for i in lst2:
    print(i)

Submission status: Accepted

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

    chars_list = [
        ['a'],
        ['aa', 'ab'],
        ['aaa', 'aab', 'aba', 'abb', 'abc'],
        ['aaaa', 'aaab', 'aaba', 'aabb', 'aabc', 'abaa', 'abab', 'abac', 'abba', 'abbb', 'abbc', 'abca', 'abcb', 'abcc', 'abcd']
    ]
    a = 'abcdefghijkl'

    if n <= 4:
        for s in chars_list[n-1]:
            print(s)
    else:
        while n - 4 > 0:
            appends_list = []
            for char in chars_list[-1]:
                for alphabet in a:
                    appends_list.append(char+alphabet)
                    if alphabet not in char:
                        break
            chars_list.append(appends_list)
            n -= 1

        for s in chars_list[-1]:
            print(s)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
def print_from_l(l):
    print(''.join(map(lambda s:chr(97+s), l)))
def g(l):
    if len(l) == n:
        print_from_l(l)
    else:
        for i in range(max(l)+2):
            g(l + [i])
g([0])

Submission status: Accepted

Solution code:
n = int(input())
a = [0]*n

def print_str():
    for i in reversed(a):
        print(chr(97+i), end='')
    print()

print_str()
while True:
    for i in range(n-1):
        if a[i] <= max(a[i+1:]):
            a[i] += 1
            for j in range(i):
                a[j] = 0
            print_str()
            break
    else:
        break

Submission status: Accepted

Solution code:
from copy import deepcopy
def f(num,N,S):
    alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t"]
    if N == num:
        S.sort()
        for i in range(len(S)):
            print(S[i])
        return
    else:
        tmp = []
        length = len(S)
        for i in range(length):
            ttmp = list(S[i])
            ttmp.sort()
            tttmp = alphabet.index(ttmp[-1])
            for j in range(tttmp+2):
                tmp.append(S[i]+alphabet[j])
                    
        S = deepcopy(tmp)
        S.sort()
        f(num+1,N,S)

N = int(input())
f(1,N,["a"])

Submission status: Accepted

Solution code:
n = int(input())
num_list = [97] * n
target = n - 1
tmp_target = n - 1
max_num = 97
if n==1:
    print('a')
while tmp_target > 0:
    print("".join(list(map(chr, num_list))))
    if max(num_list[0:target:]) >= num_list[target]:
        num_list[target] += 1
    else:
        num_list[target] = 97
        tmp_target = target - 1
        while tmp_target > 0:
            if max(num_list[0:tmp_target:]) >= num_list[tmp_target]:
                num_list[tmp_target] += 1
                break
            else:
                num_list[tmp_target] = 97
                tmp_target -= 1

Submission status: Accepted

Solution code:
def continuous(string):
    numbers = [ord(c) - 97 for c in list(string)]
    largest = max(numbers)
    flag = True
    for i in range(1, largest+1):
        if i not in numbers:
            flag = False
            break
    return flag
  
  
def solve(N):
    if N == 1:
        return "a"
    else:
        tmp = solve(N-1)
        tmp_top = ["a" + t for t in tmp]
        tmp_bottom = [t + alphabet for t in tmp for alphabet in ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"][:N]]
        tmp_bottom = [t for t in tmp_bottom if continuous(t)]
        tmp = sorted(list(set(tmp_top + tmp_bottom)))
        return tmp
      
      
N = int(input())
res = solve(N)
for s in res:
    print(s)

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.buffer.readline

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

    use = ["a"]
    if N == 1:
        print("a")
        exit()
    for i in range(1,N):
        ans = []
        for st in use:
            c = 0
            for t in st:
                c = max(c,ord(t)-ord("a"))
            for j in range(c+2):
                s = chr(97+j)
                if i == N-1:
                    print(st+s)
                else:
                    ans.append(st+s)
        use = ans
   
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = "abcdefghijklmmopkrstuvwxyz"


def solve(s, m):
    if len(s) == n:
        print(s)
        return
    for v in a:
        if ord(v)-m <= 1:
            solve(s+v, max(m, ord(v)))


solve("a", ord("a"))

Submission status: Accepted

Solution code:
n=int(input())
char=[chr(i) for i in range(97, 97+26)]

ans=["a"]
before=0

for i in range(2,n+1):
    for c in range(len(ans)):
        From=char.index(sorted(list(ans[c]))[-1])
        for m in range(From+2):
            ans.append(ans[c]+char[m])
    #print(ans)
    
b=[]

for g in range(len(ans)):
    if len(ans[g])==n:
        b.append(ans[g])

b.sort()

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    
    def rec(n, maxchr, ans):
        if n==N-1:
            print(ans)
        else:
            for i in range(maxchr+1):
                # print(i)
                rec(n+1, maxchr, ans+chr(i+97))
            rec(n+1, maxchr+1, ans+chr(maxchr+98))

    rec(0, 0, 'a')

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import itertools

bells = [[], [[0]]] + [None for i in range(9)]
bell_n = [1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975]

def search(n):
    ret = []
    ret.append( [ 0 for _ in range(n) ] )
    for k in range(1,n):
        for bi in bells[k]:
            for ids in itertools.combinations(range(1,n), k):
                st = [0 for _ in range(n)]
                for i, id in enumerate(ids):
                    st[id] = bi[i] + 1
                ret.append(st)
    return ret

for i in range(2, 11):
    bells[i] = search(i)
    assert bell_n[i] == len(bells[i])

N = int(input())
table = "abcdefghij"
outs = []
for bi in bells[N]:
    out = ""
    for b in bi:
        out += table[b]
    outs.append(out)

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

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

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

@lru_cache(None)
def rec(before, depth, MAX):
    for i in range(MAX-ord('a') +2):
        tmp = before + chr(ord('a') + i)
        if len(tmp) >= n:
            ans.append(tmp)
        else:
            MAX = max(MAX, ord(tmp[-1]) )
            rec(tmp, depth+1, MAX)


rec('a',1, ord('a'))

ans.sort()

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

Submission status: Accepted

Solution code:
n = int(input())
al = [chr(i) for i in range(97,97+26)]

dpn = ['a']
dpp = []
if n == 1:
    print('a')
    exit()
for i in range(1,n):
    for j in dpn:
        for k in al[:max(list(map(ord,list(j))))-97+2]:
            if i != n-1:
                dpp.append(j + k)
            else:
                print(j+k)
    if i != n-1:
        dpn = dpp
        dpp = []

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import deque
import copy
str_list_befor = ['0', '1', '2','3','4','5', '6', '7','8','9']
str_list_after = ['a', 'b', 'c','d','e','f', 'g', 'h','i','j']

n = int(input())

dq = deque()
dq.append([0])
if n > 1:
    for i in range(n-1):
        # print("i: " + str(i))
        for j in range(len(dq)):
            # print("j: " + str(j))
            prv = dq.popleft()
            for j in range(max(prv)+2):
                tmp = copy.copy(prv)
                tmp.append(j)
                # print(tmp)
                dq.append(tmp)
            # print(dq)

for i in range(len(dq)):
    result = ""
    tmp_r = dq.popleft()
    result = "".join(map(str, tmp_r))
    for j in range(len(str_list_befor)):
        result = result.replace(str_list_befor[j], str_list_after[j])

    print(result)