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: Accepted

Solution code:

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline




def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

res=[]
def search(seq,k,n):
    global N
    
    if k==N+1:

        tmp=[ascii_lowercase[s-1] for s in seq[1:]]
        res.append("".join(tmp))
        return 
    
    seq[k]=n
    search(seq,k+1,n+1)
    
    for l in range(1,n):
        seq[k] = l
        search(seq, k+1,n)
    

N=int(input())
seq=[-1]*(N+1)
seq[1]=1
search(seq,2,2)


res=sorted(res)

for rr in res:
    print(rr)

Submission status: Accepted

Solution code:
import collections
import copy
n=int(input())
l=['a']
c=[chr(i) for i in range(97, 97+26)]
for i in range(n-1):
  L=[]
  for j in range(len(l)):
    C=collections.Counter(l[j])
    for k in range(len(C.values())+1):
      L.append(l[j]+c[k])
  l=copy.copy(L)
l.sort()
for i in range(len(l)):
  print(l[i])

Submission status: Accepted

Solution code:
import sys, math
input = sys.stdin.readline
N = int(input())

dic = 'abcdefghijklmnopqrstuvwxyz'

def f(n, i, s):
  if n == 1:
    print(s)
    return
  for j in range(i+1):
    f(n-1, i, s + dic[j])
  if i+1 < 25:
  	f(n-1, i+1, s + dic[i+1])

f(N, 0, 'a')

Submission status: Accepted

Solution code:
N = int(input())
s = 'a'
ans = []
alpha = [chr(ord('a') + j) for j in range(10)]
#print(alpha)
def dfs(S):
  if len(S)==N:
    ans.append(S)
    #print(S)
    return None
  lis = alpha[:max([alpha.index(s) for s in S])+2]
  #print(lis)
  for t in lis:
    T = S+t
    dfs(T)
    
dfs('a')
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
n = int(input())

al = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
ss = ["a"]
if n == 1:
    print("a")
else:
    for k in range(2, n+1):
        ssn = []
        for s in ss:
            for i in range(k):
                if i > 0:
                    if al[i - 1] not in s:
                        break
                sx = s + al[i]
                if k == n:
                    print(sx)
                ssn.append(sx)
        ss = ssn

Submission status: Accepted

Solution code:
N = int(input())

def ww(s, sn, ans,n):
    global N 
    if n == N:
        ans.append(s)
        return 0
    n += 1
    for i in range(sn+1):
        if i == sn:  
            ww(s+chr(ord("a")+i), sn+1, ans, n)
        else:
            ww(s+chr(ord("a")+i), sn, ans, n)
ans = []
ww("a", 1, ans, 1)

ans.sort()

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())


from itertools import product
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

def dfs(ans, i):
    if len(ans) == n:
        print("".join(ans))
        return
    for j in range(i+1):
        dfs(ans+ascii_lowercase[j], max(j+1, i))

dfs("", 0)

Submission status: Accepted

Solution code:
N = int(input())

ans = [["a"]]

def s_func(x):
    m = -1
    for i in range(len(x)):
        m = max(m, ord(x[i]))
    ret = [chr(i) for i in range(97,m+2)]
    return ret

for i in range(N-1):
    new = []
    for j in range(len(ans[i])):
        s_list = s_func(ans[i][j])
        for s in s_list:
            new.append(ans[i][j] + s)
    ans.append(new)
ans[N-1].sort()
for a in ans[N-1]:
    print(a)

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())

queue = deque()
queue.append((0,))
while queue:
    s = queue.popleft()
    if len(s) == N:
        print(''.join('abcdefghij'[i] for i in s))
        continue
    for i in range(max(s) + 2):
        queue.append(s + (i,))

Submission status: Accepted

Solution code:
def solve(li):
    if len(li) == n:
        ans.append(li)
        return
    tmp = max(li)
    for i in range(1, tmp + 2):
        solve(li + [i])

ans = []
n = int(input())
solve([1])
res = []
alph = "abcdefghijklmnopq"

for ptn in ans:
    for i in range(n):
        ptn[i] = alph[ptn[i] - 1]
    res.append("".join(ptn))
res = sorted(res)
for i in res:
    print(i)

Submission status: Accepted

Solution code:
import bisect
import math

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % mod) % mod
    return CONV()


def getStan(n,prevAlpha):
    if n==0:
        return [""]
    if n==1:
        return [[p] for p in range(prevAlpha+2)]
    else:
        ret = []
        for p in range(prevAlpha+1):
            gs = getStan(n-1, prevAlpha)
            ret += [[p]+g for g in gs]
        gs = getStan(n-1, prevAlpha+1)
        ret+=[[prevAlpha+1]+g for g in gs]
        return ret

def main():
    N = iRaw()
    s = "a"*N
    base = ord("a")
    lastS = [chr(ord("a")+n) for n in range(N)]
    gs = getStan(N-1,0)
    for g in gs:
        print ("".join(["a"]+[chr(c+base) for c in g]))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
def fac(N):
    if N == 1:
        return [['a']]
    li = []
    for x in fac(N-1):
        n = len(set(x))
        for i in range(n+1):
            li.append(x+[chr(97+i)])
    return li
for x in fac(N):
    print(''.join(x))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
S = ['a','b','c','d','e','f','g','h','i','j']
def getResult(current:str,remain:int,used:int):
    if remain==0:
        print(current)
    else:
        for i in range(used):
            getResult(current+S[i],remain-1,used)
        getResult(current+S[used],remain-1,used+1)

def solve(N: int):
    getResult(S[0],N-1,1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: Accepted

Solution code:
chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
n = int(input())
seq = [97 for i in range(n)]
i = n - 1
print('a' * n)
while i > 0:
    if seq[i] <= max(seq[:i]):
        seq[i] += 1
        i = n - 1
        print(''.join(map(chr, seq)))
    else:
        seq[i] = 97
        i -= 1

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import copy
import queue

def main():
    mod=10**9+7
    N=I()
    q=queue.Queue()
    q.put("a")
    ans=[]
    
    
    while True:
        s=q.get()
        if len(s)==N:
            q.put(s)
            break
        s2=list(copy.deepcopy(s))
        s2.sort()
        big=ord(s2[-1])-97
        for i in range(big+2):
            q.put(s+chr(i+97))
            
    while not q.empty():
        s=q.get()
        ans.append(s)  
    
    ans.sort()
    
    for i in range(len(ans)):
        print(ans[i])

main()

Submission status: Accepted

Solution code:
import copy
def make(n, data):
    out = []
    # print(ord(data[-1]) + 1 - ord("a"))
    key = data[1]
    for i in range(key + 1):
        # print(key)
        out.append([data[0] + chr(ord("a") + i), max(key, i + 1)])
    return out

n = int(input())
ans = [["a", 1]]
for i in range(1, n):
    tmp = []

    for j in range(len(ans)):
        tmp += make(i + 1, ans[j])
            # print
    if len(tmp) >= 1:
        ans = copy.deepcopy(tmp)
    # print(ans)

for i in ans:
    print(i[0])

Submission status: Accepted

Solution code:
n = int(input())

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

alp = "abcdefghijklmnopqrstuvwxyz"

def next(s,n):
    if n==0:
        print(s)
        return
    val = len(set(s)) # 1 => only a, 2=> a and b
    for i in range(val+1):
        next(s + alp[i],n-1)

s="a"
next(s,n-1)

Submission status: Accepted

Solution code:
al=[chr(ord('a') + i) for i in range(26)]
N=int(input())
ans=[[] for _ in range(N)]
ans[0].append("a")

if N==1:
  print("a")
else:
  for i in range(1,N):    
    for item in ans[i-1]:
      lis=list(item)
      st=set(lis)
      for j in range(len(st)+1):
        ans[i].append(item +chr(ord('a') + j))
  for answer in ans[-1]:
    print(answer)

Submission status: Accepted

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

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

     ans = list()
     for i in range(n):
          ans = solve(ans)
     
     print('\n'.join(ans))

def solve(l):
     ret = list()
     if len(l) == 0:
          return ['a']

     for i in l:
          num = len(set(i))
          for n in range(num + 1):
               s = i + chr(ord('a') + n)
               ret.append(s)
     
     return ret

if __name__ == "__main__":
    main()


# 1: a
# 2: aa, ab
# 3: aaa, aab, aba, abb, abc

# 1:
# 2: 1と同じ、1と違う
# 3: 1と同じ、1と違う 1と同じ、2と同じ、1、2と違う

Submission status: Accepted

Solution code:
import string

n = int(input())

Ans = [[] for _ in range(n+1)]
Ans[1].append('a')
Strs = [x for x in string.ascii_lowercase]

for i in range(1,n):
    for ans in Ans[i]:
        Use_str = [x for x in ans]
        Use_str = set(Use_str)
        for moji in Use_str:
            add = ans + moji
            Ans[i+1].append(add)
        add = ans + Strs[len(Use_str)]
        Ans[i+1].append(add)

Answer = sorted(Ans[n])
for ans in Answer:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'

def src(s):
  i = 0
  while s != alpha[i]:
    i += 1
  return i
def super_troop(n):
  if n == 1:
    return ['a']
  else:
    L = super_troop(n-1)
    LL = []
    for i in L:
      S = [j for j in i]
      S.sort(reverse=True)
      for k in range(src(S[0])+2):
        LL.append(i + alpha[k])
    return LL
X = super_troop(N)
X.sort()
for i in range(len(X)):
  print(X[i])

Submission status: Accepted

Solution code:
n = int(input())

strings = ["a"]

for i in range(n-1):
    newstrings = []
    for s in strings:
        mx = ord('a')
        for char in s:
            mx = max(mx, ord(char))
        
        for c in range(ord('a'),mx+2):
            newstrings.append(s+chr(c))
    
    strings = newstrings

for s in strings:
    print(s)

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())
from collections import deque

def resolve():
    N = int(input())
    S = "abcdefghij"

    q = deque([("", 0, 0)])
    ans = []
    while q:
        #print(q)
        s1, i1, i2 = q.popleft()
        #print(s1, i1, i2)

        if i1 == N:
            ans.append(s1)
            continue
        for i in range(i2):
            q.append((s1+S[i], i1+1, i2))
        q.append((s1+S[i2], i1+1, i2+1))

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:

def main():
    N = int(input())
    li = 'abcdefghijklmnopqrstuvwxyz'

    def condition(t,char):
        nonlocal li
        if li.index(sorted(t)[-1]) + 1 >= li.index(char):
            return True
        else:
            return False
    def f(k):
        nonlocal li
        if k == 1:
            return ['a']
        else:
            temp = f(k-1)
            return [t+char for t in temp for char in li[:k] if condition(t, char)]

    result = f(N)
    for t in sorted(result):
        print(t)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ans = []
alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
k = int(input())
l = ['']*k
def recur(l, ind, newChar):
    if ind == k:
        ans.append(''.join(l))
        return
    for i in range(newChar):
        l[ind] = alp[i]
        recur(l, ind+1, newChar)
    l[ind] = alp[newChar]
    recur(l, ind+1, newChar+1)

recur(l,0,0)
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

words = set()
alp = list("abcdefghij")
def dfs(n, s):
    if len(s) == n:
        return
    for i in range(0, len(s)):
        for c in alp:
            if ord(c)>ord(s[i])+1:
                break
            ns = s[:i+1]+c+s[i+1:]
            if ns in words:
                continue
            words.add(ns)
            dfs(n, ns)

def main():
    n = ri()
    if n == 1:
        print("a")
        return
    dfs(n, 'a')
    for w in sorted(words):
        if len(w) == n:
            print(w)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque

S = "abcdefghij"
N = int(input())
d = deque([("a", 1, 1)])
while(len(d)>0):
    tmp = d.pop()
    if tmp[1] < N:
        for i in range(tmp[2] + 1):
            tmp2 = (tmp[0] + S[i], tmp[1] + 1, max(tmp[2], i + 1))
            d.appendleft(tmp2)
    else:
        print(tmp[0])

Submission status: Accepted

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

#整数値龍力　複数の入力
n = int(input())

s_new = 'a'
kind_new = [1]
litter =["a","b","c","d","e","f","g","h","i","j"]


for i in range(n-1):
    s_old = s_new
    kind_old = kind_new
    s_new = []
    kind_new=[]
    for j in range(len(s_old)):
        for k in range(kind_old[j]+1):
            s_new.append(s_old[j]+litter[k])
            if k > kind_old[j]-1:
            	kind_new.append(kind_old[j]+1)
            else:
            	kind_new.append(kind_old[j])

for s in s_new:
	print(s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def normal_form(n, base='', e=1, l='abcdefghij'):
    if n == 1:
        for i in range(e):
            print(base + l[i])
        return
    
    for i in range(e-1):
        normal_form(n-1, base + l[i], e)
    normal_form(n-1, base + l[e-1], e+1)


n = int(input())
normal_form(n)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())
"""
def resolve():
    a,b,c=pin()
    from math import sqrt
    cond =(c-a-b)>sqrt(a*b)*2
    print(["No","Yes"][cond])
"""
def resolve():
    N,=pin()
    from collections import deque
    from collections import Counter
    ans=deque([["a",1]])
    L=1
    abc="abcdefghij"
    #("str",chars in str)のリスト？
    if N>1:
        for i in range(2,N+1):
            while(len(ans[0][0])<N):
                temp=ans.popleft() 
                string,types=temp
                for y in range(types+1):
                    temp2=string
                    temp2+=abc[y]
                    count=Counter(temp2)
                    
                    ans.append([temp2,len(count)])
                    
    for A in ans:
        print(A[0])
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
if __name__=="__main__":resolve()

Submission status: Accepted

Solution code:
N = int(input())
char = ["a","b","c","d","e","f","g","h","i","j"]
pre = [("",0)]
for i in range(N):
    nx = []
    for s,cnt in pre:
        for c in char[:cnt]:
            nx.append((s+c,cnt))
        c = char[cnt]
        nx.append((s+c,cnt+1))
    pre = nx

for s,_ in pre:
    print(s)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs,math
from decimal import *
getcontext().prec = 50
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

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

po = cl.deque([["",-1],["",0]])
co = 0
fl = False
while True:
    kkk = po.popleft()
    if kkk[1] == -1:
        if len(po) == 0:
            exit()
        co += 1
        if co == n:
            fl = True
        po.append(["",-1])
    else:
        if fl:
            for i in range(kkk[1]+1):
                print(kkk[0]+abc[i])
        else:
            for i in range(kkk[1]+1):
                if i == kkk[1]:
                    po.append([kkk[0]+abc[i],kkk[1]+1])
                else:
                    po.append([kkk[0]+abc[i],kkk[1]])

Submission status: Accepted

Solution code:
N = int(input())

answer = [(97, 'a')]
for _ in range(N - 1):
    new_answer = []
    for i, j in answer:
        for k in range(97, i + 2):
            new_answer.append((max(k, i), j + chr(k)))
    answer = new_answer[:]

answer = [j for _, j in answer]
answer.sort()
print('\n'.join(answer))

Submission status: Accepted

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())


def makeS(len, n, k, res):
    #print(len, n, k, res)
    ans = []
    if len == n:
        return [res]

    for i in range(k + 1):
        s = chr(97+i)
        if i == k:
            l = makeS(len, n + 1, k + 1, res + s)
        else:
            l = makeS(len, n + 1, k, res + s)

        ans += l

    return ans


ans = makeS(N, 0, 0, "")

print("\n".join(ans))

Submission status: Accepted

Solution code:
n=int(input())

def go(s):
   global n
   if len(s)==n:
       print(s)
       return
   l=max(s)
   for i in range(ord('a'),ord(l)+1):
       go(s+chr(i))
   if l < 'z':
       go(s + chr(ord(l) + 1))

go("a")

Submission status: Accepted

Solution code:
def dfs(n, i, s, maxi):
    global ans
    maxi = max(i, maxi)
    s += chr(i)
    if n == N:
        ans += [s]
        return
    for ii in range(97, maxi+2):
        dfs(n+1, ii, s, maxi)

N = int(input())
i = 97
ans = []
dfs(1, 97, '', 97)
ans = sorted(ans)
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N = int(input())

def rec(i, m, ar) :
  if i == N :
    print(''.join(chr(s + 97) for s in ar))
    return 
  for j in range(min(m + 1, N)) :
    rec(i + 1, max(m, j + 1), ar + [j])


rec(0, 0, [])

Submission status: Accepted

Solution code:
n=int(input())

def f(i, s, n):
	if i==n:
		print(s)
		return
	x=len(set(s))
	for j in range(x+1):
		f(i+1, s+chr(j+97), n)
		
f(0,"",n)

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
l = ["a","b","c","d","e","f","g","h","i","j","k"]
ansl = []
d = deque()
ans = "a"
d.append([ans,0])
while len(d):
    now,m = d.pop()
    #print(now)
    if len(now) == n:
        ansl.append(now)
    else:
        for i in range(m+2):
            if i == m+1:
                d.append([now+l[i],m+1])
            else:
                d.append([now+l[i],m])
ansl.sort()
for i in ansl:
    print(i)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(100000000)
MOD = 10**9+7
INF = 10 ** 9

def main():
    n = int(input())
    S = [[] for _ in range(n)]
    S[0] = ['a']
    
    dic = {i:j for i,j in zip(range(10),'abcdefghij')}
    for i in range(1,n):
        for st in S[i-1]:
            kind = 1
            while dic[kind] in st:
                kind += 1
            for j in range(kind+1):
                S[i].append(st+ dic[j])
    print(*S[-1],sep='\n')

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

ws = [['a']]
for level in range(1, n):
    ws.append([])
    for front_w in ws[level - 1]:
        max_c = max(front_w)
        ws[level] += ([front_w + chr(c) for c in range(ord('a'), ord(max_c) + 2)])

print('\n'.join(ws[-1]))

Submission status: Accepted

Solution code:
n=int(input())
li=["a"]
alpha=["a","b","c","d","e","f","g","h","i","j"]
if n==1:
    print("a")
    exit()
else:
    for i in range(n-1):
        ans=[]
        for j in range(len(li)):
            for k in range(len(set(li[j]))+1):
                ans.append(li[j]+alpha[k])
        li=ans
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
N = int(input())


def l(i):
    return chr(i + 96)


def f(i, L):
    if i == N + 1:
        print(''.join(list(map(l, L))))
        return
    for d in range(1, min(i + 1, len(set(L)) + 2)):
        f(i + 1, L + [d])


f(1, [])

Submission status: Accepted

Solution code:
n = int(input())
fac = [1]
for d in range(1,11):
  fac.append(fac[-1]*d)
#print(fac)
l = fac[n]
fac2 = []
for d in range(n):
  fac2.append(fac[n]//fac[d+1])
for i in range(l):
  tmp = []
  cum = []
  for d in range(n):
    j = i//(fac2[d])%(d+1)
    tmp.append(j)
    if not cum:
      cum = [0]
    else:
      if j > cum[-1] + 1:
        break
      cum.append(max(cum[-1],j))
  #print(tmp)
  #print(cum)
  #for d in range(1,n):
    #if cum[d] > cum[d-1] + 1:
      #break
  else:
    ans = ''
    for d in range(n):
      ans += chr(tmp[d]+97)
    print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()

    def f(s,v):
        if len(s) == N:
            print(s)
            return
        for i in range(v):
            f(s+chr(ord('a')+i),v)
        f(s+chr(ord('a')+v),v+1)
    f('a',1)



        


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations
alpha = "abcdefghijklmnopqrstu"
n = int(input())
ans = []
for i in range(1, n+1):
    c = combinations(range(1, n), i-1)
    for ci in c:
        for s in range(i**(n-i)):
            res = 'a'
            now = 1
            j = 0
            while now<=n-1:
                while j<i-1 and now == ci[j]:
                    res+=alpha[j+1]
                    j+=1
                    now+=1
                    if now>n-1:
                        break
                if now>n-1:
                        break
                t = s%i
                if t<=j:
                    res+=alpha[t]
                else:
                    break
                now+=1
                s//=i
            if len(res) == n:
                ans.append(res)          
ans.sort()
print(*ans, sep = '\n')

Submission status: Accepted

Solution code:
N = int(input())

alphabets = "abcdefghij"

def call( n, string, limit):
  """stringに対してn回後ろに付与するとしたらどうなるか、リストで頂戴。
  limitまでの文字しか使っちゃダメたよ"""
  if n ==0 :
    return set([string])
  
  res = set()
  for char in alphabets[:limit]:
    # print(string+char)
    res |= call(n-1, string+char, limit)
  res |= call(n-1, string+alphabets[limit], limit+1)
  return res
  
for i in sorted(list(call(N-1, "a", 1))):
  print(i)

Submission status: Accepted

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


def gen(path, maxOrd):
    if len(path) == N:
        print("".join(chr(ord("a") + x) for x in path))
    else:
        for x in range(maxOrd + 2):
            path.append(x)
            gen(path, max(maxOrd, x))
            path.pop()


gen([], -1)

Submission status: Accepted

Solution code:
N = int(input())

q = [(1, [0])]
for i in range(N - 1):
    old_q = q
    q = []
    for m, l in old_q:
        for apd in range(m):
            q.append((m, l + [apd]))
        q.append((m + 1, l + [m]))

ans = ["".join([chr(x + 97) for x in xx[1]]) for xx in q]
print(
    *ans,
    sep="""
"""
)

Submission status: Accepted

Solution code:
def next(S='a'):
    idx = len(S)
    cnt = len(set(list(S)))
    if idx == N:
        print(S)
        return
    for i in range(min(N,idx)+1):
        if cnt < i:
            break
        next(S +ls[i])


N = int(input())
ls = ['a','b','c','d','e','f','g','h','i','j']
next()

Submission status: Accepted

Solution code:
n = int(input())
moji = "abcdefghijklmnopqrstuvwxyz"
#print(len(moji))

lis = [[0]]
for i in range(n-1):
  temp = []
  for s in lis:
    next = max(s) + 1
    for j in range(0, next+1):
      temp.append(s + [j])
  else:
    lis = temp
#print(lis)

for s in lis:
  for char in s:
    print(moji[char], end="")
  print()

Submission status: Accepted

Solution code:
n=int(input())
s="abcdefghij"
ans=[["a",1]]
def solve():
	for x in ans:
		if len(x[0])<n:
			for j in range(x[1]+1):
				if j<=x[1]-1:
					ans.append([x[0]+s[j],x[1]])
				else:
					ans.append([x[0]+s[j],x[1]+1])
solve()
ans.sort()
for x in ans:
	if len(x[0])==n:
		print(x[0])

Submission status: Accepted

Solution code:
from string import ascii_lowercase as abc
from itertools import product
def inpl(): return list(map(int, input().split()))

N = int(input())
ans = []
searched = set()
trans = str.maketrans({k: v for k, v in zip(list("0123456789"), list(abc[:10]))})
for X in product(*[range(x) for x in range(1, N+1)]):
    checked = [-1]*10
    res = 0
    i = 0
    for x in X:
        res *= 10
        if checked[x] == -1:
            checked[x] = i
            i+= 1
        res += checked[x]
    if not res in searched:
        searched.add(res)
        ans.append(res)
    
for a in sorted(ans):
    print(str(a).zfill(N).translate(trans))

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


n = ii()
dp = []
dp.append((1,"a"))
for i in range(1,n):
    dpat = []
    tmp = i+1
    for j in range(len(dp)):
        for i in range(dp[j][0] + 1):
            if i == dp[j][0]:
                dpat.append((i+1,dp[j][1] + chr(97+i)))
            else:
                dpat.append((dp[j][0],dp[j][1] + chr(97+i)))
    dp = dpat
if n == 1:
    print("a")
else:
    for i in range(len(dp)):
        print(dp[i][1])

Submission status: Accepted

Solution code:
N = int(input())
# alpha = [chr(ord("a")+i) for i in range(10)]
ans = [[] for _ in range(11)]
ans[0].append("a")
for i in range(10):
    for e in ans[i]:
        idx = 0
        for c in e:
            idx = max(idx, ord(c)-ord('a'))
        for j in range(idx+2):
            ans[i+1].append(e+chr(ord("a")+j))
for i in range(len(ans[N-1])):
    print(ans[N-1][i])

Submission status: Accepted

Solution code:
#A
if False:
    A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K=int(input())
    print(A[K-1])

#B
if False:
    H,W=map(int,input().split())
    ans=0
    if H==1 or W==1:
        ans+=1
    else:
        ans+=(H//2)*W
        if H%2!=0:
            ans+=W//2
            ans+=W%2
    print(ans)

#C
if False:
    A,B,C=map(int,input().split())
    if 4*A*B<(C-A-B)**2:
        if C-A-B>=0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

#D
from collections import deque

N=int(input())
alp='abcdefghijkl'
q=deque()
q.append(['a',1])
ans=[]
while q:
    s,i=q.popleft()
    if len(s)==N:
        ans.append(s)
    else:
        for j in range(i+1):
            # print(j)
            tmp=[]
            tmp.append(s+alp[j])
            tmp.append(max(i,j+1))
            q.append(tmp)
            # print(tmp)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
ans = []
type = [[1]]
que = []
N = int(input())
for i in range(N-1):
    que = type
    type = []
    while len(que) != 0:
        t = que.pop()
        ma = max(t)
        for j in range(1,ma+2):
            type.append(t + [j])
type.sort()
char = " abcdefghijklmnopqrstuvwxyz"
for a in type:
    print("".join(map(lambda x: char[x], a)))

Submission status: Accepted

Solution code:
input = raw_input

alphas = "abcdefghijklmnopqrs"

n = int(input())

if n == 1:
    print("a")
elif n == 2:
    for out in ["aa", "ab"]:
        print(out)

elif n >= 3:
    former_prefixs = ["aa", "ab"]
    next_i = 3
    while True:
        cur_prefixs = []
        for prefix in former_prefixs:
            prefix_nc = len(set(prefix))
            for c in alphas[:prefix_nc+1]:
                out = prefix + c
                if next_i == n:
                    print(out)
                cur_prefixs.append(out)

        if next_i == n:
            break
        next_i += 1
        former_prefixs = cur_prefixs