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:
n = str(input())
num2alpha = lambda c: chr(c+97)

def plus(string):
    tmp = []
    for i in range(0,min(int(n)+1,int(string[-1])+2)):
        tmp.append(string+str(i))
    return tmp

if n == "1":
    print(1)
else:
    ans = ["0"]
    for i in range(int(n)-1):
        for j,a in enumerate(ans):
            ans[j] = plus(a)
        ans = sum(ans,[])
    for i in ans:
        for j in list(i):
            print(num2alpha(int(j)),end="")
        print()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

def search(arr):
  global N, char
  if len(arr) == N:
    ans = ''.join([char[x] for x in arr])
    print(ans)
    return
  else:
    for i in range(arr[-1] + 2):
      arr_next = arr + [i]
      search(arr_next)

search([0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
c = 'abcdefghij'

def join(s, k, n):
    if len(s) == n:
        return [s]
    ans = []
    for i in range(n - len(s), 0, -1):
        ans += join(s + c[k] * i, k + 1, n)
    return ans

n = int(input())
ans = join('', 0, n)
for x in ans:
    print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = ['a'] * n

while 1:
    print(''.join(ans))
    for i in range(n-1, 0, -1):
        if ord(ans[i]) <= ord(ans[i-1]):
            ans[i] = chr(ord(ans[i]) + 1)
            for j in range(i+1, n):
                ans[j] = 'a'
            break
    else:
        break

Submission status: Wrong Answer

Solution code:
def dfs(out, ln, n):
    if len(out) == n:
        print(out)
    else:
        for i in range(ln, n):
            l = chr(ord('a') + i)
            dfs(out+l, i, n)

n = int(input())
dfs('a', 0, n)

Submission status: Wrong Answer

Solution code:
import itertools as iters

def enlong(s):
    l = s[-1] + 1
    return [s + [i] for i in range(1,l+1)]

N = int(input())
alpha = "abcdefghijk"
R = [[1]]
for _ in range(N-1):
    S = []
    for r in R:
        S += enlong(r)
    R = S[::]
for r in R:
    s = "".join([alpha[ss-1] for ss in r])
    print(s)

Submission status: Wrong Answer

Solution code:
import itertools as iters

N = int(input())
alpha = "abcdefghijk"
for s in iters.product(range(1,N+1),repeat=N-1):
    #print(s)
    r = [alpha[ss-1] for ss in s]
    print("a"+"".join(r))

Submission status: Wrong Answer

Solution code:
import itertools as iters

N = int(input())
alpha = "abcdefghijk"
S = [list(range(1,n+2)) for n in range(N)]

for s in iters.product(*S):
    #print(s)
    r = [alpha[ss-1] for ss in s]
    print("".join(r))

Submission status: Wrong Answer

Solution code:
n = int(input())

for i in range(n):
    ketaume = '0'+str(n)+'b'
    print(format(i, ketaume).translate(str.maketrans({'0': 'a', '1': 'b'})))

Submission status: Wrong Answer

Solution code:
n=int(input())
#ans=[]
num=(2**(n-1))
for i in range(num):
    b=(bin(i)[2:].zfill(n))
    tmp=""
    for each in b:
        if each=="0":
            tmp+="a"
        else:
            tmp+="b"
    #ans.append(tmp)
    print(tmp)
#print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
alpha = "abcdefghij"
ans = []
N = int(input())

def get_right(S):
    alpha_idx = 0
    for i in range(len(S)):
        idx = S.find(alpha[i])
        if idx > 0:
            alpha_idx = idx
    return alpha_idx + 2


def dfs(S):
    if len(S) == N:

        ans.append(S)
    else:
        right = get_right(S)
        seq = alpha[:right]
        for c in seq:
            dfs(S+c)
    return

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

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = ["a"]
for i in range(N-1):
    new = []
    for j in range(len(ans)):
        l = ord(ans[j][-1])-95
        add = [chr(ord("a") + idx) for idx in range(l)]
        for k in add :
            new.append(ans[j] + k)
    ans = new

for p in ans:
    print(p)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
alpha = "abcdefghij"
ans = []
N = int(input())

def dfs(S):
    if len(S) == N:

        ans.append(S)
    else:
        right = alpha.find(S[-1])+2
        seq = alpha[:right]
        for c in seq:
            dfs(S+c)
    return

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
alpha = "abcdefghij"
ans = []
N = int(input())

def dfs(S):
    if len(S) == N:

        ans.append(S)
    else:
        right = min(alpha.find(S[-1])+2, (len(S)+1))
        seq = alpha[:right]
        for c in seq:
            dfs(S+c)
    return

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

Submission status: Wrong Answer

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

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n=int(input())
	s="abcdefghijklmn"

	li=[[] for _ in range(10)]
	li[0]="a"

	for i in range(1,10):
		for t in li[i-1]:
			for j in range(i+1):
				if s[j]=="a" or ord(t[-1])<=ord(s[j])<=ord(t[-1])+1:
					li[i].append(t+s[j])

	for i in li[n-1]:
		print(i)


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n=int(input())
	s="abcdefghijklmn"

	li=[[] for _ in range(10)]
	li[0]="a"

	for i in range(1,10):
		for t in li[i-1]:
			for j in range(i+1):
				if ord(t[-1])+1>=ord(s[j]):
					li[i].append(t+s[j])

	for i in li[n-1]:
		print(i)


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
import math
# import decimal
# import queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # queue
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def dfs(s,pos):
    global n
    if pos==n:
        print(s)
        return
    for i in range(ord('a'),ord('a')+pos+1):
        t = s
        t += chr(i)
        dfs(t,pos+1)

def main():
    global n
    n = int(input())
    dfs("",0)
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math


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


result = []


def create( max_letter, remaining_depth, text ):
    if remaining_depth == 0:
        result.append(text)
        return
    
    for i in range(0,max_letter+1):
        new_text = text + data[i]
        create( i+1,remaining_depth-1,new_text )
        
    
        
        





N = int(input())

create( 0,N,"")

result.sort()
for line in result:
    print(line)

Submission status: Wrong Answer

Solution code:
import math


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


result = []


def create( max_letter, remaining_depth, text ):
    if remaining_depth == 0:
        result.append(text)
        return
    
    for i in range(0,max_letter+1):
        new_text = text + data[i]
        create( max_letter+1,remaining_depth-1,new_text )
        
    
        
        





N = int(input())

create( 0,N,"")

result.sort()
for line in result:
    print(line)

Submission status: Wrong Answer

Solution code:
n=int(input())
abc='abcdefghij'
def dfs(i,a,s):
    if i==n:
        print(s)
    else:
        for j in range(0,a+1):
            dfs(i+1,j+1,s+abc[j])
dfs(0,0,'')

Submission status: Wrong Answer

Solution code:
n=int(input())

def dfs(ans,count):
    if len(ans)==n:
        print(ans)
    else:
        for i in range(n):
            dfs(ans+chr(97+i),count+1)

dfs("a",0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[[] for _ in range(n)]
a[0]="a"
al=["a","b","c","d","e","f","g","h","i","j"]
b=[[] for _ in range(n)]
b[0]=[1]
for i in range(1,n):
    for j in range(len(a[i-1])):
        for k in range(b[i-1][j]+1):
            a[i].append(a[i-1][j]+al[k])
            if b[i-1][j]<=i+1:
                b[i].append(b[i-1][j])
            else:
                b[i].appemd(b[i-1][j]+1)
for i in range(len(a[n-1])):
    print(a[n-1][i])

Submission status: Wrong Answer

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

def dfs(str_list, now):
    str_list.append(chr(now))
    if len(str_list) == n:
        print(''.join(str_list))
    else:
        chr_a = ord('a')
        for c in range(chr_a, now + 2, 1):
            str_list_cp = copy.deepcopy(str_list)
            dfs(str_list_cp, c)

dfs([], ord('a'))

Submission status: Wrong Answer

Solution code:
n = int(input())
L = [['a','a']]
for i in range(1,n):
    new = []
    for j in range(len(L)):
        temp = L[j][1]
        cur = ord(L[j][0])-96
        for k in range(cur+1):
            ap = temp+chr(97+k)
            if chr(97+k) < L[j][0]:
                new.append([L[j][0], ap])
            else:
                new.append([chr(97+k), ap])
    L = new
L.sort()
for i in range(len(L)):
    print(L[i][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
L = ['a']
for i in range(1,n):
    new = []
    for j in range(len(L)):
        temp = L[j]
        cur = ord(temp[len(temp)-1])-95
        for k in range(cur):
            ap = temp+chr(97+k)
            new.append(ap)
    L = new
L.sort()
for i in range(len(L)):
    print(L[i])

Submission status: Wrong Answer

Solution code:
N = int(input())

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]

ans = []

# mx: 現時点でのmax
def dfs(s, mx):
    print(':', s, mx)
    if len(s) == N:
        # print(s)
        ans.append(s)
        return
    
    for i in range(mx + 2):
        ns = s + chars[i]
        if i == mx + 1:
            nmx = i
        else:
            nmx = mx
        dfs(ns, nmx)

dfs('a', 0)


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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
alpha = [chr(ord('a') + i) for i in range(26)]

def dfs(s, max_i):
  if len(s) == N:
    print(s)
  else:
    for i in range(97,max_i+1):
      dfs(s+chr(i), i if i != max_i else max_i+1)

dfs('', 97)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
alpha = [chr(ord('a') + i) for i in range(26)]

def dfs(s, max_i):
  if len(s) == N:
    print(s)
  else:
    for i in range(97,max_i+1):
      dfs(s+chr(i), i if i != max_i else i+1)

dfs('', 97)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
alpha = [chr(ord('a') + i) for i in range(26)]

def dfs(s, max_i):
  if len(s) == N:
    print(s)
  else:
    for i in range(97,max_i+1):
      dfs(s+chr(i), i+1)

dfs('', 97)

Submission status: Wrong Answer

Solution code:
N = int(input())
alpha = [chr(ord('a') + i) for i in range(26)]

def dfs(s, max_i):
  if len(s) == N:
    print(s)
  else:
    for i in range(97,max_i+1):
      dfs(s+chr(i), i+1)

dfs('', 97)

Submission status: Wrong Answer

Solution code:
N = int(input())

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]

ans = []

def dfs(s):
    if len(s) == N:
        # print(s)
        ans.append(s)
        return
    
    end = s[-1]
    end_i = chars.index(end)
    for i in range(end_i + 2):
        ns = s + chars[i]
        # print('-', i, ns)
        dfs(ns)

dfs('a')


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

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]


def dfs(s):
    if len(s) == N:
        print(s)
        return
    
    end = s[-1]
    end_i = chars.index(end)
    for i in range(end_i + 2):
        ns = s + chars[i]
        # print('-', i, ns)
        dfs(ns)

dfs('a')

Submission status: Wrong Answer

Solution code:
N = int(input())

alphabets = 'abcdefghijklmnopqrstuvwxyz'

def dfs(s, max_idx):
  if len(s) == N:
    print(s)
    return
  else:
    for i in range(0, max_idx+1):
      t = s
      t = t + alphabets[i]
      dfs(t, max(i, max_idx)+1)
    
dfs("", 0)

Submission status: Wrong Answer

Solution code:
N = int(input())

alphabets = 'abcdefghijklmnopqrstuvwxyz'

def dfs(s, max_idx):
  if len(s) == N:
    print(s)
    return
  else:
    for i in range(0, max_idx+1):
      t = s
      t = t + alphabets[i]
      dfs(t, max(i, max_idx+1))
    
dfs("a", 1)

Submission status: Wrong Answer

Solution code:
N = int(input())

alphabets = 'abcdefghijklmnopqrstuvwxyz'

def dfs(s, max_idx):
  if len(s) == N:
    print(s)
    return
  else:
    for i in range(0, max_idx+1):
      t = s
      t = t + alphabets[i]
      dfs(t, max(i, max_idx))
    
dfs("a", 1)

Submission status: Wrong Answer

Solution code:
N = int(input())

alphabets = "abcdefghijklmnopqrstuvwxyz"

def dfs(s, max_idx):
  if len(s) == N:
    print(s)
    return
  else:
    for i in range(0, max_idx+1):
      t = s
      t = t + alphabets[i]
      dfs(t, max(i, max_idx))
    
dfs("a", 1)

Submission status: Wrong Answer

Solution code:
import math
from heapq import heappush, heappop

N = int(input())
q = []

for i in range(1 << N):  
  s = ''.join('b' if i & (1 << x) else 'a' for x in range(N))
  heappush(q, s)
  
                 
for _ in range(math.ceil((1 << N) / 2)):
  s = heappop(q)
  print(s)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

N = int(input())

q = []

for i in range(1 << N):  
  s = ''.join('b' if i & (1 << x) else 'a' for x in range(N))
  heappush(q, s)
  
                 
for _ in range((1 << N) // 2):
  s = heappop(q)
  print(s)

Submission status: Wrong Answer

Solution code:
S = "abcdefghijklmn"


def calc(depth, a, ans):
    if 0 < depth:
        for i in range(a + 2):
            calc(depth - 1, i, ans + S[i])
    else:
        print(ans)
        return


def main():

    N = int(input())

    calc(N, -1, "")


main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n=int(input())
al=[chr(ord('a') + i) for i in range(26)]
d=deque([])
d.append([0])
# print(d)
while 1:
    if len(d[0])==n:
        break
    tmp=d.popleft()
    for i in range(tmp[-1]+2):
        d.append(tmp+[i])
    
d=list(d)
d.sort()
for i in range(len(d)):
    tmp=""
    for j in range(len(d[0])):
        tmp+=al[d[i][j]]
    print(tmp)

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n=int(input())
al=[chr(ord('a') + i) for i in range(26)]
d=deque([])
d.append([0])
# print(d)
while 1:
    if len(d[0])==n:
        break
    tmp=d.popleft()
    for i in range(tmp[-1]+2):
        d.append(tmp+[i])
    
for i in range(len(d)):
    tmp=""
    for j in range(len(d[0])):
        tmp+=al[d[i][j]]
    print(tmp)

Submission status: Wrong Answer

Solution code:
n = int(input())

def dfs(s):
  if len(s) == n:
    print(s)
  else:
    for i in range(ord(s[len(s) - 1]) - ord('a') + 2):
      dfs(s + chr(i + ord('a')))
      
s = 'a'
dfs(s)

Submission status: Wrong Answer

Solution code:
n = int(input())

def dfs(s):
  if len(s) == n:
    print(s)
  else:
    for i in range(ord(s[len(s) - 1]) - ord('a') + 1):
      s += chr(i + ord('a'))
      dfs(s)
      
s = 'a'
dfs(s)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)


def dfs(s):
    if len(s) == 0:
        new_s = 'a'
        if len(new_s) != n:
            dfs(new_s)
        else:
            print(new_s)
    else:
        for i in range(ord('a'), ord(s[-1]) + 2):
            new_s = s + chr(i)
            if len(new_s) != n:
                dfs(new_s)
            else:
                print(new_s)


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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)


def dfs(s):
    if len(s) == 0:
        new_s = 'a'
        if len(new_s) != n:
            dfs(new_s)
        else:
            print(new_s)
    else:
        for i in range(ord('a'), ord(s[-1]) + 2):
            new_s = s + chr(i)
            if len(new_s) != n:
                dfs(new_s)
            else:
                print(new_s)


n = int(input())
string = ''
dfs(string)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  def dfs(s):
    if len(s) == n:
      print(s)
      return
    for i in range(ord('a'), ord(s[-1])+2):
      dfs(s + chr(i))
  dfs('a')
      
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    
    def dfs(s, s_n):
        if len(s) == N:
            print(s)
        else:
            cp = ord('a')
            for i in range(cp, cp+N):
                dfs(s + chr(i), '')

    dfs('a', '')

solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n=int(input())
al=[chr(ord('a') + i) for i in range(26)]
norm=defaultdict(list)
for i in range(11):
  if i==0:
    norm[1]=['a']
  else:
    for char in norm[i-1]:
      last=char[-1]
      range_digit=al.index(last)+2
      for s in al[0:range_digit]:
        norm[i].append(char+s)

for char in norm[n]:
  print(char)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  def dfs(s, depth=1):
    if depth == n:
      print(s)
      return
    for i in range(ord(s[-1]), ord(s[-1])+2):
      dfs(s + chr(i), depth+1)
  dfs('a')
      
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  def dfs(s, depth=1):
    if depth == n:
      print(s)
      return
    for i in range(ord(s[-1]), ord('a')+n):
      dfs(s + chr(i), depth+1)
  dfs('a')
      
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = ['a']
for i in range(N-1):
    tmp = []
    for s in ans:
        j = ord(s[-1]) - ord('a') + 1
        for k in range(j+1):
            tmp.append(s + chr(ord('a') + k))
    ans = tmp
print(*ans, sep='\n')

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())
ans = []
sets = {}
def dfs(s,keta):
  # print(s)
  if keta == n+1:
    # for sude in ans:
    #   doukei = 1
    #   for i in range(n-1):
    #     for j in range(i+1,n):
    #       if not ((sude[i] == sude[j] and s[i] == s[j]) or (sude[i] != sude[j] and s[i] != s[j])):
    #         doukei = 0
    #   if doukei: 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:
n=int(input())
print('a'*n)
string="abcdefghij"
if n==1:
    exit()
for i in range(n):
    print(string[i],end="")

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
l = list(range(N))
lst = []
for i in itertools.product(l,repeat = N):
    if i[0] != 0:
        break
    flg = True
    for j in range(len(i)-1):
        if i[j+1] > i[j] + 1:
            flg = False
            break
    if flg:
        lst.append(i)
for i in lst:
    for j in i:
        print(chr(ord('a')+j),end="")
    print("")

Submission status: Wrong Answer

Solution code:
N = int(input())

answer = [(97, 'a')]
for _ in range(N - 1):
    new_answer = []
    for i, j in answer:
        for k in range(97, i + 1):
            new_answer.append((k, j + chr(k)))
        new_answer.append((i+1,j+chr(i+1)))
    answer = new_answer[:]

answer = [j for _, j in answer]
answer.sort()
print('\n'.join(answer))

Submission status: Wrong Answer

Solution code:
N = int(input())
X = [chr(ord('a') + i) for i in range(N)]

ans = ['a']
# 何文字目以降を変更するか
for i in range(1, N):
    next_ans = []
    for s in ans:
        max_s = max(s)
        for x in X:
            next_ans.append(s + x)
            if s == x:
                break
        next_ans.append(s + chr(ord(max_s) + 1))
    ans = next_ans

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

Submission status: Wrong Answer

Solution code:
def f(n, count=0, i=0, lst=[]):
    global ans
    if count == n:
        s = ""
        for j in range(count):
            s += chr(ord("a") + lst[j])
        ans.append(s)
        return
    if i == 0:
        lst.append(i)
        f(n, count + 1, i=i+1, lst=lst)
    else:
        for j in range(i + 1):
            f(n, count + 1, i=max(i, j), lst=lst+[j])

import sys
sys.setrecursionlimit(10000)
n = int(input())
ans = []
f(n)
ans.sort()
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = [chr(ord('a') + i) for i in range(N)]

ans = ['a']
# 何文字目以降を変更するか
for i in range(1, N):
    next_ans = []
    for s in ans:
        max_s = max(s)
        for x in X:
            next_ans.append(s + x)
            if s == x:
                break
        next_ans.append(s + chr(ord(max_s) + 1))
    ans = next_ans

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

Submission status: Wrong Answer

Solution code:
n=int(input())


A='abcdefghijklmnopqrstuvwxyz'

def dfs(s,mx):
    if len(s)==n:
        print(s)
    else:
        for c in range(mx):
            if c==mx-1:
                dfs(s+A[c],mx+1)
            else:
                dfs(s+A[c],mx)



print(dfs('',1))

Submission status: Wrong Answer

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

def dfs(string,n):
    if len(string)==n:
        print(string)
    else:
        s=string
        for i in range(97,max([ord(j)for j in string])+2):
            dfs(string+chr(i),n)
        

dfs(start,n)
print(len(ans))
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
from collections import deque

ans= deque()
n=int(input())
ans.append("a"*n)

ds=["a","b","c"]

def str_plus(s):
    s1,s2,s3 = (s + x for x in ds)
    return s1,s2,s3

for i in range(1,n):
    s="a"*(n-i) + "b"

    deq = deque()
    deq.append(s)

    if i==1:
        ans.append(s)
    else:
        while len(deq) > 0:
            sa = deq.popleft()
            s1,s2,s3 = str_plus(sa)
            if len(s1) == n:
                ans.extend([s1,s2,s3])
            else:
                deq.extend([s1,s2,s3])

s_last=""
for i in range(n):
    s_last += chr(ord("a") + i)
ans.append(s_last)

for si in sorted(list(set(ans))):
    print(si)

Submission status: Wrong Answer

Solution code:
from collections import deque

ans= deque()
n=int(input())
ans.append("a"*n)

ds=["a","b","c"]

def str_plus(s):
    s1,s2,s3 = (s + x for x in ds)
    return s1,s2,s3

for i in range(1,n):
    s="a"*(n-i) + "b"

    deq = deque()
    deq.append(s)

    if i==1:
        ans.append(s)
    else:
        while len(deq) > 0:
            sa = deq.popleft()
            s1,s2,s3 = str_plus(sa)
            if len(s1) == n:
                ans.extend([s1,s2,s3])
            else:
                deq.extend([s1,s2,s3])

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

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()

pt = [[] for _ in range(N)]
for i in range(N):
    pt[i] = list(range(i+2))

s = 0
c = 1
S = [[s]]
ans = []
while S:
    v = S.pop()
    if len(v) == N:
        ans.append(v)
        continue
    else:
        for u in pt[v[-1]]:
            S.append(v+[u])

for i,a in enumerate(ans):
    a = list(map(lambda x: chr(x+ord('a')),a))
    ans[i] = ''.join(a)

ans.sort()

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())

A=[chr(ord('a') + i) for i in range(26)]

count = 0

for i in itertools.product(A, repeat=n):
    print(''.join(map(str,i)))
    count += 1
    if count == n:
        break

Submission status: Wrong Answer

Solution code:
import itertools
import math

N=int(input())
cnt=0
lmt=math.factorial(N-1)
L=[chr(i) for i in range(97, 97+N)]

for v in itertools.product(L, repeat=N):
    ans=''.join(v)
    print(ans)
    cnt+=1
    if cnt>lmt:
      exit()

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]+96) 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:
from collections import deque

q = deque()

q.append('a')

n = int(input())

ans_list = []
flag = 0

if n != 1:
    while flag == 0:
#            print(q)
        s = q.pop()
        if len(s) > n:
            flag = 1
        a = list(s)
#        print(s,a)
        x = chr(ord('a')-1)
        while ord(x) != ord(a[len(a)-1])+1:
            x = chr(ord(x)+1)
            y = s + x
            q.appendleft(y)
            if len(y) == n:
                ans_list.append(y)
else:
    ans_list = ['a']

ans_list = sorted(ans_list)

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

A = "abcdefghij"
N = 0
def dfs(s, lim, prev):
    global N
    if len(s) == N:
        print("".join(s))
        # s = []
        return
    for i in range(lim):
        if prev + 1 >= i:
            s.append(A[i])
            dfs(s, lim + 1, i)
            s.pop()
    # print(s)
    # dfs(s, prev)
    # s[-1] = A[prev + 1]
    # dfs(s, n+1, prev+1)

def main():
    global N
    N = int(input().strip())
    dfs([], 1, 0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    if n == 1:
        return "a"
    r = []
    def f(t):
        u = chr(ord(t[-1])+1)
        lf = len(t) == n - 1
        for c in string.ascii_lowercase:
            if c > u:
                break
            if lf:
                r.append(JA(t+[c], ""))
            else:
                f(t+[c])
    f(['a'])

    return JA(r, "\n")


print(main())

Submission status: Wrong Answer

Solution code:
from collections import deque

q = deque()

q.append('a')
ans_list = ['a']

n = int(input())

if n != 1:
    for i in range(n-1):
        for j in range(2**i):
            s = q.pop()
            a = list(s)
            b = s + chr(ord(a[len(a)-1]))
            q.appendleft(b)
            ans_list.append(b)
            c = s + chr(ord(a[len(a)-1])+1)
            q.appendleft(c)
            ans_list.append(c)

ans_list = sorted(ans_list)

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