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:
import itertools
import sys
from string import ascii_lowercase

input = sys.stdin.readline


class Solution:
    def main(self):
        n = int(input())
        done = []
        for i in range(1, n + 1):
            moji = ascii_lowercase[0:i]
            for comb in itertools.combinations_with_replacement(moji, n):
                temp = []
                cnt = 0
                before = ""
                for i, c in enumerate(comb):
                    if i == 0:
                        cnt += 1

                    elif before == c:
                        cnt += 1
                        if i == len(comb) - 1:
                            temp.append(cnt)
                    else:
                        temp.append(cnt)
                        cnt = 1
                    before = c

                f = False
                for d in done:
                    if temp == d[0]:
                        if len(set(comb)) == d[1]:
                            f = True
                            break
                if f:
                    continue
                else:
                    print(''.join(comb))
                    done.append((temp, len(set(comb))))


# Run main
if __name__ == '__main__':
    Solution().main()

Submission status: Wrong Answer

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

al = ['a', 'b', 'c' , 'd', 'e', 'f', 'g', 'h', 'i', 'j']
list = []
for i in range(n):
    if i ==0:
        list.append(al[0])
    else:
        lis = copy.deepcopy(list)
        for x in lis:
            flag = False
            for y in al[:i+1]:
                if y in x:
                    list.append(x+y)
                else:
                    if flag == False:
                        list.append(x+y)
                        flag = True

for x in list:
    print(x)

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
r=[]
for s in itertools.combinations_with_replacement([chr(i) for i in range(97, 97+26)],n):
    for _r in r:
        for p in itertools.permutations(range(0,n), 2):
            if ((_r[p[0]]==_r[p[1]]) and (s[p[0]]==s[p[1]])) or ((_r[p[0]]!=_r[p[1]]) and (s[p[0]]!=s[p[1]])):
                continue
            else:
                break
        else:
            break
    else:
        r.append(s)
for i in range(len(r)):
    print(''.join(r[i]))

Submission status: Wrong Answer

Solution code:
import string
ans = []
N = int(input())

def rec(s, i):
    if len(s) == N:
        ans.append(s)
        return
    # tmp = set()
    for c in string.ascii_lowercase[:i + 1]:
        # if len(set(s + c)) in tmp:
        #     continue
        # tmp.add(len(set(s + c)))
        rec(s + c, i + 1)

rec("a", 1)
ans.sort()
for x in ans:
    print(x)

Submission status: Wrong Answer

Solution code:
# D - String Equivalence
# abc='abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
from itertools import groupby
abc='abcdefghij'
# def dfs(n,s):
#     if n==0:
#         print(s)
#         return
#     for i in range(26):
#     dfs(n-1,s+'a')
n=int(input())
ans=set()
abc=list(abc)
# i：aを使う個数　文字列の種類数
for i in range(1,n+1):
    init_abc=[]
    init_abc=abc[:i]+(n-i)*['a']
    # print(init_abc)
    # l=list(init_abc)
    for l in permutations(init_abc):
        t_str=''
        # print(l)
        l=list(l)
        t_str=''.join(l)
        ans.add(t_str)
    # print('===')
ans=list(ans)
ans.sort()
cnt=set()
for aa in ans:
    if aa[0]=='a':
        print(aa)

Submission status: Wrong Answer

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


if N == 1:
    print('a')
elif N == 2:
    print('aa')
    print('ab')
else:
    DONELIST = ['aa']
    PROCESSLIST = ['ab']
    PROCESSLIST2 = []
    for i in range(1, N-1):
        for j in range(len(DONELIST)):
            DONELIST[j] = 'a' + DONELIST[j]
        for j in range(len(PROCESSLIST)):
            DONELIST.append('a' + PROCESSLIST[j])
            for k in range(i+1):
                PROCESSLIST2.append(PROCESSLIST[j] + chr(97+k))

        PROCESSLIST2.append(PROCESSLIST[-1] + chr(97+len(PROCESSLIST[-1])))
        PROCESSLIST = PROCESSLIST2
        PROCESSLIST2 = []

    for w in DONELIST:
        print(w)
    for w in PROCESSLIST:
        print(w)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
N = int(input())
N -= 1

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


def dfs(s, depth, maxS):

    if depth == N:
        print(s)
        return

    for i in range(maxS+1):
        dfs(s + S[i], depth+1, i+1)


dfs("a", 0, 1)

Submission status: Wrong Answer

Solution code:
i = input()
 
if int(i) == 1:
  print('a')
elif int(i) == 2:
  print('aa')
  print('ab')
else:
  x = (int(i) - 2)
  y = 3 ** x
  z = 2 ** x
  print(y + z)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n==1:
    print('a')
elif n==2:
    print('aa')
    print('ab')
elif n==3:
    print('aaa')
    print('aab')
    print('aba')
elif n==4:
    print('aaaa')
    print('aaab')
    print('aaba')
    print('aabb')
elif n==5:
    print('aaaaa')
    print('aaaab')
    print('aaaba')
    print('aaabb')
    print('aabaa')
elif n==6:
    print('aaaaaa')
    print('aaaaab')
    print('aaaaba')
    print('aaaabb')
    print('aaabaa')
    print('aaabab')
elif n==7:
    print('aaaaaaa')
    print('aaaaaab')
    print('aaaaaba')
    print('aaaaabb')
    print('aaaabaa')
    print('aaaabab')
    print('aaaabba')
elif n==8:
    print('aaaaaaaa')
    print('aaaaaaab')
    print('aaaaaaba')
    print('aaaaaabb')
    print('aaaaabaa')
    print('aaaaabab')
    print('aaaaabba')
    print('aaaaabbb')
elif n==9:
    print('aaaaaaaaa')
    print('aaaaaaaab')
    print('aaaaaaaba')
    print('aaaaaaabb')
    print('aaaaaabaa')
    print('aaaaaabab')
    print('aaaaaabba')
    print('aaaaaabbb')
    print('aaaaabaaa')
elif n==10:
    print('aaaaaaaaaa')
    print('aaaaaaaaab')
    print('aaaaaaaaba')
    print('aaaaaaaabb')
    print('aaaaaaabaa')
    print('aaaaaaabab')
    print('aaaaaaabba')
    print('aaaaaaabbb')
    print('aaaaaabaab')
    print('aaaaaababa')

Submission status: Wrong Answer

Solution code:
N = int(input())

alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
ans = []
original = []
for i in range(N):
    original.append("a")

usechr = original[:]
for chr in range(N):
    usechr = original[:]
    ans.append("".join(usechr[:-chr-1] + alphabet[:chr+1]))
ans.sort()

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
import math

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

N = int(input())
if N == 1:
  print(al[0])
else:
  S = [[""] * math.factorial(i+1) for i in range(N-1)]
  S[0][0] = al[0]

  for i in range(1, N-1):
    prev_S = S[i-1]
    al_use = al[:i+1]
    S[i] = [s + a for s in prev_S for a in al_use]

  prev_S = S[N-2]
  al_use = al[:N]
  for s in prev_S:
    for a in al_use:
      print(s + a)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    s = 'abcdefghijkl'
    ans = []
    from heapq import heapify, heappop, heappush

    def f(t: str):
        if len(t) == N:
            heappush(ans, t)
            return
        
        if len(t) >= 2:
            x = s.index(max(list(t)))+1
        else:
            x = len(t)+1
        for i in range(x):
            f(t+s[i])


    
    f('')
    # print(ans)
    c = 0
    # print(len(ans))
    while len(ans):
        print(heappop(ans))
        c += 1


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

L =  [[[] for i in range(10)] for j in range(10)]
#print(L)
L[0][0].append('a')
#print(L[0])
for i in range(1, n):
    for j in range(i+1):
        if j == 0:
            t = chr(j + ord('a'))
            for c in L[i-1][j]:
                L[i][j].append(c+t)
        else:
            t = chr(j + ord('a'))
            for c in L[i-1][j-1]:
                L[i][j].append(c+t)
            for c in L[i-1][j]:
                L[i][j].append(c+t)
#print(L)

ans = []
for i in range(10):
    for c in L[n-1][i]:
        ans.append(c)
ans.sort()
for c in ans:
    print(c)

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
ans = [0]

if N > 1:
  ans1 = []
  a = max(ans)+1
  for i in range(a+1):
    c = copy.copy(ans)
    c.append(i)
    ans1.append(c)
    
if N > 2:
  ans2 = []
  for j in range(len(ans1)):
    a = max(ans1[j])+1
    for i in range(a+1):
      c = copy.copy(ans1[j])
      c.append(i)
      ans2.append(c)

if N > 3:
  ans3 = []
  for j in range(len(ans2)):
    a = max(ans2[j])+1
    for i in range(a+1):
      c = copy.copy(ans2[j])
      c.append(i)
      ans3.append(c)
      

if N > 4:
  ans4 = []
  for j in range(len(ans3)):
    a = max(ans3[j])+1
    for i in range(a+1):
      c = copy.copy(ans3[j])
      c.append(i)
      ans4.append(c)


if N > 5:
  ans5 = []
  for j in range(len(ans4)):
    a = max(ans4[j])+1
    for i in range(a+1):
      c = copy.copy(ans4[j])
      c.append(i)
      ans5.append(c)

      
if N > 6:
  ans6 = []
  for j in range(len(ans5)):
    a = max(ans5[j])+1
    for i in range(a+1):
      c = copy.copy(ans5[j])
      c.append(i)
      ans6.append(c)

if N > 7:
  ans7 = []
  for j in range(len(ans6)):
    a = max(ans6[j])+1
    for i in range(a+1):
      c = copy.copy(ans6[j])
      c.append(i)
      ans7.append(c)

if N > 8:
  ans8 = []
  for j in range(len(ans7)):
    a = max(ans7[j])+1
    for i in range(a+1):
      c = copy.copy(ans7[j])
      c.append(i)
      ans8.append(c)

if N > 9:
  ans9 = []
  for j in range(len(ans8)):
    a = max(ans8[j])+1
    for i in range(a+1):
      c = copy.copy(ans8[j])
      c.append(i)
      ans9.append(c)
      
aaa = "abcdefghij"
if N == 1:
  print("a")    
    
elif N ==2:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==3:
  for i in ans2:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==4:
  for i in ans3:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans4:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==7:
  for i in ans6:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==8:
  for i in ans7:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==9:
  for i in ans8:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
    
elif N ==10:
  ans9.sort()
  for i in ans9:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
done = 0
res = set()
pool = list('abcdefghijklmnopqrstuvwxyz')


def make_string(done):
    parent = [-1] * N

    def find(x):
        if parent[x] == -1:
            return x
        else:
            res = parent[x] = find(parent[x])
            return res

    def union(x, y):
        x = find(x)
        y = find(y)
        if x != y:
            parent[x] = y
    for x in range(N ** 2 // 2):
        if done & (1 << x):
            i, j = divmod(x, N)
            union(i, j)
    string = [None] * N
    j = 0
    for i in range(N):
        if string[i] is None:
            string[i] = pool[j]
            string[find(i)] = pool[j]
            j += 1
    return ''.join(string)


def dp(done, memo={}):
    if done in memo:
        return
    elif done == (1 << ((N ** 2) // 2)) - 1:
        return
    else:
        res.add(make_string(done))
        for i in range((N ** 2) // 2):
            if done & (1 << i):
                continue
            else:
                memo[done] = True
                dp(done | (1 << i), memo)


dp(0)
for x in sorted(list(res)):
    print(x)

Submission status: Wrong Answer

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


def next_chr(ch):
    res = []
    for i in range(-1, 2):
        if ord(ch) + i >= ord("a") and ord(ch) + i <= ord("z"):
            res.append(chr(ord(ch)+i))
    return res


def answer(s, i):
    if i == N:
        ch = next_chr(s[-1])
        for m in ch:
            ans.append("".join([s, m]))
    else:
        i += 1
        ch = next_chr(s[-1])
        for m in ch:
            answer("".join([s, m]), i)

if N == 1:
    print("a")
else:
    answer("a", 2)
    ans = sorted(ans)
    for c in ans:
        print(c)

Submission status: Wrong Answer

Solution code:
N = int(input()) # 数字を変数に格納

List = [[] for i in range(N)]

for i in range(N):
    for j in range(i+1):
        List[i].append(chr(97+j))

flag = 0
point = [0]*(N+1)

while flag != 1:
    chars = ''
    i = 0
    while len(chars) < N:
        if i != 0 and point[i-1]+1 < point[i]:
            point[i-1] += 1
            point[i] = 0
            break
        chars += List[i][point[i]]
        if i == N-1:
            point[i] += 1
        if point[i] == N:
            flag = 1
        i += 1
    if len(chars) == N:
        print(chars)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import combinations_with_replacement
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(read())
acc = 0

for comb in combinations_with_replacement(range(N), N):
    flag = True
    for i in range(N):
        if comb[i] > i:
            flag = False
    if flag:
        print(''.join([chr(97 + i) for i in comb]))

Submission status: Wrong Answer

Solution code:
chars = ['a','b','c','d','e','f','g','h','i','j']
length = int(input())
def cals(words, num, length):
  work = words
  for val in range(0 , num + 1):
    temp = work + chars[val]
    if num + 1 == length:
      print(temp)
    else:
      cals(temp, num + 1, length)
cals('',0 , length)

Submission status: Wrong Answer

Solution code:
n = int(input())

if n==1:
  print("a")
elif n==2:
  print("aa")
  print("ab")
elif n==3:
  print("aaa")
  print("aab")
  print("abb")
  print("aba")
  print("abc")
elif n==4:
  print("aaaa")
  print("aaab")
  print("aaba")
  print("abaa")
  print("aabb")
  print("abba")
  print("abab")
  print("abbb")
  print("aabc")
  print("abac")
  print("abca")
  print("abbc")
  print("abcb")
  print("acbc")
  print("abcc")
  print("abcd")
else:
  print("")

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

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

    alpha = 'abcdefghijk'

    for i in range(1,N):
        res = []
        pre = dp[i-1]
        for s in pre:
            for j in range(i+1):
                temp = s + alpha[j]
                res.append(temp)
        dp[i] = res

    res = dp[N-1]
    res = sorted(res)

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



main()

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 1:
    print('a')
if n == 2:
    print('aa')
    print('ab')
if n == 3:
    print('aaa')
    print('aab')
    print('aba')

Submission status: Wrong Answer

Solution code:
from itertools import permutations
from itertools import combinations

def main():
    N = int(input())
    word = ['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']
    cand = list()
    ans = []
    if N == 1:
        print('a')
        exit()
    if N == 2:
        print('aa')
        print('ab')
        exit()
    for i in range(N):
        for j in range(N):
            if i >= j:
                continue
            cand.append((i,j))
    cand.sort()
    ans = list()
    for i in range(1,N):
        for j in combinations(cand,i):
            words = ['z'] * N
            for m, n in j:
                words[m] = 'a'
                words[n] = 'a'
            ans.append(words)

    for n,m in enumerate(ans):
        for j, k in enumerate(m):
            if j == 0:
                pre = k
                if k != 'a':
                    ans[n][j] = 'a'
            else:
                if pre == k:
                    ans[n][j] = ans[n][j-1]
                else:
                    ans[n][j] = chr(ord(ans[n][j-1]) + 1)
                pre = k
    ans2 = set()
    for i in ans:
        tmp = ''.join(i)
        ans2.add(tmp)
    ans3 = list(ans2)
    ans3.sort()
    for j in ans3:
        print(j)

    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
N = int(input())
N -= 1

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


def dfs(s, depth, maxS):

    if depth == N:
        print(s)
        return

    for i in range(maxS+1):
        if i == maxS:
            dfs(s + S[i], depth+1, i+1)
        else:
            dfs(s + S[i], depth+1, i)


dfs("a", 0, 1)

Submission status: Wrong Answer

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

xlist=list
for l in range(len(list)-1):
    xl=[str(c) for c in xlist[l]]

    if xl.count("a")==0:
        list.remove(list[l])
        
    else:
        for o in range(n-l):
            if xl.count(k[l])==0 and xl.count(k[l+o-1])!=1:
                
                list.remove(list[l])
list.sort()
for i in list:
    print(i)

Submission status: Wrong Answer

Solution code:
n=int(input())
ag='aaaaaaaaaa'
ainit=ag[0:n]
alist=[]
alpha=['a','b','c','d','e','f','g','h','i','j']
if n==1:
    print(ainit)
else:
    print(ainit)
    ainit2=ainit[0:n-1]+'b'
    print(ainit2)
    alist.append(ainit2)
    for i in range(n-2):
        alistc=alist
        alist=[]
        for j in range(len(alistc)):
            s=alistc[j][1:n]
            #print(s)
            for k in range(i+3):
                sout=s+alpha[k]
                print(sout)
                alist.append(sout)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
s_lis = ["a"]
s_list = np.array(s_lis)
for i in range(N-1):
    ss = np.array([])
    for s in s_list:
        ss = np.append(ss,s + (s[-1]))
        ss = np.append(ss,s + chr(ord(s[-1])+1))
        if ord(s[-1]) > ord('a'):
            ss = np.append(ss,s + chr(ord(s[-1])-1))
    s_list = np.copy(ss)
if N == 1 :
    print (s_lis[0])
else :
    for i in ss:
        print(i)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque
N = int(input())

s = 'a'
queue = deque()
queue.append(s)
# for i in range(N):
while True:
    a = queue.popleft()
    if len(a) == N:
        queue.append(a)
        break
    origin = a
    a = a[-1]
    end = chr(ord(a)+2)
    while a != end:
        queue.append(origin+a)
        a = chr(ord(a)+1)
ans = []
while queue:
    ans.append(queue.popleft())
for s in sorted(ans):
    print(s)

Submission status: Wrong Answer

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

def output(s, itb):
    global n
    global tb
    global ans

    for i in range(n - len(s)):
        t = s + tb[itb] * (i + 1)
        if len(t) == n:
            ans.append(t)
        elif len(t) < n:
            output(t, itb + 1)

output('', 0)
for a in sorted(ans):
    print(a)

Submission status: Wrong Answer

Solution code:
import itertools
alp = [chr(ord('a') + i) for i in range(26)]
N = int(input())
allS = list(itertools.combinations_with_replacement(alp[0:N], N))
answers = []
PatternList = []
for s in allS:
    pattern = []
    letters = []
    num = 0
    for l in s:
        if not(l in letters):
            letters.append(l)
        pattern.append(letters.index(l))
    if not(pattern in PatternList):
        PatternList.append(pattern)
        answers.append(s)
for answer in answers:
    print(' '.join(answer))

Submission status: Wrong Answer

Solution code:
n=int(input())

def saiki(l,n):
  tmp=[]
  for limit,s in enumerate(l):
    for i in range(n):
      if i>=limit+n+1: break
      tmp.append(s+chr(ord('a')+i))
  return tmp

ans=['a']
for i in range(1,n):
  ans=saiki(ans,i+1)
print(*ans,sep='\n')

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    abc = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j')
    past = [[0, 'a']]

    if N == 1:
        print('a')
    else:
        for i in range(1, N):
            ns = []
            for s in past:
                for j in range(s[0] + 2):
                    ns.append([j, s[1] + abc[j]])
            past = ns
            if i == N - 1:
                for s in sorted(past, key=lambda x:x[1]):
                    print(s[1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    loop = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
    ans = []

    ans.append('a' * N)
    for i in range(N-1):
        for j in range(loop[i]):
            remain = N - (i + 1)
            # print(remain, loop[i])
            a = 'a' * remain
            n = 'b' * (j)
            m = 'a' * (N - remain - (j + 1))
            ans.append(a + 'b' + m + n)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def display_ans(ans):
    new_ans = []
    for a in ans:
        new_a = []
        for aa in a:
            new_a.append(chr(aa + 97))
        new_ans.append(new_a)
    
    for new_a in new_ans:
        print(''.join(new_a))

N = int(input())

ans = []

now_list = [0] * N
ans.append(now_list[:])

while True:
    for i in reversed(range(len(now_list))):
        if now_list[i - 1] == now_list[i]:
            # 平ら
            now_list[i] = now_list[i] + 1
            # 後ろがあれば初期化
            if i != N - 1:
                for j in range(i + 1, N):
                    now_list[j] = 0
            ans.append(now_list[:])
            if now_list[i] == N - 1:
                display_ans(ans)
                sys.exit()
            
            break
        elif now_list[i - 1] > now_list[i]:
            # 上がれる
            now_list[i] += 1
            # 後ろがあれば初期化
            if i != N - 1:
                for j in range(i + 1, N):
                    now_list[j] = 0
            ans.append(now_list[:])
            break
        else:
            # 下れる
            pass

Submission status: Wrong Answer

Solution code:
N=int(input())
ans = []
def same(c):
    if len(c)==N:
        ans.append(c)
        return
    else:
        for i in range(ord('a'),ord(c[-1])+2):
            same(c+chr(i))
same('a')
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    s = 'abcdefghijkl'
    ans = []
    from heapq import heapify, heappop, heappush

    def f(t: str):
        if len(t) == N:
            heappush(ans, t)
            return
        
        if len(t) >= 2:
            x = s.index(max(list(t)))+2
        else:
            x = len(t)+1
        for i in range(x):
            f(t+s[i])


    
    f('')
    # print(ans)
    c = 0
    # print(len(ans))
    while len(ans) and c < 10:
        print(heappop(ans))
        c += 1


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

N = int(input())
 
def func(n):
  if n <= 1:
    return ["a"]
  S = []
  for i in func(n - 1):
    S.append("a" + i)
    S.append("a" + i.replace("a","x").replace("b","a").replace("x","b"))
    
  return S
 
Ans = func(N)

Ans = list(set(Ans))
Ans.sort()
for i in Ans:
  print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
cs = 'abcdefghijklmn'
cm = {cs[i]:i for i in range(len(cs))}

def rec(string, l):
    if (l >= n):
        print(string)
        return 0
    now = string[-1]
    k = max(cm[string[i]]+1 for i in range(len(string)))
    k = max(k, cm[now] + 2)
    for c in cs[:k]:
        rec(string + c,l+1)

rec('a',1)

Submission status: Wrong Answer

Solution code:
n = int(input())

L =  [[[] for i in range(10)] for j in range(10)]
#print(L)
L[0][0].append('a')
#print(L[0])
for i in range(1, n):
    for j in range(10):
        if j == 0:
            t = chr(j + ord('a'))
            for c in L[i-1][j]:
                L[i][j].append(c+t)
        else:
            t = chr(j + ord('a'))
            for c in L[i-1][j-1]:
                L[i][j].append(c+t)
            for c in L[i-1][j]:
                L[i][j].append(c+t)
#print(L)

ans = []
for i in range(10):
    for c in L[n-1][i]:
        ans.append(c)
ans.sort()
for c in ans:
    print(c)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
l = [ord('a')] * N
result = []
result.append(''.join(map(chr,l)))
bin = [0]*N
binMax = 2**(N-1)

def binAdd(i=1):
    if bin[-i]==1:
        bin[-i] = 0
        binAdd(i+1)
    else:
        bin[-i] = 1

def recF():
    binAdd()
    x = 0
    for i in range(N):
        if bin[i] == 1:
            x+= 1
            l[i] = l[i] + x
    result.append(''.join(map(chr,l)))


for i in range(binMax-1):
    l = [ord('a')] * N
    recF()

for s in result:
    print(s)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
ans = []
def solve(x, y, m, n, s):
    if m == n:
        ans.append(s)
        return
    for i in range(x, y):
        solve(i, y+1, m+1, n, s + chr(ord("a") + i))

def main():
    n = int(input())
    solve(0, 2, 1, n, "a")
    ans.sort()
    for s in ans:
        print(s)

if __name__ == "__main__":
    main()