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:
# D - String Equivalence
from string import ascii_lowercase


def dfs(n: int) -> list:
    if n == 1:
        return ["a"]
    cur = dfs(n - 1)
    result = []
    for s in cur:
        for c in ascii_lowercase[: len(s) + 1]:
            result.append(s + c)
    return result


def main():
    N = int(input())
    result = dfs(N)
    result.sort()
    print("\n".join(result))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# 同型→文字数カウントのパターンが同じ
# 標準形→文字数辞書順の最も速いもの


N = read_a_int()


moji = 'abcdefghij'
candi = []
moji = moji[:N]


def dfs(now, i):
    # j....一つ前の文字のidx
    # 文字を作って返す
    if i == N:
        candi.append(now)
        return
        # return now
    for j in range(i + 1):
        dfs(now + moji[j], i + 1)


dfs('', 0)

print(*sorted(candi), sep='\n')


# for i in range(1, N + 1):  # 何番目まで使うか
#     mojisyu = moji[:i]  # ここで使う文字種類
#     # 文字種類でaを先頭にできるだけ標準形を列挙したい
#     for j in range(1, i):

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 14 22:00:05 2020

@author: naoki
"""
import sys
import itertools
#print(sys.getdefaultencoding())

N = int(input())
all_list = []
for i in range(0,N+1):
    if i != 1:
        all_list.extend(list(itertools.combinations(range(N),i)))

answer = [["x"] * N for _ in range(len(all_list))]
for i in range(len(answer)):
    num = 1
    exist = False
    for p in range(len(answer[i])):
        if p in all_list[i] and exist == False:
            Same = num
            answer[i][p] = Same
            num +=1
            exist = True
        elif p in all_list[i] and exist == True:
            answer[i][p] = Same
        else:
            answer[i][p] = num
            num += 1
            
char_ans = [[chr(answer[j][i]) for i in range(N)]for j in range(len(answer))]

ans = []
for i in range(len(char_ans)):
    ans.append("".join(str(j) for j in char_ans[i]))
ans = sorted(ans)

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

Submission status: Wrong Answer

Solution code:
import string
n = int(input())
cs = string.ascii_lowercase
cm = {cs[i]:i for i in range(len(cs))}

def rec(st):
    if (len(st) >= n):
        print(st)
        return 0
    k = max(cm[st[i]] for i in range(len(st)))
    if (k == cm[st[-1]]):
        k += 1
    for c in cs[: k + 1]:
        rec(st+c)
    
    
rec('a')

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    ans = []

    def solve(s, n, xset):
        if n == N:
            ans.append(s)
            return

        for i in range(len(xset) + 1):
            tmp = xset
            tmp.add(chr(ord('a') + i))
            solve(s + chr(ord('a') + i), n + 1, tmp)

    sset = set()
    sset.add('a')
    solve('a', 1, sset)
    ans.sort()
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

abc = list('abcdefghijk')


def solve(ans):
    if len(ans) == n:
        print(*ans, sep='')
    else:
        idx = abc.index(ans[-1])
        for i in range(idx+2):
            nans = ans + [abc[i]]
            solve(nans)


solve(['a'])

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=[[] for _ in range(10) ]
for i in range(10):
  ans[i]=["" for _ in range(int(2**i))]
ans[0]=["a"]
ans[1]=["aa","ab"]
abc=["a","b","c","d","e","f","g","h","i","j"]
if n>2:
  for i in range(2,n):
    str=ans[i-1]
    ii=0
    for x in str:
      jj=abc.index(x[-1])
      ans[i][ii]=x+"a"
      ans[i][ii+1]=x+abc[jj+1]
      ii+=2
#print(len(ans[n-1]))

for x in ans[n-1]:
    print(x)

Submission status: Wrong Answer

Solution code:
import sys
import time
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())

groups = []

def dfs(s, n):
    if n == N:
        print(s)
        return True
    # for ns in 'abcdefghijklmnopqrstuvwxyz'[:n+1]:
    for i, ns in enumerate('abcdefghij'[:n+1]):
        dfs(s+ns, max(i, n+1))

dfs('', 0)

Submission status: Wrong Answer

Solution code:
import itertools

def resolve():
    n = int(input())
    l = ['a', 'b']

    exceptstr = 'bbbbbbbbbb'
    exceptstr = exceptstr[:n]
    for v in itertools.combinations_with_replacement(l, n):
        str = ''.join(v)
        if str != exceptstr:
            print(str)
            
resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = []

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


def dfs(s, n):
    lst.append(s)
    if n == N:
        return
    else:
        for i in range(n + 1):
            dfs(s + d[i], n + 1)


dfs('a', 1)
for i in range(len(lst)):
    if len(lst[i]) == N:
        print(lst[i])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

n = I()
lst = ['a','b','c','d','e','f','g','h','i','j']
cnt = n
ans = []

def dfs(s,num,kinds):
    if num == n:
        ans.append(s)
        return
    for i in range(kinds+1):
        dfs(s+lst[i],num+1,i+1)
    return 

dfs('',0,0)

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())

if n == 3:
    print("aaa", "aab", "aba", "abb", "abc")

Submission status: Wrong Answer

Solution code:
import string

def dfs(w, d):
    if len(w) == N:
        print(w)
        return
    for i in range(d):
        dfs(w + wordlst[i], d + 1)
N = int(input())
anslst = []
nlst = [0] * N
wordlst = string.ascii_lowercase
dfs('a', 2)

Submission status: Wrong Answer

Solution code:
import string

N = int(input())
S = string.ascii_letters[:N] 
S_idx = {s:i for i, s in enumerate(S)}

def main(s, n):
    if n >= N:
        return print(s)
    idx =  S_idx[s[-1]]
    for i in S[:idx+2]:
        main(s+i, n+1)
        
main('a', 1)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=n
a=["a","b","c","d","e","f","g","h","i"]
for i in range(97,97+n+1):
  ans_l=a[:n-m]
  if m>1:
    for j in range(2**(m-1)-1):
      ans=[chr(i)]*m
      for k in range(m):
        if (j>>k)&1:
          ans[m-1-k]=chr(i+1)
      print("".join(ans_l+ans))
  elif m==1:
    print("".join(ans_l+[chr(i)]))
  m-=1

Submission status: Wrong Answer

Solution code:
def rec(S,depth):
    if depth == 0:
        print(S)
        return
    else:
        list_mozi=list(dict.fromkeys(list(S)))
        for j in range(len(list_mozi)):
            rec(S+list_mozi[j],depth-1)
        rec(S+chr(ord(list_mozi[len(list_mozi)-1])+1),depth-1)

N=int(input())
rec("a",N-1)

Submission status: Wrong Answer

Solution code:
N = int(input())

# mx = count up flag
def dfs(s, mx):
    print('dfs(', s, ', ', str(mx), ')')
    if len(s) == N:
        print(s)
    else:
        for c in range(ord('a'), mx+1):
            dfs(s+chr(c), mx + 1 if c == mx else mx)

dfs("", ord('a'))

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:
            for k in range(j+1):
                t = chr(k + 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 = list(set(ans))
ans.sort()
for c in ans:
    print(c)

Submission status: Wrong Answer

Solution code:
def cur(n):
    if ans[n]!=[]: return ans[n]
    for x in cur(n-1):
        tmp1=[0]+[x[i] for i in range(n-1)]
        tmp2=[0]+[x[i]+1 for i in range(n-1)]
        ans[n].append(tmp1)
        ans[n].append(tmp2)
        if sum(x)!=0:
            for k in range(1,max(x)+1):
                tmp3=[0]+[x[i] for i in range(n-1)]
                for i in range(1,n):
                    if tmp3[i]>k: tmp3[i]-=1
                    elif tmp3[i]==k: tmp3[i]=0
                    else: tmp3[i]+=1
                ans[n].append(tmp3)
    
    return ans[n]

def pri(x):
    s=""
    for i in range(p):
        s+=chr( ord("a")+x[i] )
    print(s)

p=int(input())
ans=[[] for i in range(11)]
ans[1]=[[0]]
ans[2]=[[0,0],[0,1]]
cur(p)

ans[p].sort()
pri(ans[p][0])
for i in range(1,len(ans[p])):
    if ans[p][i]!=ans[p][i-1]: pri(ans[p][i])

Submission status: Wrong Answer

Solution code:
import string
#n = int(input())
n = 5
cs = string.ascii_lowercase
cm = {cs[i]:i for i in range(len(cs))}

def rec(st, m):
    if (len(st) >= n):
        print(st)
        return 0
    for c in cs[:m+1]:
        rec(st + c,max(cm[c]+1,m))

rec('a',1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
n = int(input())

def dfs(s, mx):
  if len(s) == n:
    print(s)
  else:
    dfs(s+chr(ord("a")+mx), mx)
    dfs(s+chr(ord("a")+mx+1), mx+1)

dfs("a", 0)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
n = int(input())

def dfs(s, mx):
  if len(s) == n:
    print(s)
  else:
    dfs(s+chr(ord("a")+mx), mx)
    dfs(s+chr(ord("a")+mx+1), mx+1)

dfs("", 0)

Submission status: Wrong Answer

Solution code:
import sys
import re

l = sys.stdin.readline()
l = int(l)
out = []
def x(stri,l,depth):
  str = 'abcdefghij'
  for i in range(0,l-depth+1):
    cdepth = depth
    cstri = stri
    cstri += str[i] 
    cdepth -= 1
    if( cdepth == 0):
	out.append(cstri)
    else:
	x(cstri,l,cdepth)


stri = 'a'
if( l == 1):
 print stri
 exit(0)
x(stri,l,l-1)

ret = {}
count = 0
for i in out:
  prev = '0'
  moji = ""
  uniq = ""
  for j in i:
    if( prev == j ):
      moji += "E"
    else:
      if( j not in uniq ):
        uniq += j
      if( prev > j ):
        moji += "U"
      else:
        moji += "D"
    prev = j
  moji += str(len(uniq))
  if( moji not in ret.values()):
    print i
  ret[count] = moji
  count += 1

sys.stdout.flush()

Submission status: Wrong Answer

Solution code:
from itertools import*
from collections import*

start="a"
n=int(input())
d=defaultdict(set)
c=1
ans=[]

def dfs(tf,string,n,c):
    if len(string)==n:
        ans.append(string)
    else:
        s=string
        c+=1
        
        for sc in range(c):
            s=chr(97+sc)
#            print(s)
            tmp=string+s
            x=defaultdict(list)
            for k,v in enumerate(tmp):
                x[v].append(k)
            lc=0
            tmpl=[0]*len(tmp)
            for l in x.values():
                for i in l:
                    tmpl[i]=lc
                lc+=1
            if d[tuple(tmpl)]:
                continue
            else:
                d[tuple(tmpl)]=1
                dfs(d,tmp,n,c)

dfs(d,start,n,c)


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

Submission status: Wrong Answer

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

for i in range(0,len(ans)):
  while len(ans[i]) < n:
    k = ord(ans[i][-1])
    for j in range(97,k+2):
      ans.append(ans[i] + chr(j))
    del ans[i]

sorted(ans)
for i in range(0,len(ans)):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from itertools import combinations

def solve(N: int):   
    d = {n:[] for n in range(1, N+1)} 
    d[1] = [[1]]

    for n in range(1, N):
        
        for lst in d[n]:
            last_element = lst[-1]

            for new_element in range(1, last_element+2):
                d[n+1].append(lst+[new_element])

    ans_lst = d[N]

    for i, lst in enumerate(ans_lst):
        ans_lst[i] = ''.join([chr(num+96) for num in lst])

    for lst in ans_lst:
        print(lst)
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
from itertools import*
from collections import*

start="a"
n=int(input())
d=defaultdict(set)
c=1


def dfs(tf,string,n,c):
    if len(string)==n:
        print(string)
    else:
        s=string
        c+=1
        
        for sc in range(c):
            s=chr(97+sc)
#            print(s)
            tmp=string+s
            x=defaultdict(list)
            for k,v in enumerate(tmp):
                x[v].append(k)
            lc=0
            tmpl=[0]*len(tmp)
            for l in x.values():
                for i in l:
                    tmpl[i]=lc
                lc+=1
            if d[tuple(tmpl)]:
                continue
            else:
                d[tuple(tmpl)]=1
                dfs(d,tmp,n,c)

dfs(d,start,n,c)
print("b"+(n-1)*"a")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from itertools import combinations

def solve(N: int):   
    d = {n:[] for n in range(1, N+1)} 
    d[1] = [[1]]

    for n in range(1, N):
        
        for lst in d[n]:
            last_element = lst[-1]

            for new_element in range(1, last_element+2):
                d[n+1].append(lst+[new_element])

    ans_lst = d[N]

    for i, lst in enumerate(ans_lst):
        ans_lst[i] = ''.join([chr(num+96) for num in lst])
        print(ans_lst[i])
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())
ans = []


def next_chr(ch):
    res = []
    g = ord(ch) - ord("a") + 2
    for i in range(g):
        res.append(chr(ord("a")+i))
    return res


def answer(s, i):
    if i == N:
        ch = next_chr(max(s))
        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:
# input1 = list(map(int, (input().split())))


def func(n, sss, d):
    for i in range(n + 1):
        if d == N:
            print(sss + s[i])
        else:
            func(i + 1, sss + s[i], d+1)


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

N = int(input())

func(0, "", 1)

Submission status: Wrong Answer

Solution code:
alpha=['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']
le=int(input())
if le==1:
    print("a")
elif le==2:
    print("aa")
    print("ab")
else:
    al=["aa","ab"]
    for i in range(le-2):
        al=["a"+i for i in al]
        for i1 in range(len(al)):
            val=al[i1][0]+"b"+al[i1][2:]
            al.append(val)
        al.append("".join(alpha[:i+3]))
        al=sorted(list(set(al)))
    for i in al:
        print(i)

Submission status: Wrong Answer

Solution code:
from sys import stdin,setrecursionlimit
import string
from itertools import combinations_with_replacement
setrecursionlimit(10**7)
n = int(stdin.readline().rstrip())
alpha = "abcdefghijklmn"
kazu = set("")
#0~9までの数字を列挙
li = [str(i) for i in range(n)]
#重複ありで組み合わせを全探索
lin = list(combinations_with_replacement(li, n))
for i in lin:
    #数列にする
    s = ''.join(map(str, i))
    point = 0
    moto = s[:]
    while True:
        flag = False
        for j in s:
            #数字が出てきたらアルファベットに置換する
            if j in "0123456789":
                s = s.replace(j,alpha[point])
                point += 1
                flag = True
                break
        if flag == False:
            break
    kazu.add(s)
kazu = list(kazu)
kazu.sort()
for i in kazu:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
alpha_dict = {}
for i,c in enumerate(range(ord('A'),ord('Z')+1)):
  alpha_dict[i] = str(chr(c)).lower()


ans = []
def dfs(s, mx, ans):
  if len(s) == n:
    ans += [s]
    return 
  else:
    for i in range(mx+1):
      dfs(s+alpha_dict[i], max(i, mx+1), ans)

dfs("", 0, ans)
ans = sorted(ans)
for a in ans:
  print(a)

Submission status: Wrong Answer

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

alphabets = list('abcdefghijklmnopqrstuvwxyz')

N = int(input())

if N == 1:
    print('a')
else:
    tmp = ['a']
    for i in range(1, N):
        result = []
        for s in tmp:
            for alphabet in set(list(s)):
                result.append(s+alphabet)
            result.append(s+alphabets[len(set(list(s)))])
            tmp = result
    print('\n'.join(result))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

old = ["a"]
new = []
for i in range(1, N):
    for word in old:
        for j in range(i+1):
            # if word[-1] == dic[j] or (j>0 and word[-1] == dic[j-1]) or dic_r[word[-1]] >= j:
            if word+dic[j] not in new:
                new.append(word+dic[j])
    old = new.copy()
    new = []

for i in old:
    print(i)
# n = int(input())
# r = 'a',
# for _ in range(n - 1):
#   r = [s + c for s in r for i, c in enumerate(s + chr(ord(max(s)) + 1)) if c not in s[:i]]
# print(*r, sep='\n')

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
alp="abcdefghijklmnopqrstuvwxyz"
l=["a"]
now=[]
flag=0
now=[]

if N==1:
    print(l[0])
    flag=1
else:
    for x in range(N-1):
        for i in range(len(l)):
            now.append(l[i]+"a")
            now.append(l[i]+"b")
        l=copy.deepcopy(now)
        now=[]



if flag!=1:
    l.sort()
    for i in l:
        print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())


def f(s, I):
    if len(s) >= n:
        print(s)
    else:
        for i in range(I+1):
            f(s + chr(ord('a') + i), i+1)


f('a', 1)

Submission status: Wrong Answer

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


def next_chr(ch):
    res = []
    g = ord(ch) - ord("a") + 2
    for i in range(g):
        res.append(chr(ord("a")+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:
def dfs(now, count):
    if count == n:
        print(now)
    else:
        for i in range(count + 1):
            dfs(now + al[i], count + 1)


n = int(input())

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

dfs('a', 1)

Submission status: Wrong Answer

Solution code:
from itertools import permutations

N = int(input())
ans = []
S = set()

for p in permutations(range(N)):
    D = [-1] * N
    A = []
    for i in range(N):
        for j in range(N):
            if D[j] < p[i]:
                D[j] = p[i]
                A.append(j)
                break
    s = ''.join(map(lambda x:chr(x+97),A))
    if s not in S:
        print(s)
        S.add(s)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int):
    ans = []
    if N == 1:
        print('a')
        return
    if N == 2:
        print('aa')
        print('ab')
        return
    for i in range(2**(N-1)):
        s = str(format(i, 'b')).zfill(N-1).replace('0', 'a').replace('1', 'b')
        ans.append('a' + s)
    last = ''
    for i in range(N):
        last += chr(ord('a') + i)
    for i in sorted(ans):
        print(i)
    print(last)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
def main():
    import sys
    input = sys.stdin.readline

    p = int(input())
    lis = []
    if p == 1:
        print("a")
    else:
        for i in range(2,p+1):
            n = (2 ** (i-1)) - 1
            lis1 = []
            for j in range(n+1):
                lis1.append(format(j,"b").zfill(i))
            lis.append(lis1)
        lis_cor = [lis[0]]
        for i in range(1,len(lis)):
            lisnew = []
            for j in range(len(lis[i])):
                num = lis[i][j].count("1")
                if num > 1:
                    lisnew.append(lis[i][j])
                    for x in lis_cor[num-2]:
                        x1 = str(int(x) + int(lis[i][j]))
                        lisnew.append(x1.zfill(i+2))
                else:
                    lisnew.append(lis[i][j])
            lis_cor.append(lisnew)
        str_lis = ["a","b","c","d","e","f","g","h","i","j","k"]
        st = ""
        lis_cor1 = list(set(lis_cor[p-2]))
        st_l = []
        for y in lis_cor1:
            for j in range(len(y)):
                st1 = str_lis[int(y[j])]
                st += st1
            st_l.append(st)
            st = ""
        
        st2 = list(set(st_l))
        st2.sort()
        for x in st2:
            print(x)
            
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


N = int(input())
ans = set()
a = ord('a')


def f(c, A, done):
    global N, a
    if done == N:
        ans.add(''.join(A))
    else:
        B = list(A)
        idx = B.index(0, 0)
        B[idx] = c
        tdone = done + 1
        for i in range(2 ** (N - tdone) - 1, -1, -1):
            k = i
            C = B[:]
            nDone = tdone
            idx = 0
            while k > 0:
                if k & 1 == 1:
                    idx = C.index(0, idx + 1)
                    C[idx] = c
                    nDone += 1
                k >>= 1
            f(chr(ord(c) + 1), tuple(C), nDone)


A = [0] * N
f('a', tuple(A), 0)
ans = list(ans)
ans.sort()
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
def main():
    N = int(input())
    s = ''
    l = []
    def calc3(s, N):
        if len(s) == N:
            l.append(s)
            return
        if len(s) > 0:
            c = s[-1]
            s2 = s[:]
            z = ord(c) - ord('a') + 2
            for i in range(z):
                st = s[:]
                st += chr(ord('a')+i)
                calc3(st[:], N)
        else:
            c = 'a'
            s += chr(ord(c))
            calc3(s[:], N)
    calc3(s[:], N)
    l = sorted(set(l))
    for i in l:
        print(i)
main()

Submission status: Wrong Answer

Solution code:
from itertools import*
from collections import*

start="a"
n=int(input())
d=defaultdict(set)
c=1


def dfs(tf,string,n,c):
    if len(string)==n:
        print(string)
    else:
        s=string
        c+=1
        
        for sc in range(c):
            s=chr(97+sc)
#            print(s)
            tmp=string+s
            x=defaultdict(list)
            for k,v in enumerate(tmp):
                x[v].append(k)
            lc=0
            tmpl=[0]*len(tmp)
            for l in x.values():
                for i in l:
                    tmpl[i]=lc
                lc+=1
            if d[tuple(tmpl)]:
                continue
            else:
                d[tuple(tmpl)]=1
                dfs(d,tmp,n,c)

dfs(d,start,n,c)

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")
    print("abb")
    print("abc")
elif N == 4:
    print("aaaa")
    print("aaab")
    print("aaba")
    print("aabb")
    print("aabc")
    print("abaa")
    print("abab")
    print("abbb")
    print("abbc")
    print("abca")
    print("abcb")
    print("abcc")
    print("abcd")

Submission status: Wrong Answer

Solution code:
import string

def dfs(w):
    if len(w) == N:
        print(w)
        return
    for i in range(N):
        dfs(w + string.ascii_lowercase[i])

N = int(input())
anslst = []
nlst = [0] * N
wordlst = string.ascii_lowercase
dfs('a')

Submission status: Wrong Answer

Solution code:
N =int(input())

if N==1:
    print("a")
    exit()
if N==2:
    print("aa")
    print("ab")
    exit()

ans=["aa","ab"]

def func(s, n=-1):
    ns = []
    for ch in s:
        # A - Z
        if ('A' <= ch and ch <= 'Z'):
            ns.append(chr((ord(ch) - ord('A') - n) % 26 + ord('A')))
        # a - z
        elif ('a' <= ch and ch <= 'z'):
            ns.append(chr((ord(ch) - ord('a') - n) % 26 + ord('a')))
        # 0 - 9
        elif ('0' <= ch and ch <= '9'):
            ns.append(chr((ord(ch) - ord('0') - n) % 10 + ord('0')))
        # no change for other characters
        else:
            ns.append(ch)
    return "".join(ns)

# print(func("aabb"))

for _ in range(N-2):
    riv=[func(i) for i in ans]
    riv.append(func(ans[-1])[:-1]+'a')
    riv.sort()
    # print(riv)
    a = ans+riv
    ans=['a'+i for i in a]

for i in ans:
    print(i)

Submission status: Wrong Answer

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

    p = int(input())
    lis = []
    if p == 1:
        print("a")
    else:
        for i in range(2,p+1):
            n = (2 ** (i-1)) - 1
            lis1 = []
            for j in range(n+1):
                lis1.append(format(j,"b").zfill(i))
            lis.append(lis1)
        lis_cor = [lis[0]]
        for i in range(1,len(lis)):
            lisnew = []
            for j in range(len(lis[i])):
                num = lis[i][j].count("1")
                if num > 1:
                    lisnew.append(lis[i][j])
                    for x in lis_cor[num-2]:
                        x1 = str(int(x) + int(lis[i][j]))
                        lisnew.append(x1.zfill(i+2))
                else:
                    lisnew.append(lis[i][j])
            lis_cor.append(lisnew)
        str_lis = ["a","b","c","d","e","f","g","h","i","j","k"]
        st = ""
        lis_cor1 = list(set(lis_cor[p-2]))
        st_l = []
        for y in lis_cor1:
            for j in range(len(y)):
                st1 = str_lis[int(y[j])]
                st += st1
            st_l.append(st)
            st = ""
        
        st_l.sort()
        for x in st_l:
            print(x)
            



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"]
results = []
if n == 1:
    results = ["a"]
elif n == 2:
    results = ["aa", "ab"]
elif n == 3:
    results = ["aaa", "aab", "aba", "abb", "abc"]
elif n == 4:
    results = ["aaaa", "aaab", "aaba", "aabb", "aabc", "abaa", "abab", "abac", "abba", "abbb", "abbc", "abca", "abcb", "abcc", "abcd"]

# results = []
# for i in range(n):
#     if i == 0:
#         results.append(["a"])
#     else:
#         standards = []
#         for result in results[i-1]:
#             abcs = list(set(result))
#             abcs.append(abc[len(abcs)])
#             for a in abcs:
#                 standards.append(result + a)
#         results.append(standards)

for result in results:
    print(result)

Submission status: Wrong Answer

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

def nex(lis):
    li = copy.copy(lis)
    if len(li) == N:
        print(''.join([chr(97+i) for i in li]))
        return 

    for x in range(li[-1]+2):
        li2 = copy.copy(li)
        li2.append(x)
        nex(li2)
        
nex([0])