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 mi():return map(str,input().split())

n=int(input())
ans=["Sorry"]
if n==1:ans=["a"]
if n==2:ans=["aa","ab"]
if n==3:ans=["aaa","aab","aba","abb","abc"]
if n==4:ans=['aaaa', 'aaab','aaba', 'aabb', 'aabc','abaa', 'abab', 'abac','abba', 'abbb', 'abbc','abca', 'abcb', 'abcc', 'abcd']

for i in ans:
  print(i)

Submission status: Wrong Answer

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from itertools import combinations_with_replacement as cwr
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
#from fractions import gcd
enu = enumerate

sys.setrecursionlimit(10**7)
N = int(input())

# i: num of different char
s = ['a'] * N
end = [chr(i) for i in range(97, 97+N)]

l = list(cwr(end, N))

nl = []
for val in l:
    addflg = True
    shuruisuu = len(set(val))
    for i in range(N):
        if not(addflg):
            break

        if i < N-1:
            if val[i] > val[i+1]:
                addflg = False
                break

        if ord(val[i])-97 > i:
            addflg = False
            break

        if ord(val[i])-97 >= shuruisuu:
            addflg = False
            break

    if addflg:
        nl.append(val)

for nli in nl:
    print(''.join(nli))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from itertools import combinations


def input():
    return sys.stdin.readline()[:-1]


def solve():
    al=[chr(ord('a') + i) for i in range(26)]
    n = int(input())
    a = np.arange(n).tolist()
    base = "a"*n
    res = []
    for i in range(1, n+1):
        base = list("a"*n)
        com = list(combinations(a,i))
        for j, c in enumerate(com):
            for j, num in enumerate(sorted(list(c))):
                base[int(num)] = al[j]
            res.append(''.join(base))
    res = list(sorted(list(set(res))))
    for ans in res:
        print(ans)

    


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def chg(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

N = int(input())
li = list("abcdefghij")

import sys
if N==1:
    print("a")
    sys.exit()
for i in range(10**6):
    mm = str(chg(i,N)).zfill(N)
    cnt = -1
    li1 = []
    for j in range(N):
        a = int(mm[j])
        if str(a) in li1:
            continue
        elif a-1==cnt:
            cnt += 1
            li1.append(str(a))
            continue
        break
    else:
        for j in range(N):
            print(li[int(mm[j])],end="")
        print()
    # print(mm)

# print(10*9*8*7*6*5*4*3*2)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 1:
  hoge = ["a"]
  for i in range(len(hoge)):
    print(i)
if n == 2:
  hoge = ["aa", "ab"]
  for i in range(len(hoge)):
    print(i)
if n == 3:
  hoge = []
  for a in ["a", "b", "c"]:
    for b in ["a", "b", "c"]:
      for c in ["a", "b", "c"]:
        hoge.append(a + b + c)
  hoge.sort()
  for i in range(len(hoge)):
    print(i)

if n == 4:
  hoge = []
  for a in ["a", "b", "c", "d"]:
    for b in ["a", "b", "c", "d"]:
      for c in ["a", "b", "c", "d"]:
        for d in ["a", "b", "c", "d"]:
          hoge.append(a + b + c + d)
  hoge.sort()
  for i in range(len(hoge)):
    print(i)

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
fct=1
for i in range(n):
    fct*=i+1
    
mx=[i+1 for i in range(n)]
flg=[[]*n for i in range(n)]
for i in range(n):
    for j in range(n):
        if j<mx[i]:
            flg[i].append(chr(ord('a')+j))

s=''
'''
for i in range(fct):
    ss=[]
    if i==0:
        ss="a"*n
    else :
        for j in reversed(range(n)):
            ii=i
            if ii<0:
                ii=0
            mi=min(mx[j]-1,i)
            ss.insert(0,flg[j][mi])
            i-=mi
    if s==''.join(ss):
        break
    s=''.join(ss)
    print(s)
'''
if n==1:
    print('a')
elif n==2:
    for i,j in itertools.product(flg[0],flg[1]):
        print(i+j)
elif n==3:
    for i in itertools.product(flg[0],flg[1],flg[2]):
        print(''.join(i))
elif n==4:
    for i in itertools.product(flg[0],flg[1],flg[2],flg[3]):
        print(''.join(i))
elif n==5:
    for i in itertools.product(flg[0],flg[1],flg[2],flg[3],flg[4]):
        print(''.join(i))
elif n==6:
    for i in itertools.product(flg[0],flg[1],flg[2],flg[3],flg[4],flg[5]):
        print(''.join(i))
elif n==7:
    for i in itertools.product(flg[0],flg[1],flg[2],flg[3],flg[4],flg[5],flg[6]):
        print(''.join(i))
elif n==8:
    for i in itertools.product(flg[0],flg[1],flg[2],flg[3],flg[4],flg[5],flg[6],flg[7]):
        print(''.join(i))
elif n==9:
    for i in itertools.product(flg[0],flg[1],flg[2],flg[3],flg[4],flg[5],flg[6],flg[7],flg[8]):
        print(''.join(i))
elif n==10:
    for i in itertools.product(flg[0],flg[1],flg[2],flg[3],flg[4],flg[5],flg[6],flg[7],flg[8],flg[9]):
        print(''.join(i))

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
        
        if len(t) >= 2:
            x = s.index(t[-1])+2
        else:
            x = len(t)+1
        for i in range(x):
            f(t+s[i])


    
    f('')
    # print(ans)
    c = 0
    # print(len(ans))
    while len(ans) and c < 10:
        print(heappop(ans))
        c += 1


    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())
chars = ["a","b","c","d","e","f","g","h","i","j"]
def ds(s,depth,ind):
    for i in range(ind): #初回→1個
        if depth == n:
            print(s)
            return
        next_chr = chars[i]
        # for j in range(ind + 1):
        ds(s + next_chr, depth + 1, ind = i + 2)
    return
ds("",0,1)


# for i in range(n):



# k = (n - 1)
# # n 桁 → 関係は nC2 * 2個の関係がありうる
# # abc とあったら a = b とか a =cとか
# while k != 0:
#
#     for i in range(2 ** k):  # 2**k個の制約がある k回目 → 2 ** (k) の束縛がある
#         for i1 in range(n - k - 1, n):  # i1番目のアルファベット
#             #着目する文字が0文字目 = 1文字目  0文字目 = 2文字目 って感じになっていく
#             for i2 in range(i1 + 1, n):  # i2番目のアルファベット
#                 ans = ""
#                 # 1→等しい 0 → 等しくない
#                 # 等しくない場合 chr + 1をする
#                 next_chr = "a"
#                 for j in range(1 , n): #追加する 番目 1番目に追加とか
#                     ralation = i2 - i1 -1 #番目の関係
#                     if ralation < 0:
#                         pass
#                     elif  ((ralation  >> j) & 1): #束縛されていたら
#                         next_chr = chr(ord(next_chr) + 1)
#                 ans += next_chr
#             print(ans)#
#
#     k -=1
#
#

Submission status: Wrong Answer

Solution code:
n = int(input())
s = "abcdefghijk"

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")
elif n == 4:
    print("aaaa")
    print("aaab")
    print("aaba")
    print("aabb")
    print("aabc")
    print("abaa")
    print("abab")
    print("abbb")
    print("abbc")
    print("abcc")
    print("abcd")

Submission status: Wrong Answer

Solution code:
def dfs(ans, n, l):
    if len(ans) == n:
        print(ans)
        return ans
    for x in l:
        dfs(ans + x, n, l)


n = int(input())
s = 'abcdefghij'
l = [s[i] for i in range(n)]

ans = 'a'
dfs(ans, n, l)

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = {0:"a", 1:"b", 2:"c", 3:"d", 4:"e", 5:"f", 6:"g", 7:"h", 8:"i", 9:"j"}
dic_r = {"a":0, "b":1, "c":2, "d":3, "e":4, "f":5, "g":6, "h":7, "i":8, "j":9}

old = ["a"]
new = []
for i in range(1, N):
    for word in old:
        for j in range(i+1):
            if word[-1] == dic[j] or (j>0 and word[-1] == dic[j-1]) or dic_r[word[-1]] >= j:
                new.append(word+dic[j])
    old = new.copy()
    new = []
for i in old:
    print(i)

Submission status: Wrong Answer

Solution code:
import itertools

n = input()
n = int(n)

num = [i for i in range(n)]
pairs = [i for i in itertools.combinations(num, 2)]

hoge = len(pairs) + 1
for i in range(1, hoge):
    comb = itertools.combinations(pairs, i)

    dup_check = set()
    for c in comb:
        c_list = list(c)
        dup_check.clear()
        for pair in c_list:
            dup_check.add(pair[0])
            dup_check.add(pair[1])

        if len(dup_check) != len(c_list)*2:
            continue

        ret = [''] * n
        chr_i = 97
        for i in range(n):
            if ret[i] is not '':
                continue

            used = False
            for pair in c_list:
                if pair[0] == i:
                    ret[i] = chr(chr_i)
                    ret[pair[1]] = chr(chr_i)
                    used = True
                    chr_i += 1
                    break
            if used:
                c_list.remove(pair)
            else:
                ret[i] = chr(chr_i)
                chr_i += 1

        retstr = ""
        for c in ret:
            retstr += c
        print(retstr)


retstr = ""
chr_i = 97
for i in range(n):
    retstr += chr(chr_i)
    chr_i += 1
print(retstr)

Submission status: Wrong Answer

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

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

rec([0], 1)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
s = ["a","b","c","d","e","f","g","h","i"]
n=int(input())
l = ["a"]

x = 1
while(x <= n):
    ll = l
    l = []
    for i in ll:
        for j in s[:x-1]:
            l.append(i + j)
    l.append("".join(s[:x]))
    x = x + 1
print(l)

Submission status: Wrong Answer

Solution code:


n = int(input())


result = []
start = ''

# n=5だったら11111~12345の全組み合わせを生成してみる

def search(loopcnt, now, prev):
    if loopcnt > n:
        result.append(prev)
    else:
        for k in range(1, now+2):
            if k == 10:
                k =0
            search(loopcnt + 1, k, prev + str(k))
        
n -= 1
search(0, 0, '')

set(result)

kouho = [ chr(97+i) for i in range(n+1) ]

for r in result:
    for c in r:
        print(kouho[int(c)-1], end='')
    print()

Submission status: Wrong Answer

Solution code:
n = int(input())
def func2(n):
    if n == 1:
        return "a"
    ll = []
    for head in func2(n-1):
        for tail in [chr(i + 97) for i in range(2) ]:
           ll.append(head + tail)
    return ll

def func3(n):
    if n == 3:
        return ["abc"]
    ll = []
    for head in func3(n-1):
        for tail in [chr(i + 97) for i in range(3) ]:
           ll.append(head + tail)
    return ll

def func4(n):
    if n == 4:
        return ["abcd"]
    ll = []
    for head in func4(n-1):
        for tail in [chr(i + 97) for i in range(4) ]:
           ll.append(head + tail)
    return ll

def func5(n):
    if n == 5:
        return ["abcde"]
    ll = []
    for head in func5(n-1):
        for tail in [chr(i + 97) for i in range(5) ]:
           ll.append(head + tail)
    return ll

if n == 1:
    print("a")
elif n == 2:
    for i in func2(n):
        print(i)
elif n == 3:
    for i in func2(n) + func3(n):
        print(i)
elif n == 4:
    for i in func2(n) + func3(n) + func4(n):
        print(i)
elif n == 5:
    for i in func2(n) + func3(n) + func4(n) + func5(n):
        print(i)

Submission status: Wrong Answer

Solution code:
def chg(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

N = int(input())
li = list("abcdefghij")

import sys
if N==2:
    print("aa")
    print("ab")
    sys.exit()
for i in range(10**6):
    mm = str(chg(i,N)).zfill(N)
    cnt = -1
    li1 = []
    for j in range(N):
        a = int(mm[j])
        if str(a) in li1:
            continue
        elif a-1==cnt:
            cnt += 1
            li1.append(str(a))
            continue
        break
    else:
        for j in range(N):
            print(li[int(mm[j])],end="")
        print()
    # print(mm)

# print(10*9*8*7*6*5*4*3*2)

Submission status: Wrong Answer

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

DONELIST = []
PROCESSLIST = ['a']
PROCESSLIST2 = []
for i in range(N-1):
    for j in range(len(DONELIST)):
        DONELIST[j] = 'a' + DONELIST[j]
    for j in range(len(PROCESSLIST)):
        DONELIST.append('a' + PROCESSLIST[j])
        for k in range(i+1):
            if PROCESSLIST[j] + chr(97+k) not in DONELIST:
                PROCESSLIST2.append(PROCESSLIST[j] + chr(97+k))
        PROCESSLIST2.append(PROCESSLIST[-1] + chr(97+len(PROCESSLIST[-1])))
    PROCESSLIST = PROCESSLIST2
    PROCESSLIST2 = []

for w in DONELIST:
    print(w)
for w in PROCESSLIST:
    print(w)

Submission status: Wrong Answer

Solution code:
k=["a","b","c","d","e","f","g","h","i","j"]
n=int(input())
list=[]
yl=[]
for i in range(n):
    list.append(k[i])
    yl.append(k[i])
    for _ in range(n-1):
        for j in range(n):
            list[i]=yl[i]+k[j]
xlist=list
for l in range(len(list)-1):
    xl=[str(c) for c in xlist[l]]

    if xl.count("a")==0:
        list.remove(list[l])
        break
    for o in range(n-l):
        if xl.count(k[l])==0 and xl.count(k[l+o-1])!=1:
            list.remove(list[l])
list.sort()
for i in list:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [ [] for _ in range(11) ]
a[0].append("a")

alp = "abcdefghijklmn"
for i in range(1, 10):
    for aa in a[i-1]:
        for c in alp[:i+1]:
            if ord(aa[-1])+1 < ord(c): continue

            a[i].append(aa+c)

for ans in a[n-1]:
    print(ans)

Submission status: Wrong Answer

Solution code:
def calc3(l, s, N):
    if len(s) == N:
        print(s)
        return l
    if len(s) > 0:
        c = s[-1]
        s2 = s[:]
        s += chr(ord(c))
        l = calc3(l, s[:], N)
        s2 += chr(ord(c)+1)
        l = calc3(l, s2[:], N)
    else:
        c = 'a'
        s += chr(ord(c))
        l = calc3(l, s[:], N)
def main():
    N = int(input())
    l = []
    s = ''
    l = calc3(l, s[:], N)
main()

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())

alpha = 'abcdefghijklmnopqrstuvwxyz'

text = alpha[:N]

textl = list(itertools.product(text, repeat=N))
S = len(textl) // 2
newtextl = textl[:S]
for ans in newtextl:
    ansl = ''.join(ans)
    print(ansl)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = 'abcdefghijklmnopqrstuvwxyz'

for i in range(n):
  s = ''
  for j in range(i+1):
    s += p[j]
  if n % len(s) == 0:
    a = s*(n//len(s))
    print(a)
  else:
    b = n % len(s)
    #print(b)
    a = s*(n//len(s)) + s[:b]
    print(a)

Submission status: Wrong Answer

Solution code:
N=int(input())
alp="abcdefghij"
S=[""for i in range(N)]

def gen(cnt,rem):
    if rem==0:
        print("".join(S))
    else:
        for i in range(min(N,cnt+2)):
            S[N-rem]=alp[i]
            gen(i,rem-1)            

S[0]="a"
gen(0,N-1)

Submission status: Wrong Answer

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
a = ("a", "b", "c", "d", "e")
N = int(input())
L = [0]*N

alpha=list('abcdefghij')
print('a'*N)
for i in range(N,0,-1):
    for j in range(i,N,1):
        L[j]+=1
        print(''.join([alpha[i] for i in L]))

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)]
if n!=4:
    exit()
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.index("b")!=num:
            a[num]="c"
            f(num+1)
f(1)

Submission status: Wrong Answer

Solution code:
n = int(input())

results = []
if n == 1:
    results = ["a"]
elif n == 2:
    results = ["aa", "ab"]
elif n == 3:
    results = ["aaa", "aab", "aba", "abb", "abc"]
elif n == 4:
    results = ["aaaa", "aaab", "aaba", "aabb", "aabc", "abaa", "abab", "abac", "abba", "abbb", "abbc", "abca", "abcb", "abcc", "abcd"]

for result in results:
    print(result)

Submission status: Wrong Answer

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

def rec(s, k, leng):
    if leng >= 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), leng+1)

rec([0], 1, 1)

Submission status: Wrong Answer

Solution code:
def to_iso(lst):
    chars = set(lst)
    mp = list(chars)
    mp.sort()
    repl = {c: None for c in mp}

    for i in range(len(mp)):
        repl[mp[i]] = chr(97 + i)

    return [repl[c] for c in lst]


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)]
    result = set()

    for perm in comb([], alphabet[:n], n):
        result.add("".join(to_iso(perm)))

    result = list(result)
    result.sort()
    for r in result:
        print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())

def Base_10_to_n(X, n):
    if (int(X//n)):
        return Base_10_to_n(int(X//n), n)+str(X%n)
    return str(X%n)

def Base_n_to_10(X,n):
    out = 0
    for i in range(1,len(str(X))+1):
        out += int(X[-i])*(n**(i-1))
    return out#int out

d2a = {
    '0': 'a',
    '1': 'b',
    '2': 'c',
    '3': 'd',
    '4': 'e',
    '5': 'f',
    '6': 'g',
    '7': 'h',
    '8': 'i',
    '9': 'j',
}

limit_str = '0123456789'
for i in range(N):
    start = int(limit_str[:i+1])
    end = int(limit_str[:i+2])
    if i == N-1:
        print('abcdefghij'[:i+1])
        break
    if i == 0:
        print('a'*N)
        continue
    # print(start,end)
    num = Base_n_to_10(str(start), i+1)
    while True:
        bc = Base_10_to_n(num, i+1)
        if int(bc) >= end:
            break
        sl = len(bc)
        # print('#', bc, sl, limit_str[:sl+1])
        if int(bc) <= int(limit_str[:sl+1]):
            bcs = bc.zfill(N)
            for k, v in d2a.items():
                bcs = bcs.replace(k, v)
            print(bcs)
            # print(bc)
        num += 1

Submission status: Wrong Answer

Solution code:
def chg(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

N = int(input())
li = list("abcdefghij")

for i in range(10**6):
    mm = str(chg(i,N)).zfill(N)
    cnt = -1
    li1 = []
    for j in range(N):
        a = int(mm[j])
        if str(a) in li1:
            continue
        elif a-1==cnt:
            cnt += 1
            li1.append(str(a))
            continue
        break
    else:
        for j in range(N):
            print(li[int(mm[j])],end="")
        print()
    # print(mm)

# print(10*9*8*7*6*5*4*3*2)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from itertools import combinations


def input():
    return sys.stdin.readline()[:-1]


def solve():
    al=[chr(ord('a') + i) for i in range(26)]
    n = int(input())
    a = np.arange(n).tolist()
    base = "a"*n
    res = []
    for i in range(1, n+1):
        base = list("a"*n)
        com = list(combinations(a,i))
        for j, c in enumerate(com):
            for j, num in enumerate(sorted(list(c))):
                base[int(num)] = al[j]
            res.append(''.join(base))
    for ans in list(set(res)):
        print(ans)

    


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

ans = []
d= ['a','b','c','d','e','f','g','h','i','j']
fa = math.factorial(n)+1
for i in range(math.factorial(n)):
    tu = 'a'
    ii = i
    for j in range(2,n+1):
        for k in range(j):
            hh = i % j
            if hh <k+1 and hh >=k:
                tu += d[k]
        fa = fa/2
    ans.append(tu)

for i in range(n):
    for j,jj in enumerate(ans):
        if not d[i] in jj:
            for k in range(i+1,n):
                if d[k] in jj:
                    ans[j] = jj.replace(d[k],d[i])
                    break
print('\n'.join(sorted(set(ans))))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = ['a','b','c','d','e','f','g','h','i','j']
L = A[0:N]
for p in range(1):
    if N == 1:
        print(A[p])
    for q in range(2):
        if N == 2:
            print(A[p] + A[q])
        for r in range(3):
            if N == 3:
                print(A[p] + A[q] + A[r])
            for s in range(4):
                if N == 4:
                    print(A[p] + A[q] + A[r] + A[s])
                for t in range(5):
                    if N == 5:
                        print(A[p] + A[q] + A[r] + A[s] + A[t])
                    for u in range(6):
                        if N == 6:
                            print(A[p] + A[q] + A[r] + A[s] + A[t] + A[u])
                        for v in range(7):
                            if N == 7:
                                print(A[p] + A[q] + A[r] + A[s] + A[t] + A[u] + A[v])
                            for w in range(8):
                                if N == 8:
                                    print(A[p] + A[q] + A[r] + A[s] + A[t] + A[u] + A[v] + A[w])
                                for x in range(9):
                                    if N == 9:
                                        print(A[p] + A[q] + A[r] + A[s] + A[t] + A[u] + A[v] + A[w] + A[x])
                                    for y in range(10):
                                        if N == 10:
                                            print(A[p] + A[q] + A[r] + A[s] + A[t] + A[u] + A[v] + A[w] + A[x] + A[y])

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import math
from collections import deque
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

#max(chr(ord("z")+1), 
def tami(re,res,cnt):
  if cnt == N:
    ans.append(res)
    return
  for i in range(ord("a"), min(ord("z")+1, ord(re)+2)):
    tami(chr(i),res+chr(i),cnt+1)

N = I()

ans = []
tami(chr(ord("a")-1),"",0)
ans.sort()
for i in ans:
  print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())

def normal_form(x):
    if x == 1:
        return ['a']
    temp = normal_form(x-1)
    res = []
    for i, s in enumerate(temp):
        if i == 0:
            k = 2
        elif i == len(temp)-1:
            k = x
        else:
            k = x-1
        for j in range(k):
            res.append(s+chr(j+97))
    return res

print('\n'.join(normal_form(n)))

Submission status: Wrong Answer

Solution code:
def chg(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

N = int(input())
li = list("abcdefghij")

for i in range(10**6):
    mm = str(chg(i,N)).zfill(N)
    cnt = -1
    li1 = []
    for j in range(N):
        a = int(mm[j])
        if str(a) in li1:
            continue
        elif a-1==cnt:
            cnt += 1
            li1.append(str(a))
            continue
        break
    else:
        for j in range(N):
            print(li[int(mm[j])],end="")
        print()
    # print(mm)

print(10*9*8*7*6*5*4*3*2)

Submission status: Wrong Answer

Solution code:
from collections import deque


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

    #    for c in range(ord('a'), ord('z') + 1):
    # print(chr(c))

    #s = set()
    #l = []
    av = ord('a')
#    zv = ord('z')

    def to_s(ary):
        # return "".join(map(str, ary))
        ans = "".join(map(lambda v: chr(v + av), ary))
        # s.add(ans)
        # l.append(ans)
        return ans

    def search(i, v, ary):
        if i >= N:
            print(to_s(ary))
            return

        for u in range(0, v + 2):
            ary[i] = u
            search(i + 1, u, ary)

    ary = [0] * N
    search(1, 0, ary)

    # print(len(l))
    # print(len(s))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin,setrecursionlimit
import string
setrecursionlimit(10**7)
n = int(stdin.readline().rstrip())
alpha = string.ascii_lowercase
from itertools import combinations_with_replacement
kazu = set()
li = [str(i) for i in range(n)]
lin = list(combinations_with_replacement(li, n))
for i in lin:
    s = ''.join(map(str, i))
    point = 0
    for j in s:
        if j in "0123456789":
            s = s.replace(j,alpha[point])
            point += 1
    kazu.add(s)
kazu = list(kazu)
kazu.sort()
for i in kazu:
    print(i)

Submission status: Wrong Answer

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

if N > 1:
  ans1 = []
  a = max(ans)+1
  for i in range(a+1):
    c = copy.copy(ans)
    c.append(i)
    ans1.append(c)
    
if N > 2:
  ans2 = []
  for j in range(len(ans1)):
    a = max(ans1[j])+1
    for i in range(a+1):
      c = copy.copy(ans1[j])
      c.append(i)
      ans2.append(c)

if N > 3:
  ans3 = []
  for j in range(len(ans2)):
    a = max(ans2[j])+1
    for i in range(a+1):
      c = copy.copy(ans2[j])
      c.append(i)
      ans3.append(c)
      

if N > 4:
  ans4 = []
  for j in range(len(ans3)):
    a = max(ans3[j])+1
    for i in range(a+1):
      c = copy.copy(ans3[j])
      c.append(i)
      ans4.append(c)


if N > 5:
  ans5 = []
  for j in range(len(ans4)):
    a = max(ans4[j])+1
    for i in range(a+1):
      c = copy.copy(ans4[j])
      c.append(i)
      ans5.append(c)

      
if N > 6:
  ans6 = []
  for j in range(len(ans5)):
    a = max(ans5[j])+1
    for i in range(a+1):
      c = copy.copy(ans5[j])
      c.append(i)
      ans6.append(c)

if N > 7:
  ans7 = []
  for j in range(len(ans6)):
    a = max(ans6[j])+1
    for i in range(a+1):
      c = copy.copy(ans6[j])
      c.append(i)
      ans7.append(c)

if N > 8:
  ans8 = []
  for j in range(len(ans7)):
    a = max(ans7[j])+1
    for i in range(a+1):
      c = copy.copy(ans7[j])
      c.append(i)
      ans8.append(c)

      
if N > 9:
  ans9 = []
  for j in range(len(ans8)):
    a = max(ans8[j])+1
    for i in range(a+1):
      c = copy.copy(ans8[j])
      c.append(i)
      ans9.append(c)

aaa = "abcdefghijklmnop"
if N == 1:
  print("a")    
    
elif N ==2:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==3:
  for i in ans2:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==4:
  for i in ans3:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans4:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==7:
  for i in ans6:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==8:
  for i in ans7:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==9:
  for i in ans8:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==10:
  for i in ans9:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)

Submission status: Wrong Answer

Solution code:
n = int(input())
def func2(n):
    if n == 1:
        return "a"
    ll = []
    for head in func2(n-1):
        for tail in [chr(i + 97) for i in range(2) ]:
           ll.append(head + tail)
    return ll

def func3(n):
    if n == 3:
        return ["abc"]
    ll = []
    for head in func3(n-1):
        for tail in [chr(i + 97) for i in range(3) ]:
           ll.append(head + tail)
    return ll

def func4(n):
    if n == 4:
        return ["abcd"]
    ll = []
    for head in func4(n-1):
        for tail in [chr(i + 97) for i in range(4) ]:
           ll.append(head + tail)
    return ll

if n == 1:
    print("a")
elif n == 2:
    for i in func2(n):
        print(i)
elif n == 3:
    for i in func2(n) + func3(n):
        print(i)
elif n == 4:
    for i in func2(n) + func3(n) + func4(n):
        print(i)

Submission status: Wrong Answer

Solution code:
s_l= []
n=int(input())
print("a"*n)

def splus(s):
    s1 = s + "a"
    s2 = s + "b"
    s3 = s + "c"
    return s1, s2, s3

for i in range(1,n):
    s="a"*(n-i) + "b"
    s_l = [s]
    for j in range(i-1):
        for k in range(len(s_l)):
            sa = s_l.pop(k)
            s1,s2,s3 = splus(sa)
            s_l.append(s1)
            s_l.append(s2)
            s_l.append(s3)
    for sa in sorted(s_l):
        print(sa)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    al = "abcdefghij"
    if n == 1:
        print("a")
    elif n == 2:
        print("aa", "ab", sep="\n")
    elif n == 3:
        print("aaa", "aab", "aba", "abb", "abc", sep="\n")
    elif n == 4:
        print("aaaa", "aaab", "aaba","aabb", "aabc", "abaa", "abab", "abac","abba", "abbb", "abbc", "abca","abcb","abcc","abcd", sep="\n")


if __name__ == '__main__':
    main()