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:
#!/usr/bin/env python
# coding: utf-8

# In[56]:


N = int(input())


# In[59]:


num2alpha = lambda c: chr(c%26+97)


# In[61]:


ans = []
for i in range(2**(N-1),2**N):
    mylist = list(format(i,"b"))
    word = ""
    cnt = -1
    for x in mylist:
        if x == "1":
            cnt += 1
        word += num2alpha(cnt)
    ans += [word]
for w in ans:
    print(w)


# In[ ]:

Submission status: Wrong Answer

Solution code:
alphabet = 'abcdefghijklmnopqrstuvwxyz'

def print_tree(node,bfr=[]):
  if len(node)==1: #ex. node = [0]
    for i in bfr:
      print(alphabet[i],end='')
    print(alphabet[node[0]])
  else:# ex. node = [0,[[0],[1]]]
    add = node[0]
    for next_node in node[1]:
      print_tree(next_node,bfr+[add])
    
def N_Str(N,root=0):
  if N == 1:
    return [root]
  else:
    nexts = [N_Str(N-1,i) for i in range(root+2)]
    return [root,nexts]

N = int(input())
#print(N_Str(N))
print_tree(N_Str(N))

Submission status: Wrong Answer

Solution code:
N=int(input())
S='abcdefghijklmnopqrstuvwxyz'
A=['a']
for _ in range(N-1):
    now=[]
    for a in A:
        b=S.index(a[-1])+1
        for i in range(b+1):
            now.append(a+S[i])
    A=now.copy()
A.sort()
for a in A:
    print(a)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

ans=[]

st='a'

temp=0
now=0

def dfs(st,n,now,temp):
  if now==n-1:
    ans.append(st)
  else:
    for f in range(0,temp+2):
      dfs(st+al[f],n,now+1,f)
    
dfs(st,n,0,0)

for h in ans:
  print(h)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

ans=[]

st='a'

temp=0
now=0

def dfs(st,n,now,temp):
  if now==n-1:
    ans.append(st)
  else:
    dfs(st+al[temp],n,now+1,temp)
    dfs(st+al[temp+1],n,now+1,temp+1)
    
dfs(st,n,0,0)

for h in ans:
  print(h)

Submission status: Wrong Answer

Solution code:
#
# panasonic2020b d
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1"""
        output = """a"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2"""
        output = """aa
ab"""
        self.assertIO(input, output)


def resolve():
    global N
    N = int(input())

    T = []
    func(1, "", T)

    for t in T:
        print(t)


def func(p, w, T):
    if len(w) == N:
        T.append(w)
        return

    for i in range(min(p, N)):
        nw = w + chr(ord("a")+i)
        func(p+1, nw, T)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
l = []
for i in range(1,N+1):
  print("".join(["a"]*(N - i) + [chr(ord("a") + j) for j in range(i)]))

Submission status: Wrong Answer

Solution code:
def dfs(cnt, s, now):
    if cnt == n:
        ans.append(s)
        return
    for i in range(now+1):
        dfs(cnt+1, s+al[i], i+1)

n = int(input())
ans = []
al = [chr(i) for i in range(97, 97+26)]
dfs(0, "", 0)
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())

def main(l):
  tmp = []
  for s in l:
    n = ord(s[-1])
    for i in range(97, n+2):
      tmp.append(s+chr(i))
  return tmp
  
l = ['a']
for i in range(1, N):
  l = main(l)
for i in range(len(l)):
  print(l[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
from copy import copy

L = ["a"]
if n == 1:
    print(L[0])
    exit()
    
for i in range(n-1):
    li = []
    for s in L:
        max1 = s[-1]
        S = ""
        for j in range(ord(max1)-95):
            S = s + chr(97+j)
            #print(ord(max1)-95,chr(ord(max1)+j))
            li.append(S)
    L = copy(li)
    
for i in range(len(L)):
    print(L[i])

Submission status: Wrong Answer

Solution code:
from itertools import permutations

N=int(input())
ans = ['']*N

al = 'abcdefghij'
d = {al[i]:i for i in range(N)}

def dfs(h=[]):
    if len(h)==N:
        print(''.join(h))
        return
    for i in range(d[h[-1]]+2):
        h.append(al[i])
        dfs(h)
        h.pop()
    return
  
dfs(['a'])

Submission status: Wrong Answer

Solution code:
N=int(input())
alpha=["a","b","c","d","e","f","g","h","i","j"]
from collections import deque
que=deque(["0"])
ans=[]
after=[]
while que:
   A=que.popleft()
   after.append(A)
   if len(A)==N:
      ans.append(A)
   else:
      if A+str(int(A[-1])+1) not in after:
         que.append(A+str(int(A[-1])+1))
      if A+str(int(A[-1])) not in after:
         que.append(A+str(int(A[-1])))
      if A+str(int(A[-1])-1) not in after and int(A[-1])!=0:
         que.append(A+str(int(A[-1])-1))
l=[]
for i in ans:
   tmp=""
   for j in i:
      tmp+=alpha[int(j)]
   l.append(tmp)
l.sort()
for i in l:print(i)

Submission status: Wrong Answer

Solution code:
N=int(input())
alpha=["a","b","c","d","e","f","g","h","i","j"]
from collections import deque
que=deque(["0"])
ans=[]
after=[]
while que:
   A=que.popleft()
   after.append(A)
   if len(A)==N:
      ans.append(A)
   else:
      if A+str(int(A[-1])+1) not in after:
         que.append(A+str(int(A[-1])+1))
      if A+str(int(A[-1])) not in after:
         que.append(A+str(int(A[-1])))
      if A+str(int(A[-1])-1) not in after and int(A[-1])!=0:
         que.append(A+str(int(A[-1])-1))
for i in ans:
   tmp=""
   for j in i:
      tmp+=alpha[int(j)]
   print(tmp)

Submission status: Wrong Answer

Solution code:
N = int(input())

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


def dfs(ans, keep_num, n):
    if n == N - 1:
        for i in range(keep_num + 2):
            print(ans + lis[i])
    else:
        for i in range(n + 1):
            dfs(ans + lis[i], max(i, keep_num), n + 1)


dfs('', -1, 0)

Submission status: Wrong Answer

Solution code:
N = int(input())

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


def dfs(ans, keep_num, n):
    if n == N - 1:
        for i in range(keep_num + 2):
            print(ans + lis[i])
    else:
        for i in range(n + 1):
            dfs(ans + lis[i], max(i, keep_num), n + 1)


dfs('', 0, 0)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
y = [chr(97+i) for i in range(n)]
u = list(itertools.combinations_with_replacement(y, n))
u = u[:(n*n+1)//2]
for i in u:
    print("".join(i))

Submission status: Wrong Answer

Solution code:
N = int(input())

tarans = {'1':'a','2':'b','3':'c','4':'d','5':'e','6':'f','7':'g','8':'h','9':'i'}
ans = ['1']

for i in range(2,N+1):
    temp = []

    for num in ans:
        for k in range(2):
            s = '1'
            for j in range(len(num)):
                s = s + str(int(num[j])+k)
            temp.append(s)
    ans = temp

ans.sort()

for s in ans:
    print(s.replace("10",'j').translate(str.maketrans(tarans)))

Submission status: Wrong Answer

Solution code:
n = int(input())

L = []
for i in range(n):
    R = []
    if L == []:
        R.append("a")
    else:
        for j in range(len(L)):
            p1 = L[j] + chr(ord(L[j][-1]))
            R.append(p1)
            
            p2 = L[j] + chr(ord(L[j][-1])+1)
            R.append(p2)
            
            k = 1
            while ord(L[j][-1]) - ord("a") >= k:
                p3 = L[j] + chr(ord(L[j][-1])-k)
                R.append(p3)
                
                k += 1

            
    L = R

L = sorted(L)

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

Submission status: Wrong Answer

Solution code:
n = int(input())

L = []
for i in range(n):
    R = []
    if L == []:
        R.append("a")
    else:
        for j in range(len(L)):
            p1 = L[j] + chr(ord(L[j][-1]))
            R.append(p1)
            
            p2 = L[j] + chr(ord(L[j][-1])+1)
            R.append(p2)
            
            if ord(L[j][-1]) - ord("a") >= 1:
                p3 = L[j] + chr(ord(L[j][-1])-1)
                R.append(p3)
            
    L = R

L = sorted(L)

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

Submission status: Wrong Answer

Solution code:
n = int(input())

L = []
for i in range(n):
    R = []
    if L == []:
        R.append("a")
    else:
        for j in range(len(L)):
            p1 = L[j] + chr(ord(L[j][-1]))
            R.append(p1)
            
            p2 = L[j] + chr(ord(L[j][-1])+1)
            R.append(p2)
            
    L = R

L = sorted(L)

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

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(read())

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

def dfs(S, i):
    if len(S) == N:
        return ''.join(S)
    for j in range(i):
        for w in dfs(S + [alphabets[j]], i):
            return w
    for w in dfs(S + [alphabets[i]], i + 1):
        return w

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

Submission status: Wrong Answer

Solution code:
N = int(input())

a_num = 97

def dfs(s, n, cnt): #s: 現在の文字列, n: 残りの文字数, cnt: 現在の文字列の最大の値
    if n == 0:
        print(s)
        return
    for i in range(cnt+2):
        if i == cnt+1:
            dfs(s+chr(a_num+i), n-1, cnt+i)
        else:
            dfs(s+chr(a_num+i), n-1, cnt)

dfs("a", N-1, 0)

Submission status: Wrong Answer

Solution code:
N = int(input())

a_num = 97

def dfs(s, n, cnt): #s: 現在の文字列, n: 残りの文字数, cnt: 現在の文字列の最大の値
    if n == 0:
        print(s)
        return
    for i in range(cnt+2):
        dfs(s+chr(a_num+i), n-1, cnt+i)

dfs("a", N-1, 0)

Submission status: Wrong Answer

Solution code:
N = int(input())

a_num = 97

def dfs(s, n, cnt): 
    if n == 0:
        print(s)
        return
    for i in range(cnt+2):
        dfs(s+chr(a_num+i), n-1, cnt+i)

dfs("a", N-1, 0)

Submission status: Wrong Answer

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def dfs(m, N):
    if N == 0:
        yield []
    else:
        for i in range(0, m+1):
            for solution in dfs(m+1, N-1):
                yield [i]+solution

def solve():
    '''
    a
    '''
    N = read_int()
    alphabets = 'abcdefghij'
    for solution in dfs(0, N):
        print(''.join(alphabets[i] for i in solution))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = []
alphabet = [chr(i) for i in range(97, 97+26)]
alphabet_dict = {}
for i, a in enumerate(alphabet):
    alphabet_dict[a] = i
def dfs(A):
    if len(A) == n:
        ls.append(A)
        return
    l = alphabet_dict[A[-1]]
    for i in range(l+2):
        A += alphabet[i]
        dfs(A)
        A = A[:-1]
dfs('a')
ls.sort()
for i in range(len(ls)):
    print(ls[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = []
alphabet = [chr(i) for i in range(97, 97+26)]
alphabet_dict = {}
for i, a in enumerate(alphabet):
    alphabet_dict[a] = i
def dfs(A):
    if len(A) == n:
        ls.append(A)
        return
    l = alphabet_dict[A[-1]]
    for nex in [l-1,l,l+1]:
        if 0<= nex:
            A += alphabet[nex]
            dfs(A)
            A = A[:-1]
dfs('a')
ls.sort()
for i in range(len(ls)):
    print(ls[i])

Submission status: Wrong Answer

Solution code:
def main():
    from string import ascii_lowercase
    N = int(input())
    ascii_dic = {i: a for i, a in enumerate(ascii_lowercase)}
    ascii_rdic = {a: i for i, a in enumerate(ascii_lowercase)}

    def dfs(A):
        if len(A) == N:
            print("".join(A))
            return
        if not A:
            dfs(["a"])
        else:
            s = ascii_rdic[A[-1]]
            for i in range(s+2):
                dfs(A + [ascii_dic[i]])

    dfs([])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
alphabet = [chr(i) for i in range(97, 97+26)]
ls = []
# 最初はmake('',3,0)
def make(now):
    if len(now) == n:
        global ls
        ls.append(now)
    for i in range(1,n-len(now)+1):
        nex = now
        if now != '':
            next_chr = alphabet[alphabet.index(now[-1])+1]
        else:
            next_chr = 'a'
        for _ in range(i):
            nex += next_chr
        make(nex)
make('')
m = len(ls)
for i in range(m-1,-1,-1):
    print(ls[i])

Submission status: Wrong Answer

Solution code:

def main():
	n  = int(input())
	ans = []
	queue=[]
	queue.append('a')
	while len(queue)>0:
		now = queue.pop(0)
		if len(now)==n:
			ans.append(now)
			continue
		lst = now[len(now)-1]
		diff = now + chr(ord(lst)-ord('a')+1+ord('a'))
		same = now+chr(ord(lst))
		queue.append(diff)
		queue.append(same)
	ans.sort()
	for i in ans:
		print(i)
if __name__=="__main__":
	main()

Submission status: Wrong Answer

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    ans = ["a"]
    alt = [chr(ord("a") + i) for i in range(n)]
    for i in range(n-1):
        ans = [s+x for s in ans for x in alt [0:len(set(ans))+1]]
    for i in ans:
        print(i)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = []
def dfs(A):
    if len(A) == n:
        ans.append(''.join(A))
        return
    for i in range(len(A)+1):
        v = chr(i+ord('a'))
        A.append(v)
        dfs(A)
        A.pop()

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

Submission status: Wrong Answer

Solution code:
import math


def solve():
    N = int(input())
    ans = {}
    for j in range(1 << N):
        A = ['a'] * N
        lowercase = list('bcdefghijklmnopqrstuvwxyz')
        for i in reversed(range(N)):
            # print(i, j, (1 << i) & j, A)
            if (1 << i) & j:
                idx = i
                if idx == N - 1 or A[idx] > 'a':
                    continue
                A[idx] = lowercase.pop(0)
                # print(i, j, idx, A, '#')
        # print(i, j, ''.join(reversed(A)))
        ans.update({''.join(reversed(A)): 0})

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


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import deque
D1 = {i:chr(i+96) for i in range(1,27)}
D2 = {val:key for key,val in D1.items()}

N = int(input())
heap = deque([(D1[1],1)])
A = []
while heap:
    a,n = heap.popleft()
    if n<N:
        j = D2[a[-1]]
        for i in range(1,min(j+1,26)+1):
            heap.append((a+D1[i],n+1))
    if n==N:
        A.append(a)
A = sorted(list(set(A)))
for i in range(len(A)):
    print(A[i])

Submission status: Wrong Answer

Solution code:
from collections import deque
D1 = {i:chr(i+96) for i in range(1,27)}
D2 = {val:key for key,val in D1.items()}

N = int(input())
heap = deque([(D1[1],1)])
A = []
while heap:
    a,n = heap.popleft()
    if n<N:
        j = D2[a[-1]]
        for i in range(1,min(j+1,26)+1):
            heap.append((a+D1[i],n+1))
    if n==N:
        A.append(a)
A = sorted(A)
for i in range(len(A)):
    print(A[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
s = "a"
ans = []
def dfs(s,n):
  if len(s) == n:
    ans.append(s)
    return
  last = ord(s[-1])
  limit = chr(last+1)
  for i in range(26):
    temp = chr(97+i)
    if temp <= limit:
      dfs(s+temp,n)
dfs(s,N)
print(*ans,sep="\n")

Submission status: Wrong Answer

Solution code:

N = int(input())


def func(x):
    if len(x) == N:
        print("".join(x))
        return

    last = ord(x[-1]) - ord("a") + 1 if x else 0
    for i in range(min(26, last) + 1):
        x.append(chr(ord("a") + i))
        func(x)
        x.pop()


func([])

Submission status: Wrong Answer

Solution code:
import itertools
A =[chr(ord('a') + i) for i in range(26)]
N = int(input())
for i in itertools.combinations_with_replacement(A[:N],N):
    if i[0] != "a":
        continue
    
    for j in range(1,N):
        if ord(i[j]) -ord(i[j-1])>1:
            break
        
    else:
        print(*i,sep="")

Submission status: Wrong Answer

Solution code:
from copy import copy
n = int(input())
data = ["a"] * n
ans = []

def print_str(ans, data, i):
    if i == n:
        return 
    ans.append("".join(data))
    mx = max(data[i] for i in range(n))
    while ord(data[i]) + 1 <= ord(mx) + 2:
        s = copy(data)
        ans.append("".join(data))
        print_str(ans, s, i + 1)
        data[i] = chr(ord(data[i]) + 1)
    data = ["a"] * n
    print_str(ans, data, i + 1)

print_str(ans, data, 1)
ans = sorted(set(ans))
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
from copy import copy
n = int(input())
data = ["a"] * n
ans = []

def print_str(ans, data, i):
    if i == n:
        return 
    ans.append("".join(data))
    mx = max(data[i] for i in range(n))
    while ord(data[i]) + 1 <= ord(mx) + 1:
        data[i] = chr(ord(data[i]) + 1)
        s = copy(data)
        ans.append("".join(data))
        print_str(ans, s, i + 1)
    data = ["a"] * n
    print_str(ans, data, i + 1)

print_str(ans, data, 1)
ans = sorted(set(ans))
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:

n = int(input())
data = ["a"] * n
ans = ["".join(data)]
def print_str(ans, data, i):
    if i == n:
        return
    data[i] = "a"
    ans.append("".join(data))
    while ord(data[i]) + 1 <= ord(data[i - 1]) + 1:
        data[i] = chr(ord(data[i]) + 1)
        ans.append("".join(data))
        print_str(ans, data, i + 1)
    data = ["a"] * n
    print_str(ans, data, i + 1)
print_str(ans, data, 1)
ans = sorted(set(ans))
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:

n = int(input())
data = ["a"] * n
ans = ["".join(data)]
def print_str(ans, data, i):
    if i == n:
        return
    while ord(data[i]) + 1 <= ord(data[i - 1]) + 1:
        data[i] = chr(ord(data[i]) + 1)
        ans.append("".join(data))
        print_str(ans, data, i + 1)
    data = ["a"] * n
    print_str(ans, data, i + 1)
print_str(ans, data, 1)
ans = sorted(set(ans))
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:

n = int(input())
data = ["a"] * n
ans = ["".join(data)]
def print_str(ans, data, i):
    if i == n:
        return
    while ord(data[i]) + 1 <= ord(data[i - 1]) + 1:
        data[i] = chr(ord(data[i]) + 1)
        ans.append("".join(data))
        print_str(ans, data, i + 1)

print_str(ans, data, 1)
ans = sorted(set(ans))
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:

n = int(input())
ans = []
data = ["a"] * n

def print_str(ans, data, i):
    if i == n:
        return
    for j in range(i + 1):
        data[i] = chr(ord(data[i]) + j)
        ans.append("".join(data))
        print_str(ans, data, i + 1)
        data[i] = "a"

print_str(ans, data, 0)
ans = sorted(set(ans))
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import math
import queue

n = int(input())

q = queue.Queue()
q.put("a")

while True:
    c = q.get()
    if len(c) > n:
        break
    if len(c) == n:
        print(c)

    nx = c[-1]
    if nx != "a":
        q.put(c + chr(ord(nx) - 1))
    q.put(c + nx)
    q.put(c + chr(ord(nx) + 1))

Submission status: Wrong Answer

Solution code:
import itertools
#再帰関数のときのRE予防
import sys
sys.setrecursionlimit(312467) 
N = int(input())
List = []
def dfs(S):
    List.append(S)
    if len(S) < N:
      for i in range(ord("a"), ord(S[len(S)-1])+2):
        dfs(S+[chr(i)])
    return
dfs(["a"])
for i in List:
  if len(i) == N:
    print("".join(i))
  elif len(i) > N:
    break

Submission status: Wrong Answer

Solution code:
def dfs(S):
    if len(S) == N:
        print(S)
        return
    res = ord(S[-1])
    for i in range(a, res+2):
        dfs(S+chr(i))
    return

N = int(input())
a = ord('a')
dfs('a')

Submission status: Wrong Answer

Solution code:
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    d = ['a']
    for _ in range(N-1):
        tmp = []
        while d:
            w = d.pop()
            tmp.append(w+w[-1])
            tmp.append(w+chr(ord(w[-1])+1))
        d = tmp[:]
    d.sort()
    print(*d, sep='\n')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)
N = int(input())


def main(s, o, n):
    n += 1
    if n == N:
        print(s)
    else:
        for i in range(97, o + 2):
            main(s + chr(i), i, n)


main("a", 97, 0)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=["a","b","c","d","e","f","g","h","i","j"]
a="a"
ans=["a"]
for i in range(1,n):
    tt=[]
    for j in l[:i+1]:
        for k in ans:
            tt.append(k+j)
    ans=tt
ans.sort()
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
DP = [[] for i in range(10)]
DP[0] = ['a']
for i in range(9):
    for w in DP[i]:
        num = alpha.index(w[-1])
        for j in range(num+1):
            DP[i+1].append(w + alpha[j])
        if num + 1 <= 9:
            DP[i+1].append(w + alpha[num+1])
N  = int(input())
for w in DP[N-1]:
    print(w)

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())

N = I()

ANS = [[] for _ in range(N+1)]

for i in range(1,N+1):
    if i == 1:
        ANS[i].append('a')
    else:
        for a in ANS[i-1]:
            for j in range(97,ord(a[-1])+2):
                ANS[i].append(a+chr(j))
print(*ANS[N],sep='\n')

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())

N = I()

ANS = [[] for _ in range(N+1)]

for i in range(1,N+1):
    if i == 1:
        ANS[i].append('a')
    else:
        for a in ANS[i-1]:
            ANS[i].append(a+a[-1])
            ANS[i].append(a+chr(ord(a[-1])+1))
print(*ANS[N],sep='\n')

Submission status: Wrong Answer

Solution code:
#coding: utf-8

n = int(input())

def f(level):
    if level == 1:
        return ["a"]
    ret = []
    for x in f(level-1):
        for c in range(ord("a"), ord(x[-1])+2):
            ret.append(x + chr(c))
    return ret

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

dfs([], 0)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

# x1+x2+x3+...xN = X (x>=0) 
def nHk_list(N,X):
    if N == 0: return []
    elif N == 1: return [[X]]

    border = [i for i in range(X+1)]
    res = []
    for S in itertools.combinations_with_replacement(border, N-1):
        # print(S)
        pre = 0
        sub = []
        for s in S:
            sub.append(s-pre)
            pre = s
        sub.append(X-pre)
        res.append(sub)
    return res


INF=10**20
def main():
    N=ii()
    alphabet = ["a","b","c","d","e","f","g","h","i","j"]

    ans = []
    for c in range(1,N+1):
        # print("___\nc",c)
        for X in nHk_list(c,N-c):
            # print("X:",X,"c:",c,"N-c:",N-c)
            V = []
            for i in range(len(X)):
                x = X[i]
                V.append(list(itertools.combinations_with_replacement(alphabet[:i+1],x)))

            # print("V",V)
            U = itertools.product(*V)
            base = alphabet[:c]
            for u in U:
                char = ""
                for i in range(c):
                    char += alphabet[i] + "".join(list(u[i]))
        
                ans.append(char)
        
    
    ans.sort()
    # ans.append("".join(alphabet[:N]))
    print(*ans,sep='\n')

            
            

        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

# x1+x2+x3+...xN = X (x>=0) 
def nHk_list(N,X):
    if N == 0: return []
    elif N == 1: return [[X]]

    border = [i for i in range(X+1)]
    res = []
    for S in itertools.combinations_with_replacement(border, N-1):
        # print(S)
        pre = 0
        sub = []
        for s in S:
            sub.append(s-pre)
            pre = s
        sub.append(X-pre)
        res.append(sub)
    return res


INF=10**20
def main():
    N=ii()
    alphabet = ["a","b","c","d","e","f","g","h","i","j"]

    ans = []
    for c in range(1,N+1):
        # print("___\nc",c)
        for X in nHk_list(c,N-c):
            # print("X:",X,"c:",c,"N-c:",N-c)
            V = []
            for i in range(len(X)):
                x = X[i]
                V.append(list(itertools.combinations_with_replacement(alphabet[:i+1],x)))

            # print("V",V)
            U = itertools.product(*V)
            base = alphabet[:c]
            for u in U:
                char = ""
                for i in range(c):
                    char += alphabet[i] + "".join(list(u[i]))
        
                ans.append(char)
        
    
    # ans.append("".join(alphabet[:N]))
    print(*ans,sep='\n')

            
            

        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

# x1+x2+x3+...xN = X (x>=0) 
def nHk_list(N,X):
    if X == 0: return []
    border = [i for i in range(X)]
    res = []
    for S in itertools.combinations(border, N-1):
        pre = -1
        sub = []
        for s in S:
            sub.append(s-pre)
            pre = s
        sub.append(X-1-pre)
        res.append(sub)
    return res


INF=10**20
def main():
    N=ii()
    alphabet = ["a","b","c","d","e","f","g","h","i","j"]

    ans = []
    for c in range(1,N+1):
        # print("___\nc",c)
        for X in nHk_list(c,N-c):
            # print("X",X)
            V = []
            for i in range(len(X)):
                x = X[i]
                V.append(list(itertools.combinations_with_replacement(alphabet[:i+1],x)))

            # print("V",V)
            U = itertools.product(*V)
            base = alphabet[:c]
            for u in U:
                char = ""
                for i in range(c):
                    char += alphabet[i] + "".join(list(u[i]))
        
                ans.append(char)
        
    
    ans.append("".join(alphabet[:N]))
    print(*ans,sep='\n')

            
            

        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import string

def dfs(s,n):
    if n == N:
        print(s)
        return
    else:
        # print(s,n)
        for i in range(N-n):
            dfs(string.ascii_lowercase[i]+s,n+1)

N = int(input())
dfs("",0)

Submission status: Wrong Answer

Solution code:
n=int(input())

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,s):
  if keta==n:
    global ans
    ans.append(s)
    return

  for i in range(keta+1):
    dfs(keta+1,s+abc[i])

ans=[]
dfs(1,'a')

for i in ans:
  print(i)

Submission status: Wrong Answer

Solution code:
n=int(input())

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,s):
  if keta==n:
    global ans
    ans.append(s)
    return

  inx=abc.index(s[-1])
  for i in range(inx+2):
    dfs(keta+1,s+abc[i])

ans=[]
dfs(1,'a')

for i in ans:
  print(i)

Submission status: Wrong Answer

Solution code:
n=int(input())

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,s):
  if keta==n:
    global ans
    ans.append(s)
    return

  inx=abc.index(s[-1])
  for i in range(inx+2):
    dfs(keta+1,s+abc[i])

ans=[]
dfs(1,'a')

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

Submission status: Wrong Answer

Solution code:
n=int(input())

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,s):
  if keta==n:
    global ans
    ans.append(s)
    return

  inx=abc.index(s[-1])
  for i in range(inx+2):
    dfs(keta+1,s+abc[i])

ans=[]
dfs(1,'a')

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

Submission status: Wrong Answer

Solution code:
n=int(input())

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,s):
  if keta==n:
    global ans
    ans.append(s)
    return

  for i in range(keta+1):
    dfs(keta+1,s+abc[i])

ans=[]
dfs(1,'a')

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

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def dfs(s,d,i):
    for j in range(i+1):
        s[d] = chr(ord('a')+j)
        if d < len(s) - 1:
            dfs(s, d+1, j+1)
        else:
            a.add("".join(s))

n = INT()
s = ['a']*n
a = set()
dfs(s, 0, 0)
b = sorted(list(a))
for x in b:
    print(x)