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

ans = []
def dfs(x):
    if len(x) == n:
        ans.append(x)
        return
    for i in range(0, max(x)+1):
        y = x.copy()
        y.append(i+1)
        dfs(y)
dfs([1])
#print(ans)

r = ['a','b','c','d','e','f','g','h','i','j']
for ai in ans:
    print(''.join(map(lambda x: str(r[x-1]), ai)))

Submission status: Accepted

Solution code:
N=int(input())
ABC=["a","b","c","d","e","f","g","h","i","j"]
def dfs(n,s):
  if len(s)==N:
    print(s)
    return
  
  for i in range(n+1):
    _s=s+ABC[i]
    dfs(max(n,i+1),_s)
    
dfs(0,"")

Submission status: Accepted

Solution code:
n = int(input())

#すべての要素が空になっているリストを作成
l = list('' for _ in range(n))

def dfs(i, mx):
    if i == n:
        #リストの要素同士をつなげて出力、次の文字列へ
        print(''.join(l))
        return
    
    for j in range(mx + 1):
        #l[i]はaからj番目の数に決定
        l[i] = chr(ord('a') + j)
        #(i+1)番目に取りうる文字の候補は、i番目の文字として選んだものの次のものまで
        dfs(i+1, max(j + 1, mx))

dfs(0, 0)

Submission status: Accepted

Solution code:
import sys
import re

l = sys.stdin.readline()
l = int(l)
out = []
def x(stri,l,depth):
  str = 'abcdefghij'
  use = 0
  for i in range(0,l-depth+1):
    if( use == 1):
      break
    cdepth = depth
    cstri = stri
    if ( str[i] not in cstri):
      use = 1
    cstri += str[i] 
    cdepth -= 1
    if( cdepth == 0):
	out.append(cstri)
    else:
	x(cstri,l,cdepth)


stri = 'a'
if( l == 1):
 print stri
 exit(0)
x(stri,l,l-1)

count = 0
for i in out:
  print i


sys.stdout.flush()

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# a〜z -- START --
l=['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']
# a〜z --- END ---

n=I()

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

  for i in range(x+1):
    _s=s+l[i]
    dfs(max(x,i+1),_s)

def main():
  dfs(0,'')

main()
# print(main())

Submission status: Accepted

Solution code:

class Solution:

    def solve(self, N: int):

        def dfs(prev_str: str, max_search_char: str):
            if len(prev_str) == N:
                print(prev_str)
                return
            else:

                for i in range(ord('a'), ord(max_search_char) + 1):
                    c = chr(i)
                    if i == ord(max_search_char):
                        dfs(prev_str + c, chr(i+1))
                    else:
                        dfs(prev_str + c, max_search_char)

        dfs('', 'a')


if __name__ == '__main__':

    # standard input
    N = int(input())
    # solve
    solution = Solution()
    answer = solution.solve(N)

Submission status: Accepted

Solution code:
N = int(input())

def it(i,n):
    if i == N:
        yield [None]*N
    else:
        for x in range(n):
            for d in it(i+1,n):
                d[i] = x
                yield d
        for d in it(i+1,n+1):
            d[i] = n
            yield d

print(*(''.join(chr(x+ord('a')) for x in d) for d in it(0,0)), sep='\n')

Submission status: Accepted

Solution code:
N = int(input())

def it(remain,n):
    if remain == 0:
        yield []
    else:
        for x in range(n+1):
            for d in it(remain-1,max(x+1,n)):
                d.append(x)
                yield d


print(*(''.join(chr(x+ord('a')) for x in reversed(d)) for d in it(N,0)), sep='\n')

Submission status: Accepted

Solution code:
n = int(input())
L = []
def f(s, m):
    if len(s) == n:
        L.append(s)
        return
    for i in range(97, m+2):
        f(s + chr(i), max(i, m))
f("a", 97)
for l in L:
    print(l)

Submission status: Accepted

Solution code:
def rec(pos, used, s):
    if pos == n:
        print(s)
        return
    for i in range(used):
        rec(pos + 1, used, s + chr(ord('a') + i))
    rec(pos + 1, used + 1, s + chr(ord('a') + used))

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

Submission status: Accepted

Solution code:
def dfs(s, mx):
    if len(s) == n:
        print(s)
        return
    for c in a[:mx]:
        dfs(s+c, mx)
    dfs(s+a[mx], mx+1)

n = int(input())
a = "abcdefghij"
dfs("", 0)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import itertools


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

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

    anss = []

    def _dfs(d, _max, ans):
        if d==N:
            anss.append(ans)
            return

        for i in range(ord("a"), _max+2):
            _dfs(d+1, max(_max, i), ans+chr(i))

    _dfs(1, ord("a"), "a")

    anss.sort()

    for ans in anss:
        print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+1)
        for i, c in enumerate(s[:self.index]):
            out[i] = Node(parent+c, self.index)
        out[i+1] = Node(parent+s[self.index], self.index+1)
        return out

def main():
    n = int(input())
    root = Node("a", 1)
    children = [root]
    for _ in range(n-1):
        parents, children = children, []
        for parent in parents:
            children.extend(parent.get_children())
    for child in children:
        print(child.string)

if __name__ == "__main__":
    s = "abcdefghij"
    main()

Submission status: Accepted

Solution code:
def main():
    class Node:
        __slots__ = ["string", "index"]
        def __init__(self, string, index):
            self.string = string
            self.index = index

        def get_children(self):
            parent = self.string
            out = [None]*(self.index+1)
            for i, c in enumerate(s[:self.index]):
                out[i] = Node(parent+c, self.index)
            out[i+1] = Node(parent+s[self.index], self.index+1)
            return out

    n = int(input())
    root = Node("a", 1)
    children = [root]
    for _ in range(n-1):
        parents, children = children, []
        for parent in parents:
            children.extend(parent.get_children())
    for child in children:
        print(child.string)

if __name__ == "__main__":
    s = "abcdefghij"
    main()

Submission status: Accepted

Solution code:
class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        s = "abcdefghij"
        parent = self.string
        out = [None]*(self.index+1)
        for i, c in enumerate(s[:self.index]):
            out[i] = Node(parent+c, self.index)
        out[i+1] = Node(parent+s[self.index], self.index+1)
        return out

def main():
    n = int(input())
    root = Node("a", 1)
    children = [root]
    for _ in range(n-1):
        parents, children = children, []
        for parent in parents:
            children.extend(parent.get_children())
    for child in children:
        print(child.string)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = "abcdefghij"

class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+1)
        for i, c in enumerate(s[:self.index]):
            out[i] = Node(parent+c, self.index)
        out[i+1] = Node(parent+s[self.index], self.index+1)
        return out

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Submission status: Accepted

Solution code:
n=int(input())


A='abcdefghijklmnopqrstuvwxyz'
P=['a']
X=[[] for _ in range(n)]
X[0].append('a')
for i in range(n-1):
    P.append(A[i+1])
    for j in range(len(X[i])):
        flag=False
        for k in range(len(P)):
            X[i+1].append(X[i][j]+P[k])
            if not P[k] in X[i][j]:
                flag=True
            if flag:
                break
Y=X[n-1]
for i in range(len(Y)):
    print(Y[i])

Submission status: Accepted

Solution code:
n = int(input())
s = "abcdefghij"

class Node:
#     __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+2)
        for i, c in enumerate(s[:self.index+1], 1):
            out[i] = Node(parent+c, max(i, self.index))
        return out[1:]

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Submission status: Accepted

Solution code:
n = int(input())
s = "abcdefghij"

class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+1)
        for i, c in enumerate(s[:self.index+1], 1):
            out[i-1] = Node(parent+c, max(i, self.index))
        return out

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Submission status: Accepted

Solution code:
n = int(input())
s = "abcdefghij"

class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+2)
        for i, c in enumerate(s[:self.index+1], 1):
            out[i] = Node(parent+c, max(i, self.index))
        return out[1:]

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Submission status: Accepted

Solution code:
n = int(input())
s = "abcdefghij"

class Node:
    def __init__(self, string, index):
        self.children = []
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        for i, c in enumerate(s[:self.index+1], 1):
            self.children.append(Node(parent+c, max(i, self.index)))
        return self.children

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Submission status: Accepted

Solution code:
n = int(input())
s = "abcdefghij"

class Node:
    def __init__(self, string, index):
        self.children = []
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        for i, c in enumerate(s[:self.index+1]):
            self.children.append(Node(parent+c, max(self.index, i+1)))
        return self.children

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Submission status: Accepted

Solution code:
n = int(input())
s = "abcdefghij"

class Node:
    def __init__(self, string, index):
        self.children = []
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        for i, c in enumerate(s[:self.index+1]):
            self.children.append(Node(parent+c, self.index if self.index>i else i+1))
        return self.children

root = Node("a", 1)
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Submission status: Accepted

Solution code:
n = int(input())
s = set(list("abcdefghijk"))

class Node:
    def __init__(self, char, parents):
        self.children = []
        self.string = parents+char
        self.charset = set(self.string)

    def get_children(self):
        parents = self.string
        for c in sorted(list(self.charset|set(min(s-self.charset)))):
            self.children.append(Node(c, parents))
        return self.children

root = Node("a", "")
children = [root]
for _ in range(n-1):
    parents, children = children, []
    for parent in parents:
        children.extend(parent.get_children())
for child in children:
    print(child.string)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())

alphas = "abcdefghij"
init_str = ""

def standard(moji, x):
    # print("standard({},{})".format(moji,x))
    if len(moji) == n:
        print(moji)
    else:
        for j in range(x+1):
            if j == x:
                # print("j == x")
                standard(moji + alphas[j], x + 1)
            else:
                # print("j != x")
                standard(moji + alphas[j], x)


standard(init_str, 0)

Submission status: Accepted

Solution code:
#x=今まで使った文字種数、→次はaとα個のもの。つまり1つふえる
import sys
sys.setrecursionlimit(4100000)
n=int(input())
def dfs(s, mx):
    if len(s)==n:
        print(s)
        return 0
    for i in range(ord('a'), mx+2):# ord('a')からmx+1までの数字を使いたい
        t=str(s)
        moji=str(chr(i))
        t+=moji
        dfs(t, max(mx, i))
dfs('',ord('a')-1)

Submission status: Accepted

Solution code:
N = int(input())
strlist = 'abcdefghij'

def dfs(s, i):
  if len(s) == N:
    print(s)
  else:
    for j in range(i+1):
      t = s + strlist[j]
      if j == i:
        dfs(t, i+1)
      else:
        dfs(t, i)

dfs('', 0)

Submission status: Accepted

Solution code:
N = int(input())
strlist = 'abcdefghij'

ans = [['a']]
for i in range(1, N):
  ans.append([])
  for s in ans[i-1]:
    n = ord(max(s)) - 96
    for j in range(n+1):
      ans[i].append(s+strlist[j])

print(*ans[-1], sep='\n')

Submission status: Accepted

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

N = int(input())

s = [[] for _ in range(N)]
a_ord = ord("a")

for i in range(N):
    if i == 0:
        s[0].append("a")
        continue
    for j in s[i - 1]:
        j_max_ord = max([ord(x) for x in j])
        for k in range(a_ord, j_max_ord + 2):
            s[i].append(j + chr(k))

ans = s[-1]
ans.sort()

for i in ans:
    print(i)

Submission status: Accepted

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


ans = [['a']]
for i in range(1, N):
  ans.append([])
  for s in ans[i-1]:
    n = len(set(s))
    for j in range(n+1):
      ans[i].append(s+strlist[j])

# ans.sort()
print(*ans[-1], sep='\n')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

min_char = "abcdefghij"

def dtype_tree(tree, max, num):
    for i in range(max+1):
        tgt_tree = [i]
        if num > 0:
            new_max = max
            if new_max < i+1:
                new_max = i+1
            new_tree = dtype_tree([], new_max, num-1)
            tgt_tree.append(new_tree)

        if tree == None:
            tree = tgt_tree
        else:
            tree.append(tgt_tree)
    return tree

def print_tree(tree, prefix):
    new_prefix = prefix
    if len(tree) == 1:
        print(prefix + min_char[tree[0]])
    else:
        for elem in tree:
            if type(elem) != list:
                new_prefix += min_char[elem]
#                print(new_prefix)
            else:
                print_tree(elem, new_prefix)

    return


def abc_XXX(num):
    tree = dtype_tree(None, 0, num-1)
#    print(tree)
    print_tree(tree, "")
    return

###
# main
if(__name__ == '__main__'):
    # input
    n = int(input())
    
    abc_XXX(n)
    
    # output

# else:
    # do nothing

Submission status: Accepted

Solution code:
abc = "abcdefghij"

N = int(input())

def dfs(S, i):
    if len(S) == N:
        return S

    return "\n".join([dfs(S + c, i) for c in abc[:i]] + [dfs(S + abc[i], i + 1)])

print(dfs("a", 1))

Submission status: Accepted

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

def main():

    S = ["a"]
    N = int(input())
    m = 97

    def add_str(S,m):
        if len(S)==N:
            print("".join(S))
        else:
            for j in range(97,m+2):
                add_str(S+[chr(j)], max(m,j))

    add_str(S,m)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from math import ceil
from math import floor
from math import sqrt

def next(c):
    return chr(ord(c)+1)

def step(N, pred, c, cur_max): 
    cur_max = chr(max(ord(c), ord(cur_max)))
    if N == 1:
        return [pred + c]
    else:
        ret = []
        for elem in range(ord('a'), ord(cur_max)+2):
            ret = ret + step(N-1, pred + c, chr(elem), cur_max)
        
        return ret

if __name__ == '__main__':
    input_line = 1
    for i in range(input_line):
        s = input().rstrip().split(' ')
        a = int(s[0])
        ret = step(a, "", 'a', 'a')
        for elem in ret:
            print(elem)

Submission status: Accepted

Solution code:
def mm(a):
  x = 0
  for i in range(0,len(a)):
    if x < ord(a[i]):
      x = ord(a[i])

  return x

n = int(input())
ans = ["a"]
 
for i in range(0,len(ans)):
  while len(ans[i]) < n:
    k = mm(ans[i])
    for j in range(97,k+2):
      ans.append(ans[i] + chr(j))
    del ans[i]
 
sorted(ans)
for i in range(0,len(ans)):
  print(ans[i])

Submission status: Accepted

Solution code:
cdict = "abcdefghijk"

N = int(input())

def str_func( s , num ):
  if( len(s) == N ):
    print(s)
    return
  else:
    for i in range( num ):
      if( i==num-1):
        str_func( s+cdict[i], num+1)
      else:
        str_func( s+cdict[i], num)
        
str_func( "", 1 )

Submission status: Accepted

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

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

    for z in range(count + 1):
        dfs(s + a[z], count + 1 if z == count else count)


dfs("", 0)

Submission status: Accepted

Solution code:
a='a'
for _ in range(int(input())-1):
  a=[s+c for s in a for c in sorted(set(s+chr(ord(max(s))+1)))]
print(*a,sep='\n')

Submission status: Accepted

Solution code:
N = int(input())
if N == 1:
    for i0 in range(1):
        print(chr(i0+97), sep='')
if N == 2:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            print(chr(i0+97), chr(i1+97), sep='')
if N == 3:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                print(chr(i0+97), chr(i1+97), chr(i2+97), sep='')
if N == 4:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), sep='')
if N == 5:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), sep='')
if N == 6:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        for i5 in range(max(i0, i1, i2, i3, i4) + 2):
                            print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), chr(i5+97), sep='')
if N == 7:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        for i5 in range(max(i0, i1, i2, i3, i4) + 2):
                            for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
                                print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), chr(i5+97), chr(i6+97), sep='')
if N == 8:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        for i5 in range(max(i0, i1, i2, i3, i4) + 2):
                            for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
                                for i7 in range(max(i0, i1, i2, i3, i4, i5, i6) + 2):
                                    print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), chr(i5+97), chr(i6+97), chr(i7+97), sep='')
if N == 9:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        for i5 in range(max(i0, i1, i2, i3, i4) + 2):
                            for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
                                for i7 in range(max(i0, i1, i2, i3, i4, i5, i6) + 2):
                                    for i8 in range(max(i0, i1, i2, i3, i4, i5, i6, i7) + 2):
                                        print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), chr(i5+97), chr(i6+97), chr(i7+97), chr(i8+97), sep='')
if N == 10:
    for i0 in range(1):
        for i1 in range(i0 + 2):
            for i2 in range(max(i0, i1) + 2):
                for i3 in range(max(i0, i1, i2) + 2):
                    for i4 in range(max(i0, i1, i2, i3) + 2):
                        for i5 in range(max(i0, i1, i2, i3, i4) + 2):
                            for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
                                for i7 in range(max(i0, i1, i2, i3, i4, i5, i6) + 2):
                                    for i8 in range(max(i0, i1, i2, i3, i4, i5, i6, i7) + 2):
                                        for i9 in range(max(i0, i1, i2, i3, i4, i5, i6, i7, i8) + 2):
                                            print(chr(i0+97), chr(i1+97), chr(i2+97), chr(i3+97), chr(i4+97), chr(i5+97), chr(i6+97), chr(i7+97), chr(i8+97), chr(i9+97), sep='')

Submission status: Accepted

Solution code:
a='a'
exec('a=[s+chr(c)for s in a for c in range(97,ord(max(s))+2)];'*~-int(input()))
print(*a)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(20000000)
n = int(input())

def dfs(num, l):
    if num == 0:
        return l
    l_new = []
    for s, set_size in l:
        for i in range(set_size+1):
            s_size = set_size if i < set_size else set_size + 1
            l_new.append((s + chr(ord('a') + i), s_size))
    return dfs(num-1, l_new)


ans = dfs(n-1, [("a", 1)])
ans = list(map(lambda x: x[0], ans))
ans.sort()
print("\n".join(ans))

Submission status: Accepted

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

def solve(s = "", used = 0, depth = 0):
  if len(s) == N:
    print(s)
    return
  
  for i in range(min(used + 2, depth + 1)):
    #if used + 1 < i:
    #  break
    solve(s + chars[i], max(used, i), depth + 1)

solve()

Submission status: Accepted

Solution code:
import collections
N = int(input())
stack = collections.deque("a")
charset = [chr(ord("a") + i) for i in range(26)]
ans = []
while stack:
    s = stack.pop()
    if len(s) == N:
        ans.append(s)
        continue
    my_max = 0
    for s_s in s:
        my_max = max(my_max, charset.index(s_s))
    for i in range(my_max + 2):
        stack.append(s + charset[i])
[print(a) for a in sorted(ans)]

Submission status: Accepted

Solution code:
n = int(input())


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

    for c in range(ord('a'), mx + 1 + 1):
        dfs(s + chr(c), max(mx, c))


dfs("", ord('a') - 1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)


N = int(input())
ans = []
a = ord('a')


def f(c, A):
    global N, a
    if 0 not in A:
        ans.append(''.join(A))
        return
    B = list(A)
    idx = B.index(0)
    B[idx] = c
    if 0 not in B:
        ans.append(''.join(B))
        return

    for i in range(2 ** (B.count(0)) - 1, -1, -1):
        k = i
        C = B[:]
        idx = C.index(0)
        while k > 0:
            if k & 1 == 1:
                C[idx] = c
            if 0 in C[idx + 1:]:
                idx = C.index(0, idx + 1)
            k >>= 1
        f(chr(ord(c) + 1), tuple(C))



A = [0] * N
f('a', tuple(A))
ans = list(ans)
ans.sort()
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
n=int(input())-1
l=[[] for _ in range(10)]
l[0].append('a')
for i in range(n):
  for w in l[i]:
    s = sorted(set(w))
    for c in s:
      l[i+1].append(w+c)
    l[i+1].append(w+chr(ord(s[-1])+1))  
print(*l[n],sep='\n')

Submission status: Accepted

Solution code:
al=[chr(ord('a') + i) for i in range(26)]
def dfs(N, f):
    if len(f) == N:
        return f
    else:
        result = ""
        f_index = [al.index(i) for i in f]
        for i in range(max(f_index) +1 + 1):#追加できるのは(f+1) + 1
            result +=dfs(N,  f + al[i])
        return result

N = int(input())
ans = dfs(N, 'a')
for i in range(int(len(ans) / N)):
    print(ans[N*i : N * (i+1)])

Submission status: Accepted

Solution code:
import copy

n = int(input())

ary_list = []
def f(ary, max_num):
    if len(ary) == n:
        ary_list.append(ary)
        return
    for i in range(max_num + 2):
        next_ary = copy.copy(ary)
        next_ary.append(i)
        f(next_ary, max_num + (1 if i == max_num + 1 else 0))

f([], -1)

str_list = []
for i in range(len(ary_list)):
    for j in range(n):
        ary_list[i][j] = chr(97 + ary_list[i][j])
    str_list.append("".join(ary_list[i]))

str_list = sorted(str_list)

for s in str_list:
    print(s)

Submission status: Accepted

Solution code:
def d_string_equivalence():
    from string import ascii_lowercase
    N = int(input())
    ans = []

    def dfs(string, can_use):
        if len(string) == N:
            ans.append(string)
            return None
        for ch in ascii_lowercase[:can_use + 1]:
            if ch == ascii_lowercase[can_use]:
                # この場合だけは、新しい英小文字を加えると新しい標準形が現れる
                dfs(string + ch, can_use + 1)
            else:
                # 新しい英小文字を加えても以前現れた標準形と同型になる
                dfs(string + ch, can_use)
    dfs('', 0)  # 最初は 'a' だけ置ける
    return '\n'.join(ans)

print(d_string_equivalence())

Submission status: Accepted

Solution code:
def rec(w, x, n):
    if len(w) == n:
        return print(w)
    else:
        for i in range(x + 1):
            rec(w + chr(ord('a') + i), x + 1 if i == x else x, n)


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

Submission status: Accepted

Solution code:
from string import ascii_lowercase as alphabets


N = int(input())


def dfs(s, used):
    if len(s) == N:
        print(s)
        return
    for i in range(used+2):
        t = s
        t += alphabets[i]
        dfs(t, max(used, i))


dfs("a", 0)

Submission status: Accepted

Solution code:
from itertools import combinations_with_replacement, combinations

N = int(input())

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

def dfs(S, i):
    if len(S) == N:
        yield ''.join(S)
        return

    for j in range(i):
        for w in dfs(S + [alphabets[j]], i): # S.append(hoge)は不可。Sを破壊してしまうため
            yield w

    for w in dfs(S + [alphabets[i]], i + 1):
        yield w

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

Submission status: Accepted

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

alphabet = "abcdefghij"
visited = 1
st = deque([("a", visited)])

while len(st) > 0:
    str, visited = st.popleft()

    if len(str) == N:
        print(str)
    else:
        # すでに使った文字を使う
        for x in alphabet[0 : visited]:
            st.append((str + x, visited))
        # まだ使っていない文字を使う
        # len(str) < Nだから、visited < N
        st.append((str + alphabet[visited], visited + 1))

Submission status: Accepted

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

alphabet = "abcdefghij"
visited = 1
st = deque([["a", visited]])

while len(st) > 0:
    str, visited = st.popleft()

    if len(str) == N:
        print(str)
    else:
        # すでに使った文字を使う
        for x in alphabet[0 : visited]:
            st.append([str + x, visited])
        # まだ使っていない文字を使う
        # len(str) < Nだから、visited < N
        st.append([str + alphabet[visited], visited + 1])

Submission status: Accepted

Solution code:
import math
n = int(input())

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

todo = ['a']
while len(todo)>0:
    p = todo.pop(-1)
    l = len(p)
    cou = len(set(p))
    if l < n:
        for i in range(cou+1):
            todo.append(p+d[i])
    else:
        ans.append(p)


print('\n'.join(sorted(set(ans))))

Submission status: Accepted

Solution code:
from collections import deque

def bfs(i):
    q = deque()
    q.append(["a"])
    while q:
        p = q.popleft()
        l = len(p)
        if l == i:
            print("".join(p))
        if not len(p) == i:
            for j in range(l + 1):
                if j >= 1:
                    if alph[j - 1] in p:
                        q.append(p + [alph[j]])
                else:
                    q.append(p + ["a"])
        
alph = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
n = int(input())
bfs(n)

Submission status: Accepted

Solution code:
n = int(input())

alphas = "abcdefghij"
init_str = ""

def standard(moji, i):
    if len(moji) == n:
        print(moji)
    else:
        for j in range(i):
            if j == i - 1:
                standard(moji + alphas[j], i + 1)
            else:
                standard(moji + alphas[j], i)
                

standard(init_str, 1)