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):
n = int(input())

def test(s, mx):
    if len(s) == n:
        print(s)
    else:
        for c in range(ord('a'), mx+1): 
            if c == mx:
                test(s+chr(c), mx+1)
            else:
                test(s+chr(c), mx)
test('',ord('a'))

Solution (Python):
n = int(input())
s = 'abcdefghij'


def dfs(ans, ref):
    if len(ans) == n:
        print(ans)
    else:
        l = [s[i] for i in range(ref + 1)]
        for x in l:
            if x == l[ref]:
                dfs(ans + x, ref + 1)
            else:
                dfs(ans + x, ref)


dfs('', 0)

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


def next_chr(ch):
    res = []
    g = ord(ch) - ord("a") + 2
    for i in range(g):
        res.append(chr(ord("a")+i))
    return res


def answer(s, i):
    if i == N:
        ch = next_chr(max(s))
        for m in ch:
            ans.append("".join([s, m]))
    else:
        i += 1
        ch = next_chr(max(s))
        for m in ch:
            answer("".join([s, m]), i)


if N == 1:
    print("a")
else:
    answer("a", 2)
    ans = sorted(ans)
    for c in ans:
        print(c)

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

s = {'a'}

def solve(n):
    global s
    if n == N:
        return
    new_s = set()
    for v in s:
        xc = chr(ord(max(v))+1)
        for vc in v:
            new_s.add(v + vc)
            new_s.add(v + xc)
    s = new_s
    solve(n+1)

solve(1)
ans = sorted(s)
print(*ans, sep='\n')

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

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

def dfs(res, i):
    if len(res) >= n:
        print(res)
        return
    for k in range(i):
        dfs(res+l[k], i)
    dfs(res+l[i], i+1)

dfs("", 0)

Solution (Python):
def rec(S,depth):
    if depth == 0:
        print(S)
        return
    else:
        list_mozi=list(dict.fromkeys(list(S)))
        list_mozi.sort()
        for j in range(len(list_mozi)):
            rec(S+list_mozi[j],depth-1)
        rec(S+chr(ord(list_mozi[len(list_mozi)-1])+1),depth-1)

N=int(input())
rec("a",N-1)

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

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

def dfs(s, i):
    if len(s) == N:
        return [s]
    result = []
    for j in range(i+1):
        if j == i:
            result += dfs(s+S[j], i+1)
        else:
            result += dfs(s+S[j], i)
    return result
print("\n".join(dfs("", 0)))

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

n = int(readline())

alphabets = [chr(ord('a') + x) for x in range(26)]

def dfs(s,i):
    if len(s)==n:
        print("".join(s))
    else:
        t = min(len(set(s))+1,len(s)+1)
        for i in range(t):
            dfs(s+[alphabets[i]],i)

dfs([],0)

Solution (Python):
n = int(input())
tb = 'abcdefghijklmnopqrstuvwxyz'

def output(s, m):
    if len(s) == n:
        print(s)
    else:
        for i in range(m + 1):
            if i == m:
                output(s + tb[i], m + 1)
            else:
                output(s + tb[i], m)
output("", 0)

Solution (Python):

import sys


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

def solve(N: int):
    dfs("", 0, N)

def dfs(s: str, mx: int, N: int):
    if len(s) == N:
        print(s) 
    else:
        for i in range(mx + 1):
            dfs(s + ALH[i], mx + 1 if i == mx else mx, N)
































    
    
    
    




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

def dfs(s, mx):
    if len(s) == n:
        print(s)
    else:
        for c in [chr(ord('a') + i) for i in range(ord(mx) - ord('a') + 1)]:
            dfs(s + c, chr(ord(mx) + 1) if c == mx else mx)

dfs('', 'a')

Solution (Python):
n = int(input())
abc = [chr(i) for i in range(97, 97 + n)]
def dfs(s, idx):
    if len(s) == n:
        print(s)
    else:
        for i in range(idx + 1):
            if idx == i:
                dfs(s + abc[i], idx + 1)
            else:
                dfs(s + abc[i], idx)
dfs("", 0)

Solution (Python):
from string import ascii_lowercase
from functools import lru_cache
n = int(input())

@lru_cache(maxsize=10)
def make(n):
    if n == 1:
        return ['a']
    else:
        lst = []
        for s in make(n-1):
            for c in ascii_lowercase[:len(set(s))+1]:
                lst.append(s + c)
        return lst
for s in make(n):
    print(*s, sep='')

Solution (Python):
n = int(input())
l = "abcdefghij"
def dfs(res, i):
    if len(res) >= n:
        print(res)
        return
    for k in range(i):
        dfs(res+l[k], i)
    dfs(res+l[i], i+1)
dfs("", 0)

Solution (Python):
n = int(input())
a = ord('a')

def f(x: str) -> str:
  return chr(int(x) + a)

i = 0
while i < 10 ** (n-1):
  x = str(i).zfill(n)
  maximum = 0
  flag = True
  for j, digit in enumerate(map(int, x)):
    if digit > maximum + 1:
      flag = False
      break
    elif digit == maximum + 1:
      maximum = digit
  if flag:
    print(''.join(map(f, x)))
    i += 1
  else:
    d = 10 ** (n - j)
    i = (i // d + 1) * d

Solution (Python):
n = int(input())
ans = ["a"]
for i in range(n-1):
    nans = []
    
    for s in ans:
        m = max(s)
        for x in range(ord(m)-95):
            nans.append(s+ chr(97+x))
            
    ans = nans
print("\n".join(ans))

Solution (Python):
n = int(input())
l = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
def dfs(res, i):
    if len(res) >= n:
        print(res)
        return
    for k in range(i):
        dfs(res+l[k], i)
    dfs(res+l[i], i+1)
dfs("", 0)

Solution (Python):
def dfs(now, mx):
    if len(now) == n:
        print(now)
    else:
        for i in range(1, mx + 2):
            mmx = max(mx, i)

            dfs(now + al[i], mmx)


n = int(input())

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

dfs('a', 1)

Solution (Python):
import itertools
def solve():
    N = int(input())
    alphabets = ['a','b','c','d','e','f','g','h','i','j']
    lst = []
    dfs(1, N, alphabets[:N],lst, "", 0)

def dfs(depth, N, alphabets, lst, now, mx):
    if depth > N:
        lst.append(now)
        print(now)
        return
    for i in range(0,mx+1):
        next_mx = mx
        if i == mx:
            next_mx += 1
        dfs(depth+1, N, alphabets, lst, now + alphabets[i], next_mx)

if __name__ == '__main__':
    solve()

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False



def f(s, k, N):
    if len(s) == N:
        print(s)
        return

    for i in range(k+1):
        f(s + l_alp[i], max(k, i+1), N)


def main():
    N = I()
    ans = []

    f('a', 1, N)

    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
l=[["a"]]+[[] for i in range(9)]
for i in range(9):
  for j in l[i]:
    k=len(set(list(j)))
    for h in range(k+1):
      l[i+1].append(j+chr(97+h))
for i in l[n-1]:print(i)

Solution (Python):
k = int(input())
anss = [["a"]]

for i in range(k-1):
  anss.append([])
  for j in anss[i]:
    for l in range(len(set(list(j)))+1):
      anss[i+1].append(str(j)+chr(97+l))
anss[k-1].sort()
for i in anss[k-1]:
  print(i)

Solution (Python):
import sys

N = int(sys.stdin.readline().strip())

def dfs(s, n):
	if len(s) == N:
		print(s)
	else:
		for i in range(n+1):
			dfs(s + chr(97+i), n+1 if i == n else n)

dfs("", 0)

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


def dfs(s, mx):
    if len(s) == N:
        print(s)
    else:
        for c in range(ord('a'), mx+1):
            dfs(s+chr(c), mx + 1 if c == mx else mx)

dfs("", ord('a'))

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


N = int(input())
ans = set()
a = ord('a')


def f(c, A, done):
    global N, a
    B = list(A)
    done = set(done)
    for i in range(N):
        if i not in done:
            B[i] = c
            done.add(i)
            break
    if len(done) == N:
        ans.add(''.join(B))
    else:
        for i in range(2 ** (N - len(done)) - 1, -1, -1):
            k = i
            C = B[:]
            tDone = set(x for x in range(N))
            nDone = set(x for x in done)
            for t in done:
                tDone.remove(t)
            while k > 0:
                y = min(tDone)
                if k & 1 == 1:
                    C[y] = c
                    nDone.add(y)
                tDone.remove(y)
                k >>= 1
            f(chr(ord(c) + 1), tuple(C), tuple(nDone))


A = [0] * N
f('a', tuple(A), ())
ans = list(ans)
ans.sort()
print(*ans, sep='\n')

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

def dfs(s, mx):
  if len(s) == n:
    print(s)
  else:
    for i in range(mx):
      dfs(s+chr(ord("a")+i), mx)
    dfs(s+chr(ord("a")+mx), mx+1)
    
dfs("a", 1)

Solution (Python):
n = int(input())
r = 'a',
for _ in range(n - 1):
  r = [s + c for s in r for c in set(s) | {chr(ord(max(s)) + 1)}]
print(*sorted(r), sep='\n')

Solution (Python):
import string
al = string.ascii_lowercase
N = int(input())

def dfs(s, mx):
    if len(s) == N:
        print(s)
    else:
        for i in range(mx):
            c = al[i]
            if c == al[mx-1]:
                dfs(s+c, mx+1)
            else:
                dfs(s + c, mx)

dfs('', 1)

Solution (Python):

n = int(input())

def dfs(s, kinds):
    if len(s) == n:
        print(s) 
    else:
        for i in range(kinds+1):
            new_kinds = kinds + (1 if i == kinds else 0)
            dfs(s + chr(ord('a') + i), new_kinds)

dfs('', 0)

Solution (Python):

import sys
from itertools import combinations

def solve(N: int):   
    d = {n:[] for n in range(1, N+1)} 
    d[1] = [[1]]

    for n in range(1, N):
        
        for lst in d[n]:
            last_element = lst[-1]

            for new_element in range(1, max(lst)+2):
                d[n+1].append(lst+[new_element])

    ans_lst = d[N]

    for i, lst in enumerate(ans_lst):
        ans_lst[i] = ''.join([chr(num+96) for num in lst])

    for lst in ans_lst:
        print(lst)
    
    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):
from sys import stdin
import copy

letters = [chr(i) for i in range(97, 97+26)]

ans_list = []

def main():

    input = stdin.readline

    N = int(input())   

    dp('a',N)

    for i in ans_list:
        print(i)
    
def dp(ans,N):

    for i in range(ord('a'),ord('a')+len(list(set(ans)))+1):
        if len(ans) == N:
            ans_list.append(ans)
            return
        else:
            dp(ans + chr(i),N)


if __name__ == "__main__":
    main()

Solution (Python):
from copy import deepcopy
def f(num,N,S):
    alphabet = ["a","b","c","d","e","f","g","h","i","j"]
    if N == num:
        for i in range(len(S)):
            print(S[i])
        return
    else:
        tmp = []
        length = len(S)
        for i in range(length):
            ttmp = sorted(list(S[i]))
            for j in range(alphabet.index(ttmp[-1])+2):
                tmp.append(S[i]+alphabet[j])
        S = sorted(tmp)
        f(num+1,N,S)

N = int(input())
f(1,N,["a"])

Solution (Python):
def DFS(word,n):
    if len(word)==N:
        return print(word)
    else:
        for i in range(n+1):
            DFS(word+chr(97+i),n+1 if i==n else n)


N=int(input())
DFS("",0)

Solution (Python):
def DFS(word,n):
    if len(word)==N:
        return print(word)
    else:
        for i in range(n+1):
            DFS(word+chr(97+i),n+1 if i==n else n)


N=int(input())
DFS("",0)

Solution (Python):
n = int(input())
alpha_dict = {}
for i,c in enumerate(range(ord('A'),ord('Z')+1)):
  alpha_dict[i] = str(chr(c)).lower()


ans = []
def dfs(s, mx, ans):
  if len(s) == n:
    ans += [s]
    return 
  else:
    for i in range(mx+1):
      dfs(s+alpha_dict[i], max(i+1, mx), ans)

dfs("", 0, ans)
ans = sorted(ans)
for a in ans:
  print(a)

Solution (Python):



def solve(*args: str) -> str:
    n = int(args[0])

    ret = []
    stack = [('', ord('a'))]
    while stack:
        s, c = stack.pop()
        if len(s) == n:
            ret.append(s)
        else:
            for x in range(ord('a'), c+1):
                stack.append((s+chr(x), c+1 if c == x else c))

    return '\n'.join(sorted(ret))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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

N = int(input())

def bfs(s, cnt, m):
	if cnt == N:
		print(s)
		return

	for i in range(97,ord(m)+2):
		if chr(i) > m:
			bfs(s+chr(i), cnt+1, chr(i))
		else:
			bfs(s+chr(i), cnt+1, m)

bfs('a',1,'a')

Solution (Python):


alphabets = list('abcdefghijklmnopqrstuvwxyz')

N = int(input())

if N == 1:
    print('a')
else:
    tmp = ['a']
    for i in range(1, N):
        result = []
        for s in tmp:
            alpha_list = sorted(list(set(list(s))))
            for a in alpha_list:
                result.append(s+a)
            result.append(s+alphabets[len(set(list(s)))])
            tmp = result
    print('\n'.join(result))

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


def dfs(s, mx):
    if len(s) == n:
        print(''.join([chr(ord('a') + i) for i in s]))
    else:
        for i in range(mx+1):
            dfs(s + [i], mx if i != mx else mx + 1)


dfs([], 0)

Solution (Python):
def DFS(word,n):
    if len(word)==N:
        return print(word)
    else:
        for i in range(n+1):
            DFS(word+chr(97+i),n+1 if i==n else n)


N=int(input())
DFS("",0)

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

def dfs(s, mx):
    if len(s) == N:
        print(s)
        return
    for c in 'abcdefghij'[:(ord(mx)-ord('a'))+1]:
        dfs(s+c, chr(ord(mx)+1)) if c == mx else dfs(s+c, mx)

dfs('', 'a')

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

A = [L[0]]
B = [A[0]+L[i] for i in range(2)]
C = [i+L[j] for i in B for j in range(len(set(i))+1)]
D = [i+L[j] for i in C for j in range(len(set(i))+1)]
E = [i+L[j] for i in D for j in range(len(set(i))+1)]
F = [i+L[j] for i in E for j in range(len(set(i))+1)]
G = [i+L[j] for i in F for j in range(len(set(i))+1)]
H = [i+L[j] for i in G for j in range(len(set(i))+1)]
I = [i+L[j] for i in H for j in range(len(set(i))+1)]
J = [i+L[j] for i in I for j in range(len(set(i))+1)]

Z = [A,B,C,D,E,F,G,H,I,J]

for i in Z[N-1]:
    print(i)

Solution (Python):
k = "a",
for _ in range(int(input()) - 1):
  k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)}
print(*sorted(k), sep='\n')

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

def f(s):
    if len(s) == N:
        print(s)
        return
    for i in range(97, ord(max(list(s)))+1+1):
        ns = s + chr(i)
        f(ns)

f('a')

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

N = int(input())
d = 'abcdefghij'
x = ['a']
cnt = 1

while cnt<N:
    y = []
    for i in x:
        for j in d[:len(set(i))+1]:
            y.append(i+j)
    x = y
    cnt += 1
print('\n'.join(x))

Solution (Python):
def recursion(s, mx, n):
    if len(s) == n:
        print(s)
        return
 
    c = 'a'
    while c <= mx:
        nmx = mx
        if c == mx:
            nmx = chr(ord(c) + 1)
        recursion(s + c, nmx, n)
        c = chr(ord(c) + 1)


n = int(input())
recursion("", 'a', n)

Solution (Python):
n = int(input())
alpha_dict = {}
for i,c in enumerate(range(ord('A'),ord('Z')+1)):
  alpha_dict[i] = str(chr(c)).lower()


ans = []
def dfs(s, mx, ans):
  if len(s) == n:
    ans += [s]
    return 
  else:
    for i in range(mx+2):
      dfs(s+alpha_dict[i], max(i, mx), ans)

dfs("", -1, ans)
ans = sorted(ans)
for a in ans:
  print(a)

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

def dfs(s, mx):
  global N
  if len(s) == N:
    print(s)
  else:
    for i in range(ord(mx) - ord('a') + 1):
      dfs(s + chr(ord('a') + i), chr(ord(mx) + 1) if chr(ord('a') + i) == mx else mx)

dfs('', 'a')

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

arr=[1]*N

s = ['' for i in range(N)]

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

def num2alpha(num):
    return chr(num+97)

def dfs(k,c):
    if(k==N):
        print("".join(s))
        return
    for i in range(c):
        s[k]=num2alpha(i)
        dfs(k+1,c)
    s[k]=num2alpha(c)
    dfs(k+1,c+1)

dfs(0,0)

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


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


f('a', 0)

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    s = 'abcdefghijkl'
    ans = []

    def f(t: str):
        if len(t) == N:
            ans.append(t)
            return
        
        if len(t) >= 2:
            x = s.index(max(list(t)))+2
        else:
            x = len(t)+1
        for i in range(x):
            f(t+s[i])


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


    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())
r = 'a',
for _ in range(n - 1):
  r = [s + c for s in r for c in set(s + chr(ord(max(s)) + 1))]
print(*sorted(r), sep='\n')

Solution (Python):
def DFS(word,n):
    if len(word)==N:print(word)
    else:
        for i in range(n+1):
            DFS(word+chr(97+i),n+1 if i==n else n)


N=int(input())
DFS("",0)

Solution (Python):
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 max(w_init[j]) == l[k]:
        for m in range(k + 2):
          w.append(w_init[j] + l[m])

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

Solution (Python):
d = ['a','b','c','d','e','f','g','h','i','j']

n = int(input())

result = []

def fig(s, mx):
    if len(s) == n:
        result.append(s)
        return
    
    for i in range(mx+1):
        if i == mx:
            mx += 1
        fig(s + d[i], mx)

fig('', 0)
result.sort()

for r in result:
    print(''.join(r))

Solution (Python):
from itertools import groupby

n = int(input())
r = 'a',
for _ in range(n - 1):
  r = [s + c for s in r for c, _ in groupby(sorted(s) + [chr(ord(max(s)) + 1)])]
print(*r, sep='\n')

Solution (Python):
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 dfs(s, mx):
	if len(s) == N:
		ans.append(s)
		return
	for i in range(mx+1):
		if i == mx:
			dfs(s+ascii_lowercase[i], mx+1)
		else:
			dfs(s+ascii_lowercase[i], mx)

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

Solution (Python):
N = int(input())
s = 'a'
def dfs(s,mx):
    if len(s) == N:
        print(s)
        return
    for diff in range(ord(mx)-ord('a')+2):
        nc = chr(ord('a')+diff)
        
        
        nmx = max(nc,mx)
        dfs(s+nc,nmx)
dfs('a','a')

Solution (Python):
alphabet = "abcdefghijklmnopqrstuvwxyz"
alphabet_i = {v:i for i,v in enumerate("abcdefghijklmnopqrstuvwxyz")}
N = int(input())
ans = []

memo = {}

def dfs(tmp,i):
    if i == N:
        ans.append(tmp)
        return

    maxi = max([alphabet_i[c] for c in tmp])
    for c in alphabet[:maxi+2]:
        dfs(tmp+c, i+1)

dfs("a", 1)
for s in ans:
    print(s)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
def main():
    N = int(input())
    s = ''
    l = []
    def calc3(s, N, i):
        if len(s) == N:
            l.append(s)
            return
        if len(s) > 0:
            s2 = s[:]
            z = i + 2
            for j in range(z):
                st = s[:]
                st += chr(ord('a')+j)
                if j == i + 1:
                    calc3(st[:], N, i+1)
                else:
                    calc3(st[:], N, i)
        else:
            s += 'a'
            calc3(s[:], N, i)
    calc3(s[:], N, 0)
    l = sorted(set(l))
    for i in l:
        print(i)
main()

Solution (Python):




import sys
input = sys.stdin.readline



def dfs(s,mx,N):
    if len(s) == N:
        print(s)
    else:
        alpha = 'abcdefghijk'
        for c in range(mx+1):
            if c == mx:
                mx += 1
            dfs(s+alpha[c],mx,N)


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

    dfs('',0,N)



main()

Solution (Python):
import itertools
import sys

n = int(input())
S = [0]*n
while True:
    print("".join(map(lambda x:chr(ord('a')+x),S)))
    for i in range(n-1,0,-1):
        if(i>0 and max(S[:i])>=S[i]):
            S[i] += 1
            for j in range(i+1,n):
                S[j] = 0
            break
    else:
        break

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
def main():
    N = int(input())
    s = ''
    l = []
    def calc3(s, N, i):
        if len(s) == N:
            l.append(s)
            return
        if len(s) > 0:
            s2 = s[:]
            z = i + 2
            for j in range(z):
                st = s[:]
                st += chr(ord('a')+j)
                if j == i + 1:
                    calc3(st[:], N, i+1)
                else:
                    calc3(st[:], N, i)
        else:
            s += 'a'
            calc3(s[:], N, i)
    calc3(s[:], N, 0)
    l = sorted(set(l))
    for i in l:
        print(i)
main()

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

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

    for x in range(max(li)+2):
        li2 = copy.copy(li)
        li2.append(x)
        nex(li2)
        
nex([0])

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    s = 'abcdefghijkl'
    ans = []
    from heapq import heapify, heappop, heappush

    def f(t: str):
        if len(t) == N:
            
            ans.append(t)
            return
        
        if len(t) >= 2:
            x = s.index(max(list(t)))+2
        else:
            x = len(t)+1
        for i in range(x):
            f(t+s[i])


    
    f('')
    
    c = 0
    
    
    
    
    ans.sort()
    for i in ans:
        print(i)


    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):
import sys
sys.setrecursionlimit(10**9)

N = int(input())

def bfs(s, cnt, m):
	if cnt == N:
		print(s)
		return

	for i in range(97,ord(m)+2):
		if chr(i) > m:
			bfs(s+chr(i), cnt+1, chr(i))
		else:
			bfs(s+chr(i), cnt+1, m)

bfs('a',1,'a')

Solution (Python):


n = int(input())

def dfs(s, mx):
    if len(s) == n:
        print(s)
    else:
        for i in range(ord('a'), ord(mx)+1):

            dfs(s + chr(i), chr(ord(mx) + 1) if i == ord(mx) else mx)
dfs('', 'a')

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

def dfs(s, mx):
    if len(s) == n:
        print(s)
    else:
        for c in range(ord('a'), mx+1):
            if c == mx:
                dfs(s + chr(c), mx + 1)
            else:
                dfs(s + chr(c), mx)

dfs('', ord('a'))

Solution (Python):
n = int(input())
ans = ['a']
for j in ans:
  if len(j) < n:
    t = list(j)
    t.sort()
    c = ord(t[-1])
    
    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)

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

def create_li(li):
  if len(li) >= n:
    lis.append(li)
    return
  p = max(li)
  for i in range(1, p + 2):
    cp = li[:]
    cp.append(i)
 
    create_li(cp)

lis = []
  
n = int(input())
pre = [1]
create_li(pre)
lis.sort()
al = ["a","b","c","d","e","f","g","h","i","j"]
ans = set(["".join([al[id-1] for id in i]) for i in lis])
ans = list(ans)
ans.sort()
for i in ans:
  print(i)

Solution (Python):
l = ['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 adder(n, s, index):
    if (n == 0):
        print(s)
    else:
        
        for i in range(index +2):
            adder(n-1, s+l[i],max(i,index))


n = int(input())

if (n == 1):
    print("a")
elif (n == 2):
    print("aa")
    print("ab")
else:
    adder(n-1,"a",0)

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

def resolve():
    N = int(input())
    
    def rec(n, maxchr, ans):
        if n==N:
            print(ans)
        else:
            for i in range(maxchr):
                rec(n+1, maxchr, ans+chr(i+97))
            rec(n+1, maxchr+1, ans+chr(maxchr+97))

    rec(0, 0, '')

if __name__ == '__main__':
    resolve()

Solution (Python):
def dfs(s, mx, n):
    if len(s) == n:
        print(s)
        return

    c = 'a'
    while c <= mx:
        nmx = mx
        if c == mx:
            nmx = chr(ord(c) + 1)
        dfs(s + c, nmx, n)
        c = chr(ord(c) + 1)

n = int(input())
dfs("", 'a', n)

Solution (Python):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N = ir()
    def dfs(c, x):
        if len(c) == N:
            print(c)
        else:
            nx = ord(x)-ord('a')
            for i in range(nx+1):
                if i == nx:
                    dfs(c+chr(ord('a')+i), chr(ord(x)+1))
                else:
                    dfs(c+chr(ord('a')+i), x)
    dfs('', 'a')
resolve()

Solution (Python):
n=int(input())-1
a='a'
for _ in range(n):
    a=set([s+ c for s in a for c in s+chr(ord(max(s))+1)])
print(*sorted(a),sep='\n')

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

 

 
S = "a"
 
def printer(S,max_s):
    if len(S)==N:
        print(S)
    else:
        max_s = max(ord(S[-1])-ord('a'),max_s)
        for i in range(ord('a'),ord('a')+max_s+2):        
            printer(S + chr(i),max_s)
        
printer(S,0)

Solution (Python):
from collections import Counter

N = int(input())
alpha = [chr(i) for i in range(97, 97+26)]
temp = ['a']
result = ['a']
if N >= 2:
  for n in range(2,N+1):
    result = []
    for i in temp:
      temp_list = list(i)
      type = len(Counter(temp_list))
      for j in range(type+1):
        a = i + alpha[j]
        result.append(a)
    temp = result.copy()
print('\n'.join(result))

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

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










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 sorted(results[n-1]):
    print(result)

Solution (Python):
n = int(input())
r = 'a',
for _ in range(n - 1):
  r = [s + c for s in r for c in set(s + chr(ord(max(s)) + 1))]
print(*sorted(r), sep='\n')

Solution (Python):
n = int(input())
r = 'a',
for _ in range(n - 1):
  r = [s + c for s in r for i, c in enumerate(s + chr(ord(max(s)) + 1)) if c not in s[:i]]
print(*r, sep='\n')

Solution (Python):
from collections import deque


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

    av = ord('a')

    def to_s(ary):
        ans = "".join(map(lambda v: chr(v + av), ary))
        return ans

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

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

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


if __name__ == "__main__":
    main()

Solution (Python):


def solv1():
    n=int(input())
    
    a=[[]for i in range(n)]
    a[0]=[[0]]
    
    for i in range(n-1):
        b=[]
        for pa in a[i]:
    
            el=[j for j in set(pa)]
    
            el.append(max(pa)+1)
            for l in el:
                b+=[pa+[l]]
    
        a[i+1]=b
    ans=[j for j in a[n-1]]
        
    ans=sorted(ans)
    for i in ans:
        print(''.join([chr(j+97) for j in i]))

solv1()