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())
import copy

def nex(lis,i):
    li = copy.copy(lis)
    if len(li) == N:
        print(''.join([chr(97+i) for i in li]))
        return 

    for x in range(li[-1]+2):
        li2 = copy.copy(li)
        li2.append(x)
        nex(li2, i+1)
        
nex([0],0)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
l = [ord('a')] * N
result = []
result.append(''.join(map(chr,l)))
bin = [0]*N
binMax = 2**(N-1)

def binAdd(i=1):
    if bin[-i]==1:
        bin[-i] = 0
        binAdd(i+1)
    else:
        bin[-i] = 1

def recF():
    binAdd()
    count = 0
    for i in range(N):
        if bin[i] == 1:
            count += 1
            for j in range(count):
                l[i] = l[i] + 1
                result.append(''.join(map(chr,l)))


for i in range(binMax-1):
    l = [ord('a')] * N
    recF()

for s in result:
    print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    # print("i", i)
    res = [0] * n
    if i != 0:
        res[n - i] += 1
    else:
        resstr = res
        resstr = list(map(lambda x: chr(ord("a") + x), res))
        print("".join(resstr))
        continue
    while res[n - i] == 1:
        m = 0
        p = True
        for k in range(n):
            if res[k] > m + 1:
                p = False
            m = max(m,res[k])
        resstr = res
        resstr = list(map(lambda x: chr(ord("a") + x), res))
        if p:
            print("".join(resstr))
        res[-1] += 1
        for j in range(1, i):
            #print("verf", res[: n-j], "n-j", n-j)
            if res[n - j] > max(res[:n - j]) + 1:
                res[n - j] = 0
                res[n - j - 1] += 1
                break
    continue
    resstr = list(map(lambda x: chr(ord("a") + x), res))
    print("".join(res))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=1
S=[1]*n
for x in range(n):
  print(chr(S[x]+96),end="")
print()
j=1
i=1
while i<n:
  if S[-i]>S[-i-1]:
    i=i+1
  else:
    S[-i]+=1
    if i<=j:
      for x in range(n):
        print(chr(S[x]+96),end="")
      print()
      if S==[i for i in range(1,n+1)]:
        exit()
    else:
      j=i
      for k in range(1,i):
        S[-k]=1
      i=1
      j=1
      for x in range(n):
        print(chr(S[x]+96),end="")
      print()

Submission status: Wrong Answer

Solution code:

n = int(input())
L = []
def f(sa, n, b):
    # sa='a', n=9, b='b'
#    print(sa, n, b)
    if n == 0:
        L.append(sa)
        return
    for i in range(n, 0, -1):
        x = sa + b*i
        c = chr(ord(b) + 1)
        f(x, n-i, c)
i = f('', n, 'a')
for l in L:
    print(l)

Submission status: Wrong Answer

Solution code:
n = int(input())


def f(s):
    if len(s) >= n:
        print(s)
    else:
        for i in range(len(s)+1):
            f(s + chr(ord('a') + i))


f('a')

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[[] for i in range(N+1)]
B[0].append("")
for i in range(N):
    A.append(chr(97+i))
    for j in B[i]:
        for k in A:
            B[i+1].append(j+k)
for i in B[N]:
    count=ord("a")
    yes=1
    for j in range(N):
        if ord(i[j])<=count+1:
            count=max(count,ord(i[j]))
        else:
            continue;
            yes=0
    if yes==1:
        print(i)

Submission status: Wrong Answer

Solution code:
import itertools


def main():
    abc = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j',
           11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o', 16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't',
           21: 'u', 22: 'v', 23: 'w', 24: 'x', 25: 'y', 26: 'z'
           }
    N = int(input())
    comb = itertools.combinations_with_replacement(range(0, N), N)
    checked = list()

    for c in comb:
        tmp = list()
        tmp_dict = dict()
        for enum, s in enumerate(c):
            if s in tmp_dict:
                tmp.append(tmp_dict[s])
                continue
            tmp_dict[s] = enum
            tmp.append(enum)
        tmp_integer = ''.join(str(s) for s in tmp)
        if tmp_integer in checked:
            continue
        checked.append(tmp_integer)
    for c in checked:
        for s in c:
            print(abc[int(s) + 1], end='')
        print('\n', end='')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
"""
1
a
2
aa
ab
3
aaa a3
baa a2
aba a2
aab a2
bba a1
abb a1
abc a1

"""
if N==1:
    print('a')
# まず合計がNになる数値の組み合わせを求める．１番大きい要素から決めていく
else:
    kumiawase = 2**(N-1)
    for i in range(kumiawase):
        binary = format(i, '0'+str(N-1)+'b')
        kazu=[1]
        suuji = 1
        for b in binary:
            if b == '1':
                suuji+=1
            kazu.append(suuji)
        alphabet = [chr(k+97-1) for k in kazu]
        print(''.join(alphabet))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(N - 1):
  w_init = w
  w = []
  for j in range(len(w_init)):
    for k in range(i + 2):
      if w_init[j][-1] == l[k]:
        for m in range(k + 2):
          w.append(w_init[j] + l[m])

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N = int(input())
import sys
sys.setrecursionlimit(10**6)
ans = []
new = []
from copy import copy
def make(array):
    if len(array) == N:
        ans.append(array)
    else:
        for i in range(array[-1]+2):
            array_ = copy(array)
            array_.append(i)
            make(array_)
make([0])
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:

L = []
def f(sa, n, b):
    # sa='a', n=9, b='b'
#    print(sa, n, b)
    if n == 0:
        L.append(sa)
        return
    for i in range(n, 0, -1):
        x = sa + b*i
        c = chr(ord(b) + 1)
        f(x, n-i, c)
i = f('', 10, 'a')
for l in L:
    print(l)

Submission status: Wrong Answer

Solution code:
n = int(input())

alpha = "abcdefghijklmnopqrstuvwxyz"

inp = [""]
for i in range(n):  # ふかさのループ
    out = []
    for j in range(len(inp)):  # リストのループ
        for k in range(i):  # アルファベットのループ
            out.append(inp[j] + alpha[k])
    out.append(inp[j] + alpha[i])
    inp, out = out, inp

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

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque
N = int(input())

s = 'a'
queue = deque()
queue.append(s)
end = 'a'
while True:
    a = queue.popleft()
    if len(a) == N:
        queue.append(a)
        break
    origin = a
    a = a[-1]
    s = 'a'
    end = max(chr(ord(a)+2), end)
    while s != end:
        queue.append(origin+s)
        s = chr(ord(s)+1)
ans = []
while queue:
    ans.append(queue.popleft())
for s in sorted(ans):
    print(s)

Submission status: Wrong Answer

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations, product
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(product(end, repeat=N))
#for nli in l:
#    print(''.join(nli))

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:
n=int(input())
abc='abcdefghih'
L=[]
def dfs(i,a,s):
    if i==n:
        L.append(s)
    else:
        for j in range(0,a+1):
            dfs(i+1,j+1,s+abc[j])
dfs(0,0,'')
L.sort()
for l in L:
    print(l)

Submission status: Wrong Answer

Solution code:
N = input()

N = int(N)
if N == 1:
    print("a")
    exit()
# 97 a
string_list = []


def temp(now, string, count):
    if count == N:
        string_list.append(string)
        return 0
    temp(now, string+chr(now), count+1)
    temp(now+1, string+chr(now+1), count+1)
    if now != 97:
        temp(now-1, string+chr(now-1), count+1)
    return 0


temp(97, "a", 1)
string_list.sort()
for i in string_list:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

l = 'abcdefghijklmnopqrstuvwxyz'
N = INT()

# ans = (N-1) * "a" + 

# for i in range():
# p1 = "a" * N
q = ["a"]

# def dfs():
    # a = q.pop()
    # while q:
a = "a"
k = [n for n in l[:N]]
# print(k)
# for i in range(N):
# def dfs():
kazu = []
for i in range(1, N):
    y = k[:i]
    u = k[:i+1]
    B = list(product(y, u))
    for b in B:
        # for c in b:
        kazu.append("".join(b))
kazu.sort()
print(*kazu, sep="\n")

Submission status: Wrong Answer

Solution code:
n=int(input())

A=["aa","ab"]
num2alpha = lambda c: chr(c+64)
B=[]
num2alpha(3)
if n==1:
	print("a")
	exit()
if n==2:
	print("aa")
	print("ab")
	exit()
X=['a','b','c','d','e','f','g','h','i','j']
for l in range(n-2):
	k=l+3
	for s in A:
		for m in range(n):
			B.append(s+X[m-1])
		if s[-1]!= "a":
			B.append(s+chr(ord(s[-1])+1))
	A=A+B
	B=[]
for x in A:
	if len(x)==n:
		print(x)

Submission status: Wrong Answer

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations, product
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(product(end, repeat=N))
#for nli in l:
#    print(''.join(nli))

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:
N=int(input())
ans = []
def same(c,mc):
    if len(c)==N:
        ans.append(c)
        return
    else:
        for i in range(ord('a'),ord(mc)+2):
            same(c+chr(i),chr(ord(mc)+1))
same('a','a')
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = ['a']
for j in ans:
  if len(j) < n:
    c = ord(j[-1])
    #print(c)
    for i in range(97,c+2):
      l = str(j + chr(i))
      ans.append(l)
chk = []
for i in ans:
  if len(i) == n:
    chk.append(i)
for i in chk:
  print(i)

Submission status: Wrong Answer

Solution code:
from itertools import product
from collections import deque

N = int(input())
d = deque(["b","c","d","e","f","g","h","i","j","k"])
l = ["a", "x"]

for s in list(product(l,repeat=N-1)):
  tmp = list(s)
  for i in range(len(tmp)):
    if tmp[i] == "x":
      tmp[i] = d.popleft()
  print("a"+"".join(tmp))
  d = deque(["b","c","d","e","f","g","h","i","j","k"])

Submission status: Wrong Answer

Solution code:
# Code for D - String Equivalence
# Use input() to fetch data from STDIN
n = int(input())
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def d(x):
    return a[:x+1]

def s(level, count):
    if level == 1:
        return d(count)

    array = []
    for z in range(count+1):
        array.extend([a[z] + y for y in s(level - 1, z + 1)])
    return array

for x in s(n, 0):
    print(x)

Submission status: Wrong Answer

Solution code:
from sys import stdin,setrecursionlimit
import string
setrecursionlimit(10**7)
n = int(stdin.readline().rstrip())
alpha = "abcdefghijklmn"
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
    num = 0
    moto = s[:]
    while num == 0:
        flag = False
        for j in s:
            if j in "0123456789":
                s = s.replace(j,alpha[point])
                point += 1
                flag = True
                break
        if flag == False:
            break
    kazu.add(s)
kazu = list(kazu)
kazu.sort()

for i in kazu:
    print(i)

Submission status: Wrong Answer

Solution code:
# input1 = list(map(int, (input().split())))


def func(n, sss, d):
    for i in range(n):
        if d == N:
            print(sss + s[i])
        else:
            func(i + 2, sss + s[i], d+1)


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

N = int(input())

# func(1, "", 1)

print("aaaa \
aaab\
aaba\
aabb\
aabc\
abaa\
abab\
abba\
abbb\
abbc\
abca\
abcb\
abcc\
abcd")

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 1:
    print('a')
if n == 2:
    print('aa')
    print('ab')
if n == 3:
    print('aaa')
    print('aab')
    print('aba')
if n == 4:
    print('aaaa')
    print('aaab')
    print('aaba')
    print('aabb')
if n == 5:
    print('aaaaa')
    print('aaaab')
    print('aaaba')
    print('aaabb')
    print('aabaa')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
N = int(input())
N -= 1

S = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"]


def dfs(s, depth, maxS):

    if depth == N:
        print(s)
        return

    for i in range(maxS+1):
        dfs(s + S[i], depth+1, maxS+1)


dfs("a", 0, 1)

Submission status: Wrong Answer

Solution code:
n = int(input())

w = ["a"]*n


ls = "abcdefghij"

for i in reversed(range(n)):
    for j in range(10):
        w[i] = ls[j]
        if w[i:]==ls[:n-i]:
            print(w)
            break
        else:
            print(w)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import os
import sys
import datetime
from functools import lru_cache
readline=readline = sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True


def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
ans=[]
def f(s,N):
    if(len(s)==N):
        ans.append(s)
        return
    max_=-1
    for a in s:
        max_=max(max_,ord(a)-ord("a"))
    for a in range(max_+1):
        s1=s+chr(ord(chr(max_+ord("a")))-a+1)
        f(s1,N)

#main
N=int(input())
ans=[]
if N==1:
    print("a")
else:
    f("a",N)
    ans.sort()
    print("\n".join(ans))

Submission status: Wrong Answer

Solution code:
N = input()

N = int(N)
if N == 1:
    print("a")
    exit()
# 97 a
string_list = []


def temp(now, string, count):
    if count == N:
        string_list.append(string)
        return 0
    temp(now, string+chr(now), count+1)
    temp(now+1, string+chr(now+1), count+1)
    if now != 97:
        temp(now-1, string+chr(now-1), count+1)
    return 0


temp(97, "a", 1)
string_list.sort()
print(string_list)

Submission status: Wrong Answer

Solution code:
import math
import sys
from decimal import *
import itertools

n= list(map(int, input().split()))

n = n[0]

ls = []
ts =[]
for i in range(n):
    ls.append(i+1)

for cb in itertools.product(ls, repeat=n):
    if cb[0] != 1:
        break
    ts.append(cb)

s = set()
for t in ts:
    stri = ""
    ch = 'a'
    used = {}


    for c in t:
        if c in used:
            stri += used[c]
        else:
            used[c] = ch;
            ch = chr(ord(ch) + 1)
            stri += used[c]
    s.add(stri)

ans = list(s)
sorted(ans)

for st in ans:
    print(st)

Submission status: Wrong Answer

Solution code:
from itertools import permutations

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

for p in permutations(range(N)):
    D = [-1] * N
    A = []
    for i in range(N):
        for j in range(N):
            if D[j] < p[i]:
                D[j] = p[i]
                A.append(j)
                break
    ans.append(A)

ans.sort()

for a in ans:
    s = ''.join(map(lambda x:chr(x+97),a))
    print(s)

Submission status: Wrong Answer

Solution code:
import sys
import re

l = sys.stdin.readline()
l = int(l)
out = []
def x(stri,l,depth):
  str = 'abcdefghij'
  for i in range(0,l-depth+1):
    cdepth = depth
    cstri = stri
    cstri += str[i] 
    cdepth -= 1
    if( cdepth == 0):
	out.append(cstri)
    else:
	x(cstri,l,cdepth)


stri = 'a'
if( l == 1):
 print stri
 exit(0)
x(stri,l,l-1)

ret = {}
count = 0
for i in out:
  prev = '0'
  moji = ""
  for j in i:
    if( prev == j ):
      moji += "E"
    else:
      if( prev > j ):
        moji += "U"
      else:
        moji += "D"
    prev = j
  ret[count] = moji
  count += 1
 
count = 0
kekka = {}
for i in out:
  if( ret[count] not in kekka.values()):
    print i
  kekka[count] = ret[count]
  count += 1


sys.stdout.flush()

Submission status: Wrong Answer

Solution code:
S = "abcdefghijklmn"


def main():

    N = int(input())

    if N == 1:
        for i in range(1):
            print(S[i])

    elif N == 2:
        for i in range(1):
            for j in range(i + 2):
                print(S[i] + S[j])

    elif N == 3:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    print(S[i] + S[j] + S[k])

    elif N == 4:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        print(S[i] + S[j] + S[k] + S[l])

    elif N == 5:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            print(S[i] + S[j] + S[k] + S[l] + S[m])

    elif N == 6:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            for n in range(m + 2):
                                print(S[i] + S[j] + S[k] + S[l] + S[m] + S[n])

    elif N == 7:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            for n in range(m + 2):
                                for o in range(n + 2):
                                    print(S[i] + S[j] + S[k] + S[l] + S[m] +
                                          S[n] + S[o])

    elif N == 8:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            for n in range(m + 2):
                                for o in range(n + 2):
                                    for p in range(o + 2):
                                        print(S[i] + S[j] + S[k] + S[l] +
                                              S[m] + S[n] + S[o] + S[p])

    elif N == 9:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            for n in range(m + 2):
                                for o in range(n + 2):
                                    for p in range(o + 2):
                                        for q in range(p + 2):
                                            print(S[i] + S[j] + S[k] + S[l] +
                                                  S[m] + S[n] + S[o] + S[p] +
                                                  S[q])

    elif N == 10:
        for i in range(1):
            for j in range(i + 2):
                for k in range(j + 2):
                    for l in range(k + 2):
                        for m in range(l + 2):
                            for n in range(m + 2):
                                for o in range(n + 2):
                                    for p in range(o + 2):
                                        for q in range(p + 2):
                                            for r in range(q + 2):
                                                print(S[i] + S[j] + S[k] +
                                                      S[l] + S[m] + S[n] +
                                                      S[o] + S[p] + S[q] +
                                                      S[r])


main()

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, xset):
        if n >= N:
            ans.append(s)
            return

        f = False
        cnt = 0
        for i in range(n + 1):
            if chr(ord('a') + i) not in xset:
                if f:
                    continue
                xset.add(chr(ord('a') + i))
                solve(s + chr(ord('a') + i), n + 1, xset)
                f = True
                cnt += 1
            else:
                solve(s + chr(ord('a') + i), n + 1, xset)
                cnt += 1

            if cnt == len(xset) + 1:
                break

    sset = set()
    sset.add('a')
    solve('a', 1, sset)
    ans.sort()
    for a in ans:
        print(a)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"]
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"]

results = []
for i in range(n):
    if i == 0:
        results.append(["a"])
    else:
        standards = []
        for result in results[i-1]:
            abcs = list(set(result))
            abcs.append(abc[len(abcs)])
            for a in abcs:
                standards.append(result + a)
        results.append(standards)

for result in results[n-1]:
    print(result)

Submission status: Wrong Answer

Solution code:
i = int(input())
p = print
jlist = [None] * 20
def jjj(i):
    if jlist[i-1] is not None:
        return jlist[i-1]
    if i == 1:
        return ('a')
    u = []
    # u = list(map(lambda x: 'a'+x), jjj(i-1))
    for k in range(i-1):
        u+= list(map(lambda x: 'a'+slide(x, k), jjj(i-1)))
    jlist[i-1] = u
    return u
        

def slide(s, k):
    ss = ''
    for c in s:
        cc = ord(c) + k
        ss += chr(cc)
    return ss

p('\n'.join(jjj(i)))

Submission status: Wrong Answer

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

alphabets = list('abcdefghijklmnopqrstuvwxyz')

N = int(input())

if N == 1:
    print('a')
else:
    str_tmp = ['a']
    str_final = []
    for i in range(1, N):
        for s in str_tmp:
            for alphabet in set(list(s)):
                str_final.append(s+alphabet)
            str_final.append(s+alphabets[len(set(list(s)))])
    print(str_final)

Submission status: Wrong Answer

Solution code:
import math
a = int(input())
b = 'abcdefghij'

for i in range(a):
  if i < a - 1:
    print(b[0:i]+b[i]*(a-i))
  else:
    print(b[0:i+1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
from itertools import combinations_with_replacement 
#sys.stdin=open("input.in","r")
#sys.stdout=open("output.out","w")
n=int(input())
st=["a","b"]
comb = combinations_with_replacement([0, 1,0,1,0,1,0,1,0,1], n)  
comb2=[]
comb=set(comb)
comb=sorted(comb)
for i in range(len(comb)-2):
    st=""
    for j in comb[i]:
        if j==1:
            st+="b"
        else:
            st+="a"
    print(st)
"""for i in list(comb): 
    l=list(i)
    comb2.append(l.copy())
    for j in range(len(l)):
        if l[j]==1:
            l[j]=0
        else:
            l[j]=1
    comb2.append(l)
comb2=sorted(comb2)
for i in comb2:
    l=i
    for j in range(len(l)):
        if l[j]==1:
            l[j]="b"
        else:
            l[j]="a"
    print(l)"""

Submission status: Wrong Answer

Solution code:
import string

def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n = iinp()
a = string.ascii_lowercase

k = n

while k != 0:
  for i in range(int(2**(k-1))):
    d = []
    p = len(bin(i))
    q = bin(i)
    for j in range(p-2):
      q = bin(i>>j)
      if int(q[len(q)-1]) == 1:
        d.append(k-j-2)

    for i in range(n-k+1):
      print(a[i],end="")
    for j in range(k-1):
      if k != n and (j == 0 or j == k-1-1):
        continue
      if j in d:
        print(a[n-k+1],end="")
      else:
        print(a[n-k],end="")
    print("")
  k -= 1

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = []
abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
for i in range(n):
    lst_ = lst
    lst = []
    for s in lst_:
        for j in range(10):
            if s[-1] == abc[j - 1]:
                break
            else:
                lst.append(s + abc[j])
for s in lst:
    print(s)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque
N = int(input())

s = 'a'
queue = deque()
queue.append(s)
# for i in range(N):
while True:
    a = queue.popleft()
    if len(a) == N:
        queue.append(a)
        break
    origin = a
    a = a[-1]
    s = 'a'
    end = chr(ord(a)+2)
    while s != end:
        queue.append(origin+s)
        s = chr(ord(s)+1)
ans = []
while queue:
    ans.append(queue.popleft())
for s in sorted(ans):
    print(s)