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 aa(s, n, t):
    if n == N:
        print(s)
        return
    for i in range(t):
        aa(s+chr(97+i), n+1, t)
    aa(s+chr(97+t), n+1, t+1)
    return


aa("a", 1, 1)

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

def dfs(s, mx):
  if len(s) == n:
    print(s)
    return
  for c in range(ord("a"), mx+2):
    dfs(s+chr(c), max(mx, c))


dfs("", ord("a")-1)

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

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

Solution (Python):






N = int(input())





num2alpha = lambda c: chr(c%26+97)





def dfs(s,n,cnt):
    if n == 0:
        print(s)
        return
    for i in range(cnt+2):
        if i == cnt+1:
            dfs(s+num2alpha(i),n-1,cnt+1)
        else:
            dfs(s+num2alpha(i),n-1,cnt)
dfs("a",N-1,0)

Solution (Python):
n = int(input())
v = 'abcdefghij'
def dfs(s):
  if len(s) == n:
    print (s)
    return
  for i in range(len(set(s))+1):
    dfs(s+v[i])
dfs('a')

Solution (Python):
n = int(input())
v = 'abcdefghijk'

w = []
def dfs(s,t):
  if len(s) == n:
    w.append(s)
    return
  u = len(set(s))
  for i in range(u+1):
    dfs(s+v[i],u+1)

dfs('a',1)

for i in w:
  print (i)

Solution (Python):
N=int(input())
S='abcdefghijklmnopqrstuvwxyz'
A=['a']
for _ in range(N-1):
    now=[]
    for a in A:
        b=sorted(list(a))[-1]
        bi=S.index(b)
        for i in range(bi+2):
            now.append(a+S[i])
    A=now.copy()
A.sort()
for a in A:
    print(a)

Solution (Python):
from collections import deque
def main(): 
    n = int(input())
    dq = deque([])
    dq.append([0])
    for _ in range(n-1):
        l = len(dq)
        for __ in range(l):
            s = dq.popleft()
            ls = len(set(s))
            for i in range(ls+1):
                dq.append(s+[i])
    
    for s in dq:
        s = list(map(lambda x: chr(x+ord("a")),s))
        print("".join(s))
main()

Solution (Python):



import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1"""
        output = """a"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2"""
        output = """aa
ab"""
        self.assertIO(input, output)


def resolve():
    global N
    N = int(input())

    dfs("a", "a")


def dfs(mw, s):
    if len(s) == N:
        print(s)
        return

    for i in range(ord(mw)-ord("a")+2):
        mw = max(mw, chr(ord("a")+i))
        ns = s + chr(ord("a")+i)
        dfs(mw, ns)


if __name__ == "__main__":
    
    resolve()

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

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

ans=[]

st='a'

temp=0
now=0

def dfs(st,n,now,temp):
  if now==n-1:
    ans.append(st)
  else:
    for f in range(0,temp+2):
      if f==temp+1:
        dfs(st+al[f],n,now+1,temp+1)
      else:
        dfs(st+al[f],n,now+1,temp)
    
dfs(st,n,0,0)

for h in ans:
  print(h)

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))



N=intput()

def rec(l,num):
    if len(l)==N:
        print(''.join(l))
    else:
        for i in range(num):
            ll = deepcopy(l)
            ll.append(ntos(i))
            rec(ll,num)
        ll = deepcopy(l)
        ll.append(ntos(num))
        rec(ll,num+1)
rec([],0)

Solution (Python):



import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1"""
        output = """a"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2"""
        output = """aa
ab"""
        self.assertIO(input, output)


def resolve():
    global N
    N = int(input())

    T = []
    func("a", "a", T)

    for t in T:
        print(t)


def func(mw, s, T):
    if len(s) == N:
        T.append(s)
        return

    for i in range(ord(mw)-ord("a")+2):
        mw = max(mw, chr(ord("a")+i))
        ns = s + chr(ord("a")+i)
        func(mw, ns, T)


if __name__ == "__main__":
    
    resolve()

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

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


def dfs(s):
    if len(s) >= n:
        return
    f = False
    for x in l:
        if x in s:
            ans.append(s + x)
            dfs(s + x)
        else:
            if f:
                return
            f = True
            ans.append(s + x)
            dfs(s + x)


dfs('')

ans.sort()
for x in ans:
    if len(x)==n:
        print(x)

Solution (Python):
def dfs(cnt, s, now):
    if cnt == n:
        ans.append(s)
        return
    for i in range(now+1):
        dfs(cnt+1, s+al[i], max(i+1, now))

n = int(input())
ans = []
al = [chr(i) for i in range(97, 97+26)]
dfs(0, "", 0)
for i in ans:
    print(i)

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

def main(l):
  tmp = []
  for a in l:
    n = a[1]
    for i in range(97, n+2):
      tmp.append([a[0]+chr(i), max(i, n)])
  return tmp
  
l = [['a', 97]]
for i in range(1, N):
  l = main(l)
for i in range(len(l)):
  print(l[i][0])

Solution (Python):
'''
Created on 2020/09/09

@author: harurun
'''

def dfs(s,t,N):
  if len(s)==N:
    print(s)
  else:
    c=97
    while c<=ord(t):
      if c==ord(t):
        dfs(s+chr(c),chr(ord(t)+1),N)
      else:
        dfs(s+chr(c),t,N)
      c+=1
  return

def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N=int(pin())
  dfs("",'a',N)
  return

main()

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

L = ["a"]
if n == 1:
    print(L[0])
    exit()
    
for i in range(n-1):
    li = []
    for s in L:
        max1 = max(s)
        S = ""
        for j in range(ord(max1)-95):
            S = s + chr(97+j)
            
            li.append(S)
    L = copy(li)
    
print("\n".join(L))

Solution (Python):
from copy import copy
n=int(input())
alpha="abcdefghij"
c=[0 for i in range(n)]
m=[0 for i in range(n)]
ans=[]
ans.append(copy(c))
while True:
  c[-1]+=1
  i=n-1
  while i!=0 and c[i]-2==m[i-1]:
    c[i]=0
    i-=1
    c[i]+=1
  if i==0:
    break
  for i in range(1,n):
    m[i]=max(m[i-1],c[i])
  ans.append(copy(c))
for i in ans:
  print("".join(map(lambda x:alpha[x],i)))

Solution (Python):
from itertools import permutations

N=int(input())
ans = ['']*N

al = 'abcdefghij'
d = {al[i]:i for i in range(N)}

def dfs(h=[]):
    if len(h)==N:
        print(''.join(h))
        return
    for i in range(max([d[h[-1-i]] for i in range(len(h))])+2):
        h.append(al[i])
        dfs(h)
        h.pop()
    return
  
dfs(['a'])

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

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


def dfs(ans, keep, n):
    if n == N + 1:
        print(ans)
    else:
        for i in range(keep):
            dfs(ans + lis[i], max(keep, i + 2), n + 1)


dfs('', 1, 1)

Solution (Python):
N=int(input())
alpha=[chr(ord('a') + i) for i in range(26)]
l=[]
def ans(le,alp):
   s=len(set(alp))
   if le==N:
      l.append(alp)
      return
   for i in range(s+1):
      ans(le+1,alp+alpha[i])
ans(1,"a")
for i in l:
   print(i)

Solution (Python):
import sys
import heapq
from decimal import Decimal

input = sys.stdin.readline
n = int(input())
alpha_list = [chr(i) for i in range(97, 97+26)]


def dfs(s,used_count):

    if len(s) == n:
        print(s)
        return

    for i in range(used_count+1):
        if i == used_count:
            dfs(s+alpha_list[i],used_count+1)
        else:
            dfs(s+alpha_list[i],used_count)

dfs("a",1)

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

result = ["a"]
alph = "abcdefghijklmn"

def gen(w):
    ret = []
    s = len(set(w))
    for ch in alph[:s+1]:
        ret.append(w+ch)
    return ret

i = 0
w = result[i]
while len(w) <= N:
    w = result[i]
    result.extend(gen(w))
    i += 1
    if len(w) == N:
        print(w)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
res = set()
a = ord("a")
mx = lambda x: max(list(map(ord, x))) - a
def dfs(s):
  if len(s) == N:
    res.add("".join(s))
    return
  for k in range(mx(s) + 2): dfs(s + [chr(k + a)])
dfs(["a"])
for r in sorted(res): print(r)

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

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

tmp = []

def dfs(s, i):
    if len(s) == n:
        yield s
        return
    for j in range(i):
        for k in dfs(s+alphabets[j], i):
            yield k
    for k in dfs(s+alphabets[i], i+1):
        yield k

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

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

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

tmp = []

def dfs(s, i):
    if len(s) == n:
        yield s
        return
    for j in range(i):
        for k in dfs(s+alphabets[j], i):
            yield k
    for k in dfs(s+alphabets[i], i+1):
        yield k

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

Solution (Python):
from collections import deque
n=int(input())
ans=deque(['a'])
while True:
  a=ans.popleft()
  if len(a)==n:
    ans.appendleft(a)
    break
  m=max(a)
  for i in range(ord(m)-96+1):
    ans.append(a+chr(97+i))
print(*ans,sep='\n')

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

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

dfs("", 'a')

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

a_num = 97

def dfs(s, n, cnt): 
    if n == 0:
        print(s)
        return
    for i in range(cnt+2):
        if i == cnt+1:
            dfs(s+chr(a_num+i), n-1, cnt+1)
        else:
            dfs(s+chr(a_num+i), n-1, cnt)

dfs("a", N-1, 0)

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

a_num = 97

def dfs(s, n): 
    if n == 0:
        print(s)
        return
    for i in range(ord("a"), ord(max(s))+2):
        dfs(s+chr(i), n-1)

dfs("a", N-1)

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

a_num = 97

def dfs(s): 
    if len(s) == N:
        print(s)
        return
    for i in range(ord("a"), ord(max(s))+2):
        dfs(s+chr(i))

dfs("a")

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


def dfs(s, max_ctoi, n):
    global ans
    if len(s) == n:
        ans.append(s)
        return
    else:
        for i in range(max_ctoi+1):
            if i == max_ctoi:
                dfs(s+chr(ord("a")+i), max_ctoi+1, N)
            else:
                dfs(s+chr(ord("a")+i), max_ctoi, N)


ans = []
N = int(input())
dfs("", 0, N)
ans.sort()
for a in ans:
    print(a)

Solution (Python):


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def dfs(m, N):
    if N == 0:
        yield []
    else:
        for i in range(0, m+2):
            for solution in dfs(max(m, i), N-1):
                yield [i]+solution

def solve():
    '''
    a
    '''
    N = read_int()
    alphabets = 'abcdefghij'
    for solution in dfs(-1, N):
        print(''.join(alphabets[i] for i in solution))


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
ls = []
alphabet = [chr(i) for i in range(97, 97+26)]
alphabet_dict = {}
for i, a in enumerate(alphabet):
    alphabet_dict[a] = i
def dfs(A):
    if len(A) == n:
        ls.append(A)
        return
    Max = 0
    for i in range(len(A)):
        Max = max(Max,alphabet_dict[A[i]])
    for i in range(Max+2):
        A += alphabet[i]
        dfs(A)
        A = A[:-1]
dfs('a')
ls.sort()
for i in range(len(ls)):
    print(ls[i])

Solution (Python):
def main():
    from string import ascii_lowercase
    N = int(input())
    ascii_dic = {i: a for i, a in enumerate(ascii_lowercase)}
    ascii_rdic = {a: i for i, a in enumerate(ascii_lowercase)}
    

    def dfs(A):
        if len(A) == N:
            
            print("".join(A))
            return
        if not A:
            dfs(["a"])
        else:
            s = max(ascii_rdic[a] for a in A)
            for i in range(s+2):
                dfs(A + [ascii_dic[i]])

    dfs([])

    
    
    
    
    
    
    
    
    
    
    
    


if __name__ == '__main__':
    main()

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    sushi = ["a"]
    alt = [chr(ord("a") + i) for i in range(n)]
    for i in range(n-1):
        sushi = [ans + x for ans in sushi for x in alt[:len(set(ans)) + 1]]
    for i in sushi:
        print(i)
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
def solve():
    N = int(input())
    ans = ['a']
    for i in range(N - 1):
        newest_ans = []
        for a in ans:
            A = [ord(b) for b in a]
            for t in range(min(A), max(A) + 2):
                newest_ans.append(a + chr(t))
        ans = newest_ans
    for a in sorted(ans):
        print(a)


if __name__ == "__main__":
    solve()

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re












import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
ans = ['a']
for i in range(n-1):
    tmp = []
    for s in ans:
        m = max(s)
        j = ord(m)-ord('a') + 1
        for k in range(j+1):
            tmp.append(s+chr(ord('a') + k))
    ans = tmp
print(*ans, sep='\n')

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

ans = []
def dfs(A):
    if len(A) == n:
        ans.append(''.join(A))
        return
    for i in range(len(set(A))+1):
        v = chr(i+ord('a'))
        A.append(v)
        dfs(A)
        A.pop()

dfs([])
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Solution (Python):
def dfs(S):
    if len(S) == N:
        ans.append(S)
    else:
        for c in range(max(S) + 2):
            dfs(S + [c])


N = int(input())
ans = []
dfs([0])
for li in ans:
    print("".join(chr(c + ord("a")) for c in li))

Solution (Python):
from collections import deque
D1 = {i:chr(i+96) for i in range(1,27)}
D2 = {val:key for key,val in D1.items()}
N = int(input())
que = deque([("a",1)])
A = []
while que:
    x,n = que.popleft()
    if n<N:
        imax = 0
        for i in range(len(x)):
            imax = max(imax,D2[x[i]])
        for j in range(1,min(imax+1,26)+1):
            que.append((x+D1[j],n+1))
    else:
        A.append(x)
A = sorted(list(set(A)))
for i in range(len(A)):
    print(A[i])

Solution (Python):
from collections import *

def dfs(q):
    if len(q)==N:
        print(''.join(q))
        return 
    
    M = 'a'
    
    for qi in q:
        M = max(M, qi)
        
    for i in range(ord(M)-ord('a')+2):
        q.append(alpha[i])
        dfs(q)
        q.pop()

N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
dfs(deque(['a']))

Solution (Python):
alps = 'abcdefghijklmnopqrstuvwxyz'

def dfs(last, curr_s, sl, n):
    if len(curr_s) == n:
        sl.append(curr_s)
        return

    for i in range(0,last+2):
        s = curr_s + alps[i]
        dfs(max(last,i), s, sl, n)


def main():
    n = int(input())
    sl = []
    dfs(0, 'a', sl, n)
    for s in sl: print(s)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    char_list = 'abcdefghijk'
    N = int(input())

    def dfs(s, n=N, n_char=0):
        if n == 0:
            print(s)
            return
        
        for c in char_list[:n_char]:
            dfs(s + c, n - 1, n_char)
        
        dfs(s + char_list[n_char], n - 1, n_char + 1)

    dfs('')


if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
D1 = {i:chr(i+96) for i in range(1,27)}
D2 = {val:key for key,val in D1.items()}

N = int(input())
heap = deque([(D1[1],1)])
A = []
while heap:
    a,n = heap.popleft()
    if n<N:
        imax = 0
        for i in range(len(a)):
            imax = max(imax,D2[a[i]])
        for i in range(1,min(imax+1,26)+1):
            heap.append((a+D1[i],n+1))
    if n==N:
        A.append(a)
A = sorted(list(set(A)))
for i in range(len(A)):
    print(A[i])

Solution (Python):
alps = 'abcdefghijklmnopqrstuvwxyz'
def dfs(last, curr_s, sl, n):
    if len(curr_s) == n:
        sl.append(curr_s)
        return
    for i in range(0,last+2):
        s = curr_s + alps[i]
        dfs( max(last,i), s, sl, n )   


def main():
    n = int(input())
    sl = []
    dfs(0, 'a', sl, n)
    
    for s in sl:
        print(s)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
s = "a"
ans = []
def dfs(s,n):
  if len(s) == n:
    ans.append(s)
    return
  last = 0
  for i in range(len(s)):
    last = max(last,ord(s[i]))
  limit = chr(last+1)
  for i in range(26):
    temp = chr(97+i)
    if temp <= limit:
      dfs(s+temp,n)
dfs(s,N)
print(*ans,sep="\n")

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



N = int(input())
alphas = "abcdefghijk"

from collections import deque

q = deque(['a'])
for i in range(N - 1):
    q2 = deque([])
    while len(q) > 0:
        now = q.popleft()
        for a in alphas:
            q2.append(now + a)
            if a not in now:
                break
    q = q2
for a in q:
    print(a)

Solution (Python):
import copy,collections
N = int(input())
s = ['a']
for i in range(2,N+1):

    tmp = copy.copy(s)
    tmp2 = []
    for tm in tmp:
        tc = collections.Counter(tm)
        lc = len(tc.values())
        for j in range(1,lc+2):
            tmp2.append(tm+chr(96+j))
    s = copy.copy(tmp2)
for sa in s:
    print(sa)

Solution (Python):

N = int(input())


def func(x):
    if len(x) == N:
        print("".join(x))
        return

    last = ord(max(x)) - ord("a") + 1 if x else 0
    for i in range(min(26, last) + 1):
        x.append(chr(ord("a") + i))
        func(x)
        x.pop()


func([])

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

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

dfs("a", a)

Solution (Python):
from copy import copy
n = int(input())
data = ["a"] * n
ans = ["".join(data)]

def print_str(ans, data, i):
    if i == n:
        return 
    ans.append("".join(data))
    mx = max(data[i] for i in range(n))
    while ord(data[i]) + 1 <= ord(mx) + 2:
        s = copy(data)
        ans.append("".join(data))
        print_str(ans, s, i + 1)
        data[i] = chr(ord(data[i]) + 1)
    data = ["a"] * n
    print_str(ans, data, i + 1)

print_str(ans, data, 1)
ans = sorted(set(ans))
for i in range(len(ans)):
    print(ans[i])

Solution (Python):
import math

n = int(input())

x = ["a"]
alps = "abcdefghijk"
i = 1
while i < n:
    y = []
    for t in x:
        for s in alps[:len(set(t)) + 1]:
            y.append(t + s)
    x = y
    i += 1

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

Solution (Python):
import itertools

import sys
sys.setrecursionlimit(312467) 
N = int(input())
List = []
def dfs(S):
    List.append(S)
    if len(S) < N:
      for i in range(ord("a"), ord(max(S))+2):
        dfs(S+[chr(i)])
    return
dfs(["a"])
for i in List:
  if len(i) == N:
    print("".join(i))
  elif len(i) > N:
    break

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

def dfs(s,mx):
    if len(s)==n:
        print(s)
        return
    for c in range(ord('a'),mx+2):
        t=s
        t+=chr(c)
        dfs(t,max(mx,c))

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

Solution (Python):
def dfs(S, mx):
    if len(S) == N:
        print(S)
    else:
        for i in range(a, mx+2):
            if i == mx+1:
                dfs(S+chr(i), mx+1)
            else:
                dfs(S+chr(i), mx)
    return

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

Solution (Python):
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

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

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def solve(d):
    if d == 1:
        return ['a']
    l = solve(d-1)
    rsl = []
    for w in l:
        m = ord(max(w))
        for i in range(ord('a'), m+2):
            rsl.append(w+chr(i))
    return rsl


def main():
    print(*solve(ii()), sep='\n')


if __name__ == '__main__':
    main()

Solution (Python):

import sys

sys.setrecursionlimit(10**9)
N = int(input())


def main(s, o, n):
    n += 1
    if n == N:
        print(s)
    else:
        for i in range(97, o + 2):
            main(s + chr(i), max(o, i), n)


main("a", 97, 0)

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

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)}
for i in sorted(k):print(i)

Solution (Python):
n=int(input())
l=["a","b","c","d","e","f","g","h","i","j"]
a="a"
ans=["a"]
for i in range(1,n):
    tt=[]
    for j in ans:
        s=len(set(j))
        for k in range(s+1):
            tt.append(j+l[k])
    ans=tt
ans.sort()
for i in ans:
    print(i)

Solution (Python):
alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
DP = [[] for i in range(10)]
DP[0] = ['a']
for i in range(9):
    for w in DP[i]:
        num = alpha.index(w[0])
        for i in range(1,len(w)):
            num = max(num, alpha.index(w[i]))
        for j in range(num+1):
            DP[i+1].append(w + alpha[j])
        if num + 1 <= 9:
            DP[i+1].append(w + alpha[num+1])
N  = int(input())
for w in DP[N-1]:
    print(w)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())

N = I()

ANS = [[] for _ in range(N+1)]

for i in range(1,N+1):
    if i == 1:
        ANS[i].append('a')
    else:
        for a in ANS[i-1]:
            for j in range(97,ord(max(a[k] for k in range(i-1)))+2):
                ANS[i].append(a+chr(j))
print(*ANS[N],sep='\n')

Solution (Python):


n = int(input())

def f(level):
    if level == 1:
        return ["a"]
    ret = []
    for x in f(level-1):
        s = sorted(list(set( (c for c in x))))
        s.append(chr(ord(s[-1])+1))
        for c in s:
            ret.append(x + c)
    return ret

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

Solution (Python):
import copy
k = int(input())
ans = ["a"]
for i in range(k-1):
  b = []
  for j in ans:
    t = max(j)
    for m in range(ord(t) - ord("a")+2):
      b.append(j + chr((ord("a")+m)))
  ans = b
for i in ans:
  print(i)

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

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

dfs([], 0)

Solution (Python):
import collections
alpha=['a','b','c','d','e','f','g','h','i','j']
def a(n):
  if n==1:
    return ['a']
  else:
    box=[]
    alphan=alpha[:n+1]
    for i in a(n-1):
      kind=collections.Counter(i)
      for j in range(len(kind)+1):
        box.append(i+alpha[j])
  return box
for i in a(int(input())):
  print(i)

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

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))


def nHk_list(N,X):
    if N == 0: return []
    elif N == 1: return [[X]]

    border = [i for i in range(X+1)]
    res = []
    for S in itertools.combinations_with_replacement(border, N-1):
        
        pre = 0
        sub = []
        for s in S:
            sub.append(s-pre)
            pre = s
        sub.append(X-pre)
        res.append(sub)
    return res


INF=10**20
def main():
    N=ii()
    alphabet = ["a","b","c","d","e","f","g","h","i","j"]

    ans = []
    for c in range(1,N+1):
        
        for X in nHk_list(c,N-c):
            
            V = []
            for i in range(len(X)):
                x = X[i]
                V.append(list(itertools.product(alphabet[:i+1],repeat=x)))

            
            U = itertools.product(*V)
            base = alphabet[:c]
            for u in U:
                char = ""
                for i in range(c):
                    char += alphabet[i] + "".join(list(u[i]))
        
                ans.append(char)
        
    
    ans.sort()
    
    print(*ans,sep='\n')

            
            

        

if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque

N = int(input())
if N == 1:
  print('a')
  exit()

h = deque(['a'])

while h:
  s = h.pop()
  if len(s) == N:
    print(s)
  else:
    a = set([])
    for i in s:
      a.add(i)
    for i in range(len(a),-1,-1):
      h.append(s+chr(ord('a')+i))

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

abc='abcdefghij'

def dfs(s):
  if len(s)==n:
    print(s)
    return

  st_l=len(set(s))
  for i in range(st_l+1):
    dfs(s+abc[i])

dfs('a')

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

abc='abcdefghijklmnopqrstuvwxyz'

def dfs(keta,s):
  if keta==n:
    global ans
    ans.append(s)
    return

  st_l=len(set(s))
  for i in range(st_l+1):
    dfs(keta+1,s+abc[i])

ans=[]
dfs(1,'a')

for i in ans:
  print(i)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def dfs(s,d,i):
    for j in range(i+1):
        s[d] = chr(ord('a')+j)
        if d < len(s) - 1:
            dfs(s, d+1, max(j+1, i))
        else:
            a.add("".join(s))

n = INT()
s = ['a']*n
a = set()
dfs(s, 0, 0)
b = sorted(list(a))
for x in b:
    print(x)

Solution (Python):
def solve(ans, p, n):
    if len(p) == n:
        s = ""
        for v in p:
            s += chr(ord("a")+v)
        ans.append(s)
        return
    for v in range(max(p)+2):
        p.append(v)
        solve(ans, p, n)
        p.pop()
    return

def main():
    n = int(input())
    ans = []
    p = [0]
    solve(ans, p, n)
    ans.sort()
    for v in ans:
        print(v)

if __name__ == "__main__":
    main()

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

def calc(x_list):
    tmp  = []
    for x in x_list:
        m = max(x)
        for alpha in range(ord('a'), ord(m) + 2):
            tmp.append(x + chr(alpha))
    if len(tmp[-1]) < n:
        tmp = calc(tmp)
    return tmp

ans = calc(['a'])
ans.sort()
if n >= 2:
    print(*ans, sep="\n")
else:
    print('a')

Solution (Python):
n = int(input())
s = "abcdefghij"
def func(a):
  if len(a) == n:
    print(a)
  else:
    for i in range(len(set(a))+1):
      func(a+s[i])
func("a")