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 = int(input())
tmp_list = list('a' * n)
num_list = [97] * n
target = n - 1
tmp_target=n-1
max_num=97
while tmp_target>0:
    print("".join(list(map(chr, num_list))))
    if max(num_list[0:target:]) >= num_list[target]:
        num_list[target] += 1
    else:
        num_list[target]=97
        tmp_target=target-1
        while tmp_target>0:
            if max(num_list[0:tmp_target:]) >=num_list[tmp_target]:
                num_list[tmp_target]+=1
                break
            else:
                num_list[tmp_target]=97
                tmp_target-=1

Submission status: Wrong Answer

Solution code:
n = int(input())


A = ['a']

for i in range(n-1):
    B = A[i:]
    for j in B:
        A.append("".join(j) + j[-1])
        A.append("".join(j) + chr(ord(j[-1]) + 1))
A = sorted(A)
for i in A:
    if len(i) == n:
        print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
alphabets = list('Zabcdefghijklmn')
s = ['a']
for i in range(2, N + 1):
    subset = alphabets[1:i + 1]
    # s = [s[j] + k for k in subset for j in range(len(s))]
    s = [s[j] + k for j in range(len(s)) for k in subset]
print(*s, sep='\n')

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 1:
    print("a")
if n == 2:
    print("aa")
    print("ab")
elif n == 3:
    print("aaa")
    print("aab")
    print("aac")
    print("abb")
    print("abc")
elif n == 4:
    print("aaaa")
    print("aaab")
    print("aabb")
    print("abbb")
else:
    print("hoge")

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
ans = ""
if n == 1:
    print("a")
    sys.exit(0)
else:
    c = 2 ** (n-1)
    for i in range(c):
        tmp = "a"
        for j in range(n-1):
            if i >> j & 1:
                tmp += "b"
            else:
                tmp += "a"
        print(tmp)

Submission status: Wrong Answer

Solution code:
n = int(input())

tank = []
res = ["a"]

for le in range(1,n):
    tank = res
    res = []
    for i in range(len(tank)):
        tmp = "a"
        for j in range(le):
            res.append(tank[i] + tank[i][j])
            if tank[i][j] > tmp:
                tmp = tank[i][j]
        res.append(tank[i] + chr(ord(tmp)+1))
    res = list(set(res))

print(*res)

Submission status: Wrong Answer

Solution code:
n=int(input())

def saiki(l,n):
  for s in l:
    tmp=[]
    for i in range(n):
      tmp.append(s+chr(ord('a')+i))
  return tmp

tmp=['a']
for i in range(1,n):
  tmp=saiki(tmp,i+1)
print(*tmp,sep='\n')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)
  
N = int(input())
#print(N)
if N == 1:
  print(1)
  sys.exit()
elif N == 2:
  print(2)
  sys.exit()

r = N - 2

ret = permutations_count(N, r) + 2
print(ret)

Submission status: Wrong Answer

Solution code:
def diff_one(l):
    prev = l[0]

    for i in range(1, len(l)):
        if abs(ord(l[i]) - ord(prev)) >= 2:
            return False
        prev = l[i]

    return True


def comb(current, rest, target: int):
    if len(current) == target:
        yield current
    elif len(current) < target and len(rest) > 0:
        for i in range(len(current) + 1):
            yield from comb(current + [rest[i]], rest, target)


if __name__ == '__main__':
    n = int(input())
    alphabet = [str(chr(i)) for i in range(97, 97 + 26)]

    for perm in comb([], alphabet[:n], n):
        if diff_one(perm):
            print("".join(perm))

Submission status: Wrong Answer

Solution code:
i = input()

if int(i) == 1:
  print(1)
elif int(i) == 2:
  print(2)
else:
  x = (int(i) - 2)
  y = 3 ** x
  z = 2 ** x
  print(y + z)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=('a','ab','abc','abcd','abcde','abcdef','abcdefg','abcdefgh','abcdefghi', 'abcdefghij')
for i in range(n):
    print((lst[i]*n)[:n])

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
from itertools import product
n = int(input())
alphabets = ascii_lowercase[:n]

def check(s):
    if s[0] == 'a':
        now = 'a'
        for i in range(1, n):
            if s[i] == chr(ord(now)+1) or s[i] == chr(ord(now)) or s[i] == 'a':
                now = s[i]
            else:
                return False
        return True
    return False

for s in product(alphabets, repeat=n):
    if check(s):
        print(*s, sep='')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    s = 'abcdefghijkl'
    ans = []
    from heapq import heapify, heappop, heappush

    def f(t: str):
        if len(t) >= N:
            heappush(ans, t)
            return
        
        for i in range(len(t)+1):
            f(t+s[i])


    
    f('')
    # print(ans)
    while len(ans):
        print(heappop(ans))


    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())
if n == 1:
    print("a")
if n == 2:
    print("aa")
    print("ab")
elif n == 3:
    print("aaa")
    print("aab")
    print("abb")
    print("abc")
elif n == 4:
    print("aaaa")
    print("aaab")
    print("aabb")
    print("abbb")
else:
    print("hoge")

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.product(range(n), repeat=n)):
    d = [1]*n
    d[0] = 0
    flag = True
    if i[0] != 0: break
    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:
moji = ['a']
n = int(input())
count = 0
for i in range(n-1):
    count +=1
    for word in moji:
        if len(word) == count:
            tmp = ord(word[count - 1])
            for j in range(97, tmp + 2):
                newword = word + chr(j)
                moji.append(newword)
moji.sort()
for words in moji:
    if len(words) == n:
        print(words)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = ["a","b","c","d","e","f","g","h","i","j"]
i = 0
def st(s,n,k):
  if k == n:
    print(s)
    return
  ss = s[-1]
  for i,w in enumerate(l):
    if w == ss:
      j = i
  for i in range(j+2):
    st(s+l[i],n,k+1)
st("a",n,1)

Submission status: Wrong Answer

Solution code:
a = int(input())
al=[chr(ord('a') + i) for i in range(a)]
loop = a
for i in al:
    for j in range(loop-1):
        al.append(i)
    loop = loop-1
import itertools
mm = list(itertools.combinations(al, a))
mm = list(set(mm))
l = []
for i in mm:
    if i[0] == 'a':
        l.append(i)
anslist = sorted(list(set(l)))
for i in anslist:
    print(''.join(i))

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 = set()
def rec(i, S):
    if S in ans:
        return
    if i == N:
        ans.add(S)
        return
    for c in S:
        rec(i+1, S+c)
    rec(i+1, S+ascii_lowercase[i])
rec(0, '')
ans = sorted(ans)
[print(s) for s in ans]

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []
def dfs(tmp,i):
    if i == N:
        ans.append(tmp)
        return
    
    for s in ["a", "b"]:
        dfs(tmp+s, i+1)
    return ans
dfs("a", 1)
for s in ans:
    print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 1:
    print("a")
elif n == 2:
    print("ab")
    print("ac")
elif n == 3:
    print("aab")
    print("aac")
    print("aad")
else:
    print("aaa")

Submission status: Wrong Answer

Solution code:
from math import factorial
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def comb(n, r):
    return factorial(n) // (factorial(r) * factorial(n - r))


def main():
    N = int(readline())
    S = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
    d = {}
    for i, s in enumerate(S):
        d[i] = s

    for i in range(2**(N-1)):
        c = 0
        tmp = ""
        for j in range(N-1,-1,-1):
            if i & (1 << j):
                c += 1
            tmp += d[c]
        print(tmp)
            

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s="abcdefghij"
end=[0,1,2,3,4,5,6,7,8,9]
lim=0
res=[0]*n
for i in res:
  print(s[i],end="")
print("")

while res!=end[:n]:
  res[(n-1)]=res[(n-1)]+1
  for i in range(n-1):
    if res[n-i-1]>(res[n-i-2]+1):
      res[n-i-1]=0
      res[n-i-2]=res[n-i-2]+1
  for i in res:
    print(s[i],end="")
  print("")

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 1:
  print('a')
elif n == 2:
  print('aa\nab')
elif n == 3:
  print('aaa\naab\naba\nabb\nabc')
elif n == 4:
  print('aaaa\naaab\naaba\naabb\naabc\nabaa\nabab\nabac\nabba\nabbb\nabbc\nabca\nabcb\nabcc\nabcd')

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.product(range(n), repeat=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:
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):
    print(ans)
    for j in ans[i-1]:
        a = 0
        for k in j:
            a = max(a,ord(k)-ord("a"))
        for k in range(a+2):
            an = j + l[k]
            ans[i].append(an)
count = ans[-1]
count.sort()
for i in count:
    print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
int2char = {i: chr(i + 96) for i in range(1, 11)}
ans = ['a']
for n in range(2, N+1):
    new_list = []
    for string in ans:
        str_set = set(string)
        for i in range(1, n+1):
            if len(str_set) + 1< i:
                continue 
            new_str = string + int2char[i]
            new_list.append(new_str)
    ans = new_list

print(sorted(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
alphabets = list('Zabcdefghijklmn')
s = ['a']
for i in range(2, N + 1):
    subset = alphabets[1:i + 1]
    s = [s[j] + k for k in subset for j in range(len(s))]
print(*s, sep='\n')

Submission status: Wrong Answer

Solution code:
N = int(input())
chrA = ["aaaaaaaaaa", "aaaaaaaaab", "aaaaaaaaba", "aaaaaaaabb", "aaaaaaaacb", "aaaaaaabaa", "aaaaaaabab","aaaaaaabba","aaaaaaabbc","aaaaaaabcb"]

for i, chra in enumerate(chrA):
    print(chra[-N:])
    if i + 1 == N:
        exit()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

if n == 1:
    print("a")
if n == 2:
    print("aa\nab")
else:
    old = []
    old.append(["aa"])
    old.append(["ab"])
    for i in range(2, n):
        result = []
        for j in range(2, i + 2):
            if j == 2:
                tmp = []
                result.append([old[0][0] + 'a'])
                result.append([old[0][0] + 'b'])
            else:
                tmp = []
                for txt in old[j - 2]:
                    for k in range(j):
                        tmp.append(txt + text[k])
                result.append(tmp)
        old = result

    for rows in old:
        for row in rows:
            print(row)

Submission status: Wrong Answer

Solution code:
n = int(input())
def print_from_l(l):
    print(''.join(map(lambda s:chr(97+s), l)))
def g(l):
    if len(l) == n:
        print_from_l(l)
    else:
        for i in range(l[-1]+2):
            g(l + [i])
g([0])

Submission status: Wrong Answer

Solution code:
moji = ['a']
n = int(input())
count = 0
for i in range(n-1):
    count +=1
    for word in moji:
        if len(word) == count:
            tmp = ord(word[count - 1])
            for j in range(97, tmp + 2):
                newword = word + chr(j)
                moji.append(newword)
for words in moji:
    if len(words) == n:
        print(words)

Submission status: Wrong Answer

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

def main():
    m='abcdefghijklmnopqrstuvwxyz'
    m=list(m)
    n=int(input())
    ans=[[] for _ in range(n)]
    ans[0].append('0')
    for i in range(1,n):
        for j in ans[i-1]:
            for k in range(i+1):
                if k<=int(j[-1])+1:
                    ans[i].append(j+str(k))
    p=[]
    for i in ans[n-1]:
        s=''
        for j in range(len(i)):
            s+=m[int(i[j])]
        p.append(s)
    p.sort()
    for i in p:
        print(i)
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
n=INT()
a=["a" for i in range(n)]
def f(num):
    global n,a
    if num==n:
        print("".join([str(n) for n in a]))
        return
    elif num==1:
        a[num]="a"
        f(num+1)
        a[num]="b"
        f(num+1)
    else:
        a[num]="a"
        f(num+1)
        a[num]="b"
        f(num+1)
        if a[num-1]!="a":
            a[num]="c"
            f(num+1)
f(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 1:
    print("a")
if n == 2:
    print("aa")
    print("ab")
elif n == 3:
    print("aaa")
    print("aab")
    print("abb")
elif n == 4:
    print("aaaa")
    print("aaab")
    print("aabb")
    print("abbb")
else:
    print("hoge")

Submission status: Wrong Answer

Solution code:
n=int(input())

tree = [[0,1]]
for _ in range(n-1):
    tree = [ t+[i]  for t in tree for i in range(1,t[-1]+2) ]
tree.sort()
for t in tree:
    print( "".join([chr(ord("a")+tt-1) for tt in t[1:] ] ) )

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("abc")
    print("baa")

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = set()
for i in range(2**N):
    n = i
    s = ""
    sr = ""
    for j in range(N):
        s = s + ("a" if n % 2 == 0 else "b")
        sr = sr + ("b" if n % 2 == 0 else "a")
        n >>= 1
    if sr < s:
        s, sr = sr, s
    if sr in ans:
        continue
    else:
        ans.add(s)

for a in ans:
    print(a)

Submission status: Wrong Answer

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

nums = [chr(i) for i in range(97, 97+N)]

tmp = []
for balls in itertools.product(nums, repeat=len(nums)):
    tmp.append(balls)
    
for i in range(len(tmp)//N):
    print("".join(list(tmp[i])))

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 minus(array):
#     m = min(array)
#     return [a-m for a in array]
# ans = list(set([tuple(minus(a)) for a in ans]))

from collections import Counter
real_ans = []
# alr = set()
# def syutu(array):
#     return tuple(sorted(list(Counter(array).values())))
# for a in sorted(ans):
#     if syutu(a) not in alr:
#         alr.add(syutu(a))
#         real_ans.append(sorted(a))

def repqqq(array):
    alpha = "abcdefghijklmn"
    temp = []
    for a in array:
        temp.append(alpha[a])
    return "".join(temp)
# print(real_ans)
ans = [repqqq(line) for line in sorted(ans)]
for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = [chr(ord('a') + i ) for i in range(n)]
ans = set()
def dfs(i,now):
  if len(now) == n:
    print(now)
    return
  for j in range(0,min(i+2,n)):
    if j != n:
      dfs(j+1,now + s[j])

dfs(0,s[0])

Submission status: Wrong Answer

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

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)
    if len(s) > 0:
        m = max(ord(c) - ord("a") for c in s) + 1
        if p + 1 != m:
            dfs(s + to[m], m)


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

Submission status: Wrong Answer

Solution code:
alpha = "abcdefghij"
N = int(input())
anss = []
for i in range(1, N+1):
    substr = alpha[:i]
    s = "a" * (N-i) + substr

    if i in [1, N]:
        anss.append(s)

    elif i == 2:
        last = s[-1]
        s = s[:-1]
        for i in reversed(range(1, N)):
            temp = s[:i] + last + s[i:]
            anss.append(temp)
    else:
        first = s[0]
        s = s[1:]
        for i in range(i-1, N):
            temp = s[:i] + first + s[i:]
            anss.append(temp)

for ans in anss:
    print(ans)

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)
    
b=[]

for g in range(len(ans)):
    if len(ans[g])==n:
        b.append(ans[g])

b.sort()

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

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
w_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
ans_list = []
for i in range(n):
    temp_word = []
    word = []
    for j in range(n):
        if temp_word == []:
            w = copy.deepcopy(w_list[0:i+1])
            temp_word.extend(w)
        aaa = temp_word.pop(0)
        word.append(aaa)
    ans_list.append(''.join(word))
for s in ans_list:
    print(s)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
memo_ls = [{i : [] for i in range(11)} for j in range(11)]
alpha = "abcdefghijklmnopqrstuvwxyz"
#memo_ls[i][j] : i個をjに分ける方法
memo_ls[1][1] = ["a"]
for i in range(1,10):
    for j in range(11):
        if j > i:
            continue
        else:
            for v in memo_ls[i][j]:
                for k in range(j):
                    memo_ls[i + 1][j].append(v + alpha[k])
                memo_ls[i+1][j+1].append(v + alpha[j])
ls = []
for i in range(11):
    for j in memo_ls[n][i]:
        ls.append(j)
print("\n".join(ls))

Submission status: Wrong Answer

Solution code:
def f(num,N,S):
    alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o"]
    if N == num:
        for i in range(len(S)):
            print(S[i])
        return
    else:
        tmp = []
        length = len(S)
        for i in range(length):
            if i == 0:
                tmp.append(S[0]+"a")
                tmp.append(S[0]+"b")
            else:
                ttmp = S[i][-1]
                ind = alphabet.index(ttmp)
                for j in range(ind+2):
                    tmp.append(S[i]+alphabet[j])
        S = list(set(tmp))
        S.sort()
        f(num+1,N,S)

N = int(input())
f(1,N,["a"])

Submission status: Wrong Answer

Solution code:
a = int(input())
arr = []
s = "abcdefghijklmnopqrstuvwxyz"
if a == 1:
    print("a")
else:
    first = s[0]
    arr.append(first*(a-1))
    for i in range(a-1):
        arr.append(first+s[i+1])
for i in range(len(arr)):
    print(arr[i])

Submission status: Wrong Answer

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


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

    if N == 1:
        print("a")
        return

    lst = ["a", "b"]

    anss = []
    ps = itertools.product(range(2), repeat=N-1)
    for combo in ps:
        ans = "a"
        for x in combo:
            if x == 1:
                ans += "a"
            else:
                ans += "b"
        anss.append(ans)

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


if __name__ == "__main__":
    solve()

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]
    word = [A]
    a = a + "a"
    A = A + alp.pop(0)
word.pop(0)
s = "\n".join(word)
print(s)

Submission status: Wrong Answer

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

def rec(s):
    if len(s) == N:
        ans.append(s)
        return
    rec(s + "a")
    rec(s + "b")

rec("a")
ans.sort()
for x in ans:
    print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
chrA = ["aaaaaaaaaa", "aaaaaaaaab", "aaaaaaaaba", "aaaaaaaabb", "aaaaaaaabc", "aaaaaaabaa", "aaaaaaabab","aaaaaaabac","aaaaaaabba","aaaaaaabbb"]

for i, chra in enumerate(chrA):
    print(chra[-N:])
    if i + 1 == N:
        exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = []
for i in range(2 ** n):
    s = ['a'] * n
    for j in range(n):
        if ((i >> j) & 1):
            s[n - 1 - j] = 'b'
    ans.append(''.join(s))
ans.sort()
for i in ans:
    if i[0] != 'b':
        print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [[] for i in range(n+1)]
s[1].append('a')
ans_s = []
for num in range(1,n):
    for st in s[num]:
        for add in range(97, max(map(ord,st))+2):
            s[num+1].append(st + chr(add))
print(s[n])

Submission status: Wrong Answer

Solution code:
N = int(input())

def f(s="a"):
    if len(s) == N:
        print(s)
        return
    for c in range(ord(s[-1]) - ord("a") + 2):
        f(s + chr(ord("a") + c))

f()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import deque
import copy
str_list_befor = ['0', '1', '2','3','4','5', '6', '7','8','9']
str_list_after = ['a', 'b', 'c','d','e','f', 'g', 'h','i','j']

n = int(input())

dq = deque()
dq.append([0])
if n > 1:
    for i in range(n-1):
        # print("i: " + str(i))
        for j in range(len(dq)):
            # print("j: " + str(j))
            prv = dq.popleft()
            for j in range(prv[-1]+2):
                tmp = copy.copy(prv)
                tmp.append(j)
                # print(tmp)
                dq.append(tmp)
            # print(dq)

for i in range(len(dq)):
    result = ""
    tmp_r = dq.popleft()
    result = "".join(map(str, tmp_r))
    for j in range(len(str_list_befor)):
        result = result.replace(str_list_befor[j], str_list_after[j])

    print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [0] * N

ED = [chr(i + 97) for i in range(N)]
ED = ''.join(ED)
ans = []
while True:
    for i in range(N - 1, 0, -1):
        if A[i] == A[i - 1] + 2:
            A[i] = 0
            A[i - 1] += 1
    ret = ['' for _ in range(N)]
    for i in range(N):
        ret[i] = chr(A[i] + 97)

    ret = ''.join(ret)
    ans.append(ret)

    if ret == ED: break
    else: A[-1] += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())

tmp_list = list('a' * n)
num_list = [97] * n
target = n - 1
tmp_target=n-1
while tmp_target>0:
    print("".join(list(map(chr, num_list))))
    if num_list[target-1] >= num_list[target]:
        num_list[target] += 1
    else:
        num_list[target]=97
        tmp_target=target-1
        while tmp_target>0:
            if num_list[tmp_target-1] >=num_list[tmp_target]:
                num_list[tmp_target]+=1
                break
            else:
                num_list[tmp_target]=97
                tmp_target-=1

Submission status: Wrong Answer

Solution code:
N = int(input())

def push_a(in_str, used_chr):
  global N
  in_str += 'a'
  if len(in_str) == N:
    print(in_str)
  else:
    push_a(in_str, used_chr)
    push_chr(in_str, used_chr)

def push_chr(in_str, used_chr):
  global N
  used_chr = chr(ord(used_chr) + 1)
  in_str += used_chr
  if len(in_str) == N:
    print(in_str)
  else:
    push_a(in_str, used_chr)
    push_chr(in_str, used_chr)

push_a('', 'a')

Submission status: Wrong Answer

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

n = int(input())
ans = []

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

def rec(before, depth):
    if len(before) >= n-1:
        for i in range(ord(before[-1])-ord('a') +2):
            tmp = before + chr(ord('a') + i)
            ans.append(tmp)
    else:
        for i in range(ord(before[-1])-ord('a') +2):
            tmp = before + chr(ord('a') + i)
            rec(tmp, depth+1)


rec('a',1)

ans.sort()

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

Submission status: Wrong Answer

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

def rec(s, k, len):
    if len >= n:
        print("".join([chr(ord("a") + x) for x in s]))
        return
    for x in range(max(s[-1]+2, k+1)):
        rec(s + [x], max(k, x), len+1)

rec([0], 1, 1)

Submission status: Wrong Answer

Solution code:
N = int(input())

que = ['a']
res = []
for i in range(1, N):
    for q in que:
        res.append(q + 'a')
        res.append(q + 'b')
    que = res
    res = []

que.sort()
for q in que:
    print(q)

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=('a','ab','abc','abcd','abcde','abcdef','abcdefg','abcdefgh','abcdefghi', 'abcdefghij')
for i in range(n):
    print(lst[i])

Submission status: Wrong Answer

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

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



if __name__ == "__main__":
    main()

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 minus(array):
    m = min(array)
    return [a-m for a in array]
ans = list(set([tuple(minus(a)) for a in ans]))

from collections import Counter
real_ans = []
alr = set()
def syutu(array):
    return tuple(sorted(list(Counter(array).values())))
for a in sorted(ans):
    if syutu(a) not in alr:
        alr.add(syutu(a))
        real_ans.append(sorted(a))

def repqqq(array):
    alpha = "abcdefghijklmn"
    temp = []
    for a in array:
        temp.append(alpha[a])
    return "".join(temp)
# print(real_ans)
ans = [repqqq(line) for line in sorted(real_ans)]
for a in ans:
    print(a)