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 collections
n=int(input())
d={'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26, 1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o', 16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v', 23: 'w', 24: 'x', 25: 'y', 26: 'z'}
lc=[["aaa",1],["aab",2],["aba",2],["abb",2],["abc",3]]

ld=[]
for j in range(len(lc)):
    for i in range(1,lc[j][1]+2):
        k=lc[j][0]+d[i]
        c = collections.Counter(k)
        ld.append([k,len(c)])
ld=sorted(ld)

le=[]
for j in range(len(ld)):
    for i in range(1,ld[j][1]+2):
        k=ld[j][0]+d[i]
        c = collections.Counter(k)
        le.append([k,len(c)])
le=sorted(le)

lf=[]
for j in range(len(le)):
    for i in range(1,le[j][1]+2):
        k=le[j][0]+d[i]
        c = collections.Counter(k)
        lf.append([k,len(c)])
lf=sorted(lf)

lg=[]
for j in range(len(lf)):
    for i in range(1,lf[j][1]+2):
        k=lf[j][0]+d[i]
        c = collections.Counter(k)
        lg.append([k,len(c)])
lg=sorted(lg)

lh=[]
for j in range(len(lg)):
    for i in range(1,lg[j][1]+2):
        k=lg[j][0]+d[i]
        c = collections.Counter(k)
        lh.append([k,len(c)])
lh=sorted(lh)

li=[]
for j in range(len(lh)):
    for i in range(1,lh[j][1]+2):
        k=lh[j][0]+d[i]
        c = collections.Counter(k)
        li.append([k,len(c)])
li=sorted(li)

lj=[]
for j in range(len(li)):
    for i in range(1,li[j][1]+2):
        k=li[j][0]+d[i]
        c = collections.Counter(k)
        lj.append([k,len(c)])
lj=sorted(lj)

if n==1:
    print("a")
elif n==2:
    l=["aa","ab"]
    print(*l)

elif n==3:
    for i in lc:
        print(i[0])
elif n==4:
    for i in ld:
        print(i[0])
elif n==5:
    for i in le:
        print(i[0])
elif n==6:
    for i in lf:
        print(i[0])
elif n==7:
    for i in lg:
        print(i[0])
elif n==8:
    for i in lh:
        print(i[0])
elif n==9:
    for i in li:
        print(i[0])
elif n==10:
    for i in lj:
        print(i[0])

Submission status: Accepted

Solution code:
N=int(input())
li=[chr(i) for i in range(97, 97+26)]
ans=['a']
def nex(ans,n):
    d=[]
    for i in ans:
        for j in range(n):
            if li[j]in i:
                d.append(i+str(li[j]))
            else:            
                k=len(set(i))
                if k+1>=j+1:
                    d.append(i+str(li[j]))
    return d
for i in range(2,N+1):
    ans=nex(ans,i)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
inp = 'a'

def AAA(arr):
    if len(arr) < N:
        for i in range(ord(max(arr))-96+1):
            AAA(arr+chr(i+1+96))
    else:
        print(arr)


AAA(inp)

Submission status: Accepted

Solution code:
std=[]
n=int(input())
cmb=[[] for i in range(n)]
cmb[0].append("a")
tmp=[[] for i in range(n)]
for i in range(1,n):
	for j in range(len(cmb)):
		for s in cmb[j]:
			for k in range(0,j+1):
				tmp[j].append(s+chr(ord("a")+k))
			tmp[j+1].append(s+chr(ord("a")+k+1))
	#print(cmb)
	cmb=tmp
	tmp=[[] for i in range(n)]
lst=[]
for i in range(len(cmb)):
	for std in cmb[i]:
		lst.append(std)
lst.sort()
for i in range(len(lst)):
	print(lst[i])

Submission status: Accepted

Solution code:
N = int(input())
def adding(s):
    if 'i' not in s:
        if 'h' not in s:
            if 'g' not in s:
                if 'f' not in s:
                    if 'e' not in s:
                        if 'd' not in s:
                            if 'c' not in s:
                                if 'b' not in s:
                                    return [s + 'a',s + 'b']
                                return [s + 'a',s + 'b',s + 'c']
                            return [s + 'a',s + 'b',s + 'c',s + 'd']
                        return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e']
                    return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e',s + 'f']
                return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e',s + 'f',s + 'g']
            return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e',s + 'f',s + 'g',s + 'h']
        return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e',s + 'f',s + 'g',s + 'h',s + 'i']
    return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e',s + 'f',s + 'g',s + 'h',s + 'i',s + 'j']
def standard(N):
    if N == 1:
        return ['a']
    else:
        A = standard(N-1)
        B = []
        for i in range(0,len(A)):
            B.extend(adding(A[i]))
        return B
A = standard(N)
for i in range(0,len(A)):
    print(A[i])

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

A, B = ['a'], []
for i in range(1, N):
  for a in A:
    for c in 'abcdefghij'[:len(set(a))+1]:
      B.append(a + c)
  A, B = B, []

for a in A:
  print(a)

Submission status: Accepted

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

std = deque([])

deque.append(std, ['a', 1])

for i in range(n-1):
    m = len(std)
    for j in range(m):
        tmp = deque.popleft(std)
        tmp_str = tmp[0]
        tmp_val = tmp[1]
        for k in range(tmp_val+1):
            append_chr = chr(ord('a')+k)
            s = tmp_str + append_chr
            if k == tmp_val:
                v = tmp_val+1
            else:
                v = tmp_val
            deque.append(std, [s, v])
            
for s, v in std:
    print(s)

Submission status: Accepted

Solution code:
n=int(input())
def f(s):
    m=ord(max(list(s))) - 97
    res = [s for _ in range(m+2)]
    for i in range(m+2):
        res[i] += chr(i+97)
    return res
def main(n):
    if n==1:
        return ["a"]
    else:
        ans = []
        for k in main(n-1):
            ans.extend(f(k))
        return ans

ans = main(n)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N = [int(i) for i in input().split()][0]
ordA = ord("a")

def recursion(x, k,  max_c, words):
  if k == 0:
    words.append(x)
    return
  for i in range(max_c+2):
    recursion(x+chr(ordA+i), k-1, max(i, max_c), words) 
  
words = []
recursion("a", N - 1, 0,  words)
for word in words:
  print(word)

Submission status: Accepted

Solution code:
N = int(input())
ans = ['a']
for i in range(N-1):
  tmpans = []
  for a in ans:
    mx = 0
    for s in a:
      mx = max(ord(s),mx)
    for c in range(ord('a'),mx+2):
      tmpans.append(''.join(list(a)+[chr(c)]))
  ans = tmpans[:]
for a in sorted(ans):
  print(a)

Submission status: Accepted

Solution code:
alp = ["a","b","c","d","e","f","g","h","i","j"]
N = int(input())
ans_list = []
for i in range(N):
    ans_list.append([])
for i in range(N):
    if i == 0:
        ans_list[i].append(["a",1])
    else:
        for j in range(len(ans_list[i-1])):
            for l in range(ans_list[i-1][j][1]+1):
                temp = ans_list[i-1][j][0] + alp[l]
                if l == ans_list[i-1][j][1]:
                    chk = ans_list[i-1][j][1]+1
                else:
                    chk = ans_list[i-1][j][1]
                ans_list[i].append([temp,chk])
for i in range(len(ans_list[N-1])):
    print(ans_list[N-1][i][0])

Submission status: Accepted

Solution code:
N = int(input())

my_list = []
for i in range(N):
    if i == 0:
        my_list.append("a")
        continue
    new_list = []
    while my_list:
        s = my_list.pop(0)
        for j in range(ord("a"), ord(max(s)) + 2):
            new_list.append(s + chr(j))
    my_list += new_list
my_list.sort()

[print(s) for s in my_list]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[[] for i in range(n)]
a[0]=[0]
k=0
s=['a']*n
t=[0]*n
while k>=0:
  if a[k]==[]:
    k-=1
    continue
  t[k]=a[k].pop(0)
  s[k]=chr(ord('a')+t[k])
  if k==n-1:
    print("".join(s))
  else:
    k+=1
    a[k]+=list(range(max(t[:k])+2))

Submission status: Accepted

Solution code:

import sys
from io import StringIO
import unittest

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

def yn(b):
    print("Yes" if b==1 else "No")
    return

def loopx(used,ans,anslen,nn):
    for x in range(0,used+2):
        ans2 = ans + base[x]
        anslen2=anslen+1
        if x==(used+1):
            used+=1
        if anslen>=nn:
            print(ans2)
        else:
            loopx(used,ans2,anslen2,nn)



inn=int(input())

loopx(-1,"",0,inn-1)

sys.exit()

Submission status: Accepted

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

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

def get_str(seq_list):
    result = []
    for seq in seq_list:
        used_char_num = len(set(seq))
        for i in range(used_char_num + 1):
            result.append(seq + chars[i])
    return result

N = int(input())

seq_list = ["a"]
for i in range(N - 1):
    tmp = seq_list[:]
    seq_list = get_str(tmp)

for s in seq_list:
    print(s)

Submission status: Accepted

Solution code:
N = int(input())
dp = [[] for _ in range(N+1)]
dp[1] = [["a"]]
for i in range(2,N+1):
    for j in range(len(dp[i-1])):
        for k in range(len(set(dp[i-1][j]))+1):
            dp[i].append(dp[i-1][j]+[chr(97+k)])
ans = dp[N]
for i in range(len(ans)):
    print("".join(ans[i]))

Submission status: Accepted

Solution code:
from sys import stdin
from collections import deque
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    d=deque()

    alp=["a","b","c","d","e","f","g","h","i","j"]
    for i in range(1,N+1):
        if i==1:
            d.append(["a",1])
        else:
            while True:
                s=d.popleft()
                if len(s[0])!=i-1:
                    d.appendleft(s)
                    break
                else:
                    for j in range(s[1]+1):
                        if j!=s[1]:
                            d.append([s[0]+alp[j],s[1]])
                        else:
                            d.append([s[0]+alp[j],s[1]+1])

    res=[]
    l=len(d)
    for i in range(l):
        res.append(d.pop()[0])

    res.sort()
    for i in range(l):
        print(res[i])
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    #print(N)
    if N == 1:
        print('a')
        return

    a=['a']
    for k in range(1,N):
        b=[]
        for t in a:
            s = set(t)
            not_in_set = True
            for i in range(k+1):
                add_char = chr(ord('a')+i)
                if add_char in s:
                    b.append(t + add_char)
                else:
                    if not_in_set:
                        b.append(t + add_char)
                        not_in_set = False
        a=b
    for s in a:
        print(s)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

import glob


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\159\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    alph = []

    def rec(self, result, now, max, N):

        if now == N:
            res = ""
            for i in result:
                res += self.alph[i]
            print(res)
            return

        if now == 0:
            result[0] = 0
            self.rec(result, now+1, 0, N)
            return

        for i in range(0, max+2):
            if i == N:
                return
            result[now] = i
            if i > max:
                self.rec(result, now+1, i, N)
            else:
                self.rec(result, now+1, max, N)

    def resolve(self):

        N = int(self.input_data())

        self.alph = "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(",")
        self.result = [0 for i in range(N)]
        self.rec(self.result, 0, 0, N)


solver = Solver(REL_PATH)
solver.exec_resolve()

Submission status: Accepted

Solution code:
n = int(input())

d = 'abcdefghijklm'


def solve(a):
    *u, = map(lambda x: d[x], a)
    return ''.join(u)


ans = [0]*n


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

while ans[0] == 0:
    print(solve(ans))
    if ans == [i for i in range(n)]:
        exit()
    q = max(ans[:n-1])
    if ans[n-1] <= q:
        ans[n-1] += 1
    else:
        j = 0
        while ans[n-1-j] > max(ans[:n-1-j]):
            ans[n-1-j] = 0
            j += 1
        ans[n-1-j] += 1

Submission status: Accepted

Solution code:
n=int(input())
L=["a"]
for i in range(n-1):
    tmp=[]
    for j in range(len(L)):
        for k in range(len(set(L[j]))+1):
            tmp.append(L[j]+chr(ord("a")+k))
    L=tmp
for j in range(len(L)):
    print(L[j])

Submission status: Accepted

Solution code:

class Solution:

    def solve(self, N: int):

        def dfs(prev_str, num_used_char):
            if len(prev_str) == N:
                print(prev_str)
                return

            for i in range(num_used_char):
                c = chr(ord('a') + i)
                dfs(prev_str + c, num_used_char)

            c = chr(ord('a') + num_used_char)
            dfs(prev_str + c, num_used_char + 1)

        dfs('a', 1)


if __name__ == '__main__':

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

Submission status: Accepted

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

alpha = alpha[:N]

counter = 1

def num(s):#文字列sに現れる文字の種類
    counter = 0
    for i in range(len(s)):
        if s[i] not in s[:i]:
            counter += 1
    return counter

while counter != N: 
    l1 = []
    for i in range(len(l)):
        for j in range(num(l[i])+1):
            l1.append(l[i]+alpha[j])
    l = l1[:]
    counter += 1
l.sort()

for k in range(len(l)):
    print(l[k])

Submission status: Accepted

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

#文字(数列)、最大数、何文字目か0からn-1、ゴールn n-1になったらプリント
def p(s,m,i,last):
    # a=97
    if i==last-1:
        print("".join([chr(97+j)for j in s]))
        return
    for k in range(m+2):
        S=copy(s)
        S.append(k)
        p(S,max(m,k),i+1,last)

def main():
    n=int(input())
    s=[0]
    p(s,0,0,n)

main()

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())

def check_ans(nums):
    cnt = 0
    for num in nums:
        num = int(num)
        if num == cnt:
            cnt += 1
        elif num < cnt:
            pass
        else:
            return False
    return True

def make_anss(anss, n):
    new_anss = []
    ns = [str(i) for i in range(n + 1)]
    for ans in anss:
        for n in ns:
            p_anss = ans + n
            if check_ans(p_anss):
                new_anss.append(p_anss)
    return new_anss

anss = ["0"]
for i in range(N - 1):
    anss = make_anss(anss, i + 1)

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

for ans in anss:
    print(ans.translate(str.maketrans(dics)))

Submission status: Accepted

Solution code:
n=int(input())
ans = ['a']
for i in range(1,n):
    ans_ = []
    for j in ans:
        for k in range(ord(max(j))-95):
            ans_.append(j+chr(97+k))
    ans = ans_.copy()
    
ans = sorted(ans)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import copy

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

n = int(input())

value = ['a']
for i in range(10):
    if len(value[0]) == n:
        break
    tmp_value = copy.copy(value)
    value = []
    for v in tmp_value:
        for j in range(n):
            value.append(v + ab[j])
            if ab[j] not in v:
                break
for v in value:
    print(v)

Submission status: Accepted

Solution code:
import sys
import math
import copy
import queue
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]

n = int(input())

def x(s,m,d):
    if d >= n:
        ans = ''
        for i in range(n):
            ans += chr(ord('a') + s[i])
        print (ans)
        return
    for i in range(m+1):
        ss = s + [i]
        m = max(m,i+1)
        x(ss,m,d+1)

x([0],1,1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)

N = int(input())
data = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
seed = ['a'] * N

def rec(S, depth, count):
    if depth == N:
        print(''.join(S))
        return
    for i in range(count+1):
        S.append(data[i])
        if i == count:
            count += 1
        rec(S, depth+1, count)
        S.pop()


rec([], 0, 0)

Submission status: Accepted

Solution code:
N = int(input())

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

ans = []
def f(List, n):
    if n == N:
        s = ""
        for l in List:
            s += L[l]
        ans.append(s)
        return None
    for i in range(max(List)+2):
        f(List+[i], n+1)

f([0], 1)        
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
n = int(input())

pre = [[0]]
ans = [[0]]
s = 'abcdefghijklmnop'

for i in range(n-1):
    ans = []
    for item in pre:
        for j in range(max(item)+2):
            ans.append(item + [j])
    pre = ans[:]

res = []
for item in ans:
    print("".join([s[c] for c in item]))

Submission status: Accepted

Solution code:


n = int(input())

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

if n == 2:
    print('aa')
    print('ab')
    exit()

words = 'abcdefghijklm'
ans = [['', -1]]

for i in range(1, n+1):
    usable = list(words[:i])
    news = []
    for candidate, limit in ans:
        for num, word in enumerate(usable):
            if num > limit + 1:
                break
            new = candidate + word
            news.append([new, max(limit, num)])
    ans = news

result = [word for word, limit in ans]
result.sort()
for res in result:
    print(res)

Submission status: Accepted

Solution code:
N = int(input())

ALP = "abcdefghij"

result = []

def mx(s):
    m = 0
    for i in s:
        if m < int(i):
            m = int(i)
    return m

def add(res):
    res_c = []
    for r in res:
        m = mx(r)
        for i in range(1, m + 2):
            res_c.append(r + str(i))
    return res_c

for n in range(N):
    if n == 0:
        result.append("1")
    else:
        result = add(result)

v = []
for i in range(1, N + 1):
    v = []
    for j in result:
        a = j.replace(str(i), ALP[i - 1])
        v.append(a)
    result = v

for r in result:
    if r == 'abcdefghia0':
        print('abcdefghij')
    else:
        print(r)

Submission status: Accepted

Solution code:
n = int(input())

alphabet = "abcdefghijk"

ans = [[] for _ in range(11)]
ans[1].append([0, "a"])

for i in range(n):
    for j, r in ans[i]:
        for k, t in enumerate(alphabet[:j+2]):
            if k == j+1:
                ans[i+1].append([j+1, r+t])
                continue
            ans[i+1].append([j, r+t])

for t in ans[n]:
    print(t[1])

Submission status: Accepted

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

list = [['a', 0]]
if N > 1:
    for n in range(N -1):
        new_list = []
        for i in range(len(list)):
            old_string = list[i][0]
            max_num = list[i][1]
            for j in range(max_num + 1):
                new_string = old_string + L[j]
                new_list.append([new_string, max_num])
            new_string = old_string + L[max_num + 1]
            new_list.append([new_string, max_num + 1])
        list = new_list
for i in range(len(list)):
    print(list[i][0])

Submission status: Accepted

Solution code:
alpha_small_ = [chr(i) for i in range(97, 97+26)] #アルファベッドの小文字

n = int(input())
ans = []
def solve(now,i):
    if len(now) == n:
        ans.append(now)
        return
    for j in range(i+1):
        solve(now+alpha_small_[j],max(i,j+1))

solve("a",1)


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

Submission status: Accepted

Solution code:

def get_normal_form(seq_type):
    curr_char = ord('a')
    return "".join([chr(curr_char + int(i)) for i in seq_type])


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

    def rec(category, acc, result):
        if len(acc) == n:
            result.append(acc)
            return result

        for c in range(category):
            result = rec(category, acc + str(c), result)
        result = rec(category + 1, acc + str(category), result)

        return result

    result = rec(1, "0", [])
    result.sort()
    for r in result:
        print(get_normal_form(r))


if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
N = int(input())

Char = [chr(97 + i) for i in range(N+10)]

ans = ["a"]
for i in range(N - 1):
    tmp = []
    for a in ans:
        rng = ord(max(a)) - 97
        for c in Char[: rng + 2]:
            tmp.append(a + c)
    ans = tmp

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

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
def rec(i,s):
    if i == n:
        ans.append(s)
        return True
    else:
        if len(set(s)) == 1:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
        if len(set(s)) == 2:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
        if len(set(s)) == 3:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
        if len(set(s)) == 4:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
        if len(set(s)) == 5:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
            rec(i+1,s+"f")
        if len(set(s)) == 6:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
            rec(i+1,s+"f")
            rec(i+1,s+"g")
        if len(set(s)) == 7:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
            rec(i+1,s+"f")
            rec(i+1,s+"g")
            rec(i+1,s+"h")
        if len(set(s)) == 8:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
            rec(i+1,s+"f")
            rec(i+1,s+"g")
            rec(i+1,s+"h")
            rec(i+1,s+"i")
        if len(set(s)) == 9:
            rec(i+1,s+"a")
            rec(i+1,s+"b")
            rec(i+1,s+"c")
            rec(i+1,s+"d")
            rec(i+1,s+"e")
            rec(i+1,s+"f")
            rec(i+1,s+"g")
            rec(i+1,s+"h")
            rec(i+1,s+"i")
            rec(i+1,s+"j")
rec(1,"a")
print("\n".join(ans))

Submission status: Accepted

Solution code:
import string
import itertools

alphabets = string.ascii_lowercase

N = int(input())

res = []


def f(s):
    return max([ord(t) - ord("a") for t in s])


def bfs(s, d):
    if d == N - 1:
        res.append(s)
        return

    for i in range(f(s) + 2):
        bfs(s + alphabets[i], d + 1)


bfs("a", 0)

res = sorted(res)
print("\n".join(res))
# print(list(bfs("a", 0)))

Submission status: Accepted

Solution code:
import string

def generate(n, res, cur = None, alphabet = None):
    if cur is None:
        cur = []
    if alphabet is None:
        alphabet = list(string.ascii_lowercase)[::-1]
    if n == 0:
        res.append(''.join(cur))
        return
    for i in range(len(cur)):
        cur.append(cur[i])
        generate(n - 1, res, cur, alphabet)
        cur.pop()
    cur.append(alphabet.pop())
    generate(n - 1, res, cur, alphabet)
    alphabet.append(cur.pop())

res = []
generate(int(input()), res=res)
res = sorted(set(res))
for row in res:
    print(row)

Submission status: Accepted

Solution code:
N = int(input())
W = 'abcdefghij'
ans = set()

for i in range(1,N+1):
  if i == 1:
    ans.add('a')
  else:
    tmp = set()
    for a in ans:
      index = W.index(sorted(list(a))[-1])
      for i in range(index+2):
        tmp.add(a+W[i])
    ans = tmp
    
for a in sorted(ans):
  print(a)

Submission status: Accepted

Solution code:
al = list("abcdefghij")
n = int(input())
w = [0 for i in range(n)]
w[-1] = -1
la = list(range(n))
while (w != la):
  w[-1] += 1
  for i in range(n-1):
    i = n-i-1
    z = False
    for j in range(n):
      if i != j and w[j] == w[i]:
        z = True
    if (not z) and (not (w[i]-1 in w)):
      w[i] = 0
      w[i-1] += 1
  c = [al[w[i]] for i in range(n)]
  print("".join(c))

Submission status: Accepted

Solution code:
def solve():
    N = int(raw_input())
    ret = [('a', 'a')]
    for i in range (2, N+1):
        tmp = []
        for stri in ret:
            for j in range(ord('a'), ord(stri[1]) + 1):
                tmp.append((stri[0] + chr(j), stri[1]))
            tmp.append((stri[0] + chr(ord(stri[1]) + 1), chr(ord(stri[1]) + 1)))
        ret = tmp
    for stri in ret:
        print stri[0]

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def main(n):
    if n == 1:
        return ['a']
    else:
        ans = []
        for a in main(n-1):
            b = '`'
            while b <= max(a):
                b = chr(ord(b) + 1)
                ans.append(a + str(b))
        return ans
N = int(input())
L = main(N)
for i in L:
    print(i)

Submission status: Accepted

Solution code:
length = int(input())
nums = []
def num_to_abc(n):
    return chr(ord("a") + n)

def f(level,already):
    if level >= length:
        nums.append(already)
        return
    else:
        for i in range(0, max(already) + 2):
            f(level + 1, already + [i])

f(1,[0])
for n in nums:
    print("".join(list(map(num_to_abc, n))))

Submission status: Accepted

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

def func(length):
    if length == 1:
        return ["a"]
    else:
        output = []
        for s in func(length-1):
            for i in range(len(set(list(s)))+1):
                output.append(s + l[i])
        return output

ans = func(N)
ans.sort()
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())

answers = [[[] for i in range(n)] for j in range(n)]
answers[0][0] = "a"
alphabets = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
if n == 1:
    print("a")
else:
    for i in range(n-1):
        for j in range(n):
            b_ans = answers[i][j]
            for one_ans in b_ans:
                for k in range(j+1):
                    answers[i+1][j].append(one_ans + alphabets[k])
                answers[i+1][j+1].append(one_ans + alphabets[j+1])
    all_answers = []
    for i in range(n):
        for single_ans in answers[n-1][i]:
            all_answers.append(single_ans)
    ans = sorted(all_answers)
    for print_ans in ans:
        print(print_ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
ans1 = ["a"]
ans2 = ["aa", "ab"]
ans3 = []
ans4 = []
ans5 = []
ans6 = []
ans7 = []
ans8 = []
ans9 = []
ans10 = []
def count(s):
    return(len(collections.Counter(s)))
    
for x in ans2:
    for i in range(count(x)+1):
        ans3.append(x+chr(97+i))
for x in ans3:
    for i in range(count(x)+1):
        ans4.append(x+chr(97+i))
for x in ans4:
    for i in range(count(x)+1):
        ans5.append(x+chr(97+i))         
for x in ans5:
    for i in range(count(x)+1):
        ans6.append(x+chr(97+i)) 
for x in ans6:
    for i in range(count(x)+1):
        ans7.append(x+chr(97+i)) 
for x in ans7:
    for i in range(count(x)+1):
        ans8.append(x+chr(97+i)) 
for x in ans8:
    for i in range(count(x)+1):
        ans9.append(x+chr(97+i)) 
for x in ans9:
    for i in range(count(x)+1):
        ans10.append(x+chr(97+i)) 

ans=[ans1, ans2, ans3, ans4, ans5, ans6, ans7, ans8, ans9, ans10]
for x in ans[N-1]:
    print(x)

Submission status: Accepted

Solution code:
# coding: utf-8

from copy import deepcopy

N = int(input())


w = []


# def rec(word, appeared):
#     print(appeared)
#     print(word)
#     print(w)
#     input()
#     new_appeared = deepcopy(appeared)

#     length = len(word)

#     if length == N:
#         w.append(word)
#         return None

#     last = appeared[-1]
#     new_appeared.append(chr(ord(last) + 1))
#     for tail in new_appeared:
#         rec(word + tail, new_appeared)


# rec("a", ["a"])


def rec(word):
    # print(appeared)
    # print(word)
    # print(w)
    # input()

    appeared = []
    for c in word:
        if c not in appeared:
            appeared.append(c)

    length = len(word)

    if length == N:
        w.append(word)
        return None

    last = appeared[-1]
    appeared.append(chr(ord(last) + 1))
    for tail in appeared:
        rec(word + tail)


rec("a")

for word in sorted(w):
    print(word)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    string = [chr(i) for i in range(97, 97+26)]
    ans = [[] for _ in range(10)]
    ans[0].append('a')
    for i in range(9):
        for s in ans[i]:
            n = len(set(s))
            for j in range(n+1):
                ans[i+1].append(''.join([s, string[j]]))
    print('\n'.join(ans[N-1]))

main()