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:
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):
            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()

"""

"""

Submission status: Wrong Answer

Solution code:
N = int(input())
S = "abcdefghijklmn"
Q = [(1,1,"a")]
A = []
while Q:
    q = Q.pop(-1)
    if q[0]==N:
        A.append(q[2])
        continue
    for i in range(q[1]+1):
        Q.append((q[0]+1,i+1,q[2]+S[i]))
for a in sorted(A):print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = "abcdefghijklmn"
Q = [(1,"a")]
A = []
while Q:
    q = Q.pop(-1)
    if q[0]==N:
        A.append(q[1])
        continue
    for i in range(S.index(q[1][-1])+2):
        Q.append((q[0]+1,q[1]+S[i]))
for a in sorted(A):print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
pw = ['a', 'b', 'c']
ans = ['' for _ in range(n)]
# print(ord('b'))
def dfs(i):
    if i == n:
        print(''.join(ans))
        return
    for j in range(97, 100):
        # print(j)
        ans[i] = chr(j)
        dfs(i+1)

dfs(0)

Submission status: Wrong Answer

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


def main():
    import sys
    input = sys.stdin.readline

    from itertools import product

    n = int(input())
    ans = list()

    for element in product('ab', repeat=n):
        s = ''.join(map(str, element))

        if s[0] == 'a':
            ans.append(s)

    print('\n'.join(map(str, sorted(ans))))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for num in range(n-1):
    x = []
    for i in range(len(w)):
        for j in range(n):
            x.append(w[i] + alphabet[j])
    w = x

for _ in range(len(w)):
    print(w[_])

Submission status: Wrong Answer

Solution code:
n = int(input())

before = ["0"]
for i in range(n-1):
    next = []
    for elem in before:
        m = 1
        for j in range(len(elem)):
            m = max(m, int(elem[j]))
        for j in range(m+1):
            next.append(elem+str(j))
    before = next[:]

before.sort()
d = {"0":"a", "1":"b", "2":"c", "3":"d", "4":"e", "5":"f", "6":"g", "7":"h", "8":"i", "9":"j"}
for elem in before:
    ans = []
    for i in range(len(elem)):
        ans.append(d[elem[i]])
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


class Graph:
    def __init__(self) -> None:
        self.graph = defaultdict(list)

    def connect(self, u, v):
        self.graph[u].append(v)

    def dfs(self, start):
        return list(self._dfs(start))

    def _dfs(self, node):
        if self.graph.get(node) is None:
            yield [node]
        else:
            for child in self.graph[node]:
                for path in self._dfs(child):
                    yield [node] + path


n = int(input())
g = Graph()
for level in range(n - 1):
    for j in range(level + 1):
        for k in range(j + 2):
            g.connect((level, j), (level + 1, k))

paths = g.dfs((0, 0))
for path in paths:
    print(''.join([chr(ord('a') + i) for level, i in path]))

Submission status: Wrong Answer

Solution code:
#coding:utf-8

def main():
    alphas = list('abcdefghijklmnopqrstuvwxyz')
    n = int(input())
    count_list = []
    for i in range(2 ** (n-1)):
        a = str(bin(i))[2:].zfill(n)
        if a.count('0') in count_list:
            pass
        count_list.append(a.count('0'))

        idx_s = 0
        now_c = 0
        res = ''
        while idx_s < n:
            if a[idx_s] == '0':
                res += 'a'
            else:
                now_c += 1
                res += alphas[now_c]
            idx_s += 1
        print(res)
    #print(count_list)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8

def main():
    alphas = list('abcdefghijklmnopqrstuvwxyz')
    n = int(input())
    count_list = []
    for i in range(2 ** n - 1):
        a = str(bin(i))[2:].zfill(n)
        if a.count('0') in count_list:
            continue
        count_list.append(a.count('0'))

        idx_s = 0
        now_c = 0
        res = ''
        while idx_s < n:
            if a[idx_s] == '0':
                res += 'a'
            else:
                now_c += 1
                res += alphas[now_c]
            idx_s += 1
        print(res)
    #print(count_list)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
alphabetlist=['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']

N=int(input())
S=[0 for i in range(0,N)]
string=''
for i in range(0,N):
    string+='a'
print(string)
digit=N-1
while True:
    if S[digit]==S[digit-1]+1:
        digit-=1
    else:
        S[digit]+=1
        for j in range(digit+1,N):
            S[j]=0
        digit=N-1
        if S[0]==1:
            break
        string=[0 for i in range(0,N)]
        for i in range(0,N):
            string[i]=alphabetlist[S[i]]
        print(''.join(string))

Submission status: Wrong Answer

Solution code:
import sys 
sys.setrecursionlimit(4100000)

N = int(input())

def dfs(i,s):
    if len(s) == N:
        
        return print(s)
    
    for x in range(97,i + 1):
        t = s + chr(x)
        
        dfs(x + 1,t)
    
    
dfs(ord("a"),"")

Submission status: Wrong Answer

Solution code:
import sys 
sys.setrecursionlimit(4100000)

N = int(input())
L = []
def dfs(i,s,ord_num):
    if i == N:
        
        if not s in L:
            L.append(s)
            return False
        
        else:
            return False
    
    if dfs(i+1,s + "a",ord_num):
        
        return True
    
    if dfs(i+1,s + chr(ord_num+1),ord_num):
        
        return True
    
    if dfs(i+1,s + chr(ord_num + 1),ord_num + 1):
        
        return True
    
    return False
    
dfs(1,"a",ord("a"))    

L.sort()

for i in L:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys 
sys.setrecursionlimit(4100000)

N = int(input())
L = []
def dfs(i,s,ord_num):
    if i == N:
        
        if not s in L:
            L.append(s)
            return print(s)
        
        else:
            return False
    
    if dfs(i+1,s + "a",ord_num):
        
        return True
    
    if dfs(i+1,s + chr(ord_num+1),ord_num):
        
        return True
    
    if dfs(i+1,s + chr(ord_num + 1),ord_num + 1):
        
        return True
    
    return False
    
dfs(1,"a",ord("a"))

Submission status: Wrong Answer

Solution code:

import sys 
sys.setrecursionlimit(4100000)

N = int(input())

def dfs(i,s,ord_num):
    if i == N:
        
        return print(s)
    
    if dfs(i+1,s + "a",ord_num):
        
        return True
    
    if dfs(i+1,s + chr(ord_num + 1),ord_num + 1):
        
        return True
    
    return False
    
dfs(1,"a",ord("a"))

Submission status: Wrong Answer

Solution code:
N = int(input())

dp = [[] for _ in range(N)]
dp[0].append('a')

for i in range(1, N):
    for strings in dp[i-1]:
        j = 97
        while j <= ord(strings[-1])+1:
            nextstr = strings
            nextstr += chr(j)
            dp[i].append(nextstr)
            j += 1

dp[N-1].sort()

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

Submission status: Wrong Answer

Solution code:
N = int(input())

dp = [[] for _ in range(N)]
dp[0].append('a')

for i in range(1, N):
    for strings in dp[i-1]:
        j = 97
        while j <= ord(strings[-1])+1:
            nextstr = strings
            nextstr += chr(j)
            dp[i].append(nextstr)
            j += 1


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

Submission status: Wrong Answer

Solution code:
s = input().split()
n = int(s[0])

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

#initialize
inis = []

def print_str( arry , num):
   str_a = ''
   for i in range(num):
     #print(arry,i)
     str_a = str_a + st[arry[i]-1]
   print(str_a)

# len = 1 .. 10
def do_number_n( len ):
   global inis
   tsti = 0
   k = len - 1    
   print_str( inis , len)
   while True:
      inis[k] += 1
      for j in range(k,0,-1):
         #print(inis[0:j],j)
         if ( max(inis[0:j]) + 2 ) <= inis[j]  :
         #if ( inis[j-1] + 2 ) <= inis[j]  :
            inis[j-1] += 1
            inis[j] = 1
         #print('test:  {},{},   {}'.format(j,k,inis))
            
      #最後まで行った。
      if inis[0] > 1 :
         return        
      print_str( inis , len)
  
def main():
  global inis
  inis = [1,1,1,1,1,1,1,1,1,1,1]
  #do_number_n(1)
  #return
  for j in range(1,n+1):
  #for j in range(n+1,1,-1):
    #print(j)
    inis = [1,1,1,1,1,1,1,1,1,1,1]
    do_number_n(j)
    
main()
exit()
#loop
i = 0
k = n - 1 
print_str( inis,3 )
while True:
   i += 1
   if i > 10 :
      break
   if ( inis[k-1] + 1 )== inis[k]  :
      inis[k-1] = inis[k-1] + 1 
      inis[k] = 1
   print_str( inis,3 )
   inis[k] = inis[k] + 1

Submission status: Wrong Answer

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

def func(S):
  q = deque([S])
  while q:
    x = q.popleft()
    if len(x) == N:
      print(x)
    else:
      #許容される文字の数=aの数
      len_a = list( i for i in x ).count('a')
      for char_no in range(ord('a'), max([ ord(i) for i in x ])+2):
        if char_no == ord('a'):
          y = x + chr(char_no)
          q.append(y)
        elif len_a <= list( i for i in x ).count(chr(char_no)):
          pass
        else:
          y = x + chr(char_no)
          q.append(y)


start = 'a'
func(start)

Submission status: Wrong Answer

Solution code:
N = int(input())

alphabet = [chr(97+i) for i in range(min(N,26))]
# print(alphabet)

dp = [[None]*N for _ in range(N)]
dp[0][0] = [alphabet[0]]
for i in range(1,N):
	dp[0][i] = []
# print(dp)


for n in range(1,N):
	for k in range(N):
		# dp[n][k] = dp[n-1][k]*k + dp[n-1][k-1]
		dp[n][k] = []
		for s in dp[n-1][k]:
			# print([s + alphabet[i] for i in range(k+1)])
			dp[n][k] += [s + alphabet[i] for i in range(k+1)]
		for s in dp[n-1][k-1]:
			dp[n][k] += [s + alphabet[k]]

# print(dp)

for k in range(N):
	# print(k, dp[N-1][k])
	for ans in sorted(dp[N-1][k]):
		if len(ans)!=0:
			print(ans)

Submission status: Wrong Answer

Solution code:
import math


def div_with_mod(x, y, mod):
    # Fermat's little theorem
    return x*pow(y, mod - 2, mod)


def comb(n, r, mod):
    # calculates C(n,r) with mod (assuming mod is prime)
    nc = n
    for rc in range(1, r):
        nc -= 1
        n = n*nc % mod
        r = r*rc % mod

    return div_with_mod(n, r, mod)


def solve():
    N = int(input())
    # ord("a") Unicode コードポイントを返す
    codepoint = ord("a")

    def dfs(word, dep):
        if dep == N:
            return print(word)

        for i in range(dep+1):
            dfs(word + chr(codepoint+i), dep+1)

    dfs("a", 1)


# Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
res = []
table = ['a']

def dfs(s, time, table):
    tab = copy.deepcopy(table)
    l = len(tab)
    mi = ord(s[0])
    for i in range(time):
        if mi < ord(s[i]):
            mi = ord(s[i])
            if s[i] in tab:
                 pass
            else:
                tab.append(s[i])
    mi += 1
    
    if time == n:
        #print(tab)
        if s in res:
            pass
        else:
            print(s)
            res.append(s)
    else:
        for i in range(l):
            dfs(s+tab[i], time+1, tab)
        dfs(s+chr(mi), time+1, tab)
            
dfs('a', 1, table)

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
res = []
table = ['a']

def dfs(s, time, table):
    tab = copy.deepcopy(table)
    mi = ord(s[0])
    for i in range(time):
        mi < ord(s[i])
        mi = ord(s[i])
        if s[i] in tab:
             pass
        else:
            tab.append(s[i])
    mi += 1
    
    if time == n:
        if s in res:
            pass
        else:
            res.append(s)
    else:
        dfs(s+chr(mi), time+1, tab)
        for i in range(len(tab)):
            dfs(s+tab[i], time+1, tab)
            
dfs('a', 1, table)

#print(res)
res.sort()
#res.reverse()
for i in range(len(res)):
    print(res[i])

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
res = []
table = ['a']

def dfs(s, time, table):
    tab = copy.deepcopy(table)
    mi = ord(s[0])
    for i in range(time):
        mi < ord(s[i])
        mi = ord(s[i])
        if s[i] in table:
             pass
        else:
            tab.append(s[i])
    mi += 1
    
    if time == n:
        if s in res:
            pass
        else:
            res.append(s)
    else:
        dfs(s+chr(mi), time+1, tab)
        for i in range(len(table)):
            dfs(s+table[i], time+1, tab)
            
dfs('a', 1, table)

#print(res)
sorted(res)
res.reverse()
for i in range(len(res)):
    print(res[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
res = []
table = ['a']

def dfs(s, time, table):
    mi = ord(s[0])
    for i in range(time):
        mi < ord(s[i])
        min= ord(s[i])
        if s[i] in table:
             pass
        else:
            table.append(s[i])
    mi += 1
    
    if time == n:
        if s in res:
            pass
        else:
            res.append(s)
    else:
        dfs(s+chr(mi), time+1, table)
        for i in range(len(table)):
            dfs(s+table[i], time+1, table)
            
dfs('a', 1, table)

#print(res)
sorted(res)
res.reverse()
for i in range(len(res)):
    print(res[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
res = []
table = ['a']

def dfs(s, time, table):
    min = ord(s[0])
    for i in range(time):
        min < ord(s[i])
        min = ord(s[i])
        table.append(s[i])
    min += 1
    
    if time == n:
        res.append(s)
    else:
        dfs(s+chr(min), time+1, table)
        for i in range(len(table)):
            dfs(s+table[i], time+1, table)
            
dfs('a', 1, table)

#print(res)
sorted(res)
che = 0
for i in range(1, len(res)):
    if res[che] == res[i]:
        che += 1
    else:
        print(res[i])
        che += 1

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(500000)

N = int(input())
global ans
ans = []
def dfs(now,rank,root_):
    root = root_[:]
    if rank == N:
        root.append(now)
        ans.append(''.join([chr(i+ord('a')) for i in root]))
    else:
        root.append(now)
        for i in range(now+2):
            dfs(i,rank+1,root)

dfs(0,1,[])
ans.sort()
print(*ans,sep='\n')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(500000)

N = int(input())
global ans
ans = []
def dfs(now,rank,root_):
    root = root_[:]
    if rank == N:
        root.append(now)
        ans.append(''.join([chr(i+ord('a')) for i in root]))
    else:
        root.append(now)
        for i in range(now+2):
            dfs(i,rank+1,root)

dfs(0,1,[])
print(*ans,sep='\n')

Submission status: Wrong Answer

Solution code:
def getStr(vars):
    if len(vars)==N:
        print(getPrintStr(vars))
        return
    
    vars.append(0)
    for i in range(0,vars[-2]+2):
        vars[-1] = i
        #print(":", i, vars)
        getStr(vars)
    del vars[-1]
    return

def getPrintStr(vars):
    ret = ""
    for i in range(len(vars)):
        ret += "abcdefghijkl"[vars[i]]
    return ret

N = int(input())
 
getStr([0])

Submission status: Wrong Answer

Solution code:
N = int(input())

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

dfs(N-1, 'a')

Submission status: Wrong Answer

Solution code:
N = int(input())


def func(S):
  q = [S]
  #ans = []
  while q:
    x = q.pop()
    if len(x) == N:
      print(x)
    elif len(x) > N:
      pass
    else:
      follow = x[-1]
      for i in range(len([ char for char in x if char == follow])):
        y = x + chr(ord(follow) + 1) * (i + 1)
        q.append(y)

for i in range(N, 0, -1):
  start = 'a' * i
  func(start)

Submission status: Wrong Answer

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

cand=["a"]

num=98
for i in range(N-1):
    temp=[]
    for item in cand:
        for i in range(num-96):
            temp.append(item+chr(i+97))
    num+=1
    cand=temp[:]

for item in cand:
    print(item)

Submission status: Wrong Answer

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

cand=["a"]

num=97
for i in range(N-1):
    temp=[]
    for item in cand:
        for i in range(max(ord(item[-1])-95,num-97)):
            temp.append(item+chr(i+97))
            num=max(num,i+97)
    cand=temp[:]

for item in cand:
    print(item)

Submission status: Wrong Answer

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

cand=["a"]


for i in range(N-1):
    temp=[]
    for item in cand:
        for i in range(ord(item[-1])-95):
            temp.append(item+chr(i+97))
    cand=temp[:]

for item in cand:
    print(item)

Submission status: Wrong Answer

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

cand=["a"]

for i in range(N-1):
    temp=[]
    for item in cand:
        temp.append(item+item[-1])
        temp.append(item+chr(ord(item[-1])+1))
    cand=temp[:]

for item in cand:
    print(item)

Submission status: Wrong Answer

Solution code:
def dfs(base, dic, swap, ma):
    if len(base) == ma:
        print(base)
    else:
        num = swap[base[-1]] + 1
        for i in range(num + 1):
            dfs(base + dic[i], dic, swap, ma)


n = int(input().strip())
dic = {0: "a",
       1: "b",
       2: "c",
       3: "d",
       4: "e",
       5: "f",
       6: "g",
       7: "h",
       8: "i",
       9: "j",
       }
swap = {v: k for k, v in dic.items()}
dfs("a", dic, swap, n)

Submission status: Wrong Answer

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


def dfs(s, i):
    if len(s) == N:
        ans = ''
        for j in range(N):
            ans += w[int(s[j])]
        print(ans)
    else:
        for k in range(i+1):
            dfs(s+str(k), i+1)


x = dfs('0', 1)

Submission status: Wrong Answer

Solution code:
# D
import itertools
from scipy.misc import comb
N = int(input())
ans_list = []
K = 0
for i in range(N):
    perm_list = ['a'] * (N - 1 - i)
    perm_list += ['x'] * (i)
    tmp_list = []
    al = [chr(ord('b') + j) for j in range(i)]

    K += comb(N-1, i)

    for v in itertools.permutations(perm_list, len(perm_list)):
        tmp = 'a'
        for j in range(len(perm_list)):
            tmp += v[j]
        tmp_list.append(tmp)
    tmp_list = list(set(tmp_list))
    
    n = len(tmp_list)
    for j in range(n):
        cnt = 0
        for k in range(N):
            if tmp_list[j][k] == "x":
                tmp_list[j] = tmp_list[j].replace("x", al[cnt], 1)
                cnt += 1
        ans_list.append(tmp_list[j])
ans_list.sort()
K = int(K)
for i in range(K):
    print(ans_list[i])

Submission status: Wrong Answer

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


def dfs(s, i):
    if i == N-1:
        ans = ''
        for i in range(N):
            ans += w[int(s[i])]
        print(ans)
    else:
        dfs(s+s[-1], i+1)
        dfs(s+str(int(s[-1])+1), i+1)


x = dfs('0', 0)

Submission status: Wrong Answer

Solution code:
N=int(input())


def combi(N,K):
    ans1=1
    ans2=1
    for i in range(K):
        ans1=ans1*(N-i)
        ans2=ans2*(K-i)
    ans=ans1//ans2
    return ans

def rec(n):
    if n==1:
        return 1
    else:
        ans=0
        for i in range(1,n+1):
            if i==1:
                ans+=1
            elif i<n:
                ans+=combi(n-1,n-i)
            elif i==n:
                ans+=rec(n-1)
        return ans

a=rec(N)

print(a)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
dic = {0: "a",
       1: "b",
       2: "c",
       3: "d",
       4: "e",
       5: "f",
       6: "g",
       7: "h",
       8: "i",
       9: "j",
       }

prev = [""]
for i in range(n):
    curr = []
    for elem in prev:
        for j in range(0, i + 1):
            curr.append(elem + dic[j])
    prev = curr
for e in prev:
    print(e)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000)
words = set()
alphabet = [chr(i) for i in range(97, 97+26)]
def add(s,j):
    if len(s) == n:
        words.add(s)
    else:
        s += j
        for i in alphabet:
            add(s,i)
n = int(input())
for i in alphabet:
    add("",i)
words = list(words)
words.sort()
#print(words)
words = words[0:n]
#print(words)
for word in words:
    print(word)

Submission status: Wrong Answer

Solution code:
n = int(input())
def dfs(s,c):
    if len(s)==n:
        print(s)
        return
    for i in range(ord("a"),ord(c)+2):
        dfs(s+chr(i),chr(i))

dfs("a","a")

Submission status: Wrong Answer

Solution code:
N = int(input())
chl = "abcdefghijk"
chli = {
  'a':0,
  'b':1,
  'c':2,
  'd':3,
  'e':4,
  'f':5,
  'g':6,
  'h':7,
  'i':8,
  'j':9
}

def ret(M):
  if M == 1:
    return "a"
  retl = []
  for stra in ret(M-1):
    maxi = min(chli[stra[-1]] + 2, 10)
    cand = chl[:maxi]
    for ch in cand:
      retl.append(stra + ch)
  return retl

ans = ret(N)

for x in ans:
  print(x)

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase as alph

def gen_pattern(N, pre=""):
  for c in alph[:ord(max(pre or "\x60"))-0x5f]:
    pattern = pre+c
    if len(pattern) == N:
      yield pattern
    else:
      yield from gen_pattern(N, pattern)

for pattern in gen_pattern(3):
  print(pattern)

Submission status: Wrong Answer

Solution code:
N = int(input())
def f(n,s):
    if n == 0:
        print(s)
        return
    for i in [chr(ord("a") + i) for i in range(N-n+1)]:
        if s != "" and ord(i) - ord(s[-1]) > 1:
            return 
        f(n-1,s+i)
f(N,"")

Submission status: Wrong Answer

Solution code:
n = int(input())

alphabet = 'abcdefghij'
s = [-1 for i in range(n)]
lst = [[] for i in range(n)]
lst[0].append(0)
ind = 0
while lst[ind] != [] or ind > 0:
    if ind < n-1 and lst[ind] != []:
        s[ind] = lst[ind].pop()
        for i in range(s[ind]+1, -1, -1):
            lst[ind+1].append(i)
        ind += 1
    else:
        while lst[ind] != []:
            s[ind] = lst[ind].pop()
            ans = [alphabet[i] for i in s]
            print(''.join(ans))
        ind -= 1

Submission status: Wrong Answer

Solution code:
alp = [chr(i) for i in range(97, 97+26)]

def dfs(s, mx):
    if len(s)==N:
        print(s)
    else:
        for i in range(mx+1):
            dfs(s+alp[i], i+1)
        
N = int(input())
dfs('',0)

Submission status: Wrong Answer

Solution code:
N = int(input())
alp = [chr(i) for i in range(97, 97+26)]
for i in range(N):
    if i!=0:
        start = int('1'+'0'*(i-1))
        end = int(''.join([str(j) for j in range(1,i+1)]))
        for m in range(start, end+1):
            ids = [0]*(N-i)
            ids.extend([int(o) for o in str(m)])
            print(''.join([alp[one] for one in ids]))
    else:
        print('a'*N)

Submission status: Wrong Answer

Solution code:
N = int(input())
alp = [chr(i) for i in range(97, 97+26)]
for i in range(min(N, 26)):
    s = 'a'*(N-i)
    for j in range(i):
        s+=alp[j+1]
    print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []
def dfs(s):
    if(len(s) == N):
        ans.append(s)
        return
    else:
        next_str = ord(s[-1]) + 1
        for i in range(ord("a"), next_str + 1):
            dfs(s + chr(i))

dfs("a")

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

Submission status: Wrong Answer

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

for i in range(N):
    if i>25:
        bottom=bottom+"z"
    else:
        bottom=bottom+alpha[i]
    S=S+"a"

C=0
S=""
def F(S,loop,N,C):
    for i in range(0,loop):
        if N==C+1:
            print(S+bottom[i])
        else:
            F(S+bottom[i],i+2,N,C+1)
    return None
            
F(S,1,N,C)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
q = ["0"]
cnt = 0
while cnt < n - 1:
    qt = []
    for num in q:
        lastnum = num[-1]
        for i in range(int(lastnum) + 2):
            qt += [num + str(i)]
    q = qt.copy()
    cnt += 1
    
alp = "abcdefghijkl"
    
def show(num):
    ret = ""
    l = len(num)
    for i in range(l):
        ret += alp[int(num[i])]
    return ret

q.sort()

for num in q:
    print(show(num))

Submission status: Wrong Answer

Solution code:
n = int(input())
q = ["0"]
cnt = 0
while cnt < n - 1:
    qt = []
    for num in q:
        lastnum = num[-1]
        for i in range(int(lastnum) + 2):
            qt += [num + str(i)]
    q = qt.copy()
    cnt += 1
    
alp = "abcdefghijkl"
    
def show(num):
    ret = ""
    l = len(num)
    for i in range(l):
        ret += alp[int(num[i])]
    return ret

for num in q:
    print(show(num))

Submission status: Wrong Answer

Solution code:
N = int(input())
alphabet_list = [chr(i) for i in range(97, 97 + N)]

import collections

previous_list = ["a"]
for i in range(1, N):
    out_list = []
    for a in previous_list:
        # print(len(collections.Counter(a)))
        for al in alphabet_list[:len(collections.Counter(a))+2]:
            # print(a + al)
            out_list.append(a+al)
    previous_list = out_list

for out in previous_list:
    print(out)

Submission status: Wrong Answer

Solution code:
#N=4まで
N=int(input())
P="abcdefghij"

print(P[0]*N)
if N>1:
  print(P[0]*(N-1)+P[1])
  if N>2:
    for l in range(2):
      print(P[0]*(N-2)+P[1]+P[l])
    print(P[0]*(N-2)+P[1]+P[2])
    if N>3:
      for m in range(3):
        for n in range(3):
          print(P[0]*(N-3)+P[1]+P[m]+P[n])
      print(P[0]*(N-3)+P[1]+P[2]+P[3])