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
n =int(input())
alp = [chr(i+64) for i in range(1,n+1)]
cmbs = list(itertools.combinations_with_replacement(alp,n))
for cmb in cmbs:
    flg = False
    for i, al in enumerate(alp):
        if al in cmb:
            for a in alp[0:i]:
                if a not in cmb:
                    flg = True
                    break
            if flg:
                break
    if not flg:
        print(''.join(cmb))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N = int(input())

ans = [[] for i in range(2**(N-1))]
for i in range(N): #桁
    one_set = 2**(N-1-i)
    counter = 0
    for _ in range(len(ans)//one_set):
        second = _%2
        for j in range(one_set):
            if not ans[counter]:
                ans[counter].append(0)
            else:
                ans[counter].append(ans[counter][-1]+int(second))
            counter += 1
def repqqq(array):
    alpha = "abcdefghijklmn"
    temp = []
    for a in array:
        temp.append(alpha[a])
    return "".join(temp)
ans = [repqqq(line) for line in ans]
for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit
setrecursionlimit(10**6)

def array2D(row, col ,val=0):
    return [[val]*col for i in range(row)]

n = int(input())
t = [[1]]
for i in range(n-1):
    new_t = []
    for s in t:
        for j in range(len(s)):
            s_copy = s[:]
            s_copy[j] += 1
            s_copy.sort(reverse=True)
            if s_copy not in new_t:
                new_t.append(s_copy)
        s_copy = s+[1]
        s_copy.sort(reverse=True)
        if s_copy not in new_t:
            new_t.append(s_copy)
    t = [list(p) for p in new_t]

ans = []
for v in t:
    o = ord('a')
    str = ''
    for i in v:
        for j in range(i):
            str += chr(o)
        o += 1
    ans.append(str)
ans.sort()
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
n = int(input())

alp = [chr(v) for v in range(ord("a"), ord("z") + 1)]

results = []
def f(i=0, j=0, s="a"):
    if i == n - 1:
        return results.append(s)
    f(i + 1, j, s + alp[j])
    f(i + 1, j + 1, s + alp[j + 1])
f()
print(len(results))
print(*results, sep="\n")

Submission status: Wrong Answer

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

N = int(input())

def bfs(s, cnt):
	if cnt == N:
		print(s)
		return 0

	for i in range(97,ord(s[-1])+2):
		bfs(s+chr(i), cnt+1)

bfs('a',1)

Submission status: Wrong Answer

Solution code:
from itertools import product, combinations_with_replacement
N=int(input())
s="abcdefghij"
for i in range(N):
  c = s[:i+1]
  for p in product(s[:i+2],repeat=N-i-1):
    if p and p[0] not in c:
      break
    print(c+"".join(p))

Submission status: Wrong Answer

Solution code:
n = int(input())

stack = [(0, [])]
answers = []
while stack:
    total, digits = stack.pop()
    if total == n:
        buffers = [['a' * digits[0]]]
        alphabets = 'abcdefghiljlmnopqrstuvwxyz'
        while buffers:
            buffer = buffers.pop()
            if len(buffer) == len(digits):
                answers.append(''.join(buffer))
                continue

            x = alphabets.index(buffer[-1][0])
            for i in range(x + 2):
                if i == x: 
                    continue
                nxts = list(buffer)
                nxts.append(alphabets[i] * digits[len(buffer)])
                buffers.append(nxts)

        #     if is_a:
        #         answer.append('a' * digit)
        #     else:
        #         answer.append('b' * digit)
        #     is_a = not is_a
        # answers.append(''.join(answer))

    if total < n:
        for digit in range(1, n - total + 1):
            nxts = list(digits)
            nxts.append(digit)
            stack.append((total + digit, nxts))

answers.sort()
for answer in answers:
    print(answer)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(5000000)
N = int(input())
ans = []


def func(s):
    if len(s) == N:
        ans.append(s)
    else:
        func(s+s[-1])
        func(s+chr(ord(s[-1])+1))
        if s[-1] > 'a':
            func(s+'a')


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

Submission status: Wrong Answer

Solution code:
n = int(input())
cands = set([])

def dfs(count,i):
  if count ==0:
    cands.add(tuple(i))
  for j in range(1,count+1):
    dfs(count-j,i+[j])
dfs(n,[])

from itertools import permutations

ans = []
for c in cands:
  s = ''
  for i in range(len(c)):
    s += chr(97+i)* c[i]
    ans.extend(list(permutations(s,n)))
ans = list(set(ans))
ans.sort()
for i in range(len(ans)):
  for j in range(n):
    if ord(ans[i][j])-97 > j:
      break
  else:
    print(''.join(ans[i]))

Submission status: Wrong Answer

Solution code:
from functools import reduce
n = int(input())

alphabet = "abcdefghij"

cur = [[] for _ in range(10)]
nxt = [[] for _ in range(10)]

cur[0] = ["a"]
for _ in range(1, n):
	for i in range(10):
		for x in cur[i]:
			nxt[i].extend([x + alphabet[j] for j in range(i + 1)])
			nxt[i + 1].append(x + alphabet[i + 1])
	cur = nxt.copy()
	nxt = [[] for _ in range(10)]
ans = reduce(lambda a, b: a + b, cur)
print(*ans, sep = "\n")

Submission status: Wrong Answer

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

def update(a, m):
    for val_a, val_m in zip(a,m):
        a_new = []
        m_new = []
        for i in range(val_m + 2):
            a_new += [val_a + alp[i]]
            m_new += [max(val_m, i)]
    return a_new, m_new

a = ['a']
m = [0]

for i in range(n-1):
  a, m = update(a,m)

for v in a:
  print(v)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=['a','b','c','d','e','f','g','h','i','j']
ans=['a']
for i in range(2,n+1):
    que=L[:i]
    temp2=[]
    for moji in que:
        temp=[]
        for a in ans:
            a=''.join([a,moji])
            temp.append(a)
        temp2+=temp
    ans=temp2
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:

N = int(input())

ans = []
chars = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
def func(N, s):
    if len(s) == N:
        ans.append(s)
        return

    if len(s) == 0:
        size = 1
    else:
        size = ord(s[-1]) - 95
    for c in chars[:size]:
        func(N, s+c)

func(N,"")

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

Submission status: Wrong Answer

Solution code:
n = int(input())

alf = 'abcdefghijk'

ans = 'a'
index = 0

if n == 1:
    print(1)
    exit(0)

for _ in range(n):
    temp = ans
    temp = temp + alf[index]
    print(temp)
    index += 1

Submission status: Wrong Answer

Solution code:
n = int(input())
#lis = ['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]
ans = []
#for i in range(n):
t = ['a'] * n

ans.append(''.join(t))
for j in range(1,n):
    t = ['a'] * n
    t[j] = 'b'
    ans.append(''.join(t))
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

N = I()
ans = []
for bit in range(1 << N):
    tmp = ""

    for i in range(N):
        if bit & (1 << i):
            tmp += ("a")
        else:
            tmp += ("b")
    
    ans.append(tmp[::-1])

ans.reverse()

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

Submission status: Wrong Answer

Solution code:
N = int(input())
# 97~122
# 0~25


def chrs(X):
    r = ""
    for x in X:
        r += chr(int(x)+97)
    return r


def inv(X):
    R = ""
    for x in X:
        if x == "0":
            R += "1"
        elif x == "1":
            R += "0"
    return R


Xs = []
for i in range(2 ** N):
    X = bin(i)[2:]
    if len(X) < N:
        X = "0" * (N - len(X)) + X
    if inv(X) in Xs:
        pass
    else:
        Xs.append(X)
for X in Xs:
    print(chrs(X))

Submission status: Wrong Answer

Solution code:
alp = ["a","b","c","d","e","f","g","h","i","j"]
N = int(input())
ans_list = []
for i in range(N):
    ans_list.append([])
for i in range(N):
    if i == 0:
        ans_list[0].append("a")
    else:
        for j in range(len(ans_list[i-1])):
            if ans_list[i-1][j][-1] == "a":
                for l in range(2):
                    temp = ans_list[i-1][j] + alp[l]
                    ans_list[i].append(temp)
            elif ans_list[i-1][j][-1] == "b":
                for l in range(3):
                    temp = ans_list[i-1][j] + alp[l]
                    ans_list[i].append(temp)
            elif ans_list[i-1][j][-1] == "c":
                for l in range(4):
                    temp = ans_list[i-1][j] + alp[l]
                    ans_list[i].append(temp)
            elif ans_list[i-1][j][-1] == "d":
                for l in range(5):
                    temp = ans_list[i-1][j]+ alp[l]
                    ans_list[i].append(temp)
            elif ans_list[i-1][j][-1] == "e":
                for l in range(6):
                    temp = ans_list[i-1][j] + alp[l]
                    ans_list[i].append(temp)
            elif ans_list[i-1][j][-1] == "f":
                for l in range(7):
                    temp = ans_list[i-1][j] + alp[l]
                    ans_list[i].append(temp)
            elif ans_list[i-1][j][-1] == "g":
                for l in range(8):
                    temp = ans_list[i-1][j] + alp[l]
                    ans_list[i].append(temp)
            elif ans_list[i-1][j][-1] == "h":
                for l in range(9):
                    temp = ans_list[i-1][j] + alp[l]
                    ans_list[i].append(temp)
            elif ans_list[i-1][j][-1] == "i":
                for l in range(10):
                    temp = ans_list[i-1][j] + alp[l]
                    ans_list[i].append(temp)
for i in range(len(ans_list[N-1])):
    print(ans_list[N-1][i])

Submission status: Wrong Answer

Solution code:
from itertools import combinations_with_replacement as cb

N = int(input())
al = [chr(i) for i in range(97, 97 + 26)]

ans = []
for C in cb(al[:N], N):
    if C[0] != 'a': continue
    X = set(C)
    flag = True
    for i in range(len(X)):
        if chr(i + 97) not in X:
            flag = False
    if flag:
        ans.append(''.join(C))
ans.sort()
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
n = int(input())
lets = [chr(i) for i in range(ord("a"), ord("a") + n)]
d = {e: i for i, e in enumerate(lets)}

s = ["a"]
for i in range(1, n):
    nxt = []
    for e in s:
        let = e[-1]
        for j in range(d[let] + 2):
            nxt.append(e + lets[j])
    s = nxt

print(*s, sep="\n")

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(raw_input())
    ret = ['a']
    for i in range (2, N+1):
        tmp = []
        for stri in ret:
            for j in range(ord('a'), ord(stri[-1]) + 2):
                tmp.append(stri + chr(j))
        ret = tmp
    for stri in ret:
        print stri

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())

alf = 'abcdefghijk'

ans = 'a'
index = 0

for _ in range(n):
    temp = ans
    temp = temp + alf[index]
    print(temp)
    index += 1

Submission status: Wrong Answer

Solution code:
alf = 'abcdefghijklmnopqrstuvwxyz'
d = {c:i+1 for i,c in enumerate(alf)}
d['z']=25
def dfs(n):
    lst = []
    lst.append(['a'])
    while lst:
        a = lst.pop()
        if len(a) == n:
            print(''.join(a))
            continue
        for i in range(d[a[-1]]+1)[::-1]:
            lst.append(a + [alf[i]])

n= int(input())
dfs(n)

Submission status: Wrong Answer

Solution code:
N = int(input())

s = []

A = "abcdefghijklmnopqrstuvwxyz"

def ss(n):
    if n == 1:
        return [[0]]
    tt = ss(n-1)
    res = []
    for t in tt:
        for i in range(t[-1]+2):
            res.append(t + [i])
    return res

for s in ss(N):
    S = ''.join([A[i] for i in s])
    print(S)

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")

Submission status: Wrong Answer

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

ans = set()
for v in itertools.combinations_with_replacement(l, n):
  m = min(v)
  diff = m - 1 
  tmp = ""
  num = m-diff 
  for n in v:
    if n-diff != num:
      num += 1
    tmp += str(alpha_dict[num].lower()) 
  ans.add(tmp)

ans = sorted(list(ans))
for v in ans:
  print(v)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a = int(input())

l = 1
cur_ret = [[0]]
while l < a:
    new_ret = []
    na = new_ret.append
    for i in cur_ret:
        for j in range(i[-1]+2):
            na(i+[j])
    cur_ret = new_ret
    l+=1

def format(x):
    x = list(map(lambda x : chr(x+97),x))
    return "".join(x)

cur_ret.sort()
for i in cur_ret:
    print(format(i))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())

    ans = []

    def fanc(i, l, s):
        if l == n:
            ans.append(s)
        else:
            for x in range(i+1):
                fanc(max([x, i]) + 1, l + 1, s + chr(97 + x))
                # fanc(x + 1, l + 1, s + chr(97 + x))

    fanc(0, 0, "")

    for i in ans:
        print(i)

main()

Submission status: Wrong Answer

Solution code:
n = int(input())

strings = ["a"]

for i in range(n-1):
    newstrings = []
    for s in strings:
        mx = ord('a')
        for char in s:
            mx = max(mx, ord(char))
        
        for c in range(ord('a'),mx+2):
            newstrings.append(s+chr(c))
    
    strings = newstrings

print(strings)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

# from math import factorial as fact

N = int(input())


w = []


def rec(word):
    length = len(word)

    if length == N:
        w.append(word)
        return None

    tail = word[-1]
    if tail == "z":
        rec(word + "z")
    else:
        rec(word + tail)
        rec(word + chr(ord(tail) + 1))


rec("a")

for word in sorted(w):
    print(word)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans="a"*N
L=["b","c","d","e","f","g","h","i","j","k"]
for i in range(N-1):
    ans+="\n"+"a"*(N-1)+L[i]
print(ans)

Submission status: Wrong Answer

Solution code:
numal=lambda c:chr(c+97)
n=int(input())
unchi=[[],[],[],[],[],[],[],[],[],[]]
unchi[0].append("0")
k=1
if n>=2:
	while k<n:
		for i in range(len(unchi[k-1])):
			for u in range(int(unchi[k-1][i][k-1])+2):
				unchi[k].append(unchi[k-1][i]+str(u))
		k+=1
for i in range(len(unchi[n-1])):
	s = []
	for k in range(n):
		s.append(numal(int(unchi[n-1][i][k])))
	print("".join(s))

Submission status: Wrong Answer

Solution code:
alpha_small_ = [chr(i) for i in range(97, 97+26)] #アルファベッドの小文字

n = int(input())
ans = []
def solve(now,i):
    if len(now) == n:
        ans.append(now)
        return
    for j in range(i+1):
        solve(now+alpha_small_[j],j+1)

solve("a",1)


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

Submission status: Wrong Answer

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
C=[1]*n
Ans=[C]
cur=n-1
while cur:
  cur=0
  for i in range(n-1):
    if C[i+1]<i+2:
      cur=i+1
  D=[]
  for i in range(n):
    if i<cur:
      D.append(C[i])
    elif i==cur:
      D.append(C[i]+1)
    else:
      D.append(1) 
  if cur!=0:
    Ans.append(D)
  C=Ans[-1]
for a in Ans:
  ans=""
  for i in range(n):
    ans+=chr(a[i]+96)
  print(ans)

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase

def resolve():
    n = int(input())
    l = [[0]]
    for i in range(1, n):
        ll = []
        for j in l:
            for k in range(j[-1] + 2):
                ll.append(j + [k])
        l = ll
    for i in l:
        print("".join([ascii_lowercase[x] for x in i]))

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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


N = int(input())
ans = []
a = ord('a')


def f(l, nmax, num):
    global N, a
    if l == N:
        ans.append(''.join(num))
    else:
        for i in range(nmax + 1):
            S = num + [chr(i + a)]
            f(l + 1, nmax + 1, S)


f(0, 0, [])

ans.sort()
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
N = int(input())
if N==1:
    print('a')
    exit()
if N==2:
    print('aa')
    print('ab')
    exit()

ans = []
st = set()
import itertools
for ptn in itertools.product('abc', repeat=N):
    h = 0
    for i in range(N-1):
        for j in range(i+1,N):
            h <<= 1
            if ptn[i]==ptn[j]:
                h += 1
    if h in st: continue
    st.add(h)
    ans.append(''.join(ptn))

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

Submission status: Wrong Answer

Solution code:
import sys
n = int(sys.stdin.readline())

ans = [['a']]
plus = ('a', 'b')

for _ in range(n-1):
    l = []
    for s in ans[-1]:
        for x in plus:
            l.append(s+x)
    ans.append(l)

ans[-1].sort()
print('\n'.join(ans[-1]))

Submission status: Wrong Answer

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

def solve(N: int):
    string = "abcdefghijk"
    print("a"*N)
    ans = []
    for i in range(1,N): #i何個に分割するか
        pattern = list(itertools.combinations(list(range(1,N)),i))
        for k in range(len(pattern)):
            answer = ""

            for j in range(i):
                if j == 0:
                    answer += string[j]*pattern[k][j]
                else:
                    answer += string[j]*(pattern[k][j]-pattern[k][j-1])
            else:
                answer += string[i]*(N-pattern[k][-1])

            ans.append(answer)
    ans.sort()
    for i in range(len(ans)):
        print(ans[i])
    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())

alphabet = "abcdefghijk"


def dfs(k):
    if k == 1:
        return ["a"]

    ret = []
    for r in dfs(k - 1):
        ret += [r + t for t in alphabet[:k]]

    return ret


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

Submission status: Wrong Answer

Solution code:
from itertools import product
n=int(input())
s='abcdefghijklmnopqrstuvwxyz'
use_s=s[:n]
#print(use_s,1)
for i in product(list(use_s), repeat=n):
    ans=''.join(i)
    if use_s<ans:continue
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = [chr(ord('a') + i ) for i in range(n)]

def dfs(i,now):
  if len(now) == n:
    print(now)
    return
  for j in range(i,n):
    dfs(j+1,now + s[j])

dfs(0,s[0])

Submission status: Wrong Answer

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

def solve(N: int):
    string = "abcdefghijk"
    print("a"*N)
    ans = []
    for i in range(1,N): #i何個に分割するか
        pattern = list(itertools.combinations(list(range(1,N)),i))
        for k in range(len(pattern)):
            answer = ""

            for j in range(i):
                if j == 0:
                    answer += string[j]*pattern[k][j]
                else:
                    answer += string[j]*(pattern[k][j]-pattern[k][j-1])
            else:
                answer += string[i]*(N-pattern[k][-1])

            ans.append(answer)
    
    for i in range(len(ans)):
        print(ans[i])
    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:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

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

n = ni()

import numpy as np

for i in range(2**(n-1)):
  k = list(map(int,format(i, 'b')))
  u = len(k)
  k = [0]*(n-u) + k
  p = list(np.cumsum(k))
  ans = [str(al[j])for j in p]
  print(''.join(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = []


def dfs(s, n):
    lst.append(s)
    if n == N:
        return
    else:
        return dfs(s + 'a', n + 1), dfs(s + 'b', 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 python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

words = set()
alp = list("abcdefghij")
def dfs(n, s):
    if len(s) == n:
        return
    for i in range(0, len(s)):
        for c in alp:
            if ord(c)>ord(s[i])+1:
                break
            ns = s[:i+1]+c+s[i+1:]
            if ns in words:
                continue
            words.add(ns)
            dfs(n, ns)

def main():
    n = ri()
    dfs(n, 'a')
    for w in sorted(words):
        if len(w) == n:
            print(w)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from string import ascii_lowercase

alphs = list(ascii_lowercase)

n = int(sys.stdin.readline().rstrip())

def main():
    cur = ['a']
    for _ in range(n-1):
        nex = []
        for c in cur:
            i = ord(c[-1]) - 97
            for al in alphs[:i+2]:
                nex.append(c + al)
        cur = nex
    return sorted(cur)

if __name__ == "__main__":
    ans = main()
    print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
import string

n = int(input())

Ans = [[] for _ in range(n+1)]
Ans[1].append('a')
Strs = [x for x in string.ascii_lowercase]

for i in range(1,n):
    for ans in Ans[i]:
        Use_str = [x for x in ans]
        Use_str = set(Use_str)
        for moji in Use_str:
            add = ans + moji
            Ans[i+1].append(add)
        add = ans + Strs[len(Use_str)]
        Ans[i+1].append(add)

for ans in Ans[n]:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = ['a' for _ in range(n)]
ans = []
for i in range(2**(n-1)):
	A = ['a' for _ in range(n)]
	for j in range(n-1):
			if i & (1<<j):
				A[j+1] = 'b'

	ans.append(A)

ans.sort()
for i in ans:
	for j in i:
		print(j,end="")
	print()

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
alpha = ['a','b','c','d','e','f','g','h','i','j']
ans = []

stack = deque(['a'])

while stack:
    if len(stack[-1]) == N:
        break
    s = stack.pop()
    s_list = list(s)
    index = alpha.index(s_list[-1])
    for i in range(index+2):
        stack.appendleft(s+alpha[i])
    

stack.reverse()
for j in range(len(stack)):
    print(stack[j])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
data10 = ["aaaaaaaaaa","abcdefghij"]
n = int(input())
if n == 10:
  print(*data10,sep="\n")
  exit()
ans = []
def dfs(s,keta):
  # print(s)
  if keta == n+1:
    for sude in ans:
      for i in range(n-1):
        for j in range(i+1,n):
          if ((sude[i] == sude[j] and s[i] == s[j]) or (sude[i] != sude[j] and s[i] != s[j])):
            return
    ans.append(s)
  else:
    for i in range(keta):
      dfs(s+chr(ord("a")+i),keta+1)

dfs("",1)
ans.sort()
print(*ans,sep = "\n")

# data10 = ["aaaaaaaaaa","abcdefghij"]

Submission status: Wrong Answer

Solution code:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
alphabets = string.ascii_lowercase

N = int(input())
ans = [["a", 0]]
for i in range(N - 1):
    ans2 = copy.deepcopy(ans)
    ans = []
    for l in ans2:
        for k in range(min(l[1] + 2, i + 2)):
            ans.append([l[0] + alphabets[k], k])
for i in ans:
    print(i[0])

Submission status: Wrong Answer

Solution code:
N = int(input())

def bfs(s, cnt):
	if cnt == N:
		print(s)
		return 0

	for i in range(97,ord(s[-1])+2):
		bfs(s+chr(i), cnt+1)

bfs('a',1)

Submission status: Wrong Answer

Solution code:
import sys

N=int(input())
if N==1:
  print("a")
  sys.exit()
  
old_list=[[0]]
for i in range(1,N):
  new_list=[]
  for l in old_list:
    tail=l[-1]
    for k in range(tail+2):
      new_list.append(l+[k])
  old_list=new_list
    
#print(old_list)
llist=["a","b","c","d","e","f","g","h","i","j"]

for ll in old_list:
  #print(ll)
  str_list=[]
  for elm in ll:
    str_list.append(llist[elm])
  print("".join(str_list))

Submission status: Wrong Answer

Solution code:
def search(s):
    if len(s) > max_length:
        print(s)
    else:
        temp = s+"a"
        search(temp)
        temp = s+"b"
        search(temp)

n = int(input())
max_length = n-1

search("a")

Submission status: Wrong Answer

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

def solve(N: int):
    string = "abcdefghijk"
    print("a"*N)
    for i in range(1,N): #i何個に分割するか
        pattern = list(itertools.combinations(list(range(1,N)),i))
        for k in range(len(pattern)):
            answer = ""

            for j in range(i):
                if j == 0:
                    answer += string[j]*pattern[k][j]
                else:
                    answer += string[j]*(pattern[k][j]-pattern[k][j-1])
            else:
                answer += string[i]*(N-pattern[k][-1])

            print(answer) 
    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:
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n=int(input())
al=[chr(ord('a') + i) for i in range(15)]
def dfs(c,i):
    if i==n:
        print(c)
        return
    for k in range(ord(c[-1])-ord('a')+2):
        dfs(c+al[k],i+1)
dfs("a",1)

Submission status: Wrong Answer

Solution code:
from itertools import product
N = int(input())
X = [chr(ord('a') + i) for i in range(N)]
first_presence = {x: i for x, i in zip(X, list(range(N)))}

ans = []
# 何文字目以降を変更するか
for i in range(1, N + 1):
    can_use = X[:i]
    s = ''.join(can_use)
    for pattern in product(can_use, repeat=N - i):
        ans.append(s + ''.join(pattern))


ans.sort()
print(*ans, sep="\n")

Submission status: Wrong Answer

Solution code:
def solve(li):
    if len(li) == n:
        ans.append(li)
        return
    for i in range(1, li[-1] + 2):
        solve(li + [i])

ans = []
n = int(input())
solve([1])
res = []
alph = "abcdefghijklmnopq"

for ptn in ans:
    for i in range(n):
        ptn[i] = alph[ptn[i] - 1]
    res.append("".join(ptn))
res = sorted(res)
for i in res:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
C=[1]*n
Ans=[C]
cur=n-1
while cur:
  cur=0
  for i in range(n-1):
    if C[i+1]<i+2:
      cur=i+1
  D=[]
  for i in range(n):
    if i<cur:
      D.append(C[i])
    elif i==cur:
      D.append(C[i]+1)
    else:
      D.append(1) 
  Ans.append(D)
  C=Ans[-1]
for a in Ans:
  ans=""
  for i in range(n):
    ans+=chr(a[i]+96)
  print(ans)

Submission status: Wrong Answer

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

    for i in range(1, N):
        ns = []
        for s in past:
            for j in range(i + 1):
                ns.append(s + abc[j])
        past = ns
        for s in past:
            print(s)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

#a=0 b=1 ...
def chr2idx(c):
    return ord(c)-ord("a")
def idx2chr(x):
    return chr(ord("a")+x)

N=int(input())
ar=["a"]
if N==1:
    print("a")
    sys.exit()

for i in range(N-1):
    new_ar=[]
    L=len(ar)
    for j in range(L):
        for k in range(chr2idx(ar[j][-1])+2):
            new_ar+=[ar[j]+idx2chr(k)]
    ar=new_ar[:]

L=len(ar)
for i in range(L):
    print(ar[i])

Submission status: Wrong Answer

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

def f(n, st, pre):
    if n == 0:
        print(pre)
        return

    for i in range(n, 0, -1):
        f(n-i, st+1, pre + chr(st + 97)*i)

N = int(input())
f(N, 0, '')

Submission status: Wrong Answer

Solution code:
n=int(input())
d={'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26, 1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o', 16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v', 23: 'w', 24: 'x', 25: 'y', 26: 'z'}
lc=["aaa","aab","aba","abb","abc"]
if n==1:
    print("a")
elif n==2:
    l=["aa","ab"]
    print(*l)

elif n==3:
    print(*lc)
elif n==4:
    ld=[]
    for i in range(1,4):
        for j in range(len(lc)):
            ld.append(lc[j]+d[i])
    print(*ld)

Submission status: Wrong Answer

Solution code:
n = int(input())
n2 = (n**2) - 1
for i in range((2)**(n-1)):
    # print(i)
    ans = []
    s = list(str(format(i, '010b')))
    for i in s:
        if i == "0":
            ans.append("a")
        else:
            ans.append("b")
    
    s = ''.join([str(n) for n in ans[10-n:]])
    print(s)