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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    c = 'abcdefghij'
    a = [-1] * N
    a[0] = 0
    def f(a):
        for i in range(N):
            if a[i] == -1:
                break
        else:
            return [a[:]]
        b = max(a[:i])
        ans = []
        for j in range(b+2):
            a[i] = j
            ans.extend(f(a))
            a[i] = -1
        return ans

    for b in f(a):
        print(''.join([c[i] for i in b]))




def main():
    N = read_int()
    (slv(N))


if __name__ == '__main__':
    main()

Solution (Python):

def main():

    N = int(input())
    cur = [['a', set(['a'])]]
    for _ in range(N-1):
        temp = []
        for s, u in cur:
            for c in 'abcdefghij':
                 if c not in u:
                     temp.append([s + c, u | {c}])
                     break
                 else:
                    temp.append([s + c, u])
        cur = temp
    for s, _ in cur:
        print(s)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

ordA = ord('a')

N = int(input())

def dfs(i, sSt):
    if i == N:

        ans = ''.join([chr(ordA+S) for S in Ss])
        anss.append(ans)
    else:
        for s in range(0, sSt+2):
            Ss[i] = s
            dfs(i+1, max(s, sSt))

anss = []
Ss = [0] * N
dfs(1, 0)

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

Solution (Python):
N = int(input())

alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def norm(n, prev_list):
	out_list = []
	for line in prev_list:
		for i in range(len(set(line))+1):
			new_line = line + alphabet[i]
			out_list.append(new_line)
	return out_list

init_line = ['a']

for _ in range(N-1):
	init_line = norm(1, init_line)
for line in init_line:
	print(line)

Solution (Python):
n = int(input())
ans = [[['a']]] + [[] for _ in range(9)]
alp = ['a','b','c','d','e','f','g','h','i','j']
for i in range(n-1):
    for j in ans[i]:
        x = len(set(j))
        for k in range(x+1):
            ans[i+1].append(j+[alp[k]])
for i in ans[n-1]:
    print("".join(i))

Solution (Python):
n=int(input())
s=set()
s.add('a')
l='abcdefghijkl'
for i in range(n-1):
  s1=set()
  for t in s:
    for j in range(12):
      if l[j] in t:
        u=t+l[j]
        s1.add(u)
      else:
        u=t+l[j]
        s1.add(u)
        break
  s=s1
m=list(s)
m.sort()
for i in m:
  print(i)

Solution (Python):

N = int(input())
newL = [[0]]


for _ in range(N - 1):
    L = newL.copy()
    newL = []
    for s in L:
        for i in range(max(s) + 2):
            newL.append(s.copy() + [i])

    
di = {i: chr(ord('a') + i) for i in range(10)}
print('\n'.join([''.join(list(map(lambda x: di[x], newL[i]))) for i in range(len(newL))]))

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
q = deque()
q.append(['0',1])
qq = []
while q:
    a,b = q.popleft()
    if b >= n: 
        qq.append(a)
        continue
    ln = len(a)
    mx = 0
    for i in a:
        mx = max(mx, int(i))
    for i in range(mx+2):
        tmp = a + str(i)
        q.append([tmp,b+1])
qq.sort()
lr = len(qq)
for i in range(lr):
    a = qq[i]
    res = []
    for j in a:
        res.append(chr(ord('a') + int(j)))
    print(''.join(res))

Solution (Python):
from collections import deque
import copy
N = int(input())

q = deque()

a = ord("a")

q.append([0, 0])

while len(q) > 0:
    task = q.popleft()
    if len(task) == N + 1:
        for i in task[1:]:
            print(chr(a + i), end="")
        print()
    else:
        for i in range(task[0] + 1):
            newtask = copy.copy(task)
            newtask.append(i)
            q.append(newtask)
        newtask = copy.copy(task)
        newtask.append(task[0] + 1)
        newtask[0] = task[0] + 1
        q.append(newtask)

Solution (Python):
import copy as cp

alp  ="abcdefghij"

N = int(input())

list_old = [("a",1)]

if N == 1:
    print("a")
else:
    for i in range(N-1):
        list_new = []
        for elem in list_old:
            for j in range(elem[1]+1):
                list_new.append((elem[0]+alp[j],max(j+1, elem[1])))
        list_old = cp.deepcopy(list_new)
    for elem in list_old:
        print(elem[0])

Solution (Python):

from collections import Counter, deque







import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    chars = "abcdefghij"
    que = deque()
    que.append(("a",1))

    while que:
        s, num = que.popleft()

        if len(s) == n:
            print(s)
        else:
            for i in range(num+1):
                ss = s + chars[i]
                if i == num:
                    que.append((ss,num+1))
                else:
                    que.append((ss,num))

if __name__ == '__main__':
    main()

Solution (Python):
def examA():
    L = [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 = I()

    ans = L[K-1]
    print(ans)
    return

def examB():
    H, W = LI()
    if H==1 or W==1:
        print(1)
        return
    ans = H*W//2 + (H*W)%2
    print(ans)
    return

def examC():
    a,b,c = LI()
    if c-(a+b)<=0:
        print("No")
        return
    judge = (c-a-b)**2-4*a*b
    if judge>0:
        print("Yes")
    else:
        print("No")
    return

def examD():
    def bfs(N):
        W = [0]*(5*10**6)
        L = [""]*(5*10**6)
        que = deque()
        que.append(0)
        L[0] = "a"
        W[0] = 0
        flag = True
        ne = 0
        while(flag):
            now = que.popleft()
            nowW = W[now]
            if len(L[now])==N:
                flag = False
                break
            for i in range(W[now]+2):
                ne += 1
                W[ne] = max(nowW,i)
                que.append(ne)
                L[ne] = L[now] + alphabet[i]
        return L
    N = I()
    D = bfs(N)
    for ans in D:
        if not ans:
            break
        if len(ans)<N:
            continue
        print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examD()

"""

"""

Solution (Python):
n = int(input())

buf = [["a",97]]
a = 97

for i in range(n-1):
    next = []
    for b in buf:
        for j in range(97,b[1]+1):
            next.append([b[0]+chr(j),b[1]])
        next.append([b[0]+chr(b[1]+1),b[1]+1])
    buf = next

ans = [b[0] for b in buf]

ans.sort()




for a in ans:
    print(a)

Solution (Python):
from collections import deque

N = int(input())

d = deque()

d.append(([],0,-1))
dlen = 1
while dlen != 0:
    arr,le,ma = d.popleft()
    dlen -= 1
    if le == N:
        for a in arr:
            print('abcdefghij'[a],end='')
        print('')
        continue
    for i in range(ma+2):
        aarr = arr + [i]
        lle = le + 1
        mma = max(ma,i)
        d.append((aarr,lle,mma))
        dlen += 1

Solution (Python):
N = int(input())

def it(remain,n):
    if remain == 0:
        yield tuple()
    else:
        for x in range(n):
            for d in it(remain-1,n):
                yield (x,)+d
        for d in it(remain-1,n+1):
            yield (n,)+d


print(*(''.join(chr(x+ord('a')) for x in d) for d in it(N,0)), sep='\n')

Solution (Python):
N = int(input())
ans = []
char = ["a"]


def dfs(idx, c):
    if idx == N:
        ans.append("".join(char))
    else:
        for i in range(c+2):
            nc = chr(ord("a")+i)
            char.append(nc)
            dfs(idx+1, max(i, c))
            char.pop()

dfs(1, 0)
for i in range(len(ans)):
    print(ans[i])

Solution (Python):
def toString(s):
    return "".join([chr(x + ord('a')) for x in s])


def func(s, mx, N):
    if len(s) == N:
        print(toString(s))
        s.pop()
        return
    for i in range(mx+2):
        s.append(i)
        func(s, max(mx, i), N)
    s.pop()


def main():
    N = int(input())
    func([0], 0, N)


if __name__ == "__main__":
    main()

Solution (Python):
seq = []
res = []
def f(n, lim):
    if n == 0:
        res.append(''.join(chr(c+97) for c in seq))
        return
    for i in range(lim):
        seq.append(i)
        f(n-1, lim)
        seq.pop()
    seq.append(lim)
    f(n-1, lim+1)
    seq.pop()

f(int(input()), 0)
print('\n'.join(res))

Solution (Python):
N = int(input())

tmp = [[1]]
answer = tmp

for i in range(N - 1):
    tmp = []
    for a in answer:
        max_a = max(a)
        for j in range(1, max_a + 2):
            tmp.append(a + [j])
    answer = tmp

answer.sort()

def alpha(l):
    res = ""
    for ll in l:
        res += chr(ll + ord("a") - 1)
    return res

for a in answer:
    print(alpha(a))

Solution (Python):
import sys
range = xrange
input = raw_input

n = int(input())

ans = []

def generate(A, i = 0, j = 0):
    if j == n:
        if all(a!=n for a in A):
            return ans.append(list(A))
        return
    if i == n:
        if all(a!=n for a in A):
            return ans.append(list(A))
        i = 0
        while A[i] != n:
            i += 1
        A[i] = j + 1
        generate(A, i + 1, j + 1)
        A[i] = n
        return
    if A[i] == n:
        A[i] = j
        generate(A, i + 1, j)
        A[i] = n
    generate(A, i + 1, j)

A = [n]*n
A[0] = 0
generate(A, 1, 0)
orda = ord('a')
print '\n'.join(''.join(chr(a + orda) for a in A) for A in sorted(ans))

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


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

def nasu(x, n, e):
  if n == N:
    print(x)
    return
  for i in range(e + 1):
    if i == e:
      nasu(x + L[i], n + 1, e + 1)
    else:
      nasu(x + L[i], n + 1, e)

nasu("", 0, 0)

Solution (Python):
n=int(input())
ll=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

l=["a"]
for j in range(2,n+1):
    tmp=[]
    for s in l:
        m=len(set(list(s)))
        for i in ll[:m+1]:
            tmp.append(s+i)
    l=tmp

l.sort()
print('\n'.join(map(str,l)))

Solution (Python):
n = int(input())
c = 'abcdefghijk'
d = [[0]]
for i in range(n-1):
  pd,d = d,[]
  for j in pd:
    m = max(j)
    for k in range(m+2):
      d.append(j+[k])
for i in d:
  for j in i[:-1]:
    print(c[j],end='')
  print(c[i[-1]])

Solution (Python):
letter = ["a","b","c","d","e","f","g","h","i","j","k","l","m"]


class let():
    def __init__(self, a, b):
        self.s = a
        self.n = b

def add(s_list):
    ans = []
    for s in s_list:
        for i in range(s.n):
            ans.append(let(s.s + letter[i], s.n))
        ans.append(let(s.s + letter[s.n], s.n+1))
    
    return ans




N = int(input())


a_list = [let("a", 1)]

for i in range(N-1):
    a_list = add(a_list)

for i in a_list:
    print(i.s)

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp



class UnionFindEx:
    def __init__(self, size):
        
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main():
    N=ii()
    ABC = 'abcdefghij'
    def rec(s, cur_max, d):
        if d==0:
            print(s)
            return
        for i in range(cur_max+1+1):
            rec(s + ABC[i], max(cur_max, i), d-1)
    rec('a', 0, N-1)




main()

Solution (Python):
n = int(input())

ans_b = []
ans_n = ['a']

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

for i in range(1,n):
    ans_b = ans_n.copy()
    ans_n = []
    for j in ans_b:
        plus = 1
        ans_n.append(j+'a')
        while( j.count(s[plus-1]) > 0):
            ans_n.append(j+ s[plus])
            plus += 1

ans = sorted(ans_n)

for i in ans:
    print(i)

Solution (Python):
N = int(input())

l = ["a"]

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

while N-1:
  new_l = []
  for item in l:
    s = len(set(list(item)))
    for i in range(s+1):
      new_l.append(item+c[i])
      
  l = new_l
  N -= 1
  
for item in l:
  print(item)

Solution (Python):
def sol(k):

    def gen(d, cur, s):
        if d == k:
            yield s
            return
        for i in range(0, cur+1):
            yield from gen(d+1, max(cur, i+1), s+chr(97+i))

    return gen(0, 0, '')

def main():
    k = int(input())
    for x in sol(k):
        print(x)

if __name__ == '__main__':
    main()

Solution (Python):

import sys


def solve(N: int):
    res = []

    def rec(depth, charset, lst):
        if depth >= N:
            res.append("".join(lst))
            return

        valid_chars = [chr(ord("a") + i) for i in range(len(charset) + 1)]

        for c in valid_chars:
            rec(depth + 1, charset | set(c), lst + [c])

    rec(0, set(), [])
    print("\n".join(res))
    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))  
    solve(N)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

words = [chr(ord('a')+i) for i in range(10)]
dp = [('', 0)]
for i in range(1, N+1):
    ndp = []
    for w, c in dp:
        for k in range(c+1):
            ndp.append((w+words[k], c+1 if k == c else c))
    dp = ndp
for l in dp:
    print(l[0])

Solution (Python):
abc = "abcdefghijklmnopqrstuvwxyz"
n = int(input())

ans = []


def f(s="", x=1):
    global ans
    if len(s) == n:
        ans.append(s)
        return 0
    for i in range(x):
        f(s + abc[i], max(x, i+2))


f()
ans.sort()
for i in ans:
    print(i)

Solution (Python):
import copy

N=int(input())
ANS=[]
def next_s(L,x):
    
    if min(L)!=-1:
        ANS.append(L)
        return
    EMPTY=[]
    for i in range(N):
        if L[i]==-1:
            EMPTY.append(i)

    L[EMPTY[0]]=x

    LEN=len(EMPTY)-1
    for i in range(1<<LEN):
        S=copy.deepcopy(L)
        for j in range(LEN):
            if i & (1<<j)!=0:
                S[EMPTY[j+1]]=x

        

        next_s(S,x+1)

next_s([-1]*N,0)

ANS.sort()
for al in ANS:
    b=[chr(a+97) for a in al]
    print("".join(b))

Solution (Python):
n=int(input())
ans=[]
ap=ans.append
def f(s,t):
    if len(s)==n:
        ap(s)
        return
    else:
        for i in range(t):
            f(s+chr(97+i),t)
        else:
            f(s+chr(97+t),t+1)
f("a",1)
for i in ans:
    print(i)

Solution (Python):

N = int(input())
const = ord('a')

def sub_rekkyo(s, n):
  
  
  list_sub = [(s+chr(const+i), n) for i in range(n)]
  list_sub.append((s+chr(const+n), n+1))
  return list_sub

list_prev = [('',0)]

for i in range(N):
  list_next = []
  for s, n in list_prev:
    list_next += sub_rekkyo(s,n)
  list_prev = list_next.copy()

for s, n in list_prev:
  print(s)

Solution (Python):
n=int(input())
alp="abcdefghijklmno"

def saiki(now,st,used):
    num=now-1
    if num==0:
        print(st)
    else:
        for i in range(used+1):
            if i==len(range(used+1))-1:
                saiki(now-1,st+alp[i],used+1)
            else:
                saiki(now-1,st+alp[i],used)

saiki(n,"a",1)

Solution (Python):
import collections
n=int(input())
b=list("abcdefghij")


def func(l, a):
    if n == a:
        for ans in l:
            print(ans)
        return
    newl=[]
    for tmp in l:
        c=collections.Counter(list(tmp))
        for i in range(len(c)+1):
            newl.append(tmp + b[i])
    func(newl, a+1)

func(['a'], 1)

Solution (Python):
from collections import deque


def solve(n):
    if n == 1:
        return ["a"]
    alphabet = "abcdefghijkl"
    res_list = []
    queue = deque([("a", 0)])
    while len(queue) > 0:
        p, k = queue.popleft()
        for i in range(k + 2):
            q = p + alphabet[i]
            queue.append((q, max(i, k)))
            if len(q) == n:
                res_list.append(q)
        if len(q) > n:
            break
    return res_list


def main():
    n = int(input())
    res = solve(n)
    for r in res:
        print(r)


def test():
    assert solve(1) == ["a"]
    assert solve(2) == ["aa", "ab"]


if __name__ == "__main__":
    test()
    main()

Solution (Python):
n=int(input())
s=[["a",1]]
d=[chr(ord("a")+i)for i in range(10)]
for i in range(n-1):
    t=[]
    for j in s:
        for h in range(j[1]):
            t.append([j[0]+d[h],j[1]])
        t.append([j[0]+d[h+1],j[1]+1])
    s=t.copy()
for i in sorted(s):
    print(i[0])

Solution (Python):
def news(moji, kaz):
    kazz=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l']
    kotae=[]
    for i in range(kaz):
        kotae.append([moji+kazz[i], kaz])
    kotae.append([moji+kazz[kaz], kaz+1])
    return kotae

n=int(input())
now=[['a', 1]]
for i in range(n-1):
    new=[]
    for nw in now:
        new+=news(nw[0], nw[1])
    now=new
lenw=len(now)
for i in range(lenw):
    print(now[i][0])

Solution (Python):
n=int(input())
x=["a"]
d="abcdefghij"
i=1
while i<n:
	y=[]
	for t in x:
		for s in d[:len(set(t))+1]:
			y.append(t+s)
	x=y
	i+=1
print("\n".join(x))

Solution (Python):
import string

N = int(input())


def solve(n):
    if n == 1:
        return [[0]]
    result = []
    for v in solve(n - 1):
        x = max(v)
        for i in range(x + 2):
            result.append(list(v) + [i])
    return result


def print_strig(result):
    for r in result:
        print("".join(list(map(lambda v: string.ascii_lowercase[v], r))))


print_strig(solve(N))

Solution (Python):
N=int(input())
abc="abcdefghijklmn"

def saiki(s,m):
  if len(s)==N:
    print(s)
  else:
    for i in range(m+2):
      if i<m+1:
        saiki(s+abc[i],m)
      else:
        saiki(s+abc[i],m+1)
    
saiki("a",0)

Solution (Python):
N = int(input())

ans = []
def dp(arg, level):
    global N
    if len(arg) == N:
        ans.append(arg)
        return
    
    orda = ord('a')
    for i in range(level):
        dp(arg + chr(orda + i), level)
    dp(arg + chr(orda + level), level + 1)
    return

dp('', 0)
for ansi in ans:
    print(ansi)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
Alp = [chr(i) for i in range(97, 97+26)]

ans = []
def dfs(d, maxi, T):
    if d == N-1:
        ans.append(T)
        return
    for i in range(maxi+2):
        dfs(d+1, max(maxi, i), T + Alp[i])

dfs(0, 0, "a")
print(*ans, sep='\n')

Solution (Python):
import sys
readline = sys.stdin.readline

res = []
def fill(K, f):
    if K.count(-1) == 0:
        res.append(K)
        return 
    else:
        idx = []
        for i in range(N):
            if K[i] == -1:
                idx.append(i)
        kc = len(idx)
        for S in range(1, 1<<kc):
            if not S & 1:
                continue
            K2 = K[:]
            for j in range(kc):
                if S & (1<<j):
                    K2[idx[j]] = f
            fill(K2, f+1)
            
            
N = int(readline())
fill([-1]*N, 0)
res.sort()
res = [''.join(map(lambda x: chr(x+97), r)) for r in res]
print('\n'.join(res))

Solution (Python):
def main():
    N = int(input())
    S = 'abcdefghij'
    cur = set([(0, '')])
    for i in range(N):
        nxt = set()
        for c, s in cur:
            for m in S[:c]:
                nxt.add((c, s + m))
            nxt.add((c + 1, s + S[c]))
        cur = nxt
    cur = sorted(i[1] for i in cur)
    print('\n'.join(cur))

main()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations,product
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    res = [[[0],0]]
    for i in range(n-1):
        res = [[x+[i],max(i,y)] for (x,y) in res for i in range(y+2)]
    for j,k in res:
        for i in j:
            print(chr(i+ord("a")),end = "")
        print()
    return


if __name__ == "__main__":
    solve()

Solution (Python):
N=int(input())

tmp = [[[0],0]]
for _ in [0]*(N-1):
    tmp2 = []
    for s,m in tmp:
        for c in range(m+1):
            tmp2.append([s+[c],m])
        tmp2.append([s+[m+1],m+1])
    tmp = tmp2
for ans in tmp:
    s = "".join(["abcdefghij"[i] for i in ans[0]])
    print(s)

Solution (Python):
n = int(input())
import string
A = [chr(i) for i in range(ord("a"),ord("a")+10)]
B = {}
for i in range(10):
    B[A[i]] = i

def d(s,t,ANS):
    if len(s) == n:
        ANS.append(s)
    else:
        for i in range(t+2):
            d(s + A[i],max(i,t),ANS)
ANS = []

d("",-1,ANS)

ANS.sort()
for i in ANS:
    print(i)

Solution (Python):
N = int(input())
pool = [('a',0)]
ord_a = ord('a')
while pool:
    li, m = pool.pop()
    if len(li) == N:
        print(li)
    else:
        pool.append((li+chr(ord_a+m+1),m+1))
        for i in range(m,-1,-1):
            pool.append((li+chr(ord_a+i),m))

Solution (Python):
from collections import deque
N=int(input())
if N==1:
    print("a")
    exit()
X=[chr(i+97) for i in range(N)]

Y=[]
q=deque(["a"])
while(len(q)>0):
    r=q.pop()
    k=len(set(r))
    for i in range(k+1):
        p=r+X[i]
        if len(p)==N:
            Y.append(p)
        else:
            q.append(p)
Y.sort()
for line in Y:
    print(line)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def dfs(mx=0,s=[0]):
        if len(s)==n:
            ans.append(s)
            return
        for i in range(mx+2):
            dfs(max(mx,i),s+[i])

    n=II()
    ans=[]
    dfs()
    for ak in ans:
        print("".join(chr(a+97) for a in ak))

main()

Solution (Python):
n = int(input())
abc = 'abcdefghijklmnopqrstuvwxyz'
def sub(l, i):
    if len(l) >= n:
        print(l)
        return
    for k in range(i):
        sub(l + abc[k], i)
    sub(l + abc[i], i + 1)

sub('', 0)

Solution (Python):
import string
lower = string.ascii_lowercase

n = int(input())





ans = ['']

for i in range(n):
    new_list = []
    for word in ans:
        for new_char in lower:
            if new_char in word:
                new_list.append(word + new_char)
            else:
                new_list.append(word + new_char)
                break
    ans = new_list


for word in ans:
    print(word)

Solution (Python):
n=int(input())
def dsf(s,k):
    if len(s)==n:
        print(s)
    else:
        for i in range(k):
            dsf(s+chr(i+97),k)
        dsf(s+chr(k+97),k+1)
dsf("",0)

Solution (Python):
n=int(input())
l=[["a"],["aa","ab"],[],[],[],[],[],[],[],[]]
for i in range(2,10):
  for j in l[i-1]:
    syurui=len(set(list(j)))
    for h in range(syurui+1):
      l[i].append(j+chr(97+h))
for i in l[n-1]:print(i)

Solution (Python):
s = 'abcdefghij'
sg = s.__getitem__


def dfs(ans):
    if len(ans) == n:
        print(''.join(map(sg, ans)))
        return
    for i in range(max(ans) + 2):
        ans.append(i)
        dfs(ans)
        ans.pop()


n = int(input())
dfs([0])

Solution (Python):
def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    N = int(input())
    q = deque()
    q.append([0])

    for i in range(N):
        q_new = deque()
        while q:
            A = q.popleft()
            for j in range(1, max(A) + 2):
                A_new = A[:]
                A_new.append(j)
                q_new.append(A_new)
        q = q_new
    while q:
        A = q.popleft()
        ans = [chr(a+96) for a in A[1:]]
        print(''.join(ans))


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

def dfs(s, n):
    if len(s) == N:
        return [s]
    ret = []
    for i in range(n):
        ret += dfs(s + chr(i + ord('a')), n)
    ret += dfs(s + chr(n + ord('a')), n+1)
    return ret

for w in dfs('', 0):
    print(w)

Solution (Python):
from copy import deepcopy
def main():
    N = int( input())
    if N == 1:
        print('a')
        return
    ANS = [(1, 'a')]
    a = ord('a')
    for i in range(N-1):
        G = deepcopy(ANS)
        ANS = []
        for c, t in G:
            for j in range(c):
                ANS.append((c,t+chr(a+j)))
            ANS.append((c+1, t+chr(a+c)))
    ANS = [ t[1] for t in ANS]
    print('\n'.join(ANS))
if __name__ == '__main__':
    main()

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read




n = int(input())
c = [chr(ord("a")+i) for i in range(20)]

ans = []
def dfs(x,i,v):
    if v==n:
        ans.append(x)
        return
    
    for j in range(i+1):
        dfs(x+c[j],i,v+1)
    dfs(x+c[i+1],i+1,v+1)


dfs("",-1,0)

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

Solution (Python):
N=int(input())

begins=['a']
while(len(begins[0])<N):
    _begins=[]
    for b in begins:
        n=len(set(b))
        for i in range(n+1):
            _begins.append(b+chr(ord('a')+i))
    begins=_begins

for b in sorted(begins):
    print(b)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    n = II()
    def dfs(s):
        if len(s) == n:
            print(s)
            return
        for i in range(len(set(list(s))) + 1):
            dfs(s + chr(ord("a") + i))
    dfs("")
    return



if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
def calc(n, L, ma):
    if n == 0: 
        print("".join([chr(a+97) for a in L]))
        return L
    for i in range(ma+2):
        l = calc(n-1, L + [i], max(ma, i))

calc(N, [], -1)