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:
def cur(n):
    if ans[n]!=[]: return ans[n]
    for x in cur(n-1):
        tmp1=[0]+[x[i] for i in range(n-1)]
        tmp2=[0]+[x[i]+1 for i in range(n-1)]
        ans[n].append(tmp1)
        ans[n].append(tmp2)
        if max(x)!=0:
            for k in range(1,max(x)+1):
                tmp3=[0]+[x[i] for i in range(n-1)]
                for i in range(1,n):
                    if tmp3[i]==k: tmp3[i]=0
                    elif tmp3[i]<k: tmp3[i]+=1
                ans[n].append(tmp3)
    
    return ans[n]

def pri(x):
    s=""
    for i in range(p):
        s+=chr( ord("a")+x[i] )
    print(s)

p=int(input())
ans=[[] for i in range(11)]
ans[1]=[[0]]
ans[2]=[[0,0],[0,1]]
cur(p)

ans[p].sort()
pri(ans[p][0])
for i in range(1,len(ans[p])):
    if ans[p][i]!=ans[p][i-1]: pri(ans[p][i])

Submission status: Accepted

Solution code:
N = int(input())
a_ch = [chr(ch) for ch in range(ord('a'), ord('j') + 1)]

def DFS(s, mx):
  if len(s) == N:
    print(s)
  else:
    for i in range(mx + 1):
      if i == mx:
        DFS(s + a_ch[i], mx + 1)
      else:
        DFS(s + a_ch[i], mx)

DFS('', 0)

Submission status: Accepted

Solution code:
def cur(n):
    if ans[n]!=[]: return ans[n]
    for x in cur(n-1):
        tmp1=[0]+[x[i] for i in range(n-1)]
        tmp2=[0]+[x[i]+1 for i in range(n-1)]
        ans[n].append(tmp1)
        ans[n].append(tmp2)
        if max(x)!=0:
            for k in range(1,max(x)+1):
                tmp3=[0]+[x[i] for i in range(n-1)]
                for i in range(1,n):
                    if tmp3[i]==k: tmp3[i]=0
                    elif tmp3[i]<k: tmp3[i]+=1
                ans[n].append(tmp3)
    
    return ans[n]

def pri(x):
    s=""
    for i in range(p):
        s+=chr( ord("a")+x[i] )
    print(s)

p=int(input())
ans=[[] for i in range(11)]
ans[1]=[[0]]
ans[2]=[[0,0],[0,1]]
cur(p)

ans[p].sort()
pri(ans[p][0])
for i in range(1,len(ans[p])):
    if ans[p][i]!=ans[p][i-1]: pri(ans[p][i])

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
lst = ['a','b','c','d','e','f','g','h','i','j']
cnt = n
ans = []

def dfs(s,num,kinds):
    if num == n:
        ans.append(s)
        return
    for i in range(kinds+1):
        if lst[i] in s:
            dfs(s+lst[i],num+1,kinds)
        else:
            dfs(s+lst[i],num+1,kinds+1)
    return 

dfs('',0,0)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
# D - String Equivalence
abc = "abcdefghij"


def dfs(n: int) -> list:
    if n == 1:
        return ["a"]
    cur = dfs(n - 1)
    result = []
    for s in cur:
        for c in abc[: len(set(s)) + 1]:
            result.append(s + c)
    return result


def main():
    N = int(input())
    result = dfs(N)
    result.sort()
    print("\n".join(result))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

n = I()
lst = ['a','b','c','d','e','f','g','h','i','j']
cnt = n
ans = []

def dfs(s,num,kinds):
    if num == n:
        ans.append(s)
        return
    for i in range(kinds+1):
        if lst[i] in s:
            dfs(s+lst[i],num+1,kinds)
        else:
            dfs(s+lst[i],num+1,kinds+1)
    return 

dfs('',0,0)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
lst = ["a"]
abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
for i in range(n - 1):
    lst_ = lst
    lst = []
    for s in lst_:
        for t in abc[: len(set(s)) + 1]:
            lst.append(s + t)
for s in lst:
    print(s)

Submission status: Accepted

Solution code:
N = int(input())

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

def dfs(st, n, k):
    if n == N:
        print(st)
    else:
        for i in range(k+1):
            if i < k:
                dfs(st + alph[i], n+1, k)
            else:
                dfs(st + alph[i], n+1, k+1)

dfs("", 0, 0)

Submission status: Accepted

Solution code:
# D - String Equivalence
from string import ascii_lowercase


def dfs(n: int) -> list:
    if n == 1:
        return ["a"]
    cur = dfs(n - 1)
    result = []
    for s in cur:
        for c in ascii_lowercase[: len(set(s)) + 1]:
            result.append(s + c)
    return result


def main():
    N = int(input())
    result = dfs(N)
    result.sort()
    print("\n".join(result))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve(s):
    if len(s)==n:
        a.append(''.join(chr(c+97)for c in s))
        return
    for i in range(max(s)+2):
        solve(s+[i])
n=int(input())
a=[]
solve([0])
print(*a)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def dfs(n, s, mx):
	if len(s) == n:
		print(s)
	else:
		for i in range(97, ord(mx)+1):
			dfs(n, s + chr(i), chr(ord(mx) + 1) if i == ord(mx) else mx)
def main():
	n = INT()
	dfs(n, "", "a")


if __name__=='__main__':
	main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
N = int(input())
N -= 1

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


def dfs(s, depth, maxS):

    if depth == N:
        print(s)
        return

    for i in range(maxS+1):
        if i == maxS:
            dfs(s + S[i], depth+1, maxS+1)
        else:
            dfs(s + S[i], depth+1, maxS)


dfs("a", 0, 1)

Submission status: Accepted

Solution code:
import string

N = int(input())
S = string.ascii_letters[:N] 
S_idx = {s:i for i, s in enumerate(S)}

def main(s, n):
    if n >= N:
        return print(s)
    idx =  S_idx[max(s)]
    for i in S[:idx+2]:
        main(s+i, n+1)
        
main('a', 1)

Submission status: Accepted

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

n = int(readline())

alphabets = [chr(ord('a') + x) for x in range(26)]

def dfs(s,i):
    if len(s)==n:
        print("".join(s))
    else:
        t = min(len(set(s))+1,len(s)+1) #ループに使える文字は、現在の文字の種類+1か((a,b)の時、dは使えない)、長さ+1(1文字目は必ずa以下、2文字目は必ずb以下)の小さい方
        for i in range(t):
            dfs(s+[alphabets[i]],i) #dfsで全通り

dfs([],0)

Submission status: Accepted

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


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


def dfs(S, mx):
    global N
    if len(S) == N:
        ans.append(S)
    else:
        for c in range(0, mx + 2):
            dfs(S + chr(c + a), max(mx, c))


dfs('a', 0)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
N = int(input())
alfa = {1:'a',2:'b',3:'c',4:'d',5:'e',6:'f',7:'g',8:'h',9:'i',10:'j'}
end = [i+1 for i in range(N)]
s = [1 for i in range(N)]
def checks(s):
    if s[0] != 1:
        return False
    else:
        x = 1
        count = 1
        ch = 0
        for i in range(N):
            if s[i] == count:
                count += 1
            elif s[i] > count:
                ch = 1
                break
        if ch == 1:
            return False
        else:
            return True
            
def get_next(s):
    for i in range(1,N):
        y = list(s)
        y[-1*i] += 1
        #print(y)
        for j in range(1,i):
            y[-1*j] = 1
            #print(y)
        if checks(y):
            return(y)
            break
    return(s)
while s != end:
    #3print(end,s)
    ans = []
    for i in s:
        ans.append(alfa[i])
    print(''.join(ans))
    s = get_next(s)
ans = []
for i in s:
    ans.append(alfa[i])
print(''.join(ans))

Submission status: Accepted

Solution code:
n = int(input())

def test(s, mx):
    if len(s) == n:
        print(s)
    else:
        for c in range(ord('a'), mx+1): 
            if c == mx:
                test(s+chr(c), mx+1)
            else:
                test(s+chr(c), mx)
test('',ord('a'))

Submission status: Accepted

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


def dfs(ans, ref):
    if len(ans) == n:
        print(ans)
    else:
        l = [s[i] for i in range(ref + 1)]
        for x in l:
            if x == l[ref]:
                dfs(ans + x, ref + 1)
            else:
                dfs(ans + x, ref)


dfs('', 0)

Submission status: Accepted

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


def next_chr(ch):
    res = []
    g = ord(ch) - ord("a") + 2
    for i in range(g):
        res.append(chr(ord("a")+i))
    return res


def answer(s, i):
    if i == N:
        ch = next_chr(max(s))
        for m in ch:
            ans.append("".join([s, m]))
    else:
        i += 1
        ch = next_chr(max(s))
        for m in ch:
            answer("".join([s, m]), i)


if N == 1:
    print("a")
else:
    answer("a", 2)
    ans = sorted(ans)
    for c in ans:
        print(c)

Submission status: Accepted

Solution code:
N = int(input())

s = {'a'}

def solve(n):
    global s
    if n == N:
        return
    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(1)
ans = sorted(s)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
n = int(input())

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

def dfs(res, i):
    if len(res) >= n:
        print(res)
        return
    for k in range(i):
        dfs(res+l[k], i)
    dfs(res+l[i], i+1)

dfs("", 0)

Submission status: Accepted

Solution code:
def rec(S,depth):
    if depth == 0:
        print(S)
        return
    else:
        list_mozi=list(dict.fromkeys(list(S)))
        list_mozi.sort()
        for j in range(len(list_mozi)):
            rec(S+list_mozi[j],depth-1)
        rec(S+chr(ord(list_mozi[len(list_mozi)-1])+1),depth-1)

N=int(input())
rec("a",N-1)

Submission status: Accepted

Solution code:
N = int(input())

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

def dfs(s, i):
    if len(s) == N:
        return [s]
    result = []
    for j in range(i+1):
        if j == i:
            result += dfs(s+S[j], i+1)
        else:
            result += dfs(s+S[j], i)
    return result
print("\n".join(dfs("", 0)))

Submission status: Accepted

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

n = int(readline())

alphabets = [chr(ord('a') + x) for x in range(26)]

def dfs(s,i):
    if len(s)==n:
        print("".join(s))
    else:
        t = min(len(set(s))+1,len(s)+1)
        for i in range(t):
            dfs(s+[alphabets[i]],i)

dfs([],0)

Submission status: Accepted

Solution code:
n = int(input())
tb = 'abcdefghijklmnopqrstuvwxyz'

def output(s, m):
    if len(s) == n:
        print(s)
    else:
        for i in range(m + 1):
            if i == m:
                output(s + tb[i], m + 1)
            else:
                output(s + tb[i], m)
output("", 0)

Submission status: Accepted

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


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

def solve(N: int):
    dfs("", 0, N)

def dfs(s: str, mx: int, N: int):
    if len(s) == N:
        print(s) 
    else:
        for i in range(mx + 1):
            dfs(s + ALH[i], mx + 1 if i == mx else mx, N)

# def solve(N: int):
#     alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
#     print("a" * N)
#     for i in range(N - 1, 0, -1):
#         s = ("a" * i) + "b"
#         if i == N - 1:
#             print(s)
#             continue
#         r_len = N - 1 - i
#         for j in range((r_len + 1) ** r_len + 1):
#             if j == (r_len + 1) ** r_len:
#                 print(s, end="")
#                 for l in range(r_len):
#                     print(alph[l+2], end="")
#                 print()
#                 continue
#             nokori = j
#             s2 = s
#             prev_val = set()
#             for k in range(r_len):
#                 if k == r_len - 1:
#                     val = nokori
#                 else:
#                     val = nokori // ((r_len + 1) ** (r_len - k - 1))
#                 prev_val.add(val)
#                 nokori = nokori % ((r_len + 1) ** (r_len - k - 1))
#                 s2 += alph[val]
#                 if val >= 3 and not val - 1 in prev_val:
#                     break
#             else:
#                 print(s2)
    # if N >= 3:
    #     for i in range(N):
    #         print(alph[i], end="")
    #     print()



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

def dfs(s, mx):
    if len(s) == n:
        print(s)
    else:
        for c in [chr(ord('a') + i) for i in range(ord(mx) - ord('a') + 1)]:
            dfs(s + c, chr(ord(mx) + 1) if c == mx else mx)

dfs('', 'a')

Submission status: Accepted

Solution code:
n = int(input())
abc = [chr(i) for i in range(97, 97 + n)]
def dfs(s, idx):
    if len(s) == n:
        print(s)
    else:
        for i in range(idx + 1):
            if idx == i:
                dfs(s + abc[i], idx + 1)
            else:
                dfs(s + abc[i], idx)
dfs("", 0)

Submission status: Accepted

Solution code:
from string import ascii_lowercase
from functools import lru_cache
n = int(input())

@lru_cache(maxsize=10)
def make(n):
    if n == 1:
        return ['a']
    else:
        lst = []
        for s in make(n-1):
            for c in ascii_lowercase[:len(set(s))+1]:
                lst.append(s + c)
        return lst
for s in make(n):
    print(*s, sep='')

Submission status: Accepted

Solution code:
n = int(input())
l = "abcdefghij"
def dfs(res, i):
    if len(res) >= n:
        print(res)
        return
    for k in range(i):
        dfs(res+l[k], i)
    dfs(res+l[i], i+1)
dfs("", 0)

Submission status: Accepted

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

def f(x: str) -> str:
  return chr(int(x) + a)

i = 0
while i < 10 ** (n-1):
  x = str(i).zfill(n)
  maximum = 0
  flag = True
  for j, digit in enumerate(map(int, x)):
    if digit > maximum + 1:
      flag = False
      break
    elif digit == maximum + 1:
      maximum = digit
  if flag:
    print(''.join(map(f, x)))
    i += 1
  else:
    d = 10 ** (n - j)
    i = (i // d + 1) * d

Submission status: Accepted

Solution code:
n = int(input())
ans = ["a"]
for i in range(n-1):
    nans = []
    
    for s in ans:
        m = max(s)
        for x in range(ord(m)-95):
            nans.append(s+ chr(97+x))
            
    ans = nans
print("\n".join(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def dfs(now, mx):
    if len(now) == n:
        print(now)
    else:
        for i in range(1, mx + 2):
            mmx = max(mx, i)

            dfs(now + al[i], mmx)


n = int(input())

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

dfs('a', 1)

Submission status: Accepted

Solution code:
import itertools
def solve():
    N = int(input())
    alphabets = ['a','b','c','d','e','f','g','h','i','j']
    lst = []
    dfs(1, N, alphabets[:N],lst, "", 0)

def dfs(depth, N, alphabets, lst, now, mx):
    if depth > N:
        lst.append(now)
        print(now)
        return
    for i in range(0,mx+1):
        next_mx = mx
        if i == mx:
            next_mx += 1
        dfs(depth+1, N, alphabets, lst, now + alphabets[i], next_mx)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def f(s, k, N):
    if len(s) == N:
        print(s)
        return

    for i in range(k+1):
        f(s + l_alp[i], max(k, i+1), N)


def main():
    N = I()
    ans = []

    f('a', 1, N)

    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
l=[["a"]]+[[] for i in range(9)]
for i in range(9):
  for j in l[i]:
    k=len(set(list(j)))
    for h in range(k+1):
      l[i+1].append(j+chr(97+h))
for i in l[n-1]:print(i)

Submission status: Accepted

Solution code:
k = int(input())
anss = [["a"]]

for i in range(k-1):
  anss.append([])
  for j in anss[i]:
    for l in range(len(set(list(j)))+1):
      anss[i+1].append(str(j)+chr(97+l))
anss[k-1].sort()
for i in anss[k-1]:
  print(i)

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline().strip())

def dfs(s, n):
	if len(s) == N:
		print(s)
	else:
		for i in range(n+1):
			dfs(s + chr(97+i), n+1 if i == n else n)

dfs("", 0)

Submission status: Accepted

Solution code:
N = int(input())

# mx = count up flag
def dfs(s, mx):
    if len(s) == N:
        print(s)
    else:
        for c in range(ord('a'), mx+1):
            dfs(s+chr(c), mx + 1 if c == mx else mx)

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

Submission status: Accepted

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


N = int(input())
ans = set()
a = ord('a')


def f(c, A, done):
    global N, a
    B = list(A)
    done = set(done)
    for i in range(N):
        if i not in done:
            B[i] = c
            done.add(i)
            break
    if len(done) == N:
        ans.add(''.join(B))
    else:
        for i in range(2 ** (N - len(done)) - 1, -1, -1):
            k = i
            C = B[:]
            tDone = set(x for x in range(N))
            nDone = set(x for x in done)
            for t in done:
                tDone.remove(t)
            while k > 0:
                y = min(tDone)
                if k & 1 == 1:
                    C[y] = c
                    nDone.add(y)
                tDone.remove(y)
                k >>= 1
            f(chr(ord(c) + 1), tuple(C), tuple(nDone))


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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
n = int(input())

def dfs(s, mx):
  if len(s) == n:
    print(s)
  else:
    for i in range(mx):
      dfs(s+chr(ord("a")+i), mx)
    dfs(s+chr(ord("a")+mx), mx+1)
    
dfs("a", 1)

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:
import string
al = string.ascii_lowercase
N = int(input())

def dfs(s, mx):
    if len(s) == N:
        print(s)
    else:
        for i in range(mx):
            c = al[i]
            if c == al[mx-1]:
                dfs(s+c, mx+1)
            else:
                dfs(s + c, mx)

dfs('', 1)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d
n = int(input())

def dfs(s, kinds):
    if len(s) == n:
        print(s) 
    else:
        for i in range(kinds+1):
            new_kinds = kinds + (1 if i == kinds else 0)
            dfs(s + chr(ord('a') + i), new_kinds)

dfs('', 0)

Submission status: Accepted

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

def solve(N: int):   
    d = {n:[] for n in range(1, N+1)} 
    d[1] = [[1]]

    for n in range(1, N):
        
        for lst in d[n]:
            last_element = lst[-1]

            for new_element in range(1, max(lst)+2):
                d[n+1].append(lst+[new_element])

    ans_lst = d[N]

    for i, lst in enumerate(ans_lst):
        ans_lst[i] = ''.join([chr(num+96) for num in lst])

    for lst in ans_lst:
        print(lst)
    
    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:
from sys import stdin
import copy

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

ans_list = []

def main():

    input = stdin.readline

    N = int(input())   

    dp('a',N)

    for i in ans_list:
        print(i)
    
def dp(ans,N):

    for i in range(ord('a'),ord('a')+len(list(set(ans)))+1):
        if len(ans) == N:
            ans_list.append(ans)
            return
        else:
            dp(ans + chr(i),N)


if __name__ == "__main__":
    main()

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"]
    if N == num:
        for i in range(len(S)):
            print(S[i])
        return
    else:
        tmp = []
        length = len(S)
        for i in range(length):
            ttmp = sorted(list(S[i]))
            for j in range(alphabet.index(ttmp[-1])+2):
                tmp.append(S[i]+alphabet[j])
        S = sorted(tmp)
        f(num+1,N,S)

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

Submission status: Accepted

Solution code:
def DFS(word,n):
    if len(word)==N:
        return print(word)
    else:
        for i in range(n+1):
            DFS(word+chr(97+i),n+1 if i==n else n)


N=int(input())
DFS("",0)

Submission status: Accepted

Solution code:
n = int(input())
alpha_dict = {}
for i,c in enumerate(range(ord('A'),ord('Z')+1)):
  alpha_dict[i] = str(chr(c)).lower()


ans = []
def dfs(s, mx, ans):
  if len(s) == n:
    ans += [s]
    return 
  else:
    for i in range(mx+1):
      dfs(s+alpha_dict[i], max(i+1, mx), ans)

dfs("", 0, ans)
ans = sorted(ans)
for a in ans:
  print(a)

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

    ret = []
    stack = [('', ord('a'))]
    while stack:
        s, c = stack.pop()
        if len(s) == n:
            ret.append(s)
        else:
            for x in range(ord('a'), c+1):
                stack.append((s+chr(x), c+1 if c == x else c))

    return '\n'.join(sorted(ret))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

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

N = int(input())

def bfs(s, cnt, m):
	if cnt == N:
		print(s)
		return

	for i in range(97,ord(m)+2):
		if chr(i) > m:
			bfs(s+chr(i), cnt+1, chr(i))
		else:
			bfs(s+chr(i), cnt+1, m)

bfs('a',1,'a')

Submission status: Accepted

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

alphabets = list('abcdefghijklmnopqrstuvwxyz')

N = int(input())

if N == 1:
    print('a')
else:
    tmp = ['a']
    for i in range(1, N):
        result = []
        for s in tmp:
            alpha_list = sorted(list(set(list(s))))
            for a in alpha_list:
                result.append(s+a)
            result.append(s+alphabets[len(set(list(s)))])
            tmp = result
    print('\n'.join(result))

Submission status: Accepted

Solution code:
n = int(input())


def dfs(s, mx):
    if len(s) == n:
        print(''.join([chr(ord('a') + i) for i in s]))
    else:
        for i in range(mx+1):
            dfs(s + [i], mx if i != mx else mx + 1)


dfs([], 0)

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s, mx):
    if len(s) == N:
        print(s)
        return
    for c in 'abcdefghij'[:(ord(mx)-ord('a'))+1]:
        dfs(s+c, chr(ord(mx)+1)) if c == mx else dfs(s+c, mx)

dfs('', 'a')

Submission status: Accepted

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

A = [L[0]]
B = [A[0]+L[i] for i in range(2)]
C = [i+L[j] for i in B for j in range(len(set(i))+1)]
D = [i+L[j] for i in C for j in range(len(set(i))+1)]
E = [i+L[j] for i in D for j in range(len(set(i))+1)]
F = [i+L[j] for i in E for j in range(len(set(i))+1)]
G = [i+L[j] for i in F for j in range(len(set(i))+1)]
H = [i+L[j] for i in G for j in range(len(set(i))+1)]
I = [i+L[j] for i in H for j in range(len(set(i))+1)]
J = [i+L[j] for i in I for j in range(len(set(i))+1)]

Z = [A,B,C,D,E,F,G,H,I,J]

for i in Z[N-1]:
    print(i)

Submission status: Accepted

Solution code:
k = "a",
for _ in range(int(input()) - 1):
  k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)}
print(*sorted(k), sep='\n')

Submission status: Accepted

Solution code:
N = int(input())

def f(s):
    if len(s) == N:
        print(s)
        return
    for i in range(97, ord(max(list(s)))+1+1):
        ns = s + chr(i)
        f(ns)

f('a')

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
d = 'abcdefghij'
x = ['a']
cnt = 1

while cnt<N:
    y = []
    for i in x:
        for j in d[:len(set(i))+1]:
            y.append(i+j)
    x = y
    cnt += 1
print('\n'.join(x))

Submission status: Accepted

Solution code:
def recursion(s, mx, n):
    if len(s) == n:
        print(s)
        return
 
    c = 'a'
    while c <= mx:
        nmx = mx
        if c == mx:
            nmx = chr(ord(c) + 1)
        recursion(s + c, nmx, n)
        c = chr(ord(c) + 1)


n = int(input())
recursion("", 'a', n)

Submission status: Accepted

Solution code:
n = int(input())
alpha_dict = {}
for i,c in enumerate(range(ord('A'),ord('Z')+1)):
  alpha_dict[i] = str(chr(c)).lower()


ans = []
def dfs(s, mx, ans):
  if len(s) == n:
    ans += [s]
    return 
  else:
    for i in range(mx+2):
      dfs(s+alpha_dict[i], max(i, mx), ans)

dfs("", -1, ans)
ans = sorted(ans)
for a in ans:
  print(a)

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s, mx):
  global N
  if len(s) == N:
    print(s)
  else:
    for i in range(ord(mx) - ord('a') + 1):
      dfs(s + chr(ord('a') + i), chr(ord(mx) + 1) if chr(ord('a') + i) == mx else mx)

dfs('', 'a')

Submission status: Accepted

Solution code:
N = int(input())

arr=[1]*N

s = ['' for i in range(N)]

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

def num2alpha(num):
    return chr(num+97)

def dfs(k,c):
    if(k==N):
        print("".join(s))
        return
    for i in range(c):
        s[k]=num2alpha(i)
        dfs(k+1,c)
    s[k]=num2alpha(c)
    dfs(k+1,c+1)

dfs(0,0)

Submission status: Accepted

Solution code:
n = int(input())


def f(s, max_i):
    if len(s) >= n:
        print(s)
    else:
        for i in range(max_i+2):
            f(s + chr(ord('a') + i), max(max_i, i))


f('a', 0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    s = 'abcdefghijkl'
    ans = []

    def f(t: str):
        if len(t) == N:
            ans.append(t)
            return
        
        if len(t) >= 2:
            x = s.index(max(list(t)))+2
        else:
            x = len(t)+1
        for i in range(x):
            f(t+s[i])


    
    f('')
    ans.sort()
    for i in ans:
        print(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:
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:
def DFS(word,n):
    if len(word)==N:print(word)
    else:
        for i in range(n+1):
            DFS(word+chr(97+i),n+1 if i==n else n)


N=int(input())
DFS("",0)