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:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
L = [[[0]]]
for i in range(1, n):
    new_L = []
    for each_type in L:
        new_L += [each_type + [[i]]]
        for j in range(len(each_type)):
            new_type = deepcopy(each_type)
            new_type[j] += [i]
            new_L += [new_type]
    L = new_L


ans = []
for t in L:
    a = [''] * n
    cnt = 97
    for k in t:
        for l in k:
            a[l] = chr(cnt)
        cnt += 1
    ans += [''.join(a)]


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

Submission status: Accepted

Solution code:
N = int(raw_input())

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

prev = ["a"]

for i in range(1, N):
    temp = []
    for item in prev:
        item_list = []
        for j in range(len(item)):
            item_list.append(item[j])
        num_char = len(set(item_list))
        for j in range(num_char+1):
            temp.append(item+char_list[j])

    prev = temp


print ' '.join(map(str, prev))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

G = []

def dfs(n, string, next_usable):
    if n == 0:
        G.append(string)
        return
    for char in next_usable:
        new_string = string + char
        if char == next_usable[-1]:
            added_char = chr(ord(char) + 1)
            next_usable += added_char
        dfs(n-1, new_string, next_usable)

def main():
    N = I()
    string = 'a'
    dfs(N, '', 'a')
    for string in G:
        print(string)


main()

Submission status: Accepted

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

	lst = [['a',1]]

	for i in range(2,N+1):
		anslst = []
		for j in range(len(lst)):
			s = lst[j][0]
			n = lst[j][1]
			for l in range(n+1):
				ss = s
				if l == n:
					n += 1
				ss = ss + alp[l]
				anslst.append([ss,n])

		lst = anslst

	for i in range(len(lst)):
		print(lst[i][0])

Submission status: Accepted

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

from collections import deque

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

def gcd(n,m):
    while m:
        n,m = m, n%m
    return n

def lcm(n,m):
    return n*m//gcd(n,m)

def main():
    N = int(input())
    # N,M = linput()
    # vA = linput()
    # S = input()
    # mX = [linput() for _ in [0,]*N]

    # vR = []
    # vR_app = vR.append

    pp = "a"

    vQ = deque([])
    vQ_app = vQ.append

    vQ_app(pp)
    while vQ:
        pp = vQ.popleft()
        if len(pp)>=N: break
        ma = max(ord(s) for s in pp)
        for i in range(ord('a'), ma+2):
            vQ_app(pp + chr(i))

    # res = 0
    # res = -(-N//M)
    vQ.appendleft("a" * N)

    res = vQ
    print(*sorted(res), sep="\n")

main()

Submission status: Accepted

Solution code:
from itertools import combinations_with_replacement
from itertools import combinations
N = int(input())

alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
cand = {"a"}
for i in range(N-1):
    nex_cand = set()
    for c in cand:
        for j in range(i+2):
            a = alpha[j]
            if all(v in c for v in alpha[:j]):
                nex_cand.add(c+a)
    cand = nex_cand

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

Submission status: Accepted

Solution code:
ans =["a"]
n =int(input())
for i in range(1,n):
  plus=[]
  for s in ans:
    nn=0
    for h in range(len(s)):
      nn=max(nn,ord(s[h]))
    num=nn-ord("a")+1
    for j in range(num+1):
      plus.append(s+chr(ord("a")+j))
  ans = plus
ans.sort()
for ss in ans:print(ss)

Submission status: Accepted

Solution code:
n = int(input())

a = ord('a')
reprs = [('a', a)]
for i in range(1, n):
    tmprep = []
    for r, l in reprs:
        for j in range(l-a+2):
            tmprep.append((r+chr(a+j), max(l, a+j)))
    reprs = tmprep



for r, l in reprs:
    print(r)

Submission status: Accepted

Solution code:
N = int(input())

ans = ["a"]
for n in range(N - 1):
    nex = []
    for v in ans:
        for i in range(ord("a"), max(ord(s) for s in v) + 2):
            nex.append(v + chr(i))
    ans = nex[:]
        
print(*sorted(ans), sep="\n")

Submission status: Accepted

Solution code:
N=int(input())
alpha=["a","b","c","d","e","f","g","h","i","j","k","l"]
now=["a"]
next_list=[]
for _ in range(N-1):
    for check in now:
        count = len(set(check))

        # くっつくける
        for add in range(count+1):
            next_list.append(check + alpha[add])

    now = next_list[:]
    next_list=[]

for a in now:
    print(a)

Submission status: Accepted

Solution code:
n = int(input())
cands = set([])

def dfs(s,l,k):#str, len,kinds
  if l == n:
    cands.add(s)
  else:
    for i in range(k):
      dfs(s+chr(97+i), l+1,k)
    dfs(s+chr(97+k),l+1,k+1)

dfs('',0,0)
ans = list(cands)
ans.sort()
for a in ans:
  print(a)

Submission status: Accepted

Solution code:
N = int(input())
lst = [{'s': 'a', 'c': 1}]
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
for n in range(N - 1):
    new_lst = []
    for x in lst:
        for c in range(x['c'] + 1):
            new_s = x['s'] + alphabet[c]
            if c == x['c']:
                new_c = c + 1
            else:
                new_c = x['c']
            new_lst.append({'s': new_s, 'c': new_c})
    lst = new_lst
for x in lst:
    print(x['s'])

Submission status: Accepted

Solution code:
N=int(input())
global key
key="abcdefghij"
def normal(N):
    if N==1:
        return ["a"]
    else:
        new=[]
        lis=normal(N-1)
        for s in lis:
            i=0
            while key[i] in s:
                new.append(s+key[i])
                i+=1
            new.append(s+key[i])
    return new
lis=normal(N)
for s in lis:
    print(s)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

alpha_list = ['a','b','c','d','e','f','g','h','i','j']
string_list = []
count = 0

def extend(string,count,n):
    if len(string) >= n:
        string_list.append(string)
        return True
    else:
        for i in range(count+1):
            sc = string
            sc += alpha_list[i]
            if i == count:
                count += 1
            extend(sc,count,n)
    
extend('',count,n)

string_list.sort()
for s in string_list:
    print(s)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

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

def mm(sl, i, m):
	if len(sl)==i:
		print(''.join(sl))
		return
	for j in range(m+1):
		sl[i]=ll[j]
		mm(sl, i+1, m)
	sl[i]=ll[m+1]
	mm(sl, i+1, m+1)
	

def main():
	n = int(input())
	sl=['a']*n
	mm(sl, 1, 0)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
a = [chr(i) for i in range(97, 97+26)]
ret = []
def backtrack(N,s,i):
    #print(N,s,i)
    if N == 1:
        ret.extend([s+c for c in a[:i+1]])
        return
    for j in range(i+1):#max i+1
        #print("a:",j)
        if j == i:
            backtrack(N-1,s+a[j],i+1)
        else:
            backtrack(N-1,s+a[j],i)
backtrack(N,"",0)
for s in ret:
  print(s)

Submission status: Accepted

Solution code:
chars = 'abcdefghij'

n = int(input())

def f(gen):
    for x,s in gen:
        for i in range(x+1):
            yield (max(x,i+1), s + chars[i])

gen = [(0, "")]
for _ in range(n):
    gen = f(gen)

for __, s in gen:
    print(s)

Submission status: Accepted

Solution code:
import copy
from functools import reduce
alphabet = " abcdefghij"
def dfs(n, arr, cur):
  if cur == n:
    return print(reduce(lambda x, y:x+y, map(lambda x:alphabet[x], arr)))
  else:
    i = 1
    while i <= max(arr)+1:
      tmp = copy.copy(arr)
      tmp[cur] = i
      dfs(n, tmp, cur+1)
      i += 1

N = int(input())
dfs(N, [0]*N, 0)

Submission status: Accepted

Solution code:
chr='abcdefghijklmnopqrstuvwxyz'
a=[0]*int(input())
while 1:
  print(''.join(chr[i]for i in a))
  if a==list(range(len(a))):break
  a[-1]+=1
  i=-1
  while a[i]-max(a[:i]+[0])>1:
    a[i]=0
    i-=1
    a[i]+=1

Submission status: Accepted

Solution code:
n = int(input())

def printStrAsList(strAsList):
  result = ''
  for chrItem in strAsList:
    result += chr(97 + chrItem)
  print(result)

def printList(strAsList):
  loopTimes = max(strAsList) + 1
  isLastChr = len(strAsList) == n-1
  for i in range(loopTimes + 1):
    if isLastChr:
      printStrAsList(strAsList + [i])
    else:
      printList(strAsList + [i])

if n == 1:
  print('a')
else:
  printList([0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def print_rec(now_moji, tsugi, nokori):
    if nokori == 0:
        print(now_moji)
    else:
        for i in range(tsugi + 1):
            tsugi_moji = now_moji + chr(i + 97)
            if i == tsugi:
                print_rec(tsugi_moji, tsugi + 1, nokori - 1)
            else:
                print_rec(tsugi_moji, tsugi, nokori - 1)


n = int(input())
if n == 1:
    print("a")
else:
    print_rec("a", 1, n - 1)

Submission status: Accepted

Solution code:
alf = 'abcdefghijklmnopqrstuvwxyz'
d = {c:i+1 for i,c in enumerate(alf)}
d['z']=25
def dfs(n):
    lst = []
    lst.append([['a'],0])
    while lst:
        a,mx = lst.pop()
        if len(a) == n:
            print(''.join(a))
            continue
        for i in range(min(mx+1,25)+1)[::-1]:
            lst.append([a + [alf[i]], max(i,mx)])

n= int(input())
dfs(n)

Submission status: Accepted

Solution code:
abc = 'abcdefghij'
answer = []
n = int(input())
for bits in range(2 ** (n - 1)):
    cur_height = 1
    heights = []
    isfree = []
    for _ in range(n - 1):
        if bits % 2 == 1:
            cur_height += 1
            heights.append(cur_height)
            isfree.append(False)
        else:
            heights.append(cur_height)
            isfree.append(True)
        bits //= 2
    results = [[0]]
    for i in range(n - 1):
        new_results = []
        for result in results:
            if isfree[i]:
                for j in range(heights[i]):
                    new_results.append(result + [j])
            else:
                new_results.append(result + [heights[i] - 1])
        results = new_results
    for result in results:
        abcresult = (abc[i] for i in result)
        answer.append(''.join(abcresult))
answer.sort()
for a in answer:
    print(a)

Submission status: Accepted

Solution code:
n = int(input())
s = "abcdefghij"
a = [[] for i in range(10)]
a[0] = [[0]]
def add_word(n):
    temp = a[n-1]
    for i in range(len(temp)):
        for j in range(len(set(temp[i])) + 1):
            a[n].append(temp[i] + [j])
for i in range(1,n):
    add_word(i)

for i in a[n-1]:
    ans = ""
    for j in i:
        ans += s[j]
    print(ans)

Submission status: Accepted

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

l = 1
cur_ret = [[0]]
while l < a:
    new_ret = []
    na = new_ret.append
    for i in cur_ret:
        k = max(i) + 2
        for j in range(k):
            na(i+[j])
    cur_ret = new_ret
    l+=1

def format(x):
    x = list(map(lambda x : chr(x+97),x))
    return "".join(x)

cur_ret = list(map(format,cur_ret))
cur_ret.sort()
for i in cur_ret:
    print(i)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(5000000)
N = int(input())
ans = []


def func(s):
    if len(s) == N:
        ans.append(s)
    else:
        for i in range(ord(max(s))-95):
            func(s+chr(97+i))

func('a')
for a in sorted(ans):
    print(a)

Submission status: Accepted

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

N = int(input())

if N == 1:
    print('a')
    exit()
if N == 2:
    print('aa')
    print('ab')
    exit()

ans = ['aaa', 'aab', 'aba', 'abb', 'abc']
alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
length = 3

while length < N:
    ans2 = []
    for value in ans:
        flag = False
        for letter in alph:
            if flag:
                break
            ans2.append(value + letter)
            if letter not in value:
                flag = True
    length += 1
    ans = copy.deepcopy(sorted(ans2))

for value in ans:
    print(value)

Submission status: Accepted

Solution code:
n = int(input())

combi = [[0]]
for i in range(1, n):
    new = []
    for item in combi:
        for t in range(0, max(item) + 2):
            new.append(item + [t])
    combi = new

dicter = {0:"a", 1:"b", 2:"c", 3:"d", 4:"e", 5:"f", 6:"g", 7:"h", 8:"i", 9:"j"}

for i in combi:
    print("".join([dicter[j] for j in i]))

Submission status: Accepted

Solution code:
n=int(input())
a='abcdefghij'
ans=[['']]
for i in range(n):
    s=ans[-1][::]
    l=len(s)
    t=[]
    for j in range(i+1):
        for k in range(l):
            if j>0:
                if a[j-1] not in s[k]:
                    continue
            t.append(s[k]+a[j])
    ans.append(t)
t=sorted(ans[-1])
for s in t:
    print(s)

Submission status: Accepted

Solution code:
n = int(input())

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

def moji(mes, layer, lim):
    if(layer==n):
        print(mes)
        return
    for i in range(lim+1):
        moji(mes+l[i], layer+1, max(lim,i+1))
    return

moji("", 0, 0)

Submission status: Accepted

Solution code:
n = int(input())
alp = [chr(i) for i in range(97, 97+26)]
 
def update(a, m):
    a_new = []
    m_new = []
    for val_a, val_m in zip(a,m):
        for i in range(val_m + 2):
            a_new += [val_a + alp[i]]
            m_new += [max(val_m, i)]
    return a_new, m_new
 
a = ['a']
m = [0]
 
for i in range(n-1):
  a, m = update(a,m)
 
for v in a:
  print(v)

Submission status: Accepted

Solution code:
A=[]
B=["a"]
N=int(input())
if N>1:
 for i in range(N-1):
  A=B
  B=[]
  C=len(A)
  for j in range(C):
   F=len(A[j])
   D=0
   for f in range(F):
    D=max(ord(A[j][f])-95,D)
   for k in range(D):
    E=A[j]+chr(97+k)
    B.append(E)
for i in range(len(B)):
 print(B[i])

Submission status: Accepted

Solution code:
import copy
N = int(input())

moji = ["a","b","c","d","e","f","g","h","i","j"]
start = ["a"]
ll = [[] for i in range(11)] #0個目は使わない

def syurui(l):
    return len(set(l))

ll[1].append(["a"])

for i in range(2,N+1):
    for j in range(len(ll[i-1])):
        for k in range(syurui(ll[i-1][j])+1):
            tmp = copy.copy(ll[i-1][j])
            ll[i-1][j].append(moji[k])
            ll[i].append(ll[i-1][j])
            ll[i-1][j] = tmp

for i in range(len(ll[N])):
    kotae ="".join(ll[N][i])
    print(kotae)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
ans = []
def bfs(s,tmp):
    if len(s)==n:
        ans.append(s)
        return
    for i in range(ord('a'),ord('a')+tmp+1):
        if i==ord('a')+tmp:
            bfs(s+chr(i),tmp+1)
        else:
            bfs(s+chr(i),tmp)
bfs('a',1)
print(*ans,sep='\n')

Submission status: Accepted

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


def plse1(s, i):
    if i == 0:
        return s
    m = max(s[:i])
    if s[i] > m:
        s = plse1(s, i - 1)
        s[i] = 0
    else:
        s[i] += 1
    return s


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

s = [0] * n
while True:
    string = ''
    for i in range(n):
        string += ss[s[i]]
    print(string)
    s = plse1(s, n - 1)
    if s == [0] * n:
        break

Submission status: Accepted

Solution code:
import copy

n = int(input())
lst = ['a']
alphabet = 'abcdefghij'

for i in range(n - 1):
  new_list = []
  for word in lst:
    ch = ''
    for k in alphabet:
      ch = k
      if k in word:
        new_list.append(word + k)
      else:
        break
    new_list.append(word + k)
  lst = copy.copy(new_list)

for word in lst:
  print(word)

Submission status: Accepted

Solution code:
n=int(input())
tmp=[['1',set({1})]]
for i in range(1,n):
  tmp2=[]
  for s,c in tmp:
    for j in range(len(c)+1):
      tmp2.append([s+str((j+1)%10),c|set({j+1})])
  tmp=tmp2
ans=[]
dic={'1':'a','2':'b','3':'c','4':'d','5':'e','6':'f','7':'g','8':'h','9':'i','0':'j'}
for s,c in tmp:
  ts=''
  for tc in s:
    ts+=dic[tc]
  ans.append(ts)
ans=sorted(ans)
for s in ans:
  print(s)

Submission status: Accepted

Solution code:

N = int(input())
S = "abcdefghij"
ans = [""]
for k in range(N):
    n = []
    for e in ans:
        for f in S[:len(set(str(x) for x in e))+1]:
            n.append(e+f)
    ans = n
ans = sorted(ans)
for e in ans:
    print(e)

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())
alpha = ['a','b','c','d','e','f','g','h','i','j']
ans = []

stack = deque(['a'])

while stack:
    if len(stack[-1]) == N:
        break
    s = stack.pop()
    s_list = sorted(list(s))
    index = alpha.index(s_list[-1])
    for i in range(index+2):
        stack.appendleft(s+alpha[i])
    

stack.reverse()
for j in range(len(stack)):
    print(stack[j])

Submission status: Accepted

Solution code:
import sys
# # input = sys.stdin.buffer.readline
# def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

from string import ascii_lowercase
# print(ascii_lowercase)
d = dict(zip(ascii_lowercase, range(26)))
# print(d['a'])
N = int(input())

def nexts(s, n, maxnum):
    if n == N:
        print(s)
        return
    for i in range(maxnum+1):
        nexts(s + ascii_lowercase[i], n+1, max(maxnum,i+1))

nexts('a', 1, 1)

Submission status: Accepted

Solution code:
n = int(input())

t = []
c = 'abcdefghij'

def f(s, d, m):
  if d == 0:
    t.append(s)
    return
  
  for k in range(m+1):
    f(s*10 + k, d-1, m+1 if k==m else m)
    
f(0, n, 0)

for i in t:
  x = []
  for j in range(n):
    x.append(c[i // 10**(n-j-1) % 10])
  print(''.join(x))

Submission status: Accepted

Solution code:
N = int(input())
al = [chr(ord('a') + i) for i in range(26)]
li = ['a']
for i in range(1,N):
    k = []
    li = set(li)
    for s in li:
        count = len(set(list(s)))
        for m in range(count+1):
            nk = s+al[m]
            k.append(nk)
    li = k
n = len(li)
li.sort()
for i in range(n):
    print(li[i])

Submission status: Accepted

Solution code:
import sys

#a=0 b=1 ...
def chr2idx(c):
    return ord(c)-ord("a")
def idx2chr(x):
    return chr(ord("a")+x)

N=int(input())
ar=[["a","a"]]
if N==1:
    print("a")
    sys.exit()

for i in range(N-1):
    new_ar=[]
    L=len(ar)
    for j in range(L):
        lastchr=chr2idx(ar[j][1])
        for k in range(lastchr+1):
            new_ar+=[[ar[j][0]+idx2chr(k),idx2chr(lastchr)]]
        new_ar+=[[ar[j][0]+idx2chr(lastchr+1),idx2chr(lastchr+1)]]

    ar=new_ar[:]

L=len(ar)
for i in range(L):
    print(ar[i][0])

Submission status: Accepted

Solution code:
N = int(input())

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

res = [['a']]

def calc(prev_list):
    new_list = []
    for i in prev_list:
        for j in range(len(set(i))+1):
            new_list.append(i+[zls[j]])
    return new_list

for i in range(N-1):
    res = calc(res)

for i in res:
    print(''.join(i))

Submission status: Accepted

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

    ans = []

    def fanc(i, s):
        if len(s) == n:
            ans.append(s)
        else:
            for x in range(i + 2):
                # print(x,i,s)
                fanc(max([x, i]), s + chr(97 + x))
                # fanc(x + 1, s + chr(97 + x))

    fanc(0, "a")
    ans.sort()
    for i in ans:
        print(i)

    # print(len(ans))
main()

Submission status: Accepted

Solution code:
N = int(input())

res = []

def f(n, m):
    if n == 0:
        print("".join(res))
        return
    for i in range(m):
        res.append(chr(97+i))
        f(n-1, m)
        res.pop()
    else:
        res.append(chr(97+m))
        f(n-1, m+1)
        res.pop()

f(N, 0)

Submission status: Accepted

Solution code:
n = int(input())
lets = [chr(i) for i in range(ord("a"), ord("a") + n)]
d = {e: i for i, e in enumerate(lets)}

s = ["a"]
for i in range(1, n):
    nxt = []
    for e in s:
        mx = 0
        for l in e:
            mx = max(mx, d[l])
        for j in range(mx + 2):
            nxt.append(e + lets[j])
    s = nxt

print(*s, sep="\n")

Submission status: Accepted

Solution code:
N = int(input())

d = {1:["a"], 2:["aa", "ab"]}
for i in range(3, N+1):
    d[i] = []
    for base in d[i-1]:
        max_c = ord(max(base)) + 1
        for j in range(ord("a"), max_c+1):
            cand = base
            cand += chr(j)
            d[i].append(cand)

for i in d[N]:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
alp='abcdefghij'
ansls=[list() for _ in range(n)]
ansls[0]=[('a',1)]
for i in range(1,n):
    for s,c in ansls[i-1]:
        for j in range(c+1):
            aps = s + alp[j]
            if j==c:
                c+=1
            ansls[i].append((aps,c))

ansls[-1].sort(key=lambda x:x[0])
for s,c in ansls[-1]:
    print(s)

Submission status: Accepted

Solution code:
N = int(input())
alph = list("abcdefghij")
ans = []

if N == 1: print("a")
def roop(root,use):
    if len(root) != N:
        for i in range(use+1):
            ans = root + alph[i]
            roop(ans,max(i+1,use))
            if len(ans) == N:
                print(ans)

roop("a",1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int, ins()))
def lin(): return list(input())
def iin(): return map(int, ins())

import copy
n = ii()
dic = {1: ['a']}
dic.update({i+2:[] for i in range(9)})
def getnext(dic):
    tmp = {i+1:[] for i in range(10)}
    for i, v in dic.items():
        for j in v:
            for k in range(i+1):
                if i == k:
                    tmp[i+1].append(j+chr(k+0x61))
                else:
                    tmp[i].append(j+chr(k+0x61))
    return tmp
for i in range(n-1):
    dic = getnext(dic)
tmp = []
for i in range(10):
    tmp += dic[i+1]
tmp.sort()
for i in tmp:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
dp = []
AL = 'abcdefghijklmn'
dp.append(['a'])
if N == 1:
    print('a')
else:
    for i in range(2, N+1):
        tmp = []
        for l in dp[-1]:  # l = [['a', 'a'], ['a', 'b']]
            n = len(set(l))
            for i in range(n+1):
                tmp.append(l + AL[i])
        dp.append(tmp)

    for s in dp[N-1]:
        print(s)

Submission status: Accepted

Solution code:
n = int(input())

l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
standard = list([] for i in range(n))

for i in range(n):
    if i == 0:
        standard[0].append(['a', 0])
    else:
        for w in standard[i-1]:
            for j in range(w[1]+1):
                standard[i].append([w[0]+l[j], w[1]])
            standard[i].append([w[0]+l[w[1]+1], w[1]+1])

for w in standard[n-1]:
    print(w[0])

Submission status: Accepted

Solution code:


N = int(input())

ans = []
chars = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
def func(N, s):
    if len(s) == N:
        ans.append(s)
        return

    if len(s) == 0:
        size = 1
    else:
        size = 0
        for c in s:
            size = max(size, ord(c) - 95)
    for c in chars[:size]:
        func(N, s+c)

func(N,"")

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

Submission status: Accepted

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

n = int(input())

def rec(s, kind):
    if len(s) == n:
        print(s)
        return
    for i in range(kind+1):
        end = chr(ord('a')+i)
        if i < kind:
            rec(s+end, kind)
        else:
            rec(s+end, kind+1) 

rec('a', 1)

Submission status: Accepted

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

ans_list = [['a',0]]

for i in range(1,N):
    pre_ans_list = ans_list.copy()
    ans_list = []
    for word_info in pre_ans_list:
        word = word_info[0]
        max_word = word_info[1] # 今まで出てきたなかで一番大きいもの
        postfix = alphabets[:min(i,max_word+1)+1]
        for j,p in enumerate(postfix):
            ans_list.append([word+p,max(j,max_word)])
for a in ans_list:
    print(a[0])

Submission status: Accepted

Solution code:
from functools import reduce
n = int(input())

alphabet = "abcdefghij"

cur = [[] for _ in range(10)]
nxt = [[] for _ in range(10)]

cur[0] = ["a"]
for _ in range(1, n):
	for i in range(10):
		for x in cur[i]:
			nxt[i].extend([x + alphabet[j] for j in range(i + 1)])
			nxt[i + 1].append(x + alphabet[i + 1])
	cur = nxt.copy()
	nxt = [[] for _ in range(10)]
ans = reduce(lambda a, b: a + b, cur)
ans.sort()
print(*ans, sep = "\n")

Submission status: Accepted

Solution code:
import sys
from string import ascii_lowercase

alphs = list(ascii_lowercase)

n = int(sys.stdin.readline().rstrip())

def main():
    cur = ['a']
    for _ in range(n-1):
        nex = []
        for s in cur:
            i = 0
            for c in s:
                i = max(i, ord(c) - 97)
            for al in alphs[:i+2]:
                nex.append(s + al)
        cur = nex
    return sorted(cur)

if __name__ == "__main__":
    ans = main()
    print(*ans, sep='\n')

Submission status: Accepted

Solution code:
from string import ascii_lowercase


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


def solve(n):
    if n == 1:
        return [["a"]]

    tmp = solve(n - 1)

    lower = list(ascii_lowercase)
    ret = []
    for t in tmp:
        m_t = max(t)
        for i in range(lower.index(m_t) + 2):
            ret.append(t + [lower[i]])
    return ret


N = int(input())
ans = solve(N)
for a in ans:
    print("".join(a))

Submission status: Accepted

Solution code:
N = int(input())

q = ['a']
for i in range(N - 1):
    nq = []
    for s in q:
        stop = ord(max(s)) + 2
        for i in range(ord('a'), stop):
            nq.append(s + chr(i))
    q = nq
for s in q:
    print(s)

Submission status: Accepted

Solution code:
from string import ascii_lowercase

def resolve():
    n = int(input())
    l = [[0]]
    for i in range(1, n):
        ll = []
        for j in l:
            for k in range(max(j) + 2):
                ll.append(j + [k])
        l = ll
    for i in l:
        print("".join([ascii_lowercase[x] for x in i]))

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
s="abcdefghij"
n=int(input())
ans=["a"]
for i in range(2,n+1):
    temp=[]
    lookup=s[:i]
    for j in ans:
        for k in lookup:
            temp.append(j+k)
            if k not in j:
                break
    ans=temp
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
words = "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 ".split()

def calcMax(current, i):
    maxC = -1
    for c in range(N):
        if(c != N - i):
            maxC = max(maxC, current[c])
    return maxC

def seek(current):
    for i in range(1, N):
        if(current[-i] <= max(current[:-i])):
            current[-i] += 1
            for j in range(i-1):
                current[N-1-j] = 0
            return True, current
    return False, current

def convert(ans):
    ansStr = ""
    for a in ans:
        ansStr += words[a]
    return ansStr

N = int(input())

ans = [0] * N

print(convert(ans))
flag, ans = seek(ans)
while(flag == True):
    print(convert(ans))
    flag, ans = seek(ans)

Submission status: Accepted

Solution code:
import sys

N=int(input())
if N==1:
  print("a")
  sys.exit()
  
old_list=[[0]]
for i in range(1,N):
  new_list=[]
  for l in old_list:
    maxl=max(l)
    for k in range(maxl+2):
      new_list.append(l+[k])
  old_list=new_list
    
#print(old_list)
llist=["a","b","c","d","e","f","g","h","i","j"]

for ll in old_list:
  #print(ll)
  str_list=[]
  for elm in ll:
    str_list.append(llist[elm])
  print("".join(str_list))

Submission status: Accepted

Solution code:
N = int(input())
alpha = "abcdefghijklmnopqrstuvwxyz"

dp = [-1]*N
dp[0] = 1


ans = []


def solve(x, n, l):  # n:種類
    if l == N:
        ans.append(x)
    else:
        for i in range(n):
            j = n
            if i == n-1:
                j += 1
            solve(x + alpha[i], j, l+1)


solve("", 1, 0)
ans.sort()
for x in ans:
    print(x)