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 itertools
n = int(input())
#li = list(itertools.product([0,1], repeat=n))
alp = list('abcdefghijklmnopqrstuvwxyz')

ans_li = ['0']
for _ in range(n-1):
    tmp = []
    for a in ans_li:
        last = 0
        for an in a:
            if int(an)>last:
                last = int(an)
        for i in range(last+2):
            tmp.append(a+str(i))
    ans_li = tmp
for bb in ans_li:
    ans = ''
    for b in bb:
        ans += alp[int(b)]
    print(ans)

Submission status: Accepted

Solution code:
def make_new_vocab(voc):
    max_let = ord(max(voc)) - 97
    let = [chr(ord('a') + i) for i in range(26)]

    for i in range(max_let + 2):
        yield voc + let[i]


n = int(input())
vocabs = ["a"]


for i in range(1, n):
    new_vocabs = []
    for voc in vocabs:
        for p in make_new_vocab(voc):
            new_vocabs.append(p)
    vocabs = new_vocabs

for ans in vocabs:
    print(ans)

Submission status: Accepted

Solution code:
def dfs(s, mx):
    if len(s) == N:
        print(s)
        return
    for c in range(ord("a"), mx + 1):
        dfs(s + chr(c), mx + 1 if c == mx else mx)

if __name__ == "__main__":
    N = int(input())
    dfs("", ord("a"))

Submission status: Accepted

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


def dfs(s):
    if len(s) == n:
        print(s)
        return 0
    for x in map(chr, range(97, ord(max(s))+2)):
        dfs(s+x)


dfs('a')

Submission status: Accepted

Solution code:
n = int(input())
alp = "abcdefghijklmnopqrstuvwxyz"
ans = []


def dfs(s):
    if len(s) == n:
        ans.append(s)
        return 0
    se = len(set(s))
    for i in range(se+1):
        dfs(s+alp[i])


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

Submission status: Accepted

Solution code:
n=int(input())
from collections import deque
d=deque(['a'])
c=[chr(i) for i in range(97, 97+26)]
ans=set([])
while d:
  y=d.pop()
  if len(y)==n:
    ans.add(y)
  now=c.index(sorted(y)[-1])
  for z in range(min(now+2,n+1)):
    if z>-1 and len(y)<n:
      d.append(y+c[z])
for z in sorted(list(ans)):
  print(z)

Submission status: Accepted

Solution code:
import collections
import numpy as np
import sys
import copy
from functools import lru_cache


sys.setrecursionlimit(10**8)
#N,K=map(int,input().split())
N=int(input())
#h=np.array(list(map(int,input().split())))
#ans=0
num2alpha = lambda c: chr(c+96)


def dfs(K,b,s):
    if len(s)==N:
        return b.append(s)
        s=""
    elif len(s)>N:
        return
    elif len(s)<N:
        x = copy.deepcopy(s)
        for i in range(N):
            if i+1-len(set(x))< 2:
                s=x+num2alpha(i+1)
                dfs(N-1, b, s)
B=list()
m=""
dfs(N-1,B,m)
for i in B:
    print(i)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()

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

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

Submission status: Accepted

Solution code:
n = int(input())

buf = [0]*n

def solv(idx,char):
    aida = n - idx
    if idx == n:
        print("".join(buf))
        return

    for i in range(char + 1):
        buf[idx] = chr(ord('a') + i)
        solv(idx+1,max(i + 1,char))

solv(0,0)

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

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

def main():
    n = int(input())
    # 一番大きいものは何か、それを保存してdfs
    def dfs(cnt, s):
        if cnt == n:
            print(s)
            return
        biggest = 'a'
        c = 0
        while c < len(s):
            if s[c] == biggest:
                biggest = chr(ord(biggest)+1)
                c += 1
            else:
                c += 1
        for i in range(0,ord(biggest) - ord('a') + 1):
            sc = chr(ord('a')+i)
            s += sc
            dfs(cnt + 1, s)
            s = s[:-1]
    dfs(0,"")
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
lis=[[]for i in range(n)]
lis[0].append([1])
for i in range(n-1):
    for j in lis[i]:
        for m in range(max(j)+1):
            lis[i+1].append(j+[m+1])
        #print(max(j))
#print(lis[n-1])
alpha=["a","b","c","d","e","f","g","h","i","j"]
for u in lis[n-1]:
    ans=""
    for j in u:
        ans+=alpha[j-1]
    print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000000)
def dfs(s,n,m,subs):
  if len(subs)==n:
    print(subs)
    return
  
  k = len(set(list(subs)))+1

  for i in range(k):
    t = "".join((subs,s[i]))
    dfs(s,n,k,t)

s = "abcdefghij"

n = int(input())
s = list(s[:n])
dfs(s,n,1,"a")

Submission status: Accepted

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

n = int(input())

a_ord = ord('a')

s = ["a"]

ans = []

def dfs(s):
    max_ord = a_ord
    for i in s:
        max_ord = max(max_ord, ord(i))
    for i in range(a_ord, max_ord + 2):
        t = s[:]
        t.append(chr(i))
        if len(t) == n:
            ans.append("".join(t))
        else:
            dfs(t)
if n == 1:
    print('a')
else:
    dfs(s)
    ans.sort()
    for w in ans:
        print(w)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

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

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())

# ls = ["a","b","c"]
# ans = list(combinations_with_replacement(ls,3))
# print(ans)

q = deque()
s = "a"
q.append(s)

while q:
    t = q.popleft()
    if len(t)==n:
        print(t)
    else:
        c = max(t)
        for j in range(97,ord(c)+2):
            nt = copy(t)
            nc = chr(j)
            nt += nc
            q.append(nt)

Submission status: Accepted

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

def dfs(str):
    if len(str) == N:
        print(*str, sep="")
        return

    M = max(str)

    for i in range(ord(M) - ord("a") + 2):
        char = alpha[i]
        str.append(char)
        dfs(str)
        str.pop()

alpha = 'abcdefghijklmnopqrstuvwxyz'
s = deque(["a"])
dfs(s)

Submission status: Accepted

Solution code:
n = int(input())

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

lst = ['a']
for i in range(n-1):
    new_lst = []
    for string in lst:
        num = ord(sorted(string)[-1])
        for j in range(ord('a'), num+2):
            new_lst.append(string+chr(j))
    lst = new_lst

for string in lst:
    print(string)

Submission status: Accepted

Solution code:
N=int(input())
alp=["a","b","c","d","e","f","g","h","i","j"]
alp=alp[:N]
ans=[]
def dfs(now):
    
    if len(now)==N:
        ans.append(now)
        return
    for i,s in enumerate(alp):
        if len(set(now))>=i:
            next_s=now+s
            dfs(next_s)
dfs("a")
ans=sorted(ans)
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

def dfs(now):
    if len(now)==N:
        print(''.join(now))
        return
    
    M = max(now)
    
    for i in range(ord(M)-ord('a')+2):
        now.append(alpha[i])
        dfs(now)
        now.pop()

N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
dfs(deque(['a']))

Submission status: Accepted

Solution code:
def saiki(n,A):

    if n == N:
        A.sort()
        for i in A:
            print(i)
        return

    alpha = list("abcdefghijklmnopqr")

    tmp = []

    for i in A:
        a = alpha.index(sorted(list(i))[-1])
        for j in range(a+2):
            tmp.append(i+alpha[j])
    
    saiki(n+1,tmp)

N = int(input())

saiki(1,["a"])

Submission status: Accepted

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


def get_range(s):
    start = ord("a")
    end = ord(max(s))
    return [chr(c) for c in range(start, end + 2)]


def pana(s):
    if len(s) == N:
        ans.append(s)
        return
    for t in get_range(s):
        pana(s + t)
    return


pana("a")
ans.sort()
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
t="abcdefghijklmnopqrstuvwxyz"
n=int(input())
ans=[]
def dfs(s):
  global ans
  if len(s)==n:
    ans.append(s)
    return 
  for i in range(len(set(s))+1):dfs(s+t[i])
  return
dfs("")
ans.sort()
for i in ans:print(i)

Submission status: Accepted

Solution code:
from collections import deque
 
n = int(input())
 
def dfs(n):
  stack = deque()
  stack.append("a")
  while stack:
    q = stack.popleft()
    if len(q) == n:
      ans.append(q) 
    if len(q) < n:
      for i in range(ord("a"), ord(max(q)) + 2):
        stack.append(q + chr(i))
    #print(stack)
    
ans = []
dfs(n)
 
print("\n".join(ans))

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())
que = deque(['a'])

while len(que) > 0:
    s = que.popleft()
    if len(s) == N:
        print(s)
    else:
        for i in range(ord(sorted(s)[-1]) - 95):
            que.append(s + chr(97 + i))

Submission status: Accepted

Solution code:
N = int(input())

def standard_string(N, st):
    if len(st) == N:
        print(st)
    elif st == "":
        standard_string(N, "a")
    else:
        for i in range(97, ord(max(st))+ 2):
            st += chr(i)
            standard_string(N, st)
            st = st[:-1]
standard_string(N, "")

Submission status: Accepted

Solution code:
a = int(input())
S = 'abcdefghij'

def dfs(s,c):
    if c == a:
        ans.append(s)
        return 
    for i in S[:c+1]:
        if i in s:dfs(s+i,c+1)
        else:
            dfs(s+i,c+1)
            return 
ans = []

dfs("",0)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
a = int(input())
S = 'abcdefghij'

def dfs(s,c):
    if c == a:
        ans.append(s)
        return 
    for i in S[:c+1]:
        if i in s:dfs(s+i,c+1)
        else:
            dfs(s+i,c+1)
            return 
ans = []

dfs("",0)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
a = ["a","b","c","d","e","f","g","h","i","j"]
def dfs(s):
  m = len(s)
  if m == n:
    ans = ""
    for i in range(n):
      ans += a[int(s[i])]
    print(ans)
  else:
    for i in range(int(max(list(s)))+2):
      dfs(s+str(i))

dfs("0")

Submission status: Accepted

Solution code:

n = int(input())

stack = [["",0] for i in range(10**6*4)]
stack[0] = ["a",1]
pos = 0    
while(pos>=0):
    if(len(stack[pos][0]) == n):
        print(stack[pos][0])
        pos-=1
    else:
        
        nowstr = stack[pos][0]
        nowlen = stack[pos][1]
        #print(nowlen)
        pos-=1
        for ii in range(nowlen+1):
            i = nowlen-ii
            pos+=1
            stack[pos][0] = nowstr+chr(ord('a')+i)
            if(i == nowlen):
                stack[pos][1] = nowlen+1
            else:
                stack[pos][1] = nowlen

Submission status: Accepted

Solution code:

N = int(input())

def dfs(x):
    if len(x) == N:
        s = "".join(chr(v + ord("a")) for v in x)
        print(s)
        return

    val = max(x)
    for i in range(val + 2):
        x.append(i)
        dfs(x)
        x.pop()

dfs([0])

Submission status: Accepted

Solution code:
from string import ascii_lowercase

n = int(input())

def f(l):
    if len(l)==n:
        print("".join([ascii_lowercase[i] for i in l]))
        return
    
    for i in range(max(l)+2):
        f(l+[i])

f([0])

Submission status: Accepted

Solution code:
n = map(int, raw_input().split(' '))[0]

def dfs(i, mx, n, cur = []):
	if i==n:
		print ''.join(cur)
		return
	for v in range(0, mx + 1): dfs(i + 1, mx + (1 if v == mx else 0), n , cur + [chr(v+ ord('a'))])

dfs(0,0,n)

Submission status: Accepted

Solution code:

n = map(int, raw_input().split(' '))[0]


def dfs(i, mx, n, res, cur = []):
	if i==n:
		res.append(''.join(cur[::]))
		return


	for v in range(0, mx + 1):
		dfs(i + 1, mx + (1 if v == mx else 0), n , res, cur + [chr(v+ ord('a'))])

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/panasonic2020/submissions/12881278
# D - String Equivalence
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    def dfs(S, available):
        if len(S) == n:
            print("".join(S))
            return

        for i in range(available + 1):
            S.append(chr(97 + i))
            dfs(S, max(available, i + 1))
            S.pop()

    dfs([], 0)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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

        for i in range(num + 1):
            t = s + chr(97 + i)
            dfs(t, max(num, i + 1))

    dfs("", 0)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    dfs("", 0, N)

def dfs(cur, n_type, N):
    if len(cur) == N:
        print(cur)
        return
    
    for offset in range(n_type+1):
        next_chr = chr(ord('a') + offset)
        next_n_type = n_type + 1 if offset==n_type else n_type
        dfs(cur+next_chr, next_n_type, N)
    
    return
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())

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

ans = []


def dfs(d, i_max, S):
    if d == N-1:
        ans.append(S)
        return
    for i in range(i_max+2):
        dfs(d+1, max(i_max, i), S + alphabets[i])


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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
strlist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def dfs(n, before):
    lensetbefore = len(set(before))
    if n == 1:
        print(before)
    if n > 1:
        for s in strlist[:lensetbefore+1]:
            dfs(n-1, before+s)

def main():
    N = int(input())
    dfs(N, 'a')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# Problem D - String Equivalence

from collections import deque

# input
N = int(input())

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

def dfs(a_list, a_len):
    if a_len==N:
        print("".join(a_list))
        return
    else:
        biggest = 97
        count = len(set(a_list)) # N<=10だからさほど時間はかからない
        for c in range(biggest, biggest + count + 1):
            ch = chr(c)
            a_list.append(ch)
            dfs(a_list, a_len+1)
            a_list.pop()

# initialization
a_nums = deque([])

# dfs search
dfs(a_nums, 0)

Submission status: Accepted

Solution code:
# 使えるのは、'a' ~ 今まで使われた次の文字
n = int(input())
def dfs(cnt,s):
    if cnt == n:
        print(s)
        return
    biggest = 'a'
    c = 0
    while c < len(s):# 最後はどこまで？
        if s[c] == biggest:
            biggest = chr(ord(biggest)+1)
            c += 1
        else:
            c += 1
    #print(c)
    for i in range(0,ord(biggest) - ord('a')+1):
        sc = chr(ord('a') + i)
        #print(sc)
        s += sc
        dfs(cnt + 1, s)
        s = s[:-1]

dfs(0,"")

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)

Submission status: Accepted

Solution code:
n=int(input())

from collections import deque

option=deque()
option.append("a")
ans=[]

while option:
    s=option.pop()
    if len(s)==n:
        ans.append(s)
        continue
    maxi=0
    for i in s:
        maxi=max(maxi,ord(i))
        
    for i in range(97,maxi+2):
        new_s=s+chr(i)
        if new_s not in option and len(new_s)<=n:
            option.append(new_s)

ans=sorted(ans)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
def dfs(s):
  if len(s) == n:
    print(s)
  else:
    max_list = []
    for _ in s:
      max_list.append(ord(_))
    for i in range(ord("a"),max(max_list) + 2):
      s = s + chr(i)
      dfs(s)
      s = s[:len(s) - 1]
      
dfs("a")

Submission status: Accepted

Solution code:
from collections import deque

n = int(input())

def dfs(n):
  stack = deque()
  stack.append("a")
  while stack:
    q = stack.popleft()
    if len(q) == n:
      ans.append(q) 
    if len(q) < n:
      for i in range(ord("a"), ord(max(q)) + 2):
        stack.append(q + chr(i))
    
ans = []
dfs(n)

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

Submission status: Accepted

Solution code:
n=int(input())
from collections import deque
def dfs():
  todo=deque([[1]])
  ret=[]
  while len(todo)>0:
    t=todo.popleft()
    if len(t)==n:
      ret.append(t)
    else:
      l=max(t)+1
      for i in range(l):
        tc=t.copy()
        tc.append(i+1)
        todo.append(tc)
  return ret
a=dfs()
n2a = lambda c: chr(c+64).lower()
for ai in a:
  #print(ai)
  print(''.join(map(n2a,ai)))

Submission status: Accepted

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


def read():
    N = int(input().strip())
    return N,

def standalize(N):

    q = list()
    alphabets = "abcdefghijklmnopqrstuvwxyz"
    
    s = []

    def dfs(i):
        """i種類の文字から選んで、sの末尾に追加する
        """
        if len(s) == N:
            q.append(''.join(s))
        else:
            for j, a in enumerate(alphabets[:i-1]):
                s.append(a)
                dfs(i)
                s.pop()
            a = alphabets[i-1]
            s.append(a)
            dfs(i+1)
            s.pop()
    
    dfs(1)
    return q

def solve(N):
    for s in standalize(N):
        print(s)

if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % outputs)

Submission status: Accepted

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


def read():
    N = int(input().strip())
    return N,

def standalize(N):

    q = list()
    alphabets = "abcdefghijklmnopqrstuvwxyz"
    
    def dfs(i, s=[]):
        """i種類の文字から選んで、sの末尾に追加する
        """
        if len(s) == N:
            q.append(''.join(s))
        else:
            for j, a in enumerate(alphabets[:i-1]):
                dfs(i, s + [a])
            a = alphabets[i-1]
            dfs(i+1, s + [a])
    
    dfs(2, s=['a'])
    return q

def solve(N):
    for s in standalize(N):
        print(s)

if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % outputs)

Submission status: Accepted

Solution code:
n=int(input())
l=[['a1']]+[[] for _ in range(9)]
for i in range(9):
  for b in l[i]:
    t=b[-1]
    for p in range(int(t)):
      l[i+1].append(b[:-1]+chr(97+p)+t)
    l[i+1].append(b[:-1]+chr(97+int(t))+str(int(t)+1))
for i in l[n-1]:
  if len(i)==12:
    print(i[:-2])
  else:
    print(i[:-1])

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

N = int(input())
ans = []
def dfs(i,standard):
    if i == N:
        ans.append(standard)
        return
    before_M = max(ord(s) for s in standard)
    for j in range(97,before_M + 2):
        dfs(i + 1,standard + chr(j))
dfs(1,'a')
print('\n'.join(ans))

Submission status: Accepted

Solution code:
def main():
    from string import ascii_lowercase

    N = int(input())

    ans = []

    def dfs(s='a', ma='a'):
        if len(s) == N:
            ans.append(s)
            return

        for c in ascii_lowercase:
            dfs(s + c, max(c, ma))
            if c > ma: break

    dfs()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def dfs(s):
    if len(s) == n:
        print(s)
    else:
        for x in map(chr, range(97, ord(max(s))+2)):
            dfs(s+x)


dfs("a")

Submission status: Accepted

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


def dfs(s):
    if len(s) == n:
        ls.append(s)
        return 0
    else:
        for x in map(chr, range(97, ord(max(s))+2)):
            dfs(s+x)


dfs("a")
ls.sort()
for x in ls:
    print(x)

Submission status: Accepted

Solution code:
n = int(input())

d = 'abcdefghijklm'


def conv(s):
    s = list(map(lambda x: d[x], s))
    return ''.join(s)


def dfs(s, k):
    if len(s) == n:
        print(s)
    else:
        for i in range(k):
            dfs(s+d[i], k)
        dfs(s+d[k], k+1)


dfs('a', 1)

Submission status: Accepted

Solution code:
n = int(input())

d = 'abcdefghijklm'


def conv(s):
    s = list(map(lambda x: d[x], s))
    return ''.join(s)


def dfs(s):
    if len(s) == n:
        print(conv(s))
    else:
        mx = max(s)+1
        for i in range(mx+1):
            dfs(s+[i])


dfs([0])

Submission status: Accepted

Solution code:
N=int(input())

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

from collections import deque
from collections import Counter
abc="abcdefghijklmnopqrstuvwxyz"
ans=["a"]

for i in range(1,N):
    d=deque(ans)
    ans=[]
    while d:
        temp=d.popleft()
        temp2=list(temp)
        cnt=Counter(temp2)
        L=len(cnt)
        for j in range(L+1):
            ans.append(temp+abc[j])

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
n = int(input())
a = ["a","b","c","d","e","f","g","h","i","j"]
def dfs(s, max_x, LEN):
  if LEN == n:
    print(s)
  else:
    for c in a[:a.index(max_x)+2]:
      dfs(s+c, max(max_x,c), LEN+1)
dfs("a", "a", 1)

Submission status: Accepted

Solution code:
s="abcdefghij"
n=int(input())
ans=[["a",1]]
c=1
while(c<n):
    an=[]
    for i in ans:
        lim=min(i[1]+1,10)
        for j in range(lim):
            if (j==i[1]) and (j!=10):
                an.append([i[0]+s[j],i[1]+1])
            else:
                an.append([i[0]+s[j],i[1]])
    ans=an
    c+=1
for i in ans:
    print(i[0])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
if __name__ == '__main__':
    def solve(s, a):
        if len(s) == n:
            print(s)
        else:
            for c in range(ord("a"), a + 1):
                if c == a:
                    solve(s + chr(c), a + 1)
                else:
                    solve(s + chr(c), a)
    n = int(input())
    solve("", ord("a"))

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
def p(S):
    str = ""
    for s in S:
        str += chr(ord("a")+int(s))
    print(str)

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

def up(i):
    if i == 0:
        return True
    S[i] += 1
    if S[i] == max(S[:i]) + 2:
        S[i] = 0
        return up(i-1)
    return False

while True:
    p(S)
    if up(N-1):
        break

Submission status: Accepted

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

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	ansL = [[] for i in range(10)]
	ansL[0].append(["a", 1])
	for i in range(N - 1):
		n = len(ansL[i])
		for j in range(n):
			for k in range(ansL[i][j][1]):
				ansL[i + 1].append([ansL[i][j][0] + chr(97 + k), ansL[i][j][1]])
			ansL[i + 1].append([ansL[i][j][0] + chr(97 + ansL[i][j][1]), ansL[i][j][1] + 1])

	n = len(ansL[N - 1])
	for i in range(n):
		print(ansL[N - 1][i][0])
	



if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N=int(input())
A=["a"]
if N==1:
    print("a")
    exit()
else:
    S="abcdefghijklmn"
    slist=list(S) 
    for i in range(2,N+1):
        temp=[[] for _ in range(N)]
        for j in range(i-1):
            for w in A[j]:
                for u in slist[:j+1]:
                    temp[j].append(w+u)
                temp[j+1].append(w+slist[j+1])
        A=temp
    B=[]    
    for j in range(N):
        for t in A[j]:
            B.append(t)
    B.sort()
    for i in range(len(B)):
        print(B[i])

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    N = int(input())
    if N==1:
        print('a')
    else:
        q = ['a']
        for _ in range(N - 1):
            nq = []
            for j in q:
                for k in range(ord('a'), ord(max(j)) + 2):
                    nq.append(j + chr(k))
            q=nq

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

resolve()

Submission status: Accepted

Solution code:
N = int(input())
alpha = [chr(ord("a") + i) for i in range(26)]


def dfs(n, s):
    if len(s) == n:
        print(s)
        return
    cnt = len(set(s))
    cnt += 1

    for a in alpha[:cnt]:
        ns = s + a
        dfs(n, ns)


dfs(N, "")

Submission status: Accepted

Solution code:
N = int(input())

from collections import deque

q = deque()

q.append('a')

while True:
    str = q.popleft()
    temp_lst = list(str) + [chr(ord('a') + len(set(str)))]
    temp_lst = list(set(temp_lst))
    temp_lst.sort()
    for c in temp_lst:
        q.append(str + c)
    if len(str) < N:
        continue
    elif len(str) == N:
        print(str)
    else:
        break

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


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

    que = queue.Queue()
    que.put(('a', ord('a')))

    while not que.empty():
        res, m = que.get()
        if len(res) < N:
            for i in range(ord('a'), min(ord('z'), m + 1) + 1):
                que.put((res + chr(i), max(m, i)))
        elif len(res) == N:
            print(res)
        else:
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def num_to_str(n):
    return chr(97 + n)

def str_to_num(s):
    return ord(s) - 97

def dfs(s,m,n,N,ans):
    if n == N:
        ans.append(s)
        return
    for i in range(m+2):
        dfs(s+num_to_str(i),max(m,i),n+1,N,ans)

def main():
    N = int(input())
    ans = []
    dfs('a',0,1,N,ans)
    ans.sort()
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def ST(A,k):
    #標準形の文字列を与えたときに
    #長さが1大きい標準形の文字列の集合を出力
    OP = []
    for a in A:
        max_cord = 0
        for i in range(len(a)):
            max_cord = max(ord(a[i]),max_cord)
        for i in range(97,max_cord+2):
            OP.append(a+chr(i))
    return OP

N = int(input())

n,A = 1,["a"]
while n < N:
    A = ST(A,n)
    n += 1

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

Submission status: Accepted

Solution code:
n=int(input())
s='abcdefghij'
def f(string):
  r=[]
  for i in range(len(string)):
    m=0
    for j in string[i]:
      if ord(j)-97 > m:
        m=ord(j)-97
    for j in range(m+2):
      r.append(string[i] + s[j])
  return r
string=['a']
for i in range(n-1):
  string=f(string)
for a in string:
  print(a)