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 permutationWithRepetitionListRecursive(data, r):
    if r <= 0:
        return []

    result = []
    _permutationWithRepetitionListRecursive(data, r, [], result)
    return result

def _permutationWithRepetitionListRecursive(data, r, progress, result):
    if r == 0:
        result.append(progress)
        return
    for i in range(len(data)):
        _permutationWithRepetitionListRecursive(data, r - 1, progress + [data[i]], result)
    

n =int(input())
alp = [chr(i+96) for i in range(1,n+1)]

pros = permutationWithRepetitionListRecursive(alp,n)
for pro in pros:
    print(''.join(pro))

Submission status: Wrong Answer

Solution code:
import itertools
from sys import exit

N = int(input())

seq = 'abcdefghij'
print('a' * N)
if N == 1:
    exit()

print('a' * (N - 1) + 'b')
if N == 2:
    exit()

for i in range(1, N - 1):
    lst = ['a'] * (N - i - 1) + ['b']
    it = itertools.product(seq[:i + 1], repeat=i)
    while True:
        try:
            print(''.join(map(str, lst + list(next(it)))))
        except StopIteration:
            break
    print(''.join(map(str, lst)) + seq[2:i+2])

Submission status: Wrong Answer

Solution code:
n = int(input())

aa = ["a"]
for i in range(1,n):
    sub = []
    for j in range(len(aa)):
        for k in range(i):
            if not aa[j] + chr(97+k) in sub:
                sub.append(aa[j] + chr(97 + k))
    sub.append(aa[len(aa) - 1] + chr(97 + i))
    aa = sub
for i in range(len(aa)):
    print(aa[i])

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],max(i,j+1))

solve("a",1)


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

print(len(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []
def dfs(s):
    if(len(s) == N):
        ans.append(s)
        return
    else:
        next_str = chr(ord(s[-1]) + 1)
        pre_str = chr(ord(s[-1]) - 1)
        dfs(s + s[-1])
        dfs(s + next_str)
        if(s[-1] != "a"):
            dfs(s + pre_str)

dfs("a")

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = ['a'] * n
ans = []
ans.append(''.join(s))
for i in range(1,n):
    for j in range(i,n):
        s = ['a'] * n
        s[j] = 'b'
        ans.append(''.join(s))
ans.sort()
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    ans = []

    def solve(s, n):
        if n <= 1:
            ans.append(s)
            return

        for i in range(ord(s[-1]) + 2 - ord('a')):
            solve(s + chr(ord('a') + i), n - 1)

    solve('a', N)
    ans.sort()
    for a in ans:
        print(a)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
ans1=""
ans2=""

for i in range(n):
    ans1=ans1+"a"

for j in range(97,n+97):
    ans2=ans2+chr(j)

print(ans1)
print(ans2)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    ans = []

    def solve(s, n):
        if n <= 1:
            ans.append(s)
            return

        for i in range(ord(s[-1]) + 2 - ord('a')):
            solve(s + chr(ord('a') + i), n - 1)

    solve('a', N)
    for a in ans:
        print(a)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**5)
to = "abcdefghij"


def dfs(s, p):
    if len(s) == n:
        print(s)
        return
    if p - 1 >= 0:
        dfs(s + to[p - 1], p - 1)
    if p >= 0:
        dfs(s + to[p], p)
    dfs(s + to[p + 1], p + 1)


n = int(input())
dfs("", -1)

Submission status: Wrong Answer

Solution code:
N = int(input())

my_list = []
for i in range(N):
    if i == 0:
        my_list.append("a")
        continue
    new_list = []
    while my_list:
        s = my_list.pop(0)
        for j in range(ord("a"), ord(s[-1]) + 2):
            new_list.append(s + chr(j))
    my_list += new_list
my_list.sort()

[print(s) for s in my_list]

Submission status: Wrong Answer

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

ans=["a"]
before=0

for i in range(2,n+1):
    for c in range(len(ans)):
        From=char.index(ans[c][-1])
        for m in range(From+2):
            ans.append(ans[c]+char[m])
    #print(ans)
    
for g in range(len(ans)):
    if len(ans[g])==n:
        print(ans[g])

Submission status: Wrong Answer

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

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

    use = [""]
    for i in range(1,N+1):
        ans = []
        for st in use:
            for j in range(i):
                s = chr(97+j)
                if i == N:
                    print(st+s)
                else:
                    ans.append(st+s)
        use = ans
   
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = [int(i) for i in input().split()][0]
ordA = ord("a")

def recursion(x, k, c, words):
  if k == 0:
    words.append(x)
    return
  for i in range(c+2):
    recursion(x+chr(ordA+i), k-1, i, words) 
  
words = []
recursion("a", N - 1, 0, words)
for word in words:
  print(word)

Submission status: Wrong Answer

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

dpn = ['']
dpp = ['']*1
l = 1
for i in range(n):
    for j in range(len(dpn)):
        for k in range(i+1):
            if i <= n:
                dpp[j*(i+1)+k] = dpn[j] + al[k]
            else:
                print(dpn[j] + al[k])
    dpn = dpp
    l *= i+2
    dpp = ['']*l

Submission status: Wrong Answer

Solution code:
n=int(input())
l = ['a','b','c','d','e','f','g','h','i','j','k','l']
arr = ['a']
for i in range(2,n+1):
    temp = []
    for x in l[:i]:
        for y in arr:
            temp.append(y+x)
    arr = temp
for x in arr:
    print(x)

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 = ["0"]
for i in range(1, N):
    ans2 = copy.deepcopy(ans)
    ans = []
    for l in ans2:
        for k in range(int(l[-1]) + 2):
            ans.append(l + str(k))
for i in ans:
    s = ""
    for l in range(N):
        s += alphabets[int(i[l])]
    print(s)

Submission status: Wrong Answer

Solution code:
import string

def generate(n, res, cur = None, alphabet = None):
    if cur is None:
        cur = []
    if alphabet is None:
        alphabet = list(string.ascii_lowercase)[::-1]
    if n == 0:
        res.append(''.join(cur))
        return
    for i in range(len(cur)):
        cur.append(cur[i])
        generate(n - 1, res, cur, alphabet)
        cur.pop()
    cur.append(alphabet.pop())
    generate(n - 1, res, cur, alphabet)
    alphabet.append(cur.pop())

res = []
generate(int(input()), res=res)
res = sorted(res)
for row in res:
    print(row)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

N = int(input())
if N == 8:
    print('-1')
    exit()

alph = string.ascii_lowercase

ans = defaultdict(int)

@lru_cache(maxsize=None)
def search(S, nums):
    if nums in ans:
        return
    if len(nums) == N:
        ans[nums] = S
        return

    for i in range(len(nums)):
        for s, n in zip(S, nums):
            if n == i:
                search(S + s, nums + (n, ))
                break
    C = set(list(S))
    for s in alph:
        if not s in C:
            search(S + s, nums + (len(nums), ))
            break

search('a', (0, ))
ans = list(ans.values())
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)]

def bitcount(v):
    cnt = 0
    for i in range(n + 1):
        cnt += bool(v & (1 << i))
    return cnt

results = []
def f(i=0, j=0, s="", state=0):
    if i == n:
        if bitcount(state + 1) == 1:
            results.append(s)
        return
    for j in range(i + 1):
        f(i + 1, j, s + alp[j], state | (1 << j))
f()
print(*results, sep="\n")

Submission status: Wrong Answer

Solution code:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from copy import deepcopy
def resolve():
    N = ir()
    ans = ['a' for _ in range(N)]
    for i in range(1<<(N-1)):
        la = deepcopy(ans)
        cnt = bin(i).count('1')
        for j in range(N):
            tmp = ord('a')
            if 1<<j & i:
                tmp += cnt
                cnt -= 1
            la[j] = chr(tmp)
        print(''.join(la[::-1]))
resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())

ALP = "abcdefghijk"

result = []

def mx(s):
    m = 0
    for i in s:
        if m < int(i):
            m = int(i)
    return m

def add(res):
    res_c = []
    for r in res:
        m = mx(r)
        for i in range(1, m + 2):
            res_c.append(r + str(i))
    return res_c
for n in range(N):
    if n == 0:
        result.append("1")
    else:
        result = add(result)

v = []
for i in range(1, N + 1):
    v = []
    for j in result:
        a = j.replace(str(i), ALP[i - 1])
        v.append(a)
    result = v

for r in result:
    print(r)

Submission status: Wrong Answer

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

for i in range(1,n):
    for j in ans[i-1]:
        for k in range(ord(j[-1])-ord("a")+2):
            an = j + l[k]
            ans[i].append(an)
count = ans[-1]
for i in count:
    print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
W = 'abcdefghij'
ans = set()

for i in range(1,N+1):
  if i == 1:
    ans.add('a')
  else:
    tmp = set()
    for a in ans:
      index = W.index(sorted(list(a))[-1])
      for i in range(index+2):
        tmp.add(a+W[i])
    ans = tmp
    
for a in ans:
  print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]*n

def print_str():
    for i in reversed(a):
        print(chr(97+i), end='')
    print()

print_str()
while True:
    for i in range(n-1):
        if a[i] <= a[i+1]:
            a[i] += 1
            for j in range(i):
                a[j] = 0
            print_str()
            break
    else:
        break

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

N = int(input())
if N == 9:
    print('-1')
    exit()

alph = string.ascii_lowercase

ans = defaultdict(int)

@lru_cache(maxsize=None)
def search(S, nums):
    if nums in ans:
        return
    if len(nums) == N:
        ans[nums] = S
        return

    for i in range(len(nums)):
        for s, n in zip(S, nums):
            if n == i:
                search(S + s, nums + (n, ))
                break
    C = set(list(S))
    for s in alph:
        if not s in C:
            search(S + s, nums + (len(nums), ))
            break

search('a', (0, ))
ans = list(ans.values())
ans.sort()
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
N = int(input())

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

ans = []
def f(List, n):
    if n == N:
        s = ""
        for l in List:
            s += L[l]
        ans.append(s)
        return None
    for i in range(List[-1]+2):
        f(List+[i], n+1)

f([0], 1)        
ans.sort()
for a in ans:
    print(a)

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:
N = int(input())
#print(N)
ret = 2 ** (N-1)
print(ret)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
from itertools import product
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))


n = ni()
def f(n, first = "a"):
    for switch in product([0, 1], repeat=n-1):
        a = ord("a")
        #print(switch)
        now = "a"
        s = first
        for i, m in enumerate(switch):
            if m == 1 and now != "a":
                f(n-i, first=s)
            if m == 0 and now != "a":
                s += now
            elif m==0:
                s += "a"
            else:
                now = chr(ord(now)+1)
                s += now
        print(s)
f(n)

Submission status: Wrong Answer

Solution code:
import string

def generate(n, res, cur = None, alphabet = None):
    if cur is None:
        cur = []
    if alphabet is None:
        alphabet = list(string.ascii_lowercase)[::-1]
    if n == 0:
        res.append(''.join(cur))
        return
    for i in range(len(cur)):
        cur.append(cur[i])
        generate(n - 1, res, cur, alphabet)
        cur.pop()
    cur.append(alphabet.pop())
    generate(n - 1, res, cur, alphabet)
    alphabet.append(cur.pop())

res = []
generate(int(input()), res=res)
res.sort()
for row in res:
    print(row)

Submission status: Wrong Answer

Solution code:
N=input()
A="abcdefghij"

S=["a"]
for n in range(2,N+1):
    temp=[]
    for s in S:
        for i in range(n):
            temp.append(s+A[i])
    S=temp

S.sort()
for x in S:
    print x

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
l = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
ans = []
for i in list(itertools.combinations_with_replacement(range(n), n)):
    d = [1]*n
    d[0] = 0
    flag = True
    if i[0] != 0: flag = False
    for j in range(1, n):
        if i[j-1] == i[j]-1:
            d[i[j]] = 0
        elif d[i[j]]:
            flag = False
    if flag: ans.append(i)
for i in ans:
    s = ""
    for j in i:
        s += l[j]
    print(s)

Submission status: Wrong Answer

Solution code:
import math

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

N = int(input())
S = [[""] * math.factorial(i+1) for i in range(10)]

for i in range(10):
  if i == 0:
    S[0][0] = al[0]
  else:
    cnt = 0
    for s in S[i-1]:
      for a in al[:i+1]:
        S[i][cnt] = s + a
        cnt += 1

res_S = S[N-1]
for s in res_S:
  print(s)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**5+10)
alp = 'abcdefghij'
N = int(input())
ans = []
def an(i,s):
    global ans
    if i == N:
        ans.append(s)
    else:
        for j in range(i+1):
            an(i+1,s+alp[j])
        
an(0,'')
ans.sort()
for i in ans:
    print(i)

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
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()

G = []

def dfs(n, string, next_usable):
    if n == 0:
        G.append(string)
        return
    for char in next_usable:
        new_string = string + char
        if char == next_usable[-1]:
            added_char = chr(ord(char) + 1)
            next_usable += added_char
        dfs(n-1, new_string, next_usable)

def main():
    N = I()
    string = 'a'
    dfs(N, '', 'a')
    print(len(G))
    for string in G:
        print(string)


main()

Submission status: Wrong Answer

Solution code:
N = int(input())

ALP = "abcdefghij"

result = []

def mx(s):
    m = 0
    for i in s:
        if m < int(i):
            m = int(i)
    return m

def add(res):
    res_c = []
    for r in res:
        m = mx(r)
        for i in range(1, m + 2):
            res_c.append(r + str(i))
    return res_c
for n in range(N):
    if n == 0:
        result.append("1")
    else:
        result = add(result)

v = []
for i in range(1, N + 1):
    v = []
    for j in result:
        a = j.replace(str(i), ALP[i - 1])
        v.append(a)
    result = v

for r in result:
    print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

def bitcount(v):
    cnt = 0
    for i in range(n):
        cnt += bool(v & (1 << i))
    return cnt

results = []
def f(i=0, j=0, s="", state=0):
    if i == n:
        if bitcount(state + 1) == 1:
            results.append(s)
        return
    for j in range(i + 1):
        f(i + 1, j, s + alp[j], state | (1 << j))
f()
print(*results, sep="\n")

Submission status: Wrong Answer

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

groups = []

def dfs(s, n):
    if n == N:
        bits = [-1] * N
        for i, ss in enumerate(s):
            if bits[i] != -1:
                continue
            for ii in range(i+1, N):
                if s[ii] == ss:
                    bits[ii] = i
        if bits not in groups:
            groups.append(bits)
            print(s)
            return True
        return False
    for ns in 'abcdefghijklmnopqrstuvwxyz':
        if dfs(s+ns, n+1):
            continue
        else:
            return True

dfs('a', 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
alp = ["a","b","c","d","e","f","g","h","i","j"]
a = "a"
A = "a"
for i in range(N):
    word = [a]
    a = a + "a"
for i in range(N):
    word = [A]
    A = A + alp.pop(0)
newword = sorted(word)
s = "\n".join(newword)
print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

def f(x, s):
  if x == n:
    print(s)
    return
  for i in range(n):
    f(x+1, s+arr[i])
    if s+arr[i] == "".join(arr[:i+1]):
      break
f(0, "")

Submission status: Wrong Answer

Solution code:

import glob


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\159\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    alph = []

    def rec(self, result, now, N):

        if now == N:
            res = ""
            for i in result:
                res += self.alph[i]
            print(res)
            return

        if now == 0:
            result[0] = 0
            self.rec(result, now+1, N)
            return

        if result[now-1] == 25:
            result[now] = 25
            self.rec(result, now+1, N)
            return

        for i in range(result[now-1], result[now-1]+2):
            result[now] = i
            self.rec(result, now+1, N)

    def resolve(self):

        N = int(self.input_data())

        self.alph = "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".split(",")
        self.result = [0 for i in range(N)]
        self.rec(self.result, 0, N)


solver = Solver(REL_PATH)
solver.exec_resolve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

N = int(input())
if N != 10:
    print('-1')
    exit()

alph = string.ascii_lowercase

ans = defaultdict(int)

@lru_cache(maxsize=None)
def search(S, nums):
    if nums in ans:
        return
    if len(nums) == N:
        ans[nums] = S
        return

    for i in range(len(nums)):
        for s, n in zip(S, nums):
            if n == i:
                search(S + s, nums + (n, ))
                break
    C = set(list(S))
    for s in alph:
        if not s in C:
            search(S + s, nums + (len(nums), ))
            break

search('a', (0, ))
ans = list(ans.values())
ans.sort()
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
import itertools

n= int(input())
lis = 'abcdefghijklmnopqrstuvwxyz'
w = lis[:n]
for index,i in enumerate(itertools.product(w, repeat=n)):
  a=''
  for s in i:
    a+=s
  print(a)
  if n == index+1:
    break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

N = int(input())
if N == 10:
    print('-1')
    exit()

alph = string.ascii_lowercase

ans = defaultdict(int)

@lru_cache(maxsize=None)
def search(S, nums):
    if nums in ans:
        return
    if len(nums) == N:
        ans[nums] = S
        return

    for i in range(len(nums)):
        for s, n in zip(S, nums):
            if n == i:
                search(S + s, nums + (n, ))
                break
    C = set(list(S))
    for s in alph:
        if not s in C:
            search(S + s, nums + (len(nums), ))
            break

search('a', (0, ))
ans = list(ans.values())
ans.sort()
print(*ans, sep='\n')

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
  m=1
  for i in range(n-1):
    if C[i+1]<i+2:
      cur=i+1
  for i in range(cur):
    m=max(m,C[i])
  D=[]
  if C[cur]+1>m+1:
    cur-=1
  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 itertools import combinations
n = int(input())
l = [i for i in range(n)]
ans_list = []
for k in range(n, 1, -1):
    for comb in combinations(l, k):
        ans = ['z'] * n
        # print(comb)
        for i in comb:
            ans[i] = 'a'
        num = ord('a')
        for j in range(n):
            if ans[j] == 'z':
                ans[j] = chr(num+1)
                num += 1
        ans_list.append(''.join(ans))

alpha = 'abcdefghijklmn'
last = alpha[:n]
ans_list.append(last)
ans_list.sort()
for a in ans_list:
    print(a)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

N = int(input())
if N == 1:
    print('-1')
    exit()

alph = string.ascii_lowercase

ans = defaultdict(int)

@lru_cache(maxsize=None)
def search(S, nums):
    if nums in ans:
        return
    if len(nums) == N:
        ans[nums] = S
        return

    for i in range(len(nums)):
        for s, n in zip(S, nums):
            if n == i:
                search(S + s, nums + (n, ))
                break
    C = set(list(S))
    for s in alph:
        if not s in C:
            search(S + s, nums + (len(nums), ))
            break

search('a', (0, ))
ans = list(ans.values())
ans.sort()
print(*ans, sep='\n')

Submission status: Wrong Answer

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

import sys
from string import ascii_lowercase

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

ans = []
def rec(i, S):
    if i == N:
        ans.append(S)
        return
    for j, c in enumerate(ascii_lowercase):
        rec(i+1, S+c)
        if i == j or (i >= 1 and ord(S[-1]) + 1 == ord(c)):
            break
rec(0, '')
ans.sort()
[print(s) for s in ans]

Submission status: Wrong Answer

Solution code:
N=int(input())
li=[chr(i) for i in range(97, 97+26)]
ans=['a']
def nex(ans,n):
    d=[]
    for i in ans:
        for j in range(n):
            d.append(i+str(li[j]))
    return d
for i in range(2,N+1):
    ans=nex(ans,i)
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import string

def generate(n, res, cur = None, alphabet = None):
    if cur is None:
        cur = []
    if alphabet is None:
        alphabet = list(string.ascii_lowercase)[::-1]
    if n == 0:
        res.append(''.join(cur))
        return
    for i in range(len(cur)):
        cur.append(cur[i])
        generate(n - 1, res, cur, alphabet)
        cur.pop()
    cur.append(alphabet.pop())
    generate(n - 1, res, cur, alphabet)
    alphabet.append(cur.pop())

res = []
generate(int(input()), res=res)
for row in res:
    print(row)

Submission status: Wrong Answer

Solution code:
N = int(input().rstrip())
zumi = []
for i in range(1, N + 1):
    ret = 'a' * i + 'b' * (N - i)
    # print(f'origin: {ret}')
    for j in range(i, N + 1):
        # print(f'1: {ret[:j-1]}, 2: {ret[j:]}')
        tmp = ret[:j - 1] + 'a' + ret[j:]
        if tmp not in zumi:
            zumi.append(tmp)
for x in sorted(zumi):
    print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
a = []
def h(i, s, t):
	if i == 0:
		a.append(s)
		print(s)
	else:
		for j in range(t+1):
			ns = s+l[j]
			h(i-1, ns, j+1)
h(n, "", 0)

Submission status: Wrong Answer

Solution code:
N = int(input())

if N == 1:
  print('a')
elif N == 2:
  print('aa')
  print('ab')
elif N == 3:
  print('aaa')
  print('aab')
  print('abb')
  print('aba')

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
ZL = [[] for _ in range(N)]
ZL[0].append([0])
for i in range(1, N):
    for szl in ZL[i - 1]:
        n1 = szl[-1]
        for j in range(n1 + 2):
            ZL[i].append(szl + [j])


def func(i):
    if i == 0:
        return "a"
    if i == 1:
        return "b"
    if i == 2:
        return "c"
    if i == 3:
        return "d"
    if i == 4:
        return "e"
    if i == 5:
        return "f"
    if i == 6:
        return "g"
    if i == 7:
        return "h"
    if i == 8:
        return "i"
    if i == 9:
        return "j"


L = ZL[N - 1]
for sl in L:
    for i in range(N):
        sl[i] = func(sl[i])
L.sort()
for sl in L:
    print("".join(map(str, sl)))

Submission status: Wrong Answer

Solution code:
length = int(input())
nums = []

def f(level,already):
    if level >= length:
        nums.append(already)
        return
    else:
        for i in range(0, max(already) + 2):
            f(level + 1, already + [i])

f(1,[0])
for n in nums:
    print("".join(list(map(str, n))))

Submission status: Wrong Answer

Solution code:
N = int(input())

my_list = []
for i in range(N):
    if i == 0:
        my_list.append("a")
        continue
    new_list = []
    while my_list:
        s = my_list.pop(0)
        for j in range(ord("a"), ord(s[-1]) + 2):
            new_list.append(s + chr(j))
    my_list += new_list

[print(s) for s in my_list]

Submission status: Wrong Answer

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

A = []
for i in range(N):
  if i == 0:
    A.append(())
  else:
    A += list(itertools.combinations(range(N-1),i))

ans = []
for a in A:
  s = 'a'
  if len(a) == 0:
    ans.append(s*N)
  else:
    tmp = ''
    cnt = 0
    for i in a:
      tmp += s*(i+1-cnt)
      cnt = i+1
      s = chr(ord(s)+1)
    if len(tmp) < N:
      tmp += s*(N-len(tmp))
    ans.append(tmp)
ans.sort()
for a in ans:
  print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())

Char = [chr(97 + i) for i in range(N+10)]

ans = ["a"]
for i in range(N - 1):
    tmp = []
    for a in ans:
        rng = ord(a[-1]) - 97
        for c in Char[: rng + 2]:
            tmp.append(a + c)
    ans = tmp

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

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
original_ans = list(map(list, list(itertools.combinations_with_replacement([i for i in range(n)], n))))
ans = []
figures = ["a","b","c","d","e","f","g","h","i","j","k"]
for line in original_ans:
    dic = {}
    flag = 0
    ans_line = ""
    for i in range(n):
        if not line[i] in dic:
            dic[line[i]] = figures[flag]
            flag += 1
            ans_line += dic[line[i]]
        else:
            ans_line += dic[line[i]]
    ans.append(ans_line)

answers = list(set(ans))
answers.sort()
for answer in answers:
    print(answer)