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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
def dfs():
  todo=[[1]]
  ret=[]
  while len(todo)>0:
    t=todo.pop()
    if len(t)==n:
      ret.append(t)
    else:
      t.append(t[-1])
      todo.append(t)
      tc=t.copy()
      tc[-1]+=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: Wrong Answer

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=[]):
        """[1, i]の範囲で文字を選択して、sの末尾に追加する
        """
        if len(s) == N:
            q.append(''.join(s))
        else:
            for j in range(1, i+2):
                a = alphabets[j-1]
                dfs(j, s + [a])
    
    dfs(1, 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: Wrong Answer

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]:
  print(i[:-1])

Submission status: Wrong Answer

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
    for j in range(97,ord(standard[-1]) + 2):
        dfs(i + 1,standard + chr(j))
dfs(1,'a')
print('\n'.join(ans))

Submission status: Wrong Answer

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

    N = int(input())

    ans = []

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

        flg = False
        for c in ascii_lowercase:
            dfs(s + c)
            if flg: break
            if c == s[-1]:
                flg = True

    dfs()

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    ans = []

    def dfs(s):
        if len(s) == N:
            ans.append(s)
            return

        for c in (s[-1], chr(ord(s[-1]) + 1)):
            dfs(s + c)

    dfs('a')

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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(s[-1])+2)):
            dfs(s+x)


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

Submission status: Wrong Answer

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(s[-1])+2)):
            dfs(s+x)

dfs("a")

Submission status: Wrong Answer

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+1):
            dfs(s+d[i], k+1)


dfs('a', 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = ["a","b","c","d","e","f","g","h","j","k"]
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: Wrong Answer

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

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

def up(i):
    if i == 0:
        return True
    S[i] += 1
    if S[i] == T[i]:
        S[i] = 0
        if T[i] < N:
            T[i] += 1
        return up(i-1)
    return False

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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
    for j in range(N):
        for t in A[j]:
            print(t)

Submission status: Wrong Answer

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):
            for j in q:
                nq = []
                for k in range(ord('a'), ord(max(j)) + 2):
                    nq.append(j + chr(k))
                q=nq

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

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
n = int(input())
d = {s: i for i, s in enumerate(ascii_lowercase)}
a = [s for s, i in d.items()]
ans = []

def dfs(k, s):
    if n == k:
        ans.append(s)
    elif n > k:
        for i in range(max([d[c] for c in s])+2):
            v = s + a[i]
            dfs(k+1, v)
dfs(1,"a")
ans.sort()
for k in ans:
    print(k)
print('\n')

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
n = int(input())
d = {s: i for i, s in enumerate(ascii_lowercase)}
a = [s for s, i in d.items()]
ans = []

def dfs(k, s):
    if n == k:
        ans.append(s)
    elif n > k:
        for i in range(max([d[c] for c in s])+2):
            v = s + a[i]
            dfs(k+1, v)
dfs(1,"a")
ans.sort()
for k in ans:
    print(k)

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
n = int(input())
d = {s: i for i, s in enumerate(ascii_lowercase)}
# r = {i: s for i, s in enumerate(ascii_lowercase)}
a = [s for s, i in d.items()]
# print(d['a'])
# print(r)
ans = []

def dfs(k, s):
    if n == k:
        ans.append(s)
    elif n > k:
        # 元の文字+1まで(a:0, b:1, ...)
        # print(max([d[c] for c in s])+1)
        for i in range(max([d[c] for c in s])+2):
            v = s + a[i]
            # print(v)
            dfs(k+1, v)
dfs(1,'a')
# print(ans)
ans.sort()
for k in ans:
    print(k)

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
n = int(input())
d = {s: i for i, s in enumerate(ascii_lowercase)}
# r = {i: s for i, s in enumerate(ascii_lowercase)}
a = [s for s, i in d.items()]
# print(d['a'])
# print(r)
ans = []

def dfs(k, s):
    if n == k:
        ans.append(s)
    elif n > k:
        # 元の文字+1まで(a:0, b:1, ...)
        # print(max([d[c] for c in s])+1)
        for i in range(max([d[c] for c in s])+2):
            v = s + a[i]
            # print(v)
            dfs(k+1, v)
dfs(1,'a')
# print(ans)
for k in ans:
    print(k)

Submission status: Wrong Answer

Solution code:

N = int(input())
AOrd = ord('a')
S = [AOrd] * N


def printout(arr):
    out = []
    for o in arr:
        out.append(chr(o))
    print(''.join(out))


def S_Incr(i, j):
    if S[j] <= S[i]:
        S[j] += 1
        return True
    else:
        return False


def S_IncrMajor(i):
    if (i > 0) and (S[i] <= S[i-1]):
        S[i] += 1
        for j in range(i+1, N, 1):
            S[j] = AOrd
        return True
    else:
        return False


pos = N - 1
printout(S)
while (pos > 0):
    while S_Incr(pos-1, pos):
        printout(S)
    if S_IncrMajor(pos-1):
        pos = N - 1
        printout(S)
    else:
        pos -= 1
exit()

Submission status: Wrong Answer

Solution code:

N = int(input())
AOrd = ord('a')
S = [AOrd] * N


def printout(arr):
    out = []
    for o in arr:
        out.append(chr(o))
    print(''.join(out))


def S_Incr(i, j):
    if S[j] <= S[i]:
        S[j] += 1
        return True
    else:
        return False


def S_IncrMajor(i):
    if (i > 0) and (S[i] <= S[i-1]):
        S[i] += 1
        for j in range(i+1, N, 1):
            S[j] = AOrd
        return True
    else:
        return False

Submission status: Wrong Answer

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.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: Wrong Answer

Solution code:

N = int(input())
AOrd = ord('a')
S = [AOrd] * N


def printout(arr):
    out = []
    for o in arr:
        out.append(chr(o))
    print(''.join(out))


def S_Incr(i, j):
    if S[j] <= AOrd + i:
        S[j] += 1
        return True
    else:
        return False


def S_IncrMajor(i):
    if (i > 0) and (S[i] < AOrd + i):
        S[i] += 1
        for j in range(i+1, N, 1):
            S[j] = AOrd
        return True
    else:
        return False


pos = N - 1
printout(S)
while (pos > 0):
    while S_Incr(pos-1, pos):
        printout(S)
    if S_IncrMajor(pos-1):
        pos = N - 1
        printout(S)
    else:
        pos -= 1
exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
lexi = 'abcdefghij'
for i in range(0, N, 1):
    print(lexi[:i+1])

Submission status: Wrong Answer

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')

    while not que.empty():
        res = que.get()
        if len(res) < N:
            c = res[-1]
            for i in range(ord('a'), ord(c) + 2):
                que.put(res + chr(i))
        elif len(res) == N:
            print(res)
        else:
            break


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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()
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import string

alphabet = string.ascii_lowercase

n = int(input())

def DFS(before,keta,num):
    if keta == n:
        print(before)
        return
    for i in before:
        num = max(num,alphabet.index(i))
    for j in range(num+1):
        DFS(before+alphabet[j],keta+1,num+1)
DFS("",0,0)

Submission status: Wrong Answer

Solution code:
import string

alphabet = string.ascii_lowercase

n = int(input())

def DFS(before,keta):
    num = 0
    if keta == n:
        print(before)
        return
    for i in before:
        num = min(num,alphabet.index(i))+1
        
    for j in range(num+1):
        DFS(before+alphabet[j],keta+1)

DFS("",0)

Submission status: Wrong Answer

Solution code:
import string

alphabet = string.ascii_lowercase

n = int(input())

def DFS(before,keta):
    num = 0
    if keta == n:
        print(before)
        return
    for i in before:
        num = max(num,alphabet.index(i))+1
    for j in range(num+1):
        DFS(before+alphabet[j],keta+1)
DFS("",0)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

dfs('', 0)

Submission status: Wrong Answer

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

if N == 1:
	print('a')
	sys.exit()
else:
	ans = []
	def solve(s):
		if len(s) == N:
			ans.append(s)
			return 
		cp = s[-1]
		o = ord(cp)
		for n in range(97, o+2):
			solve(s + chr(n))
	solve('a')
	for a in ans:
		print(a)

Submission status: Wrong Answer

Solution code:
def main():
    from string import ascii_lowercase
    dic = {s: i for i, s in enumerate(ascii_lowercase)}
    rdic = {i: s for i, s in enumerate(ascii_lowercase)}
    N = int(input())
    ans = []

    def dfs(n, s):
        if N < n:
            return
        elif n == N:
            ans.append(s)
            return
        else:
            for i in range(dic[s[-1]]+2):
                v = s + rdic[i]
                dfs(n+1, v)
    dfs(1, "a")
    ans.sort()
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8

n = int(input()) # 1 <= n <= 10

lis = [0 for i in range(n)]
last = 0
now = 0
now_s = ''
a_list = ['a','b','c','d','e','f','g','h','i','j']

def converter(x,a,n):
    #a進数からn進数への変換
    t = 0
    out = 0
    y = -1
    while not x == 0:
        y = x % n
        out += y * (a ** t)
        x = (x - y) / n
        t += 1
    return int(out)

for i in range(n):
    last += i * (10 ** (n - i - 1))

last = converter(last,n,10) + 1

while not now == last:
    now = converter(now,10,n)
    d = now
    now_s = ''
    for i in range(n):
        c = d // (10 ** (n - i - 1))
        now_s += a_list[c]
        d -= c * (10 ** (n - i - 1))
    print(now_s)
    now = converter(now,n,10)
    now += 1

Submission status: Wrong Answer

Solution code:
N=int(input())
words=["a","b","c","d","e","f","g","h","i","j"]
list=[]
ans=""
def Division(n):
    if n == 0:
        return [ ]
    l = [ [ n ] ]
    for i in range(n - 1, 0, -1):
        for a in Division(n - i):
            if a[0] <= i:
                l.append([ i ] + a)
    return l

def AVE(A):
    if not len(A)==10:
        for i in range(0,10-len(A)):
            A.append(0)
    return A
Q=Division(N)
for i in range(0,len(Q)):
    ans=""
    for j in range(10):
        if ((AVE(Q[i]))[j])==0:
            pass
        else:
            ans+=words[j]*((AVE(Q[i]))[j])
            if len(ans)==N:
                list.append(ans)
list=sorted(list)
for i in  range(0,len(Q)):
    print(list[i])

Submission status: Wrong Answer

Solution code:
N=int(input())
words=["a","b","c","d","e","f","g","h","i","j"]
list=[]
ans=""
def Division(n):
    if n == 0:
        return [ ]
    l = [ [ n ] ]
    for i in range(n - 1, 0, -1):
        for a in Division(n - i):
            if a[0] <= i:
                l.append([ i ] + a)
    return l

def AVE(A):
    if not len(A)==10:
        for i in range(0,10-len(A)):
            A.append(0)
    return A
Q=Division(N)
for i in range(0,len(Q)):
    ans=""
    for j in range(10):
        if ((AVE(Q[i]))[j])==0:
            pass
        else:
            ans+=words[j]*((AVE(Q[i]))[j])
            if len(ans)==N:
                list.append(ans)
for i in  range(0,len(Q)):
    print(list[i])

Submission status: Wrong Answer

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

l0=['a']
l1=[]
li=[0]
li1=[]
alp=[chr(i) for i in range(97, 97+26)]

for i in range(1,N):
    for j, l in enumerate(l0):
        ind=0
        while ind<=li[j]+1:
            l1.append(l+alp[ind])
            if ind==li[j]+1: li1.append(li[j]+1)
            else: li1.append(li[j])
            ind+=1
    l0=l1.copy()
    l1=[]
    li=li1.copy()
    li1=[]

print(l0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
ans = []
for i in range(2 ** (n-1)):
    val = 0
    s = [val]
    for j in range(n-1):
        if i & 1 << j:
            val += 1
        s.append(val)
    ans.append(s)

orda = ord("a")
for line in ans:
    print("".join([chr(item + orda) for item in line]))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n = int(readline())
bit = [list(itertools.product([0, 1], repeat=(n - i))) for i in range(1, n)]
if n == 1:
    print('a')
    exit()
check = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
for k in range(1, n):
    memo = ''
    for j in range(k):
        memo += check[j]
    for i in range(2 ** (n - k) - 1):
        ans = ''
        for j in range(n - k):
            if bit[k - 1][i][j] == 0:
                ans += check[k - 1]
            else:
                ans += check[k]
        print(memo + ans)
print(memo + check[n - 1])

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n = int(readline())
bit = list(itertools.product([0, 1], repeat=(n - 1)))
if n == 1:
    print('a')
    exit()
for i in range(2 ** (n - 1)):
    ans = ''
    for j in range(n - 1):
        if bit[i][j] == 0:
            ans += 'a'
        else:
            ans += 'b'
    print('a' + ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

def dfs(s,mx):
    if len(s)==n:
        print(s)
        return None
    for i in range(ord('a'),(mx+1)+1):
        dfs(s+chr(i),max(mx,i))
dfs('',ord('a'))

Submission status: Wrong Answer

Solution code:
n=int(input())
def abcd(n,s):
    if len(s)==n:
        print(s)
        return
    if len(s)==0:
        abcd(n,'a')
    else:
        x=ord(s[-1])+1
        for j in range(97,x+1):
            abcd(n,s+chr(j))
    
abcd(n,"")

Submission status: Wrong Answer

Solution code:
from collections import deque

def dfs(q):
    if len(q)==N:
        print(''.join(q))
        return
    
    for i in range(min(26, ord(q[-1])-ord('a')+2)):
        q.append(alpha[i])
        dfs(q)
        q.pop()
    
N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
dfs(deque(['a']))

Submission status: Wrong Answer

Solution code:
def dfs(s):
    if len(s)>n:
        return
    t.append(s)
    for c in 'abcdefghij':
        if -1<=ord(c)-ord(s[-1])<=1:
            dfs(s+c)

n=int(input())
if n==1:
    print('a')
    exit(0)
t=[]
ans=[]
dfs('a')

for tt in t:
    if len(tt)==n:
        ans.append(tt)
ans.sort()
print(*ans,sep='\n')

Submission status: Wrong Answer

Solution code:
def dfs(s):
    if len(s)>n:
        return
    t.append(s)
    for c in 'abcdefghij':
        if ord(c)-ord(s[-1])<=1:
            dfs(s+c)

n=int(input())
if n==1:
    print('a')
    exit(0)
t=[]
ans=[]
dfs('a')

for tt in t:
    if len(tt)==n:
        ans.append(tt)
ans.sort()
print(*ans,sep='\n')

Submission status: Wrong Answer

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

def dfs(i,c,d):
	if i==n:
		ans.append(c)
		return
	for j in range(0,d+1):
		dfs(i+1,c+chr(97+j),d+(i==d))

dfs(0,"",0)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = ["a"]
for i in range(n-1):
    tmp = [a + chr(ord("a")+j) for j in range(i+2) for a in ans]
    ans = tmp

ans.sort()
for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = ['a']*(n)
#print(''.join(s))

def dfs(x,alp):
    if x == n:
        print(''.join(s))
        return
    
    for i in range(alp+1):
        #print(x,alp,i)
        s[x] = chr(i+ord("a"))
        dfs(x+1,min(i+1,alp+1))
        #print(alp)


dfs(0,0)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = ['a']*(n)
#print(''.join(s))

def dfs(x,alp):
    if x == n-1:
        print(''.join(s))
        return
    
    for i in range(alp+2):
        #print(x,alp)
        s[x+1] = chr(i+65+32)
        dfs(x+1,min(alp+i,alp+1))
        #print(alp)


dfs(0,0)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = ['a']*(n)
#print(''.join(s))

def dfs(x,alp):
    if x == n-1:
        print(''.join(s))
        return
    
    for i in range(alp+2):
        #print(x+1)
        s[x+1] = chr(i+65+32)
        dfs(x+1,alp+1)



dfs(0,0)

Submission status: Wrong Answer

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

arrays = list("abcdefghij")
pat_dic = {i:arrays[i] for i in range(N)}
par_patterns = list(range(10))

patterns = par_patterns[:N]
def next_search(arr,N):
    tmp = arr.copy()
    if len(tmp) == N:
        print(''.join([pat_dic[tmp[i]] for i in range(N)]))
        return None
    for st in patterns:
        if max([0]+tmp)+1 < st:
            continue
        tmp.append(st)
        if tmp[0] != 0:
            continue

        next_search(tmp, N)
        tmp = arr.copy()

Submission status: Wrong Answer

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

arrays = list("abcdefghij")
pat_dic = {i:arrays[i] for i in range(N)}
par_patterns = list(range(10))

patterns = par_patterns[:N]
def next_search(arr,N):
    tmp = arr.copy()
    if len(tmp) == N:
        if check_criteria(tmp):
            print([pat_dic[tmp[i]] for i in range(N)])
        return None
    for st in patterns:
        tmp.append(st)
        next_search(tmp, N)
        tmp = arr.copy()

def check_criteria(arr):
    order = []
    if arr[0] != 0:
        return False
    for val in arr:
        if val in order:
            continue
        else:
            order.append(val)
    for idx in range(1,len(order)):
        if order[idx] - order[idx-1] == 1:
            continue
        else:
            return False
    return True
        
next_search([], N)

Submission status: Wrong Answer

Solution code:
N = int(input())
seed = "a"
alpha = "abcdefghij"


def dfs(num, string):
    if num == 1:
        print(string)
    else:
        for i in range(num):
            dfs(num - 1, string + alpha[i])


dfs(N, "a")

Submission status: Wrong Answer

Solution code:
n=int(input());s=['a']
while len(s)>0:
  t=s.pop(-1)
  if len(t)==n:print(t)
  else:
    for a in range(ord(t[-1])+1,96,-1):s.append(t+chr(a))

Submission status: Wrong Answer

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

num_to_alp = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e', 5:'f', 6:'g', 7:'h', 8:'i', 9:'j'}
alp_to_num = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9}
words = deque([[0]])

def next_letters(x):
    letters = deque([])
    for i in range(x + 2):
        letters.append(i)
    return letters

while len(words[0]) < n:
    word = words.popleft()
    letters = next_letters(max(word[-1], max(word) - 1))
    for l in letters:
        l = [l]
        words.append(word + l)

for word in words:
    word = [num_to_alp[i] for i in word]
    print(''.join(word))

Submission status: Wrong Answer

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

num_to_alp = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e', 5:'f', 6:'g', 7:'h', 8:'i', 9:'j'}
alp_to_num = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9}
words = deque(['a'])

def next_letters(letter):
    x = alp_to_num[letter] + 2
    letters = []
    for i in range(x):
        letters.append(num_to_alp[i])
    return letters

while len(words[0]) < n:
    word = words.popleft()
    letters = next_letters(word[-1])
    for l in letters:
        words.append(word + l)

for w in words:
    print(w)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans_list = ["a"]  # 生成元の初期状態 (N = 1 の答え)
alphabet = [chr(ord("a") + i) for i in range(N)]  # 使用するアルファベット

for i in range(N - 1):
    ans_list = [ans + x for ans in ans_list for x in alphabet[:len(ans) + 1]]

for ans in ans_list:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
# 最後の数字+1以下じゃないとだめ
# abc -> 次はa,b,c,d

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

strs = ["a"]
cnt = 1
while cnt < N:
    tmps = []
    for s in strs:
        for i in range(dic.index(s[-1])+2):
            tmps.append(s+dic[i])
    cnt += 1
    strs = tmps[:]
for s in strs:
    print(s)

Submission status: Wrong Answer

Solution code:
str = 'abcdefghijklmnop'
def bt(n,m,s):
  if n == 0:
    print(s)
    return
  for c in range(m):
    bt(n-1,m,s+str[c])
  #introduce another character
  bt(n-1,m+1,s+str[m])
n = int(input())

Submission status: Wrong Answer

Solution code:
def examA():
    L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K = I()

    ans = L[K-1]
    print(ans)
    return

def examB():
    H, W = LI()
    if H==1 or W==1:
        print(1)
        return
    ans = H*W//2 + (H*W)%2
    print(ans)
    return

def examC():
    a,b,c = LI()
    if c-(a+b)<=0:
        print("No")
        return
    judge = (c-a-b)**2-4*a*b
    if judge>0:
        print("Yes")
    else:
        print("No")
    return

def examD():
    def bfs(N):
        W = [0]*(5*10**6)
        L = [""]*(5*10**6)
        que = deque()
        que.append(0)
        L[0] = "a"
        W[0] = 0
        flag = True
        ne = 0
        while(flag):
            now = que.popleft()
            nowW = W[now]
            if len(L[now])==N:
                flag = False
                break
            for i in range(W[now]+2):
                ne += 1
                W[ne] = max(nowW,i)
                que.append(ne)
                L[ne] = L[now] + alphabet[i]
        return L
    N = I()
    D = bfs(N)
    for ans in D:
        if not ans:
            break
        if len(ans)<N:
            continue
        print(ans)
    return

def examD2():
    N = I()
    def dfs(n,s,i):
        if len(s)==n:
            return
        for k in range(i+1):
            if len(s)==n-1:
                print(s+alphabet[k])
            dfs(n,s+alphabet[k],max(i+1,k))
        return
    dfs(N,"",0)
    return

def examE():
    def LCS_R(S,T):
        N = len(S); M = len(T)
        dp = [[inf] * (M + 1) for _ in range(N + 1)]
        dp_S = [[""] * (M + 1) for _ in range(N + 1)]
        dp[0][0] = 0
        for i in range(N):
            for j in range(M):
                if S[i] == T[j] or S[i] == "?" or T[j] == "?":
                    dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + 1)
                    if dp[i + 1][j + 1]==dp[i][j] + 1:
                        cur = S[i]
                        if S[i] == "?" or T[j] == "?":
                            cur = "?"
                        dp_S[i+1][j+1] = dp_S[i][j] + cur
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]+1)
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)
                if dp[i + 1][j] == dp[i][j] + 1:
                    dp_S[i + 1][j] = dp_S[i][j] + S[i]
                if dp[i][j + 1] == dp[i][j] + 1:
                    dp_S[i][j + 1] = dp_S[i][j] + T[j]
        dp[N][M] = min(dp[N][M], dp[N-1][M] + 1)
        dp[N][M] = min(dp[N][M], dp[N][M-1] + 1)
        if dp[N][M] == dp[N-1][M] + 1:
            dp_S[N][M] = dp_S[N-1][M] + S[N-1]
        if dp[N][M] == dp[N][M-1] + 1:
            dp_S[N][M] = dp_S[N][M-1] + T[M-1]

        i = N; j = M
        rep = []
        while i > 0 and j > 0:
            if dp[i][j] == dp[i - 1][j]:
                rep.append(S[i-1])
                i -= 1
            elif dp[i][j] == dp[i][j - 1]:
                rep.append(T[j-1])
                j -= 1
            else:
                rep.append(S[i - 1])
                i -= 1
                j -= 1

        return dp,dp_S

    A = SI()
    B = SI()
    C = SI()

    a1,d1 = LCS_R(A,B)
    a2,d2 = LCS_R(B,C)
    a3,d3 = LCS_R(C,A)


    S1,d1 = LCS_R(d1[-1][-1],C)
    S2,d2 = LCS_R(d2[-1][-1],A)
    S3,d3 = LCS_R(d3[-1][-1],B)

    ans = min(S1[-1][-1],S2[-1][-1],S3[-1][-1])
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examD2()

"""

"""