Problem:
 Score : 400 points    Problem Statement In this problem, we only consider strings consisting of lowercase English letters.  Strings s and t are said to be isomorphic when the following conditions are satisfied:   |s| = |t| holds.  For every pair i, j , one of the following holds:  s_i = s_j and t_i = t_j .  s_i \neq s_j and t_i \neq t_j .     For example, abcac and zyxzx are isomorphic, while abcac and ppppp are not.  A string s is said to be in normal form when the following condition is satisfied:   For every string t that is isomorphic to s , s \leq t holds. Here \leq denotes lexicographic comparison.   For example, abcac is in normal form, but zyxzx is not since it is isomorphic to abcac , which is lexicographically smaller than zyxzx .  You are given an integer N .
Print all strings of length N that are in normal form, in lexicographically ascending order.      Constraints  1 \leq N \leq 10  All values in input are integers.         Input Input is given from Standard Input in the following format:  N       Output Assume that there are K strings of length N that are in normal form: w_1, \ldots, w_K in lexicographical order.
Output should be in the following format:  w_1  :  w_K         Sample Input 1 1      Sample Output 1 a       Sample Input 2 2      Sample Output 2 aa
ab

Solution (Python):
import sys
from collections import deque

def solve():
    N = int(input())
    AB = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
    Ans = []
    q = deque()
    q.append(("a", 1, 0))
    while q:
        current, length, maxW = q.popleft()
        if length == N: Ans.append(current)
        else:
            q.append((current + "a", length + 1, maxW))
            for k in range(maxW + 1):
                q.append((current + AB[k + 1], length + 1, max(k + 1, maxW)))
    Ans.sort()
    for a in Ans: print(a)
    return 0

if __name__ == "__main__":
    solve()

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

def ans(a, c):
    if len(a)==n-1:
        for i in range(c):
            print(a+s[i])
    else:
        for i in range(c):
            a+=s[i]
            if i==c-1:
                ans(a, c+1)
            else:
                ans(a,c)
            a=a[0:-1]

ans('', 1)

Solution (Python):
numal=lambda c:chr(c+97)
n=int(input())
unchi=[[],[],[],[],[],[],[],[],[],[]]
unchi[0].append("0")
k=1
if n>=2:
	while k<n:
		for i in range(len(unchi[k-1])):
			t=max(map(int, unchi[k-1][i]))
			for u in range(t+2):
				unchi[k].append(unchi[k-1][i]+str(u))
		k+=1
for i in range(len(unchi[n-1])):
	s = []
	for k in range(n):
		s.append(numal(int(unchi[n-1][i][k])))
	print("".join(s))

Solution (Python):
import string

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


def a(s="", distinct=0):
  if len(s) == N:
    print(s)
    return

  for i in range(distinct + 1):
    c = S[i]
    a(s + c, distinct + (1 if c not in s else 0))


a()

Solution (Python):
from copy import deepcopy
N = int(input())
alp = list('abcdefghij')
ans = ['a']
for _ in range(2, N+1):
    m = len(ans)
    tmp = []
    for i in range(m):
        a = ans[i]
        n = len(set(a))
        for s in alp[:n+1]:
            tmp.append(a+s)
    tmp.sort()
    ans = deepcopy(tmp)
for a in ans:
    print(a)

Solution (Python):
import numpy as np
N = int(input())
letters = 'abcdefghij'
count = 0
L = ['']
while count < N:
    next_L = []
    for i in L:
        n = len(np.unique(i))
        for l in letters[:n+1]:
            next_L.append(i + l)
    L = next_L
    count += 1

for j in next_L:
    print(j)

Solution (Python):
from itertools import product, combinations_with_replacement
N=int(input())
s="abcdefghij"
 
def get_gen(a, N):
  for c in s[:s.index(max(a))+2 if a else 1]:
    t = a+c
    if len(t) == N:
      print(t)
    else:
      get_gen(t,N)

get_gen("", N)

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def dfs(set_list, n):
    global N
    for i, s in enumerate(set_list):
        new_set = s.copy()
        new_set.add(n)
        new_set_list = set_list.copy()
        new_set_list[i] = new_set
        if n == N - 1:
            min_string(new_set_list)
        else:
            dfs(new_set_list, n + 1)
    set_list.append(set([n]))
    if n == N - 1:
        min_string(set_list)
    else:
        dfs(set_list, n + 1)


def min_string(set_list):
    global N

    j = 0
    ret_list = [0 for _ in range(N)]
    for s in set_list:
        for i in s:
            ret_list[i] = j

        j += 1

    print(''.join([chr(j + ord("a")) for j in ret_list]))


def resolve():
    global N
    
    N = [int(x) for x in sys.stdin.readline().split()][0]  
    
    

    
    
    
    

    logger.debug('{}'.format([]))

    dfs([], 0)


if __name__ == "__main__":
    resolve()





import sys
from io import StringIO
import unittest

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)

Solution (Python):
N = int(input())
int2char = {i: chr(i + 96) for i in range(1, 11)}
ans = ['a']
for n in range(2, N+1):
    new_list = []
    for string in ans:
        str_set = set(string)
        for i in range(1, n+1):
            if len(str_set) + 1< i:
                continue 
            new_str = string + int2char[i]
            new_list.append(new_str)
    ans = new_list
ans = sorted(ans)
for a in ans:
    print(a)

Solution (Python):
n = int(input())
alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
def doukei(n):
  if n == 1:
    return [["a", "a"]]
  k = doukei(n-1)
  ans = []
  for i in range(len(k)):
    key = k[i][1]
    ans.append([k[i][0]+"a", key])
    for j in range(1, 10):
      if key == alpha[j-1]:
        ans.append([k[i][0]+alpha[j], alpha[j]])
        break
      else:
        ans.append([k[i][0]+alpha[j], k[i][1]])
  return ans
answer = doukei(n)
for i in range(len(answer)):
  print(answer[i][0])

Solution (Python):

import sys
import itertools

def solve(N: int):
    string = "abcdefghijk"
    if N == 1:
        print("a")
        return


    answer = []
    def dfs(s,various):
        if len(s) == N:
            return s
        new = dfs(s+string[various],various+1)
        if new:
            answer.append(new)

        for i in range(various):
            n = dfs(s+string[i],various)
            if n:
                answer.append(n)

    dfs("a",1)
    answer.sort()
    for i in range(len(answer)):
        print(answer[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 string

normal_set = set()
def reccursion(n, _s, cur):

    if len(_s) == n:
        global normal_set
        normal_set.add(_s)
        
        return

    for i in range(cur + 1):
        next_s = _s + string.ascii_lowercase[i]
        reccursion(n, next_s, cur)
    
    if cur + 1 < n:
        next_cur = cur + 1
        next_s = _s + string.ascii_lowercase[cur + 1]
        reccursion(n, next_s, next_cur)

def solve():
    n = int(input())
    reccursion(n, "a", 0)

    global normal_set
    normal_set = sorted(list(normal_set))
    
    for _s in normal_set:
        print(_s)

if __name__ == "__main__":
    solve()

Solution (Python):
l = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n"]
n = int(input())
ans = [[] for i in range(n)]
ans[0].append("a")

for i in range(1,n):
    
    for j in ans[i-1]:
        a = 0
        for k in j:
            a = max(a,ord(k)-ord("a"))
        for k in range(a+2):
            an = j + l[k]
            ans[i].append(an)
count = ans[-1]
count.sort()
for i in count:
    print(i)

Solution (Python):
import sys
sys.setrecursionlimit(10**5+10)
alp = 'abcdefghij'
N = int(input())
ans = []
def an(i,now,s):
    global ans
    if i == N:
        ans.append(s)
    else:
        for j in range(i+1):
            if j > now+1:
                continue
            an(i+1,max(j,now),s+alp[j])
        
an(0,0,'')
ans.sort()
for i in ans:
    print(i)

Solution (Python):
import sys
n = int(input())
memo_ls = [{i : [] for i in range(11)} for j in range(11)]
alpha = "abcdefghijklmnopqrstuvwxyz"

memo_ls[1][1] = ["a"]
for i in range(1,10):
    for j in range(11):
        if j > i:
            continue
        else:
            for v in memo_ls[i][j]:
                for k in range(j):
                    memo_ls[i + 1][j].append(v + alpha[k])
                memo_ls[i+1][j+1].append(v + alpha[j])
ls = []
for i in range(11):
    for j in memo_ls[n][i]:
        ls.append(j)
print("\n".join(sorted(ls)))

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

s = []

A = "abcdefghijklmnopqrstuvwxyz"

def ss(n):
    if n == 1:
        return [[0]]
    tt = ss(n-1)
    res = []
    for t in tt:
        m = max(t)
        for i in range(m + 2):
            res.append(t + [i])
    return res

for s in ss(N):
    S = ''.join([A[i] for i in s])
    print(S)

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

def f(idx, mx, str):
    
    if idx==n:
        print(str)
        return
    for i in range(mx+1+1):
        f(idx+1, max(i, mx), str+chr(ord('a')+i))

f(0,-1,"")

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

normal_form = ["a"]

n = int(input())
for i in range(n-1):
  new_normal_form = []
  for s in normal_form:
    usingchars = len(set(s))
    for i in range(usingchars+1):
      new_normal_form.append(s+char[i])
  normal_form = new_normal_form

for s in normal_form:
  print(s)

Solution (Python):




def main():
    n = int(input().strip())
    parts("", 0, 0, n)


def parts(char, pos, used, n):
    if pos == n:
        print(char)
        return

    a_ord = ord("a")
    for u in range(used):
        parts(char + chr(a_ord + u), pos + 1, used, n)
    u = used + 1
    parts(char + chr(a_ord + u - 1), pos + 1, u, n)


if __name__ == '__main__':
    main()

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

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

def solve(n):
    if n == 1:
        return ['a']
    elif n == 2:
        return ['aa', 'ab']
    else:
        chars = alphabets[0:n]
        result = []
        for retsu in solve(n - 1):
            done = False
            for char in chars:
                if char in retsu:
                    result.append(retsu + char)
                else:
                    if not done:
                        result.append(retsu + char)
                        done = True
                    else:
                        break
        return result

print("\n".join(solve(N)))

Solution (Python):
n = int(input())
s = [[] for i in range(n+1)]
s[1].append('a')
ans_s = []
for num in range(1,n):
    for st in s[num]:
        for add in range(97, max(map(ord,st))+2):
            s[num+1].append(st + chr(add))
for sw in s[n]:
    print(sw)

Solution (Python):
from sys import stdin
import numpy as np
from operator import itemgetter
import sys
sys.setrecursionlimit(1000000)
N = int(stdin.readline().rstrip().split()[0])

MOD = 10**9 + 7


def f(_arr,a, n, num):
  arr = _arr+[a]
  if n == N:
    
    def print_abc(array):
      abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
      pr = []
      for a in array:
        pr.append(abc[a])
      print("".join(pr))
    print_abc(arr)
    return 0
  for i in range(num+1):
    if i==num:
      f(arr,i,n+1,num+1)
    else:
      f(arr,i,n+1,num)
  
f([], 0, 1, 1)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

def res(n, cur, ln, k):
    if ln == n:
        print(cur)
        return
    for i in range(k+2):
        res(n, cur + chr(ord("a") + i), ln+1, max(k,i))
    


def main():
    n = getN()
    res(n, "a", 1, 0)
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
alph = {'a':'b','b':'c','c':'d','d':'e','e':'f','f':'g','g':'h','h':'i','i':'j','j':'k'}
result = ['a']
for i in range(N-1):
    s = []
    for j in result:
        for k in range(len(j)):
            s.append(j+j[k])
        s.append(j+alph[max(j)])
    result = s

result = list(set(result))
result.sort()
for j in result:
    print(j)

Solution (Python):

D = int(input())

S = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")


def f(x):
    if x == 0:
        return ["a"]

    else:
        t =  f(x - 1)
        r = []
        for s in t:
            num = len(set(list(s)))
            for i in range(num+1):
                r.append(s+S[i])
        return r

ans = f(D-1)


print(" ".join(map(str, ans)))

Solution (Python):



def f(X, n, d):
    if n == 0:
        print(''.join(map(lambda x:chr(x+97), X)))
        return

    for i in range(0, d):
        X[-n] = i
        f(X, n-1, d)

    X[-n] = d
    f(X, n-1, d+1)



N = int(input())
X = [0]*N

f(X, N, 0)

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

alp = [chr(v) for v in range(ord("a"), ord("z") + 1)]

def bitcount(v):
    cnt = 0
    for i in range(n + 1):
        cnt += bool(v & (1 << i))
    return cnt

results = []
def f(i=0, s=""):
    if len(s) == n:
        results.append(s)
        return

    for j in range(i + 1):
        if i != j:
            f(i, s + alp[j])
    f(i + 1, s + alp[i])
f()
print(*results, sep="\n")

Solution (Python):
import collections
n=int(input())
d={'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26, 1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o', 16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v', 23: 'w', 24: 'x', 25: 'y', 26: 'z'}
lc=[["aaa",1],["aab",2],["aba",2],["abb",2],["abc",3]]

ld=[]
for j in range(len(lc)):
    for i in range(1,lc[j][1]+2):
        k=lc[j][0]+d[i]
        c = collections.Counter(k)
        ld.append([k,len(c)])
ld=sorted(ld)

le=[]
for j in range(len(ld)):
    for i in range(1,ld[j][1]+2):
        k=ld[j][0]+d[i]
        c = collections.Counter(k)
        le.append([k,len(c)])
le=sorted(le)

lf=[]
for j in range(len(le)):
    for i in range(1,le[j][1]+2):
        k=le[j][0]+d[i]
        c = collections.Counter(k)
        lf.append([k,len(c)])
lf=sorted(lf)

lg=[]
for j in range(len(lf)):
    for i in range(1,lf[j][1]+2):
        k=lf[j][0]+d[i]
        c = collections.Counter(k)
        lg.append([k,len(c)])
lg=sorted(lg)

lh=[]
for j in range(len(lg)):
    for i in range(1,lg[j][1]+2):
        k=lg[j][0]+d[i]
        c = collections.Counter(k)
        lh.append([k,len(c)])
lh=sorted(lh)

li=[]
for j in range(len(lh)):
    for i in range(1,lh[j][1]+2):
        k=lh[j][0]+d[i]
        c = collections.Counter(k)
        li.append([k,len(c)])
li=sorted(li)

lj=[]
for j in range(len(li)):
    for i in range(1,li[j][1]+2):
        k=li[j][0]+d[i]
        c = collections.Counter(k)
        lj.append([k,len(c)])
lj=sorted(lj)

if n==1:
    print("a")
elif n==2:
    l=["aa","ab"]
    print(*l)

elif n==3:
    for i in lc:
        print(i[0])
elif n==4:
    for i in ld:
        print(i[0])
elif n==5:
    for i in le:
        print(i[0])
elif n==6:
    for i in lf:
        print(i[0])
elif n==7:
    for i in lg:
        print(i[0])
elif n==8:
    for i in lh:
        print(i[0])
elif n==9:
    for i in li:
        print(i[0])
elif n==10:
    for i in lj:
        print(i[0])

Solution (Python):
N=int(input())
li=[chr(i) for i in range(97, 97+26)]
ans=['a']
def nex(ans,n):
    d=[]
    for i in ans:
        for j in range(n):
            if li[j]in i:
                d.append(i+str(li[j]))
            else:            
                k=len(set(i))
                if k+1>=j+1:
                    d.append(i+str(li[j]))
    return d
for i in range(2,N+1):
    ans=nex(ans,i)
for i in ans:
    print(i)

Solution (Python):
N = int(input())
inp = 'a'

def AAA(arr):
    if len(arr) < N:
        for i in range(ord(max(arr))-96+1):
            AAA(arr+chr(i+1+96))
    else:
        print(arr)


AAA(inp)

Solution (Python):
std=[]
n=int(input())
cmb=[[] for i in range(n)]
cmb[0].append("a")
tmp=[[] for i in range(n)]
for i in range(1,n):
	for j in range(len(cmb)):
		for s in cmb[j]:
			for k in range(0,j+1):
				tmp[j].append(s+chr(ord("a")+k))
			tmp[j+1].append(s+chr(ord("a")+k+1))
	
	cmb=tmp
	tmp=[[] for i in range(n)]
lst=[]
for i in range(len(cmb)):
	for std in cmb[i]:
		lst.append(std)
lst.sort()
for i in range(len(lst)):
	print(lst[i])

Solution (Python):
N = int(input())
def adding(s):
    if 'i' not in s:
        if 'h' not in s:
            if 'g' not in s:
                if 'f' not in s:
                    if 'e' not in s:
                        if 'd' not in s:
                            if 'c' not in s:
                                if 'b' not in s:
                                    return [s + 'a',s + 'b']
                                return [s + 'a',s + 'b',s + 'c']
                            return [s + 'a',s + 'b',s + 'c',s + 'd']
                        return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e']
                    return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e',s + 'f']
                return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e',s + 'f',s + 'g']
            return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e',s + 'f',s + 'g',s + 'h']
        return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e',s + 'f',s + 'g',s + 'h',s + 'i']
    return [s + 'a',s + 'b',s + 'c',s + 'd',s + 'e',s + 'f',s + 'g',s + 'h',s + 'i',s + 'j']
def standard(N):
    if N == 1:
        return ['a']
    else:
        A = standard(N-1)
        B = []
        for i in range(0,len(A)):
            B.extend(adding(A[i]))
        return B
A = standard(N)
for i in range(0,len(A)):
    print(A[i])

Solution (Python):
from collections import Counter

N = int(input())

A, B = ['a'], []
for i in range(1, N):
  for a in A:
    for c in 'abcdefghij'[:len(set(a))+1]:
      B.append(a + c)
  A, B = B, []

for a in A:
  print(a)

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

std = deque([])

deque.append(std, ['a', 1])

for i in range(n-1):
    m = len(std)
    for j in range(m):
        tmp = deque.popleft(std)
        tmp_str = tmp[0]
        tmp_val = tmp[1]
        for k in range(tmp_val+1):
            append_chr = chr(ord('a')+k)
            s = tmp_str + append_chr
            if k == tmp_val:
                v = tmp_val+1
            else:
                v = tmp_val
            deque.append(std, [s, v])
            
for s, v in std:
    print(s)

Solution (Python):
n=int(input())
def f(s):
    m=ord(max(list(s))) - 97
    res = [s for _ in range(m+2)]
    for i in range(m+2):
        res[i] += chr(i+97)
    return res
def main(n):
    if n==1:
        return ["a"]
    else:
        ans = []
        for k in main(n-1):
            ans.extend(f(k))
        return ans

ans = main(n)
for i in ans:
    print(i)

Solution (Python):
N = [int(i) for i in input().split()][0]
ordA = ord("a")

def recursion(x, k,  max_c, words):
  if k == 0:
    words.append(x)
    return
  for i in range(max_c+2):
    recursion(x+chr(ordA+i), k-1, max(i, max_c), words) 
  
words = []
recursion("a", N - 1, 0,  words)
for word in words:
  print(word)

Solution (Python):
N = int(input())
ans = ['a']
for i in range(N-1):
  tmpans = []
  for a in ans:
    mx = 0
    for s in a:
      mx = max(ord(s),mx)
    for c in range(ord('a'),mx+2):
      tmpans.append(''.join(list(a)+[chr(c)]))
  ans = tmpans[:]
for a in sorted(ans):
  print(a)

Solution (Python):
alp = ["a","b","c","d","e","f","g","h","i","j"]
N = int(input())
ans_list = []
for i in range(N):
    ans_list.append([])
for i in range(N):
    if i == 0:
        ans_list[i].append(["a",1])
    else:
        for j in range(len(ans_list[i-1])):
            for l in range(ans_list[i-1][j][1]+1):
                temp = ans_list[i-1][j][0] + alp[l]
                if l == ans_list[i-1][j][1]:
                    chk = ans_list[i-1][j][1]+1
                else:
                    chk = ans_list[i-1][j][1]
                ans_list[i].append([temp,chk])
for i in range(len(ans_list[N-1])):
    print(ans_list[N-1][i][0])

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

my_list = []
for i in range(N):
    if i == 0:
        my_list.append("a")
        continue
    new_list = []
    while my_list:
        s = my_list.pop(0)
        for j in range(ord("a"), ord(max(s)) + 2):
            new_list.append(s + chr(j))
    my_list += new_list
my_list.sort()

[print(s) for s in my_list]

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

Solution (Python):
n=int(input())
a=[[] for i in range(n)]
a[0]=[0]
k=0
s=['a']*n
t=[0]*n
while k>=0:
  if a[k]==[]:
    k-=1
    continue
  t[k]=a[k].pop(0)
  s[k]=chr(ord('a')+t[k])
  if k==n-1:
    print("".join(s))
  else:
    k+=1
    a[k]+=list(range(max(t[:k])+2))

Solution (Python):

import sys
from io import StringIO
import unittest

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

def yn(b):
    print("Yes" if b==1 else "No")
    return

def loopx(used,ans,anslen,nn):
    for x in range(0,used+2):
        ans2 = ans + base[x]
        anslen2=anslen+1
        if x==(used+1):
            used+=1
        if anslen>=nn:
            print(ans2)
        else:
            loopx(used,ans2,anslen2,nn)



inn=int(input())

loopx(-1,"",0,inn-1)

sys.exit()

Solution (Python):


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

def get_str(seq_list):
    result = []
    for seq in seq_list:
        used_char_num = len(set(seq))
        for i in range(used_char_num + 1):
            result.append(seq + chars[i])
    return result

N = int(input())

seq_list = ["a"]
for i in range(N - 1):
    tmp = seq_list[:]
    seq_list = get_str(tmp)

for s in seq_list:
    print(s)

Solution (Python):
N = int(input())
dp = [[] for _ in range(N+1)]
dp[1] = [["a"]]
for i in range(2,N+1):
    for j in range(len(dp[i-1])):
        for k in range(len(set(dp[i-1][j]))+1):
            dp[i].append(dp[i-1][j]+[chr(97+k)])
ans = dp[N]
for i in range(len(ans)):
    print("".join(ans[i]))

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

    alp=["a","b","c","d","e","f","g","h","i","j"]
    for i in range(1,N+1):
        if i==1:
            d.append(["a",1])
        else:
            while True:
                s=d.popleft()
                if len(s[0])!=i-1:
                    d.appendleft(s)
                    break
                else:
                    for j in range(s[1]+1):
                        if j!=s[1]:
                            d.append([s[0]+alp[j],s[1]])
                        else:
                            d.append([s[0]+alp[j],s[1]+1])

    res=[]
    l=len(d)
    for i in range(l):
        res.append(d.pop()[0])

    res.sort()
    for i in range(l):
        print(res[i])
if __name__=="__main__":
    main()

Solution (Python):
def main():
    N=int(input())
    
    if N == 1:
        print('a')
        return

    a=['a']
    for k in range(1,N):
        b=[]
        for t in a:
            s = set(t)
            not_in_set = True
            for i in range(k+1):
                add_char = chr(ord('a')+i)
                if add_char in s:
                    b.append(t + add_char)
                else:
                    if not_in_set:
                        b.append(t + add_char)
                        not_in_set = False
        a=b
    for s in a:
        print(s)
    return

if __name__ == '__main__':
    main()

Solution (Python):

import glob



REL_PATH = 'ABC\\159\\D'


TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    alph = []

    def rec(self, result, now, max, N):

        if now == N:
            res = ""
            for i in result:
                res += self.alph[i]
            print(res)
            return

        if now == 0:
            result[0] = 0
            self.rec(result, now+1, 0, N)
            return

        for i in range(0, max+2):
            if i == N:
                return
            result[now] = i
            if i > max:
                self.rec(result, now+1, i, N)
            else:
                self.rec(result, now+1, max, N)

    def resolve(self):

        N = int(self.input_data())

        self.alph = "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".split(",")
        self.result = [0 for i in range(N)]
        self.rec(self.result, 0, 0, N)


solver = Solver(REL_PATH)
solver.exec_resolve()

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

d = 'abcdefghijklm'


def solve(a):
    *u, = map(lambda x: d[x], a)
    return ''.join(u)


ans = [0]*n


if n == 1:
    print('a'*n)
    exit()

while ans[0] == 0:
    print(solve(ans))
    if ans == [i for i in range(n)]:
        exit()
    q = max(ans[:n-1])
    if ans[n-1] <= q:
        ans[n-1] += 1
    else:
        j = 0
        while ans[n-1-j] > max(ans[:n-1-j]):
            ans[n-1-j] = 0
            j += 1
        ans[n-1-j] += 1

Solution (Python):
n=int(input())
L=["a"]
for i in range(n-1):
    tmp=[]
    for j in range(len(L)):
        for k in range(len(set(L[j]))+1):
            tmp.append(L[j]+chr(ord("a")+k))
    L=tmp
for j in range(len(L)):
    print(L[j])

Solution (Python):

class Solution:

    def solve(self, N: int):

        def dfs(prev_str, num_used_char):
            if len(prev_str) == N:
                print(prev_str)
                return

            for i in range(num_used_char):
                c = chr(ord('a') + i)
                dfs(prev_str + c, num_used_char)

            c = chr(ord('a') + num_used_char)
            dfs(prev_str + c, num_used_char + 1)

        dfs('a', 1)


if __name__ == '__main__':

    
    N = int(input())
    
    solution = Solution()
    answer = solution.solve(N)

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

alpha = alpha[:N]

counter = 1

def num(s):
    counter = 0
    for i in range(len(s)):
        if s[i] not in s[:i]:
            counter += 1
    return counter

while counter != N: 
    l1 = []
    for i in range(len(l)):
        for j in range(num(l[i])+1):
            l1.append(l[i]+alpha[j])
    l = l1[:]
    counter += 1
l.sort()

for k in range(len(l)):
    print(l[k])

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


def p(s,m,i,last):
    
    if i==last-1:
        print("".join([chr(97+j)for j in s]))
        return
    for k in range(m+2):
        S=copy(s)
        S.append(k)
        p(S,max(m,k),i+1,last)

def main():
    n=int(input())
    s=[0]
    p(s,0,0,n)

main()

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

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

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())

def check_ans(nums):
    cnt = 0
    for num in nums:
        num = int(num)
        if num == cnt:
            cnt += 1
        elif num < cnt:
            pass
        else:
            return False
    return True

def make_anss(anss, n):
    new_anss = []
    ns = [str(i) for i in range(n + 1)]
    for ans in anss:
        for n in ns:
            p_anss = ans + n
            if check_ans(p_anss):
                new_anss.append(p_anss)
    return new_anss

anss = ["0"]
for i in range(N - 1):
    anss = make_anss(anss, i + 1)

dics = {
    "0": "a",
    "1": "b",
    "2": "c",
    "3":"d",
    "4":"e",
    "5":"f",
    "6":"g",
    "7":"h",
    "8":"i",
    "9":"j"
    }

for ans in anss:
    print(ans.translate(str.maketrans(dics)))

Solution (Python):
n=int(input())
ans = ['a']
for i in range(1,n):
    ans_ = []
    for j in ans:
        for k in range(ord(max(j))-95):
            ans_.append(j+chr(97+k))
    ans = ans_.copy()
    
ans = sorted(ans)
for i in ans:
    print(i)

Solution (Python):
import copy

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

n = int(input())

value = ['a']
for i in range(10):
    if len(value[0]) == n:
        break
    tmp_value = copy.copy(value)
    value = []
    for v in tmp_value:
        for j in range(n):
            value.append(v + ab[j])
            if ab[j] not in v:
                break
for v in value:
    print(v)

Solution (Python):
import sys
import math
import copy
import queue
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]

n = int(input())

def x(s,m,d):
    if d >= n:
        ans = ''
        for i in range(n):
            ans += chr(ord('a') + s[i])
        print (ans)
        return
    for i in range(m+1):
        ss = s + [i]
        m = max(m,i+1)
        x(ss,m,d+1)

x([0],1,1)

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)

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

def rec(S, depth, count):
    if depth == N:
        print(''.join(S))
        return
    for i in range(count+1):
        S.append(data[i])
        if i == count:
            count += 1
        rec(S, depth+1, count)
        S.pop()


rec([], 0, 0)

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

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

ans = []
def f(List, n):
    if n == N:
        s = ""
        for l in List:
            s += L[l]
        ans.append(s)
        return None
    for i in range(max(List)+2):
        f(List+[i], n+1)

f([0], 1)        
ans.sort()
for a in ans:
    print(a)

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

pre = [[0]]
ans = [[0]]
s = 'abcdefghijklmnop'

for i in range(n-1):
    ans = []
    for item in pre:
        for j in range(max(item)+2):
            ans.append(item + [j])
    pre = ans[:]

res = []
for item in ans:
    print("".join([s[c] for c in item]))