Problem:


Score : 400 points

Problem Statement

In this problem, we only consider strings consisting of lowercase English letters.

Strings s and t are said to be isomorphic when the following conditions are satisfied:

|s| = |t| holds.

For every pair i, j, one of the following holds:

s_i = s_j and t_i = t_j.

s_i \neq s_j and t_i \neq t_j.

For example, abcac and zyxzx are isomorphic, while abcac and ppppp are not.

A string s is said to be in normal form when the following condition is satisfied:

For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.

For example, abcac is in normal form, but zyxzx is not since it is isomorphic to abcac, which is lexicographically smaller than zyxzx.

You are given an integer N.
Print all strings of length N that are in normal form, in lexicographically ascending order.

Constraints

1 \leq N \leq 10

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Assume that there are K strings of length N that are in normal form: w_1, \ldots, w_K in lexicographical order.
Output should be in the following format:

w_1
:
w_K

Sample Input 1

1

Sample Output 1

a

Sample Input 2

2

Sample Output 2

aa
ab



Sample input:
1


Sample output:
a

Submission status: Wrong Answer

Solution code:
def dfs(n):
    adj = [chr(i+97) for i in range(26)]
    
    stack = ['a']
    combs = []
    while stack:
        node = stack.pop()
        if len(node) == n:
            combs.append(node)
        else:
            limit = ord(node[-1])%97 +2
            for child in adj[:limit]:
                cand = node+child
                stack.append(node+child)
    return combs

def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    res = dfs(n)
    for ans in res:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import combinations_with_replacement

N = int(input())
C = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
DP = [set() for _ in range(N)]
DP[0].add((1, 'a'))

for i in range(1, N):
    for num, s in DP[i-1]:
        for j in range(num):
            DP[i].add((num, s + C[j]))
        DP[i].add((num + 1, s + C[num]))
A = []
for ax in DP[N-1]:
    A.append(ax)
A.sort()
for a, s in A:
    print(s)

Submission status: Wrong Answer

Solution code:
from itertools import combinations_with_replacement

N = int(input())
C = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
Ans = set()

for ans in combinations_with_replacement(C[:N], N):
    a = ''
    d = dict()
    now = ord('a')
    for c in ans:
        if c not in d:
            d[c] = chr(now)
            now += 1
        a += d[c]
    Ans.add(a)

A = []
for ax in Ans:
    A.append(ax)
A.sort()
for a in A:
    print(a)

Submission status: Wrong Answer

Solution code:
def solve(n):
    s = ["a"] * n
    for i in range(n):
        print("".join(s))
        s[-i-1] = "b"

n = int(input())
solve(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
def sub(l, d):
  if d == N:
    s = "".join(["abcdefghijklmnopqrstuvwxyz"[i] for i in l])
    print(s)
    return
  for j in range(d+1):
    sub(l+[j], d+1)
sub([], 0)

Submission status: Wrong Answer

Solution code:
N = int(input())

#文字数分aで埋める
#末尾をbにする
#一桁上の文字+1文字までは許容するルールで増加させていく

import itertools

stop_combination = [chr(i) for i in range(97,97+N)]
combination_list = list(itertools.combinations_with_replacement(stop_combination,N))

printed_expression = set()

for combination in combination_list:
    #print(combination,":",end="")

    if list(combination) == stop_combination:
        print(''.join(map(str, combination)))
        break

    character_dict = dict()
    character_number = 0
    alternative_expression = ""

    for character in combination:
        if character not in character_dict:
            character_dict[character] = character_number
            alternative_expression += str(character_number)
            character_number += 1
        else:
            alternative_expression += str(character_dict[character])

    #print(alternative_expression)

    if alternative_expression not in printed_expression:
        print(''.join(map(str, combination)))
        printed_expression.add(alternative_expression)

Submission status: Wrong Answer

Solution code:
N = int(input())

#文字数分aで埋める
#末尾をbにする
#一桁上の文字+1文字までは許容するルールで増加させていく

ans = [0 for _ in range(N)]
stop = [i for i in range(N)]

def ans_print(ans_list):
    ans = list()
    for a in ans_list:
        ans.append(chr(a+97)) #97でaが出る

    print(''.join(map(str, ans)))
    return 0

if N == 1:
    print("a")
else:
    while 1:
        ans_print(ans)
        
        ans[-1] += 1

        for i in range(N-1,0,-1):
            if ans[i] > ans[i-1]+1:
                ans[i-1] += 1
                ans[i] = 0
                
        if ans == stop:
            ans_print(ans)
            break

Submission status: Wrong Answer

Solution code:
n = int(input())
import copy
for i in range(2**(n-1)):
    p = []
    s = copy.deepcopy(i)
    for j in range(n):
        if s&1 == 0:
            p.append('a')
        else:
            p.append('b')
        s >>= 1
    p.reverse()
    print(''.join(p))

Submission status: Wrong Answer

Solution code:
from collections import deque
N=int(input())
d=deque()
d.append("a")
dall=deque()
dall.append(d)
i=0
while i<N-1:
    length=len(dall)
    j=0
    while j<length:
        l=dall.popleft()
        st=l.pop()
        l.append(st)
        llen=len(l)
        for k in range(ord(st)-ord("a")+2):
            q = deque()
            for m in range(llen):
                c = l.popleft()
                q.append(c)
                l.append(c)
            q.append(chr(ord("a")+k))
            dall.append(q)
        j=j+1
    i=i+1
    #print(dall)
    #input()
#print(len(dall))
ans=[]
for i in range(len(dall)):
    ans.append("".join(dall[i]))
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
from collections import deque
N=int(input())
d=deque()
d.append("a")
dall=deque()
dall.append(d)
i=0
while i<N-1:
    length=len(dall)
    j=0
    while j<length:
        l=dall.popleft()
        st=l.pop()
        l.append(st)
        llen=len(l)
        for k in range(ord(st)-ord("a")+2):
            q = deque()
            for m in range(llen):
                c = l.popleft()
                q.append(c)
                l.append(c)
            q.append(chr(ord("a")+k))
            dall.append(q)
        j=j+1
    i=i+1
    #print(dall)
    #input()
#print(len(dall))
ans=[]
for i in range(len(dall)):
    print("".join(dall[i]))

Submission status: Wrong Answer

Solution code:
al = "abcdefghijklmnopqrstuvwxyz"
def dfs(s: "char", max_char: "int", n: "int", k):
    if(n<k):
        dfs(s+al[max_char], max_char, n+1, k)
        dfs(s+al[max_char+1], max_char+1, n+1, k)


    if n==k:
        print(s)



def main():
    k = int(input())
    #文字を選ぶ選ばないdfs
    dfs("a", 0, 1, k)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
alp = [chr(ord("a") + x) for x in range(26)]

def dfs(S):
    if len(S) == n:
        print(S)
    else:
        for i in range(len(S) + 1):
            dfs(S + alp[i])

dfs("a")

Submission status: Wrong Answer

Solution code:
import queue

n = int(input())
alp = "abcdefghijklmn"
q = queue.Queue()
q.put("a")
while not q.empty():
    qi = q.get()
    if len(qi) == n:
        print(qi)
    elif len(qi) < n:
        idx = alp.index(qi[-1])
        for i in range(idx+2):
            q.put(qi+alp[i])

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
added = set()
ans = []
a = [[chr(97+i) for i in range(j)] for j in range(1,N+1)]
for x in product(*a):
    temp = 'a'
    count = 1
    appeared = set('a')
    rle = []
    for y in x[1:]:
        appeared.add(y)
        if y != temp:
            rle.append(count)
            count = 1
            temp = y
        else:
            count += 1
    rle.append(count)
    rle.append(len(appeared))
    t = tuple(rle)
    if t not in added:
        print(''.join(x))
        added.add(t)

Submission status: Wrong Answer

Solution code:
from itertools import combinations_with_replacement

N = int(input())
added = set()
ans = []
for x in combinations_with_replacement(range(N),N):
    count = 0
    appeared = set()
    temp = []
    order = [float('inf')] * N
    for y in x:
        if y not in appeared:
            order[y] = 97 + count
            count += 1
            appeared.add(y)
            temp.append(chr(order[y]))
        else:
            temp.append(chr(order[y]))
    s = ''.join(temp)
    if s not in added:
        ans.append(s)
        added.add(s)
for x in sorted(ans):
    print(x)

Submission status: Wrong Answer

Solution code:
from itertools import combinations_with_replacement

N = int(input())
printed = set()
for x in combinations_with_replacement(range(N),N):
    count = 0
    appeared = set()
    temp = []
    order = [float('inf')] * N
    for y in x:
        if y not in appeared:
            order[y] = 97 + count
            count += 1
            appeared.add(y)
            temp.append(chr(order[y]))
        else:
            temp.append(chr(order[y]))
    s = ''.join(temp)
    if s not in printed:
        print(s)
        printed.add(s)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d

n = int(input())

def dfs(s, n, path):
    if n == 0:
        path.append(s)
        return
    for i in range(n):
        dfs(chr(i + ord('a')) + s, n - 1, path)


path = []
dfs('', n, path)
for ans in path:
    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
s='abcdefghijklmnopqrstuvwxyz'
for l in itertools.combinations_with_replacement(range(1,n+1),n):
  c=1
  ans=''
  for i in l:
    if i>c:
      break
    elif i==c:
      c+=1
    ans+=s[i-1]
  if len(ans)==n:
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    if N==1:
        print('a')
        exit()
    d = deque(['a'])
    ans = []
    while d:
        s = d.popleft()
        last = ord(s[-1])
        for i in range(97,last+2):
            S = s + chr(i)
            if len(S)==N:
                ans.append(S)
            else:
                d.append(S)
    ans.sort()
    for s in ans:
        print(s)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    if N==1:
        print('a')
        exit()
    d = deque(['a'])
    ans = []
    while d:
        s = d.popleft()
        last = ord(s[-1])
        for i in range(97,last+2):
            S = s + chr(i)
            if len(S)==N:
                ans.append(S)
            else:
                d.append(S)
    for s in ans:
        print(s)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N = int(input())

lst1 = ['a']
lst2 = []
for i in range(N - 1):
    if i % 2 == 0: #lst1 -->lst2
        lst2 = []
        for s in lst1:
            last = ord(s[i]) - ord('a')
            for j in range(last + 2):
                lst2.append(s + chr(j + ord('a')))
    else:
        lst1 = []
        for s in lst2:
            last = ord(s[i]) - ord('a')
            for j in range(last + 2):
                lst1.append(s + chr(j + ord('a')))
           
if len(lst2) > len(lst1):
    lst2.sort()
    print (*lst2, sep = '\n')
else:
    lst1.sort()
    print (*lst1, sep = '\n')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N = int(input())

lst1 = ['a']
lst2 = []
for i in range(N - 1):
    if i % 2 == 0: #lst1 -->lst2
        lst2 = []
        for s in lst1:
            last = ord(s[i]) - ord('a')
            for j in range(last + 2):
                lst2.append(s + chr(j + ord('a')))
    else:
        lst1 = []
        for s in lst2:
            last = ord(s[i]) - ord('a')
            for j in range(last + 2):
                lst1.append(s + chr(j + ord('a')))
           
if len(lst2) > len(lst1):
    print (*lst2, sep = '\n')
else:
    print (*lst1, sep = '\n')

Submission status: Wrong Answer

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

alpha=list('abcdefghijk')

q=deque([])
q.append(alpha[0])

for i in range(1,n):
    qi=deque([])

    while(len(q)>0):
        qij=q.popleft()
        for j in range(len(qij)+1):
            qi.append(qij+alpha[j])

    q=qi

q=list(q)
q.sort()
for i in range(len(q)):
    print(q[i])

Submission status: Wrong Answer

Solution code:
n = int(input())

L = [0]*n
for i in range(n):
    L[i] = chr(i+ord('a'))
#print(L)_

ans = []
def dfs(A):
    if len(A) == n:
        ans.append(''.join(A))
        return
    for v in L[0:len(A)+1]:
        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:
from itertools import combinations_with_replacement,product
N=int(input())
X=['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']
Z=list(combinations_with_replacement(X,N))

for i in Z[:N]:
    print(*i, sep='')

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()

    char = [chr(i) for i in range(97, 97 + 26)]
    d = [0 for _ in range(11)]
    d[0] = 1

    def printer(d):
        s = ""
        for num in d:
            if num != 0:
                s = char[num - 1] + s

        if len(s) == n:
            print(s)
        return

    while d[n] == 0:
        printer(d)

        d[0] += 1

        for i in range(10):
            if d[i] - d[i + 1] > 1:
                d[i] = 1
                d[i + 1] += 1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()

    char = [chr(i) for i in range(97, 97 + 26)]
    d = [0 for _ in range(11)]
    d[0] = 1

    def printer(d):
        s = ""
        for num in d:
            if num != 0:
                s = char[num - 1] + s
        print(s)
        return

    while d[n] == 0:
        printer(d)

        d[0] += 1

        for i in range(10):
            if d[i] - d[i + 1] > 1:
                d[i] = 1
                d[i + 1] += 1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque


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


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)
INF = float("inf")


def main():
    N = int(input())
    q = deque(["a"])
    cnt = 1
    answer = []
    while cnt <= N:
        d = q.popleft()

        if len(d) == N:
            answer.append(d)
        cnt = max(cnt, len(d))
        for i in range(ord("a"), ord("a") + cnt + 1):
            q.append(d + chr(i))
    answer.sort()
    print(*answer, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque


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


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)
INF = float("inf")


def main():
    N = int(input())
    q = deque(["a"])
    cnt = 1
    answer = []
    while cnt <= N:
        d = q.popleft()

        if len(d) == N:
            answer.append(d)
        cnt = max(cnt, len(d))
        a = ord(d[-1])
        for i in range(ord("a"), a + 2):
            q.append(d + chr(i))
    answer.sort()
    print(*answer, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque


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


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)
INF = float("inf")


def main():
    N = int(input())
    q = deque(["a"])
    cnt = 1
    while cnt <= N:
        d = q.popleft()

        if len(d) == N:
            print(d)
        cnt = max(cnt, len(d))
        a = ord(d[-1])
        for i in range(ord("a"), a + 2):
            q.append(d + chr(i))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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


s = {}
s["a"] = 0
ans = [s]

for i in range(2, n+1):
    new_s = {}
    for t in s.items():
        for j in range(1, i):
            if t[0][-1] == w[j-1]:
                for k in range(i):
                    new_s[t[0] + w[k]]  = max(t[1], k)

    ans.append(new_s)
    s = new_s

answer = sorted(ans[n-1].keys())

for x in answer:
    
    print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())

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


s = ["a"]
ans = [s]

for i in range(2, n+1):
    new_s = []
    for t in s:
        for j in range(1, i):
            if t[-1] == w[j-1]:
                for k in range(i):
                    new_s.append(t + w[k])

    ans.append(new_s)
    s = new_s

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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


s = ["a"]
ans = [s]

for i in range(2, n+1):
    new_s = []
    for t in s:
        for j in range(1, i):
            if t[-1] == w[j-1]:
                if j == 1:
                    for k in range(i):
                        new_s.append(t + w[k])
                else:
                    for k in range(j-1):
                        new_s.append( t + w[k])
    ans.append(new_s)
    s = new_s
    
for i in range(len(ans[n-1])):
    print(ans[n-1][i])

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import combinations
def main():
    n=int(input())
    lis_s=[]
    for kugiri in range(n):
        lis=list(combinations(range(1,n),kugiri))
        lis.sort(reverse=True) 
        for l in lis:
            s=""
            ss='a'
            for moji in range(n):
                if moji in l:
                    if ss=='a':ss='b'
                    else:ss='a'
                s+=ss
            lis_s.append(s)
    lis_s.sort()
    for ll in lis_s:
        print(ll)
    

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import combinations
def main():
    n=int(input())
    lis_s=[]
    for kugiri in range(n):
        lis=list(combinations(range(1,n),kugiri))
        lis.sort(reverse=True) 
        for l in lis:
            s=""
            ss='a'
            for moji in range(n):
                if moji in l:
                    ss=chr(ord(ss)+1)
                s+=ss
            lis_s.append(s)
    lis_s.sort()
    for ll in lis_s:
        print(ll)
    

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import combinations
def main():
    n=int(input())
    for kugiri in range(n):
        lis=list(combinations(range(1,n),kugiri))
        lis.sort(reverse=True) 
        for l in lis:
            s=""
            ss='a'
            for moji in range(n):
                if moji in l:
                    ss=chr(ord(ss)+1)
                s+=ss
            print(s)
    

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
li = list(itertools.product([0,1], repeat=n))
alp = list('abcdefghijklmnopqrstuvwxyz')

ans_li = ['0']
for _ in range(n-1):
    tmp = []
    for a in ans_li:
        last = int(a[-1])+1
        for i in range(last+1):
            tmp.append(a+str(i))
    ans_li = tmp
for bb in ans_li:
    ans = ''
    for b in bb:
        ans += alp[int(b)]
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
from collections import deque
d=deque(['a'])
c=[chr(i) for i in range(97, 97+26)]
ans=set([])
while d:
  y=d.pop()
  if len(y)==n:
    ans.add(y)
  now=c.index(y[-1])
  for z in range(min(now+2,n+1)):
    if z>-1 and len(y)<n:
      d.append(y+c[z])
for z in sorted(list(ans)):
  print(z)

Submission status: Wrong Answer

Solution code:
n=int(input())
from collections import deque
d=deque(['a'])
x=[-1,0,1]
c=[chr(i) for i in range(97, 97+n)]
ans=set([])
while d:
  y=d.pop()
  if len(y)==n:
    ans.add(y)
  now=c.index(y[-1])
  for z in x:
    if now+z>-1 and len(y)<n:
      d.append(y+c[now+z])
for z in sorted(list(ans)):
  print(z)

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np
import sys
sys.setrecursionlimit(10**8)
#N,K=map(int,input().split())
N=int(input())
#h=np.array(list(map(int,input().split())))
#ans=0
num2alpha = lambda c: chr(c+96)
def dfs(K,b,s):
    if len(s)==K+1:
        return b.append(s)
    elif len(s)>=K+1:
        return
    else:
        for i in range(N):
            if i<= len(set(s)):
                s=s+num2alpha(i+1)
                dfs(K, b, s)
B=list()
m=""
dfs(N-1,B,m)
for i in B:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
def dfs(s,n,m,subs):
  if len(subs)==n:
    print(subs)
    return

  for i in range(m+1):
    t = "".join((subs,s[i]))
    dfs(s,n,i+1,t)

s = "abcdefghij"

n = int(input())
s = list(s[:n])
dfs(s,n,1,"a")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())

a_ord = ord('a')

s = ["a"]

ans = []

def dfs(s):
    last_ord = a_ord + len(s)
    for i in range(a_ord, last_ord + 1):
        t = s[:]
        t.append(chr(i))
        if len(t) == n:
            ans.append("".join(t))
        else:
            dfs(t)
if n == 1:
    print('a')
else:
    dfs(s)
    ans.sort()
    for w in ans:
        print(w)

Submission status: Wrong Answer

Solution code:
def f(n,k):
    x = chr(k)
    if n==1:
        return [chr(k)]
    if n==2:
        return [x+x,x+chr(k+1)]
    A = [x*n]
    for i in range(1,n):
        y = x*i+chr(k+1)+x*(n-i-1)
        A.append(y)
    B = f(n-1,k+1)
    for b in B:
        y = x+b
        A.append(y)
    return A
N = int(input())
A = f(N,97)
A = sorted(A)
for a in A:
    print(a)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())

a_ord = ord('a')

s = ["a"]

ans = []

def dfs(s):
    last_ord = ord(s[-1])
    for i in range(a_ord, last_ord + 2):
        t = s[:]
        t.append(chr(i))
        if len(t) == n:
            ans.append("".join(t))
        else:
            dfs(t)
if n == 1:
    print('a')
else:
    dfs(s)
    ans.sort()
    for w in ans:
        print(w)

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

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

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())

q = deque()
s = "a"
q.append(s)

while q:
    t = q.popleft()
    if len(t)==n:
        print(t)
    else:
        c = t[-1]
        for j in range(97,ord(c)+2):
            nt = copy(t)
            nc = chr(j)
            nt += nc
            q.append(nt)

Submission status: Wrong Answer

Solution code:
n = int(input())

if n == 1:
    print('a')
    exit()

lst = ['a']
for i in range(n-1):
    new_lst = []
    for string in lst:
        num = ord(string[-1])
        for j in range(ord('a'), num+2):
            new_lst.append(string+chr(j))
    lst = new_lst

for string in lst:
    print(string)

Submission status: Wrong Answer

Solution code:
def saiki(n,A):

    if n == N:
        print(len(A))
        return

    alpha = list("abcdefghijklm")

    tmp = []

    for i in A:
        a = alpha.index(sorted(list(i))[-1])
        for j in range(a+2):
            tmp.append(i+alpha[j])
    
    saiki(n+1,tmp)

N = int(input())

saiki(1,["a"])

Submission status: Wrong Answer

Solution code:
N = int(input())

def standard_string(N, st):
    if len(st) == N:
        print(st)
    elif st == "":
        standard_string(N, "a")
    else:
        for i in range(97, ord(st[-1])+ 2):
            st += chr(i)
            standard_string(N, st)
            st = st[:-1]
standard_string(N, "")

Submission status: Wrong Answer

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

dfs("0")

Submission status: Wrong Answer

Solution code:

N = int(input())

def dfs(x):
    if len(x) == N:
        s = "".join(chr(v + ord("a")) for v in x)
        print(s)
        return
    
    val = x[-1] if x else 0
    for i in range(val + 2):
        x.append(i)
        dfs(x)
        x.pop()

dfs([0])

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase

n = int(input())

def f(l):
    if len(l)==n:
        print("".join([ascii_lowercase[i] for i in l]))
        return
    
    for i in range(l[-1]+2):
        f(l+[i])

f([0])

Submission status: Wrong Answer

Solution code:
n = map(int, raw_input().split(' '))[0]

def dfs(i, n, res, cur = []):
	if i==n:
		res.append(''.join(cur[::]))
		return

	vs = range(i+1)
	for v in vs: #range(last+1, n):
		dfs(i + 1, n , res, cur + [chr(v+ ord('a'))])

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

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    def dfs(s, num):
        if len(s) == n:
            print(s)
            return

        for i in range(num + 1):
            t = s + chr(97 + i)
            dfs(t, i + 1)

    dfs("", 0)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
# 使えるのは、'a' ~ 今まで使われた次の文字
n = int(input())
def dfs(cnt,s):
    if cnt == n:
        print(s)
        return
    biggest = 'a'
    c = 0
    while c < len(s):# 最後はどこまで？
        if s[c] == biggest:
            biggest = chr(ord(biggest)+1)
            c += 1
        else:
            break
    #print(c)
    for i in range(0,c+1):
        sc = chr(ord('a') + i)
        #print(sc)
        s += sc
        dfs(cnt + 1, s)
        s = s[:-1]

dfs(0,"")

Submission status: Wrong Answer

Solution code:
# Problem D - String Equivalence

from collections import deque

# input
N = int(input())

char_list = [chr(i) for i in range(97, 97+26)]

def dfs(a_list, a_len, char_count):
    if a_len==N:
        print("".join(a_list))
    else:
        for i in range(char_count):
            a_list.append(char_list[i])
            dfs(a_list, a_len+1, i + 2)
            a_list.pop()

# initialization
a_nums = deque([])

# dfs search
dfs(a_nums, 0, 1)

Submission status: Wrong Answer

Solution code:
def DFS(word):
    if len(word)==n:print(word)
    else:
        for i in range(len(word)+1):
            DFS(word+chr(97+i))


n=int(input())
DFS("a")

Submission status: Wrong Answer

Solution code:
def DFS(word):
    if len(word)==n:print(word)
    else:
        for i in [chr(j) for j in range(97,97+n)]:
            DFS(word+i)


n=int(input())
DFS("a")

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

def main():
    N = int(input())
    letterset = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
    check = []
    for i in range(1, N+1):
        iters = itertools.product(letterset[:i], repeat=N)
        for tmp in iters:
            if len(set(tmp)) == i:
                flag = True
                if tmp[0] != 'a':
                    flag = False
                for k in range(N-1):
                    t = bisect.bisect_right(letterset, tmp[k])
                    if not tmp[k+1] in letterset[:t+1]:
                        flag = False
                if flag:
                    check.append(tmp)
                    print(''.join(tmp))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools

def main():
    N = int(input())
    letterset = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
    for i in range(1, N+1):
        iters = itertools.combinations_with_replacement(letterset[:i], N)
        for tmp in iters:
            if len(set(tmp)) == i:
                print(''.join(tmp))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools

def main():
    N = int(input())
    letterset = ['a', 'b', 'c', 'd', 'e', 'f', 'e', 'h', 'i', 'j']
    for i in range(1, N+1):
        iters = itertools.combinations_with_replacement(letterset[:i], N)
        for tmp in iters:
            if len(set(tmp)) == i:
                print(''.join(tmp))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
def dfs(s):
  if len(s) == n:
    print(s)
  else:
    final = ord(s[-1])
    for i in range(ord("a"),final+2):
      s = s + chr(i)
      dfs(s)
      s = s[:len(s) - 1]
      
dfs("a")