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:
import sys
from collections import deque

class alphabet(): #Trueなら大文字
    def __init__(self):
        self.index = dict()
        self.abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
        for i, a in enumerate(self.abc): self.index[str(i)] = a

def solve():
    N = int(input())
    AB = alphabet()
    Ans = []
    q = deque()
    q.append(("a", 1))
    while q:
        current, length = q.popleft()
        if length == N: Ans.append(current)
        else:
            q.append((current + "a", length + 1))
            for k in range(10):
                q.append((current + AB.abc[k + 1], length + 1))
                if AB.abc[k] == current[length - 1]: break
    Ans.sort()
    for a in Ans: print(a)
    return 0

if __name__ == "__main__":
    solve()

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)

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

Submission status: Wrong Answer

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

n = int(input())
num = [i for i in range(11)]
s = string.ascii_lowercase
#lis = list(itertools.combinations_with_replacement(num[0:n-1], n-1))
lis = list(itertools.product(num[0:n-1], repeat=n-1))

if n != 1:
    for li in lis:
        #print(li)
        for i in range(n-2):
            if (li[i+1] - li[i] >= 2 and li[i+1]-1 not in li) or li[0] >= 2:
                break
        else:
            print('a', end='')
            for i in range(n-1):
                print(s[li[i]], end='')
            print('')

print(s[:n])

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(1, N):
            temp = s[:i] + first + s[i:]
            anss.append(temp)

for ans in anss:
    print(ans)

Submission status: Wrong Answer

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

groups = []

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

dfs('', 0)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [0] * N

ED = [chr(i + 97) for i in range(N)]
ED = ''.join(ED)

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)
    print(ret)

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

Submission status: Wrong Answer

Solution code:
n=int(input())

def f(idx, mx, str):
    # print(idx, mx, str)
    if idx==n:
        print(str)
        return
    for i in range(mx+1):
        f(idx+1, i+1, str+chr(ord('a')+i))

f(0,0,"")

Submission status: Wrong Answer

Solution code:
print('''aaa
aab
aba
abb
abc''')

Submission status: Wrong Answer

Solution code:
import string

normal_set = set()
def reccursion(n, _s, cur):

    if len(_s) == n:
        global normal_set
        normal_set.add(_s)
        
        return

    next_s = _s + string.ascii_lowercase[cur]
    reccursion(n, next_s, cur)

    if cur + 1 < n:
        next_s = _s + string.ascii_lowercase[cur + 1]
        reccursion(n, next_s, cur + 1)

def solve():
    n = int(input())
    reccursion(n, "a", 0)

    global normal_set
    normal_set = sorted(list(normal_set))
    
    for _s in normal_set:
        print(_s)

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")

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [[[0]]]
k = 0
while k < N-1:
  c = a[k]
  a.append([])
  for r in c:
    for i in range(r[-1]+2):
      x = r + [i]
      a[k+1].append(x)
  
  k += 1
A = a[-1]
for s in A:
  ans = ""
  for i in range(N):
    ans += chr(s[i]+97)
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
d={'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26, 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'}
lc=[["aaa",1],["aab",2],["aba",2],["abb",2],["abc",3]]
if n==1:
    print("a")
elif n==2:
    l=["aa","ab"]
    print(*l)

elif n==3:
    for i in lc:
        print(i[0])
elif n==4:
    ld=[]
    for j in range(len(lc)):
        for i in range(1,lc[j][1]+2):
            k=lc[j][0]+d[i]
            c = collections.Counter(k)
            ld.append([k,len(c)])
    ld=sorted(ld)
    for i in ld:
        print(i[0])

Submission status: Wrong Answer

Solution code:
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    d = deque(['a'])
    while len(d[0])<N:
        s = d.popleft()
        if s[-1]=='a':
            d.append(s+'a')
            d.append(s+'b')
        elif s[-1]=='b':
            d.append(s+'a')
            d.append(s+'b')
            d.append(s+'c')
        else:
            d.append(s+'a')
            d.append(s+chr(ord(s[-1])+1))
    while len(d)!=0:
        print(d.popleft())


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
num = int(input())
word = "a" * num
if (num == 1):
  print(word)
else:
	print(word)	
	print(("a" * (num - 1)) + "b")

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
def input(): return sys.stdin.readline().strip()
def STR(): return input()
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 = sys.maxsize
mod = 10 ** 9 + 7

def func(spec, remain, cha):
    if spec == 1:
        return [[cha for _ in range(remain)]]
    ans = []
    for i in range(spec - 1, remain): #文字をいくつ残すか
        tmp = func(spec - 1, i, chr(ord(cha) + 1))
        for j in range(len(tmp)):
            tmp[j] = [cha for _ in range(remain - i)] + tmp[j]
        ans.extend(tmp)
    return ans
    '''
    print('tmp', tmp)
    l = len(tmp)
    res = []
    for i in range(remain):
        start = i * l
        print('start', start, 'l', l)
        res.extend(deepcopy(tmp))
        for j in range(l):
            res[start + j].insert(i, cha)
    print(res)
    return res
    '''

n = INT()
res = []
for i in range(1, n + 1): #n種類の文字
    res.extend(func(i, n, 'a'))
ans = ['' for _ in range(len(res))]
for i in range(len(res)):
    tmp = ''
    for j in range(n):
        tmp += res[i][j]
    ans[i] = tmp
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from itertools import product
N = int(input())
X = [chr(ord('a') + i) for i in range(N)]
first_presence = {x: i for x, i in zip(X, list(range(N)))}

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

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

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
t=ord('a')
cnt=[]
s=[]
#print(chr(t))
for i in range(10):
 k=0
 s=[]
 while k<=i:
  s.append(chr(t+k))
  k+=1
 cnt.append(s)
c0=cnt[0]
c1=cnt[1]
c2=cnt[2]
c3=cnt[3]
c4=cnt[4]
c5=cnt[5]
c6=cnt[6]
c7=cnt[7]
c8=cnt[8]
c9=cnt[9]
if n==1:
 print('a')
if n==2:
 print('aa')
 print('bb')
if n==3:
 for i,j,k in itertools.product(c0,c1,c2):
    print(i+j+k)
if n==4:
 for i0,i1,i2,i3 in itertools.product(c0,c1,c2,c3):
    print(i0+i1+i2+i3)
if n==5:
 for i0,i1,i2,i3,i4 in itertools.product(c0,c1,c2,c3,c4):
    print(i0+i1+i2+i3+i4)
if n==6:
 for i0,i1,i2,i3,i4,i5 in itertools.product(c0,c1,c2,c3,c4,c5):
    print(i0+i1+i2+i3+i4+i5)
if n==7:
 for i0,i1,i2,i3,i4,i5,i6 in itertools.product(c0,c1,c2,c3,c4,c5,c6):
    print(i0+i1+i2+i3+i4+i5+i6)
if n==8:
 for i0,i1,i2,i3,i4,i5,i6,i7 in itertools.product(c0,c1,c2,c3,c4,c5,c6,c7):
    print(i0+i1+i2+i3+i4+i5+i6+i7)
if n==9:
 for i0,i1,i2,i3,i4,i5,i6,i7,i8 in itertools.product(c0,c1,c2,c3,c4,c5,c6,c7,c8):
    print(i0+i1+i2+i3+i4+i5+i5+i7+i8)
if n==10:
 for i0,i1,i2,i3,i4,i5,i6,i7,i8,i9 in itertools.product(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9):
    print(i0+i1+i2+i3+i4+i5+i5+i7+i8+i9)

Submission status: Wrong Answer

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

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

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 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)
ans = [repqqq(line) for line in sorted(real_ans)]
for a in ans:
    print(a)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
print('''aaa
aab
aba
abc''')

Submission status: Wrong Answer

Solution code:
from itertools import combinations_with_replacement
n=int(input())
L='abcdefghij'
Li=L[:n]
kumiawase=list(combinations_with_replacement(Li, n))
for kumi in kumiawase:
    print(''.join(kumi))

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline().strip())
alpha = "abcdefghij"

tmp = ["a"] * N
print("".join(tmp))
for i in range(1, N):
    for j in range(0, N - i):
        tmp[N-j-1] = alpha[i]
        print("".join(tmp))

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)
    
ans.sort()

for g in range(len(ans)):
    if len(ans[g])==n:
        print(ans[g])

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
t=ord('a')
cnt=[]
s=[]
print(chr(t))
for i in range(10):
 k=0
 s=[]
 while k<=i:
  s.append(chr(t+k))
  k+=1
 cnt.append(s)
c0=cnt[0]
c1=cnt[1]
c2=cnt[2]
c3=cnt[3]
c4=cnt[4]
c5=cnt[5]
c6=cnt[6]
c7=cnt[7]
c8=cnt[8]
c9=cnt[9]
if n==1:
 print('a')
if n==2:
 print('aa')
 print('bb')
if n==3:
 for i,j,k in itertools.product(c0,c1,c2):
    print(i+j+k)
if n==4:
 for i0,i1,i2,i3 in itertools.product(c0,c1,c2,c3):
    print(i0+i1+i2+i3)
if n==5:
 for i0,i1,i2,i3,i4 in itertools.product(c0,c1,c2,c3,c4):
    print(i0+i1+i2+i3+i4)
if n==6:
 for i0,i1,i2,i3,i4,i5 in itertools.product(c0,c1,c2,c3,c4,c5):
    print(i0+i1+i2+i3+i4+i5)
if n==7:
 for i0,i1,i2,i3,i4,i5,i6 in itertools.product(c0,c1,c2,c3,c4,c5,c6):
    print(i0+i1+i2+i3+i4+i5+i6)
if n==8:
 for i0,i1,i2,i3,i4,i5,i6,i7 in itertools.product(c0,c1,c2,c3,c4,c5,c6,c7):
    print(i0+i1+i2+i3+i4+i5+i6+i7)
if n==9:
 for i0,i1,i2,i3,i4,i5,i6,i7,i8 in itertools.product(c0,c1,c2,c3,c4,c5,c6,c7,c8):
    print(i0+i1+i2+i3+i4+i5+i5+i7+i8)
if n==10:
 for i0,i1,i2,i3,i4,i5,i6,i7,i8,i9 in itertools.product(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9):
    print(i0+i1+i2+i3+i4+i5+i5+i7+i8+i9)

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)):
        for j in range(le):
            res.append(tank[i] + tank[i][j])
        res.append(tank[i] + chr(le+97))
    res = list(set(res))

print(*res)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
x = list(product([0, 1], repeat=N))
ans = []

def ctoi(c):
	return ord(c) - ord('a')

def dfs(s):
	if len(s) == N:
		ans.append(s)
		return
	if s: last = s[-1]
	for i in range(ctoi(last)+2):
		dfs(s+ascii_lowercase[i])

dfs("a")

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