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):
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 main():
    N = I()
    ans = []

    def f(t, k, n):
        if n == N:
            ans.append(t)
            return

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

    f('a', 1, 1)

    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

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

N = int(input())


def dfs(ans, max_c):
    if len(ans) == N:
        print(ans)
    else:
        for i in range(max_c + 1):
            dfs(ans + chr(ord('a') + i), max_c + 1 if i == max_c else max_c)


def solve():
    dfs('', 0)


if __name__ == '__main__':
    solve()

Solution (Python):
def dfs(s, upper):
    if len(s) == N:
        print(s)
    else:
        cur = 'a'
        while cur <= upper:
            dfs(s + cur, chr(ord(cur) + 1) if cur == upper else upper)
            cur = chr(ord(cur) + 1)


N = int(input())
dfs('', 'a')

Solution (Python):
N = int(input())
al = "abcdefghijklmnopqrstuvwxyz"
atoi = {s:i for i, s in enumerate(al)}

def func(s, i):
    if i == N:
        print(s)
        return

    maxi = max([atoi[c] for c in s])
    for c in al[:maxi+2]:
        func(s+c, i+1)

func("a", 1)

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

Solution (Python):
def main():
    N = int(input())
    ans = ['a']
    i = 0
    while i != N-1:
        tmp = set()
        i += 1
        for j in range(len(ans)):
            for k in range(i+1):
                tmp.add(ans[j]+chr(97+k))
                if chr(97+k) not in ans[j]:
                    break
        ans = list(tmp)
    ans.sort()
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()

Solution (Python):
import copy

N = int(input())
w  = [['a']]
for n in range(1,N):
    nw = [[] for _ in range(n+1)]
    for i in range(n):
        nw[i] += [x+chr(97+j) for j in range(i+1) for x in w[i]]
        nw[i+1] += [x+chr(97+i+1) for x in w[i]]
    w = copy.deepcopy(nw)

ans = []
for i in range(N):
    ans += [x for x in w[i]]
for x in sorted(ans):
    print(x)

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

if N > 1:
  ans1 = []
  a = max(ans)+1
  for i in range(a+1):
    c = copy.copy(ans)
    c.append(i)
    ans1.append(c)
    
if N > 2:
  ans2 = []
  for j in range(len(ans1)):
    a = max(ans1[j])+1
    for i in range(a+1):
      c = copy.copy(ans1[j])
      c.append(i)
      ans2.append(c)

if N > 3:
  ans3 = []
  for j in range(len(ans2)):
    a = max(ans2[j])+1
    for i in range(a+1):
      c = copy.copy(ans2[j])
      c.append(i)
      ans3.append(c)
      

if N > 4:
  ans4 = []
  for j in range(len(ans3)):
    a = max(ans3[j])+1
    for i in range(a+1):
      c = copy.copy(ans3[j])
      c.append(i)
      ans4.append(c)


if N > 5:
  ans5 = []
  for j in range(len(ans4)):
    a = max(ans4[j])+1
    for i in range(a+1):
      c = copy.copy(ans4[j])
      c.append(i)
      ans5.append(c)

      
if N > 6:
  ans6 = []
  for j in range(len(ans5)):
    a = max(ans5[j])+1
    for i in range(a+1):
      c = copy.copy(ans5[j])
      c.append(i)
      ans6.append(c)

if N > 7:
  ans7 = []
  for j in range(len(ans6)):
    a = max(ans6[j])+1
    for i in range(a+1):
      c = copy.copy(ans6[j])
      c.append(i)
      ans7.append(c)

if N > 8:
  ans8 = []
  for j in range(len(ans7)):
    a = max(ans7[j])+1
    for i in range(a+1):
      c = copy.copy(ans7[j])
      c.append(i)
      ans8.append(c)

if N > 9:
  ans9 = []
  for j in range(len(ans8)):
    a = max(ans8[j])+1
    for i in range(a+1):
      c = copy.copy(ans8[j])
      c.append(i)
      ans9.append(c)
      
aaa = "abcdefghij"
if N == 1:
  print("a")    
    
elif N ==2:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==3:
  for i in ans2:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==4:
  for i in ans3:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans4:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==6:
  for i in ans5:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==7:
  for i in ans6:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==8:
  for i in ans7:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==9:
  for i in ans8:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
    
elif N ==10:
  ans9.sort()
  for i in ans9:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)

Solution (Python):
N = int(input())
s = [[] for i in range(N)]

s[0].append("a")

def maxs(ss):
    max_ss = 0
    for i in range(len(ss)):
        max_ss = max(max_ss,ord(ss[i]))
    return max_ss

for i in range(1,N):
    for ss in s[i-1]:
        for j in range(97,maxs(ss)+2):
            s[i].append(ss+chr(j))

for ss in s[N-1]:
    print(ss)

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

same('a')
for i in ans:
    print(i)

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

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

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

al = ['a', 'b', 'c' , 'd', 'e', 'f', 'g', 'h', 'i', 'j']
list = []
for i in range(n):
    new = []
    if i ==0:
        new.append(al[0])
    else:
        lis = copy.deepcopy(list)
        for x in lis:
            flag = False
            for y in al[:i+1]:
                if y in x:
                    new.append(x+y)
                else:
                    if flag == False:
                        new.append(x+y)
                        flag = True
    list = new

for x in new:
    print(x)

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

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

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

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


"""
[
    [[a]]
    [[aa],[ab]]
    [[aaa],[aba,abb],[abc]]
]


"""
result=[["a"]]
for i in range(n-1):
    temp=[]
    for item in result[i]:
        uniqAl=len(''.join(set(item)))
        for alp in al[:uniqAl+1]:
            temp.append(item+alp)
    result.append(temp)


for item in result[-1]:
    print(item)

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

for l in range(N):
    if l == 0:
        L.append(['a'])
    else:
        applist = []
        for content in L[l-1]:
            ind = 0
            for j in range(len(content)):
                ind = max(ind,Alphabet.index(content[j]))
            for i in range(ind+2):
                applist.append(content+Alphabet[i])
        L.append(applist)

for content in L[N-1]:
    print(content)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

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

import copy
n = ni()

def f(a,b,m):
  if a == n:
    print(''.join([al[i] for i in b]))
  else:
    for i in range(m+2):
      c = copy.copy(b)
      c.append(i)
      f(a+1,c,max(m,i))

f(1,[0],0)

Solution (Python):
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

N = int(input())
alph = string.ascii_lowercase

ans = defaultdict(int)

@lru_cache(maxsize=None)
def search(S, nums):
    if nums in ans:
        return
    if len(nums) == N:
        ans[nums] = S
        return

    for i in range(len(nums)):
        for s, n in zip(S, nums):
            if n == i:
                search(S + s, nums + (n, ))
                break
    C = set(list(S))
    for s in alph:
        if not s in C:
            search(S + s, nums + (len(nums), ))
            break

search('a', (0, ))
ans = list(ans.values())
ans.sort()
print(*ans, sep='\n')

Solution (Python):
d = ['','a','b','c','d','e','f','g','h','i','j']
N = int(input())
if N == 1:
  print("a")
elif N == 2:
  print("aa")
  print("ab")
else:
  ans = [[[]]for _ in range(N - 1)]
  ans[0][0] = [1]
  ans[1][0] = [1,1]
  ans[1].append([1,2])
  ansstr = []
  for i in range(N -2):
    for i2 in range(len(ans[i + 1])):
      for i3 in range(max(ans[i + 1][i2]) + 1):
        if i == N - 3:
          ansstr.clear()
          for i4 in range(N - 1):
            ansstr.append(d[ans[i + 1][i2][i4]])
          ansstr.append(d[i3 + 1])
          print("".join(ansstr))
        else:
          ans[i + 2].append(ans[i + 1][i2] + [i3 + 1])
    if i < N - 3:
      ans[i + 2].pop(0)

Solution (Python):
d = ['','a','b','c','d','e','f','g','h','i','j']
N = int(input())
if N == 1:
  print("a")
elif N == 2:
  print("aa")
  print("ab")
else:
  ans = [[[]]for _ in range(N - 1)]
  ans[0][0] = [1]
  ans[1][0] = [1,1]
  ans[1].append([1,2])
  ansstr = []
  for i in range(N -2):
    for i2 in range(len(ans[i + 1])):
      for i3 in range(max(ans[i + 1][i2]) + 1):
        if i == N - 3:
          ansstr.clear()
          for i4 in range(N - 1):
            ansstr.append(d[ans[i + 1][i2][i4]])
          ansstr.append(d[i3 + 1])
          print("".join(ansstr))
        else:
          ans[i + 2].append(ans[i + 1][i2] + [i3 + 1])
    if i < N - 3:
      ans[i + 2].pop(0)

Solution (Python):
from string import ascii_lowercase
def main():
    n=int(input())
    Ans=['a']
    A=ascii_lowercase
    for i in range(n-1):
        Tmp=[]
        for a in Ans:
            s=set(list(a))
            for l in A:
                Tmp.append(a+l)
                if l not in s:
                    break
        Ans=Tmp[:]
    for ans in Ans:
        print(ans)
    
if __name__=='__main__':
    main()

Solution (Python):
d = ['','a','b','c','d','e','f','g','h','i','j']
N = int(input())
if N == 1:
  print("a")
elif N == 2:
  print("aa")
  print("ab")
else:
  ans = [[[]]for _ in range(N - 1)]
  ans[0][0] = [1]
  ans[1][0] = [1,1]
  ans[1].append([1,2])
  ansstr = []
  for i in range(N -2):
    for i2 in range(len(ans[i + 1])):
      for i3 in range(max(ans[i + 1][i2]) + 1):
        if i == N - 3:
          ansstr.clear()
          for i4 in range(N - 1):
            ansstr.append(d[ans[i + 1][i2][i4]])
          ansstr.append(d[i3 + 1])
          print("".join(ansstr))
        else:
          ans[i + 2].append(ans[i + 1][i2] + [i3 + 1])
    if i < N - 3:
      ans[i + 2].pop(0)

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

dic={}
ans=[]

dic['a']=1
ans.append('a')

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


for i in range(N):
    ans_temp = ans
    dic_temp = dic
    
    ans = []
    dic={}
    dic_count={}
    
    for j in ans_temp:
        new_j = 'a'+ j
        ans.append(new_j)
        dic[new_j]=dic_temp[j]
        dic_count[new_j]=1
    
    for l in ans_temp:
        num_alp = dic_temp[l]
        for m in range(num_alp+1):
            new_l = l+alp[m]

            if dic_count.get(new_l) is None:
                ans.append(new_l)
                dic_count[new_j]=1
                if m==num_alp:
                    dic[new_l]=dic_temp[l]+1
                else:
                    dic[new_l]=dic_temp[l]

        
    
        
        

for i in ans:
    print(i)

Solution (Python):
import sys
import itertools
import math
from collections import deque
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


def tami(re,res,cnt,ma):
  if cnt == N:
    ans.append(res)
    return
  for i in range(ord("a"), ma+2):
    tami(chr(i),res+chr(i),cnt+1,max(ma, i))

N = I()

ans = []
tami(chr(ord("a")-1),"",0,ord("a")-1)
ans.sort()
for i in ans:
  print(i)

Solution (Python):

import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import os
import sys
import datetime
from functools import lru_cache
readline=readline = sys.stdin.readline
sys.setrecursionlimit(2000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True


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


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

Solution (Python):
C = 'abcdefghijklmnopqrstuvwxyz'
N = int(input())
def dfs(s):
  l = len(s)
  if l >= N:
    print(s)
    return
  for i in range(l+1):
    if len(set(s)) < i:
      continue
    dfs(s+C[i])
dfs('')

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

def standard(n, cur):
  if n == 0:
    print(''.join(cur))
  else:
    newC = chr(ord(sorted(cur)[-1]) + 1)
    for c in sorted(set(cur + [newC])):
      standard(n - 1, cur + [c])

standard(N - 1, ['a'])

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

def to_str(n):
    s = [chr(i + 97) for i in reversed(n)]
    s = "".join(s)
    return s
n = [0] * N
n_max = list(reversed(list(range(N))))

s = to_str(n)
print(s)
while True:
    for j in range(N-1):
        
        if n[j] < max(n[j+1:]) + 1:
            n[j] += 1
            for k in range(j):
                n[k] = 0
            s = to_str(n)
            print(s)
            break
    if n == n_max:
        break

Solution (Python):
import copy

n = int(input())

l = ['a']
ans = []


def f(n, s, l):
    if n == 1:
        for c in l:
            ans.append(s+c)
        return

    n -= 1
    for c in l:
        if (s+c).count(l[-1]) == 0:
            f(n, s+c, l)
        else:
            ll = copy.deepcopy(l)
            ll.append(chr(ord(ll[-1])+1))
            f(n, s+c, ll)


f(n, "", l)
for ss in ans:
    print(ss)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
N = int(input())

s = 'abcdefghijklmn'

ans = []
def f(t, k, n):
    if n == N:
        ans.append(t)
        return
    for i in range(k+1):
        f(t+s[i], max(k,i+1), n+1)

f('a', 1, 1)

for a in ans:
    print(a)

Solution (Python):
alpha = "abcdefghij"
n=int(input())
patterns = ["a"]
for _ in range(n-1):
    last_patterns = patterns.copy()
    patterns = []
    for string in last_patterns:
        useful_str = alpha[:len(set(string))+1]
        for str_ in useful_str:
            patterns.append(string + str_)

for pat in patterns:
    print(pat)

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

Solution (Python):

import sys
from itertools import permutations
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    l=[[] for _ in range(N+1)]
    l[0]=[('a',ord('a'))]
    for i in range(N-1):
        for a,z in l[i]:
            for j in range(ord('a'),z+2):
                l[i+1].append((a+chr(j),max(z,j)))
    l.sort()
    for a,z in l[N]:
        print(''.join(a))

if __name__ == '__main__':
    main()

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

myList = [[0, "a"]]

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

if N == 1:
    print("a")
else:
    for indx in range(1,N):
        newMyList = []
        for strItem in myList:
            for addIndx in range(strItem[0] + 2):
                newNum = max(addIndx, strItem[0])
                newMyList.append([newNum, strItem[1] + alfList[addIndx]])
        myList = newMyList
    
    for indx in range(len(myList)):
        print(myList[indx][1])

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
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()))
n=INT()
a=["a" for i in range(n)]
def f(num):
    global n,a
    if num==n:
        print("".join([str(n) for n in a]))
        return
    elif num==1:
        a[num]="a"
        f(num+1)
        a[num]="b"
        f(num+1)
    else:
        a[num]="a"
        f(num+1)
        a[num]="b"
        f(num+1)
        try:
            if a.index("b")<num:
                a[num]="c"
                f(num+1)
            if a.index("c")<num:
                a[num]="d"
                f(num+1)
            if a.index("d")<num:
                a[num]="e"
                f(num+1)
            if a.index("e")<num:
                a[num]="f"
                f(num+1)
            if a.index("f")<num:
                a[num]="g"
                f(num+1)
            if a.index("g")<num:
                a[num]="h"
                f(num+1)
            if a.index("h")<num:
                a[num]="i"
                f(num+1)
            if a.index("i")<num:
                a[num]="j"
                f(num+1)
        except:
            pass
f(1)

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

base = ['a' for i in range(n)]

end = ['z' for i in range(n)]

def sorted_k_partitions(seq, k):
    n = len(seq)
    groups = []  

    def generate_partitions(i):
        if i >= n:
            yield list(map(tuple, groups))
        else:
            if n - i > k - len(groups):
                for group in groups:
                    group.append(seq[i])
                    yield from generate_partitions(i + 1)
                    group.pop()

            if len(groups) < k:
                groups.append([seq[i]])
                yield from generate_partitions(i + 1)
                groups.pop()

    result = generate_partitions(0)

    
    result = [sorted(ps, key = lambda p: (len(p), p)) for ps in result]
    
    result = sorted(result, key = lambda ps: tuple(map(len, ps)) + (ps,))

    return result

seq = [i+1 for i in range(n)]



res = []

for k in seq:
    for groups in sorted_k_partitions(seq, k):
        temp = ['a' for i in range(n)]
        tmp = []
        tmp = list(groups)
        tmp.sort()
        
        counter = 0
        for t in tmp:
            for e in t:
                temp[e-1] = chr(ord('a') + counter)
            counter += 1
        
        
        res.append(''.join(temp))

res.sort()

for r in res:
    print(r)

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

alphabets = list('Zabcdefghijklmn')
s = ['a']
ss = []
for i in range(2, N + 1):
    subset = alphabets[1:i + 1]
    for j in range(len(s)):
        for k in subset:
            ss.append(s[j] + k)
            if s[j].find(k) == -1:
                break
    
    s = ss
    ss = []
print(*s, sep='\n')

Solution (Python):
from string import ascii_lowercase as alps

n = int(input())

def solve(x=n, c=0, l=[]):
    if x == 0:
        print(''.join(alps[i-1] for i in l))
        return

    x -= 1

    for nc in range(1, c + 1):
        solve(x, c, l + [nc])

    solve(x, c+1, l + [c+1])

solve()

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


A = ['a']

for i in range(n-1):
    B = A[i:]
    for j in B:
        for i in range(ord("a"), ord(max(j)) + 2):
            A.append("".join(j) + chr(i))
A = sorted(A)
for i in A:
    if len(i) == n:
        print(i)

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

s = set()

def solve(n):
    global s

    if n == N:
        return

    if len(s) == 0:
        s.add('a')
        solve(n+1)
    else:
        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(0)
ans = sorted(s)
print(*ans, sep='\n')

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


A = ['a']

for i in range(n-1):
    B = A[i:]
    for j in B:
        for i in range(ord("a"), ord(max(j)) + 2):
            A.append("".join(j) + chr(i))
A = sorted(A)
for i in A:
    if len(i) == n:
        print(i)

Solution (Python):
K = int(input())-1
al = [chr(i) for i in range(97, 97+26)]
S_arr = [al[0]]
for i in range(K):
  new_S_arr = []
  for S in S_arr:
    for j in range(len(set(list(S)))+1):
      new_S_arr.append(S + al[j])
  S_arr = new_S_arr

for S in S_arr:
  print(S)

Solution (Python):
n = int(input())
a = [ [] for _ in range(11) ]
a[0].append("a")

alp = "abcdefghijklmn"
for i in range(1, 10):
    for aa in a[i-1]:
        for c in alp[:i+1]:
            max_e = max( [ord(x) for x in aa] )
            if max_e+1 < ord(c): break
            a[i].append(aa+c)

for ans in a[n-1]:
    print(ans)

Solution (Python):
n = int(input())
ch = ['a','b','c','d','e','f','g','h','i','j']
def l (num,s):
    global n
    global ch
    if num == n:
        return s
    new = []
    for i in s:
        x = len(set(i)) +1
        for j in range(x):
            p = i + ch[j]
            new.append(p)
    return num+1,new
dt = (1,['a'])
for k in range(n):
    dt = l(dt[0],dt[1])
for z in dt:
    print(z)

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

def plus(s):
  m = max(s)
  ret = []
  for i in range(ord(m)-97+2):
    ret.append(s+chr(i+97))
  return ret

s = 'a'
ws = [[] for i in range(10+1)]
ws[0].append(s)
for i in range(1,10+1):  
  for s in ws[i-1]:
    ws[i].extend(plus(s))     
    
for s in ws[n-1]:
  print(s)

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

stack=['a']
alpahbet=[chr(i) for i in range(97, 97+26)]

if n==1:
    print('a')
else:
    cnt=1
    
    while cnt<n:
        nextstack=[]

        while len(stack):
            curs=stack.pop()
            pat=set()
            for c in alpahbet:
                ret=0
                for j in range(cnt):
                    if curs[j]==c:
                        ret=ret*2
                    else:
                        ret=ret*2+1
                
                if ret in pat:
                    continue

                pat.add(ret) 
                nextstack.append(curs+c)
        
        stack=sorted(nextstack)
        cnt+=1
    
    for s in stack:
        print(s)

Solution (Python):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()

alpha =list("abcdefghij")

def dfs(string, counter, N):
    if N==counter:
        lists.append(string)
        return 
    
    for i in range(counter):
        if i==0:
            dfs(string + alpha[i], counter+1, N)
        elif alpha[i-1] in string:
            dfs(string + alpha[i], counter+1, N)

lists = []

dfs("a", 2, N+1)

for i in sorted(lists):
    print(i)

Solution (Python):
import sys


def I(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LMI(): return list(map(int, sys.stdin.readline().split()))


MOD = 10 ** 9 + 7

s = 'abcdefghijklmnop'
N = I()

for c1 in range(1):
    if N == 1:
        print(s[c1])
        continue
    for c2 in range(2):
        if N == 2:
            print(s[c1]+s[c2])
            continue
        for c3 in range(max(c1, c2) + 2):
            if N == 3:
                print(s[c1] + s[c2] + s[c3])
                continue
            for c4 in range(max(c1, c2, c3) + 2):
                if N == 4:
                    print(s[c1] + s[c2] + s[c3] + s[c4])
                    continue
                for c5 in range(max(c1, c2, c3, c4) + 2):
                    if N == 5:
                        print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] )
                        continue
                    for c6 in range(max(c1, c2, c3, c4, c5) + 2):
                        if N == 6:
                            print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6])
                            continue
                        for c7 in range(max(c1, c2, c3, c4, c5, c6) + 2):
                            if N == 7:
                                print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6] + s[c7] )
                                continue
                            for c8 in range(max(c1, c2, c3, c4, c5, c6, c7) + 2):
                                if N == 8:
                                    print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6] + s[c7] + s[c8])
                                    continue
                                for c9 in range(max(c1, c2, c3, c4, c5, c6, c7, c8) + 2):
                                    if N == 9:
                                        print(s[c1]+s[c2]+s[c3]+s[c4]+s[c5]+s[c6]+s[c7]+s[c8]+s[c9])
                                        continue
                                    for c10 in range(max(c1, c2, c3, c4, c5, c6, c7, c8, c9) + 2):
                                        print(s[c1]+s[c2]+s[c3]+s[c4]+s[c5]+s[c6]+s[c7]+s[c8]+s[c9]+s[c10])

Solution (Python):
N = int(input())
al = "abcdefghijklmnopqrstuvwxyz"
atoi = {s:i for i, s in enumerate(al)}
itoa = {i:s for i, s in enumerate(al)}

l = []
def func(s, i):
    if i == N:
        print(s)
        l.append(s)
        return
    
    
    
    
    
    

    
    maxi = max([atoi[c] for c in s])
    for c in al[:maxi+2]:
        func(s+c, i+1)
    
    
    

func("a", 1)

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

cset = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
sset = ['a'] * N
def rec(di, usedci):
    if di >= len(sset):
        print(''.join(sset))
        return
    for i in range(usedci+1):
        sset[di] = cset[i]
        rec(di+1, usedci)
    sset[di] = cset[usedci+1]
    rec(di+1, usedci+1)

rec(1, 0)

Solution (Python):

from collections import deque, defaultdict
import bisect
from math import factorial, sqrt

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

def generate_valid_strings(base):
    result = set()
    candidates = set(list(base))

    for c in candidates:
        string = base + c
        result.add(string)

    for c in ALPHABETS:
        if c not in candidates:
            string = base + c
            result.add(string)
            break

    return result


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

    all_strings = defaultdict(set)

    x = 'a'
    all_strings[1].add(x)
    for i in range(1, N):
        new_strings = set()
        prev_strings = all_strings[i]
        for string in prev_strings:
            new_strings |= generate_valid_strings(string)
        all_strings[i+1] = new_strings

    result = sorted(all_strings[N])
    for string in result:
        print(string)


if __name__ == '__main__':
    main()