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:
import math

N = int(input())
ZL = [[] for _ in range(N)]
ZL[0].append([0])
for i in range(1, N):
    for szl in ZL[i - 1]:
        n1 = max(szl)
        for j in range(n1 + 2):
            ZL[i].append(szl + [j])


def func(i):
    if i == 0:
        return "a"
    if i == 1:
        return "b"
    if i == 2:
        return "c"
    if i == 3:
        return "d"
    if i == 4:
        return "e"
    if i == 5:
        return "f"
    if i == 6:
        return "g"
    if i == 7:
        return "h"
    if i == 8:
        return "i"
    if i == 9:
        return "j"


L = ZL[N - 1]
for sl in L:
    for i in range(N):
        sl[i] = func(sl[i])
L.sort()
for sl in L:
    print("".join(map(str, sl)))

Submission status: Accepted

Solution code:
N = int(input())
az = ['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']
def norm(n, in_list):
	out_list = []
	for line in in_list:
		for i in range(len(set(line))+1):
			new_line = line + az[i]
			out_list.append(new_line)
	return out_list
init_line = ['a']
for _ in range(N-1):
	init_line = norm(1, init_line)
for line in init_line:
	print(line)

Submission status: Accepted

Solution code:
n = int(input())
s = 'a'

def func(s, count, cc):
    if count == n:
        print(s)
        return
    for i in range(min(count, cc) + 1):
        func(s + chr(ord('a') + i), count + 1, max(i+1, cc))

func(s, 1, 1)

Submission status: Accepted

Solution code:
import collections


def main():
    n = int(input())
    # if n == 1:
    #     print("a")
    # for i in range(2**(n-1)):
    #     bin_str = "0" + format(i, f'0{n-1}b')
    #     print(bin_str.replace("0", "a").replace("1", "b"))

    ret = [[] for _ in range(10)]
    ret[0] = ["a"]

    alp = "abcdefghijklmnopqrstuvwxyz"

    if n == 1:
        print(ret[n-1][0])
        return

    ind = 1
    while ind < n:
        tmp_len = len(ret[ind-1])
        for j, _r in enumerate(ret[ind-1]):
            alphabet_num = len(collections.Counter(_r))
            for k in range(alphabet_num+1):
                ret[ind].append(_r+alp[k])
        ind += 1


    for r in ret[n-1]:
        print(r)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
al = [chr(i + 97) for i in range(N)]
def sol(S):
    if len(S) == N:
        print(S)
        return
    for i in range(len(set(S)) + 1):
        sol(S + al[i])
sol('')

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

ans = set()
def rec(i, S):
    if S in ans:
        return
    if i == N:
        ans.add(S)
        return
    for c in S:
        rec(i+1, S+c)
    if i == 0:
        rec(i+1, 'a')
    else:
        li = sorted(S)
        rec(i+1, S+chr(ord(li[-1])+1))
rec(0, '')
ans = sorted(ans)
[print(s) for s in ans]

Submission status: Accepted

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

def main():
    m='abcdefghijklmnopqrstuvwxyz'
    m=list(m)
    n=int(input())
    ans=[[] for _ in range(n)]
    ans[0].append(['0','0'])
    for i in range(1,n):
        for j,mj in ans[i-1]:
            for k in range(i+1):
                if k<=int(mj)+1:
                    ans[i].append([j+str(k),str(max(int(mj),k))])
    p=[]
    for i,mi in ans[n-1]:
        s=''
        for j in range(len(i)):
            s+=m[int(i[j])]
        p.append(s)
    p.sort()
    for i in p:
        print(i)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())

l = deque(['a'])

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

for i in range(1, N):
    #print(i)
    len_l = len(l)
    for k in range(len_l):
        x = l.popleft()
        for j in range(len(set(x))+1):
            #print(i, k, j)
            l.append(x+alpha[j])
            #print(l)

#l =sorted(l)

for i in l:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

tree = [[0,1]]
for _ in range(n-1):
    tree = [ t+[i]  for t in tree for i in range(1,max(t)+2) ]
for t in tree:
    print( "".join([chr(ord("a")+tt-1) for tt in t[1:] ] ) )

Submission status: Accepted

Solution code:
n = int(input())

tank = []
res = ["a"]

for le in range(1,n):
    tank = res
    res = []
    for i in range(len(tank)):
        tmp = "a"
        for j in range(le):
            res.append(tank[i] + tank[i][j])
            if tank[i][j] > tmp:
                tmp = tank[i][j]
        res.append(tank[i] + chr(ord(tmp)+1))
    res = list(set(res))
res.sort()

for e in res:
    print(e)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    ans = [0 for _ in range(n)]
    ans[0] = 'a'
    ANS = []
    for n1 in range(0,n):
        for e1 in combinations(range(1,n),n1):
            for e in e1:
                ans[e] = 'a'
            list1 = deque()
            for i in range(1,n):
                if i not in e1:
                    list1.append(i)
            if list1:
                index = list1.popleft()
                ans[index] = 'b'
            if not list1:
                ANS.append(''.join(ans))
            for n2 in range(0,n-n1-1):
                for e2 in combinations(list1,n2):
                    for e in e2:
                        ans[e] = 'b'
                    list2 = deque()
                    for i in list1:
                        if i not in e2:
                            list2.append(i)
                    if list2:
                        index = list2.popleft()
                        ans[index] = 'c'
                    if not list2:
                        ANS.append(''.join(ans))
                    for n3 in range(0,n-n1-n2-2):
                        for e3 in combinations(list2,n3):
                            for e in e3:
                                ans[e] = 'c'
                            list3 = deque()
                            for i in list2:
                                if i not in e3:
                                    list3.append(i)
                            if list3:
                                index = list3.popleft()
                                ans[index] = 'd'
                            if not list3:
                                ANS.append(''.join(ans))
                            for n4 in range(0,n-n1-n2-n3-3):
                                for e4 in combinations(list3,n4):
                                    for e in e4:
                                        ans[e] = 'd'
                                    list4 = deque()
                                    for i in list3:
                                        if i not in e4:
                                            list4.append(i)
                                    if list4:
                                        index = list4.popleft()
                                        ans[index] = 'e'
                                    if not list4:
                                        ANS.append(''.join(ans))
                                    for n5 in range(0,n-n1-n2-n3-n4-4):
                                        for e5 in combinations(list4,n5):
                                            for e in e5:
                                                ans[e] = 'e'
                                            list5 = deque()
                                            for i in list4:
                                                if i not in e5:
                                                    list5.append(i)
                                            if list5:
                                                index = list5.popleft()
                                                ans[index] = 'f'
                                            if not list5:
                                                ANS.append(''.join(ans))
                                            for n6 in range(0,n-n1-n2-n3-n4-n5-5):
                                                for e6 in combinations(list5,n6):
                                                    for e in e6:
                                                        ans[e] = 'f'
                                                    list6 = deque()
                                                    for i in list5:
                                                        if i not in e6:
                                                            list6.append(i)
                                                    if list6:
                                                        index = list6.popleft()
                                                        ans[index] = 'g'
                                                    if not list6:
                                                        ANS.append(''.join(ans))
                                                    for n7 in range(0,n-n1-n2-n3-n4-n5-n6-6):  
                                                        for e7 in combinations(list6,n7):
                                                            for e in e7:
                                                                ans[e] = 'g'
                                                            list7 = deque()
                                                            for i in list6:
                                                                if i not in e7:
                                                                    list7.append(i)
                                                            if list7:
                                                                index = list7.popleft()
                                                                ans[index] = 'h'
                                                            if not list7:
                                                                ANS.append(''.join(ans))
                                                            for n8 in range(0,n-n1-n2-n3-n4-n5-n6-n7-7):  
                                                                for e8 in combinations(list7,n8):
                                                                    for e in e8:
                                                                        ans[e] = 'h'
                                                                    list8 = deque()
                                                                    for i in list7:
                                                                        if i not in e8:
                                                                            list8.append(i)
                                                                    if list8:
                                                                        index = list8.popleft()
                                                                        ans[index] = 'i'
                                                                    if not list8:
                                                                        ANS.append(''.join(ans))
                                                                    for n9 in range(0,n-n1-n2-n3-n4-n5-n6-n7-n8-8):  
                                                                        for e9 in combinations(list8,n9):
                                                                            for e in e9:
                                                                                ans[e] = 'i'
                                                                            list9 = deque()
                                                                            for i in list8:
                                                                                if i not in e9:
                                                                                    list9.append(i)
                                                                            if list9:
                                                                                index = list9.popleft()
                                                                                ans[index] = 'j'
                                                                            ANS.append(''.join(ans))
    ANS = list(set(ANS))
    ANS.sort()
    for i in range(len(ANS)):
        print(ANS[i])
        
if __name__ == "__main__":
    main()

Submission status: Accepted

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

sys.setrecursionlimit(10 ** 5)
to = "abcdefghij"


def dfs(s):
    if len(s) == n:
        print(s)
        return
    m = max(ord(c) - ord("a") for c in s) + 1
    for i in range(m + 1):
        dfs(s + to[i])


n = int(input())
dfs("a")

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
X = [chr(ord('a') + i) for i in range(N)]
first_presence = {x: i for x, i in zip(X, list(range(N)))}

ans = ['a']
R = ['a']
# 何文字目以降を変更するか
for i in range(1, N):
    nr = []
    for r in R:
        mr = max(r)
        for x in X:
            nr.append(r + x)
            if mr == x:
                break
        nr.append(r + chr(ord(mr) + 1))
    R = nr

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

Submission status: Accepted

Solution code:
import sys
from collections import deque

def solve():
    N = int(input())
    AB = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
    Ans = []
    q = deque()
    q.append(("a", 1, 0))
    while q:
        current, length, maxW = q.popleft()
        if length == N: Ans.append(current)
        else:
            q.append((current + "a", length + 1, maxW))
            for k in range(maxW + 1):
                q.append((current + AB[k + 1], length + 1, max(k + 1, maxW)))
    Ans.sort()
    for a in Ans: print(a)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

def ans(a, c):
    if len(a)==n-1:
        for i in range(c):
            print(a+s[i])
    else:
        for i in range(c):
            a+=s[i]
            if i==c-1:
                ans(a, c+1)
            else:
                ans(a,c)
            a=a[0:-1]

ans('', 1)

Submission status: Accepted

Solution code:
numal=lambda c:chr(c+97)
n=int(input())
unchi=[[],[],[],[],[],[],[],[],[],[]]
unchi[0].append("0")
k=1
if n>=2:
	while k<n:
		for i in range(len(unchi[k-1])):
			t=max(map(int, unchi[k-1][i]))
			for u in range(t+2):
				unchi[k].append(unchi[k-1][i]+str(u))
		k+=1
for i in range(len(unchi[n-1])):
	s = []
	for k in range(n):
		s.append(numal(int(unchi[n-1][i][k])))
	print("".join(s))

Submission status: Accepted

Solution code:
import string

S = string.ascii_lowercase
N = int(input())


def a(s="", distinct=0):
  if len(s) == N:
    print(s)
    return

  for i in range(distinct + 1):
    c = S[i]
    a(s + c, distinct + (1 if c not in s else 0))


a()

Submission status: Accepted

Solution code:
from copy import deepcopy
N = int(input())
alp = list('abcdefghij')
ans = ['a']
for _ in range(2, N+1):
    m = len(ans)
    tmp = []
    for i in range(m):
        a = ans[i]
        n = len(set(a))
        for s in alp[:n+1]:
            tmp.append(a+s)
    tmp.sort()
    ans = deepcopy(tmp)
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
letters = 'abcdefghij'
count = 0
L = ['']
while count < N:
    next_L = []
    for i in L:
        n = len(np.unique(i))
        for l in letters[:n+1]:
            next_L.append(i + l)
    L = next_L
    count += 1

for j in next_L:
    print(j)

Submission status: Accepted

Solution code:
from itertools import product, combinations_with_replacement
N=int(input())
s="abcdefghij"
 
def get_gen(a, N):
  for c in s[:s.index(max(a))+2 if a else 1]:
    t = a+c
    if len(t) == N:
      print(t)
    else:
      get_gen(t,N)

get_gen("", N)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def dfs(set_list, n):
    global N
    for i, s in enumerate(set_list):
        new_set = s.copy()
        new_set.add(n)
        new_set_list = set_list.copy()
        new_set_list[i] = new_set
        if n == N - 1:
            min_string(new_set_list)
        else:
            dfs(new_set_list, n + 1)
    set_list.append(set([n]))
    if n == N - 1:
        min_string(set_list)
    else:
        dfs(set_list, n + 1)


def min_string(set_list):
    global N

    j = 0
    ret_list = [0 for _ in range(N)]
    for s in set_list:
        for i in s:
            ret_list[i] = j

        j += 1

    print(''.join([chr(j + ord("a")) for j in ret_list]))


def resolve():
    global N
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # h_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    dfs([], 0)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1"""
        output = """a"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2"""
        output = """aa
ab"""
        self.assertIO(input, output)

Submission status: Accepted

Solution code:
N = int(input())
int2char = {i: chr(i + 96) for i in range(1, 11)}
ans = ['a']
for n in range(2, N+1):
    new_list = []
    for string in ans:
        str_set = set(string)
        for i in range(1, n+1):
            if len(str_set) + 1< i:
                continue 
            new_str = string + int2char[i]
            new_list.append(new_str)
    ans = new_list
ans = sorted(ans)
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
n = int(input())
alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
def doukei(n):
  if n == 1:
    return [["a", "a"]]
  k = doukei(n-1)
  ans = []
  for i in range(len(k)):
    key = k[i][1]
    ans.append([k[i][0]+"a", key])
    for j in range(1, 10):
      if key == alpha[j-1]:
        ans.append([k[i][0]+alpha[j], alpha[j]])
        break
      else:
        ans.append([k[i][0]+alpha[j], k[i][1]])
  return ans
answer = doukei(n)
for i in range(len(answer)):
  print(answer[i][0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int):
    string = "abcdefghijk"
    if N == 1:
        print("a")
        return


    answer = []
    def dfs(s,various):
        if len(s) == N:
            return s
        new = dfs(s+string[various],various+1)
        if new:
            answer.append(new)

        for i in range(various):
            n = dfs(s+string[i],various)
            if n:
                answer.append(n)

    dfs("a",1)
    answer.sort()
    for i in range(len(answer)):
        print(answer[i])
    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))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import string

normal_set = set()
def reccursion(n, _s, cur):

    if len(_s) == n:
        global normal_set
        normal_set.add(_s)
        
        return

    for i in range(cur + 1):
        next_s = _s + string.ascii_lowercase[i]
        reccursion(n, next_s, cur)
    
    if cur + 1 < n:
        next_cur = cur + 1
        next_s = _s + string.ascii_lowercase[cur + 1]
        reccursion(n, next_s, next_cur)

def solve():
    n = int(input())
    reccursion(n, "a", 0)

    global normal_set
    normal_set = sorted(list(normal_set))
    
    for _s in normal_set:
        print(_s)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
l = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n"]
n = int(input())
ans = [[] for i in range(n)]
ans[0].append("a")

for i in range(1,n):
    
    for j in ans[i-1]:
        a = 0
        for k in j:
            a = max(a,ord(k)-ord("a"))
        for k in range(a+2):
            an = j + l[k]
            ans[i].append(an)
count = ans[-1]
count.sort()
for i in count:
    print(i)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**5+10)
alp = 'abcdefghij'
N = int(input())
ans = []
def an(i,now,s):
    global ans
    if i == N:
        ans.append(s)
    else:
        for j in range(i+1):
            if j > now+1:
                continue
            an(i+1,max(j,now),s+alp[j])
        
an(0,0,'')
ans.sort()
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
n = int(input())
memo_ls = [{i : [] for i in range(11)} for j in range(11)]
alpha = "abcdefghijklmnopqrstuvwxyz"
#memo_ls[i][j] : i個をjに分ける方法
memo_ls[1][1] = ["a"]
for i in range(1,10):
    for j in range(11):
        if j > i:
            continue
        else:
            for v in memo_ls[i][j]:
                for k in range(j):
                    memo_ls[i + 1][j].append(v + alpha[k])
                memo_ls[i+1][j+1].append(v + alpha[j])
ls = []
for i in range(11):
    for j in memo_ls[n][i]:
        ls.append(j)
print("\n".join(sorted(ls)))

Submission status: Accepted

Solution code:
N = int(input())

s = []

A = "abcdefghijklmnopqrstuvwxyz"

def ss(n):
    if n == 1:
        return [[0]]
    tt = ss(n-1)
    res = []
    for t in tt:
        m = max(t)
        for i in range(m + 2):
            res.append(t + [i])
    return res

for s in ss(N):
    S = ''.join([A[i] for i in s])
    print(S)

Submission status: Accepted

Solution code:
n=int(input())

def f(idx, mx, str):
    # print(idx, mx, str)
    if idx==n:
        print(str)
        return
    for i in range(mx+1+1):
        f(idx+1, max(i, mx), str+chr(ord('a')+i))

f(0,-1,"")

Submission status: Accepted

Solution code:
char = ["a","b","c","d","e","f","g","h","i","j"]

normal_form = ["a"]

n = int(input())
for i in range(n-1):
  new_normal_form = []
  for s in normal_form:
    usingchars = len(set(s))
    for i in range(usingchars+1):
      new_normal_form.append(s+char[i])
  normal_form = new_normal_form

for s in normal_form:
  print(s)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    n = int(input().strip())
    parts("", 0, 0, n)


def parts(char, pos, used, n):
    if pos == n:
        print(char)
        return

    a_ord = ord("a")
    for u in range(used):
        parts(char + chr(a_ord + u), pos + 1, used, n)
    u = used + 1
    parts(char + chr(a_ord + u - 1), pos + 1, u, n)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

def solve(n):
    if n == 1:
        return ['a']
    elif n == 2:
        return ['aa', 'ab']
    else:
        chars = alphabets[0:n]
        result = []
        for retsu in solve(n - 1):
            done = False
            for char in chars:
                if char in retsu:
                    result.append(retsu + char)
                else:
                    if not done:
                        result.append(retsu + char)
                        done = True
                    else:
                        break
        return result

print("\n".join(solve(N)))

Submission status: Accepted

Solution code:
n = int(input())
s = [[] for i in range(n+1)]
s[1].append('a')
ans_s = []
for num in range(1,n):
    for st in s[num]:
        for add in range(97, max(map(ord,st))+2):
            s[num+1].append(st + chr(add))
for sw in s[n]:
    print(sw)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
from operator import itemgetter
import sys
sys.setrecursionlimit(1000000)
N = int(stdin.readline().rstrip().split()[0])

MOD = 10**9 + 7


def f(_arr,a, n, num):
  arr = _arr+[a]
  if n == N:
    #print(arr)
    def print_abc(array):
      abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
      pr = []
      for a in array:
        pr.append(abc[a])
      print("".join(pr))
    print_abc(arr)
    return 0
  for i in range(num+1):
    if i==num:
      f(arr,i,n+1,num+1)
    else:
      f(arr,i,n+1,num)
  
f([], 0, 1, 1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

def res(n, cur, ln, k):
    if ln == n:
        print(cur)
        return
    for i in range(k+2):
        res(n, cur + chr(ord("a") + i), ln+1, max(k,i))
    # res(n, cur + chr(ord("a") + k+1), ln + 1, k+1)


def main():
    n = getN()
    res(n, "a", 1, 0)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
alph = {'a':'b','b':'c','c':'d','d':'e','e':'f','f':'g','g':'h','h':'i','i':'j','j':'k'}
result = ['a']
for i in range(N-1):
    s = []
    for j in result:
        for k in range(len(j)):
            s.append(j+j[k])
        s.append(j+alph[max(j)])
    result = s

result = list(set(result))
result.sort()
for j in result:
    print(j)

Submission status: Accepted

Solution code:
# input
D = int(input())

S = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")

# process
def f(x):
    if x == 0:
        return ["a"]

    else:
        t =  f(x - 1)
        r = []
        for s in t:
            num = len(set(list(s)))
            for i in range(num+1):
                r.append(s+S[i])
        return r

ans = f(D-1)

# output
print(" ".join(map(str, ans)))

Submission status: Accepted

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


def f(X, n, d):
    if n == 0:
        print(''.join(map(lambda x:chr(x+97), X)))
        return

    for i in range(0, d):
        X[-n] = i
        f(X, n-1, d)

    X[-n] = d
    f(X, n-1, d+1)



N = int(input())
X = [0]*N

f(X, N, 0)

Submission status: Accepted

Solution code:
n = int(input())

alp = [chr(v) for v in range(ord("a"), ord("z") + 1)]

def bitcount(v):
    cnt = 0
    for i in range(n + 1):
        cnt += bool(v & (1 << i))
    return cnt

results = []
def f(i=0, s=""):
    if len(s) == n:
        results.append(s)
        return

    for j in range(i + 1):
        if i != j:
            f(i, s + alp[j])
    f(i + 1, s + alp[i])
f()
print(*results, sep="\n")