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 itertools import combinations
alpha = "abcdefghijklmnopqrstu"
n = int(input())
ans = []
for i in range(1, n+1):
    c = combinations(range(1, n), i-1)
    for ci in c:
        for s in range(i**(n-i)):
            res = 'a'
            now = 1
            j = 0
            while now<=n-1:
                while j<i-1 and now == ci[j]:
                    res+=alpha[j+1]
                    j+=1
                    now+=1
                    if now>n-1:
                        break
                if now>n-1:
                        break
                t = s%i
                if t<=j:
                    res+=alpha[t]
                else:
                    break
                now+=1
                s//=i
            if len(res) == n:
                ans.append(res)          
ans.sort()
print(*ans, sep = '\n')

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

alphabets = "abcdefghij"

def call( n, string, limit):
  """stringに対してn回後ろに付与するとしたらどうなるか、リストで頂戴。
  limitまでの文字しか使っちゃダメたよ"""
  if n ==0 :
    return set([string])
  
  res = set()
  for char in alphabets[:limit]:
    
    res |= call(n-1, string+char, limit)
  res |= call(n-1, string+alphabets[limit], limit+1)
  return res
  
for i in sorted(list(call(N-1, "a", 1))):
  print(i)

Solution (Python):
N, = list(map(int, input().split()))


def gen(path, maxOrd):
    if len(path) == N:
        print("".join(chr(ord("a") + x) for x in path))
    else:
        for x in range(maxOrd + 2):
            path.append(x)
            gen(path, max(maxOrd, x))
            path.pop()


gen([], -1)

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

q = [(1, [0])]
for i in range(N - 1):
    old_q = q
    q = []
    for m, l in old_q:
        for apd in range(m):
            q.append((m, l + [apd]))
        q.append((m + 1, l + [m]))

ans = ["".join([chr(x + 97) for x in xx[1]]) for xx in q]
print(
    *ans,
    sep="""
"""
)

Solution (Python):
def next(S='a'):
    idx = len(S)
    cnt = len(set(list(S)))
    if idx == N:
        print(S)
        return
    for i in range(min(N,idx)+1):
        if cnt < i:
            break
        next(S +ls[i])


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

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


lis = [[0]]
for i in range(n-1):
  temp = []
  for s in lis:
    next = max(s) + 1
    for j in range(0, next+1):
      temp.append(s + [j])
  else:
    lis = temp


for s in lis:
  for char in s:
    print(moji[char], end="")
  print()

Solution (Python):
n=int(input())
s="abcdefghij"
ans=[["a",1]]
def solve():
	for x in ans:
		if len(x[0])<n:
			for j in range(x[1]+1):
				if j<=x[1]-1:
					ans.append([x[0]+s[j],x[1]])
				else:
					ans.append([x[0]+s[j],x[1]+1])
solve()
ans.sort()
for x in ans:
	if len(x[0])==n:
		print(x[0])

Solution (Python):
from string import ascii_lowercase as abc
from itertools import product
def inpl(): return list(map(int, input().split()))

N = int(input())
ans = []
searched = set()
trans = str.maketrans({k: v for k, v in zip(list("0123456789"), list(abc[:10]))})
for X in product(*[range(x) for x in range(1, N+1)]):
    checked = [-1]*10
    res = 0
    i = 0
    for x in X:
        res *= 10
        if checked[x] == -1:
            checked[x] = i
            i+= 1
        res += checked[x]
    if not res in searched:
        searched.add(res)
        ans.append(res)
    
for a in sorted(ans):
    print(str(a).zfill(N).translate(trans))

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


n = ii()
dp = []
dp.append((1,"a"))
for i in range(1,n):
    dpat = []
    tmp = i+1
    for j in range(len(dp)):
        for i in range(dp[j][0] + 1):
            if i == dp[j][0]:
                dpat.append((i+1,dp[j][1] + chr(97+i)))
            else:
                dpat.append((dp[j][0],dp[j][1] + chr(97+i)))
    dp = dpat
if n == 1:
    print("a")
else:
    for i in range(len(dp)):
        print(dp[i][1])

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

ans = [[] for _ in range(11)]
ans[0].append("a")
for i in range(10):
    for e in ans[i]:
        idx = 0
        for c in e:
            idx = max(idx, ord(c)-ord('a'))
        for j in range(idx+2):
            ans[i+1].append(e+chr(ord("a")+j))
for i in range(len(ans[N-1])):
    print(ans[N-1][i])

Solution (Python):

if False:
    A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K=int(input())
    print(A[K-1])


if False:
    H,W=map(int,input().split())
    ans=0
    if H==1 or W==1:
        ans+=1
    else:
        ans+=(H//2)*W
        if H%2!=0:
            ans+=W//2
            ans+=W%2
    print(ans)


if False:
    A,B,C=map(int,input().split())
    if 4*A*B<(C-A-B)**2:
        if C-A-B>=0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')


from collections import deque

N=int(input())
alp='abcdefghijkl'
q=deque()
q.append(['a',1])
ans=[]
while q:
    s,i=q.popleft()
    if len(s)==N:
        ans.append(s)
    else:
        for j in range(i+1):
            
            tmp=[]
            tmp.append(s+alp[j])
            tmp.append(max(i,j+1))
            q.append(tmp)
            
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Solution (Python):
ans = []
type = [[1]]
que = []
N = int(input())
for i in range(N-1):
    que = type
    type = []
    while len(que) != 0:
        t = que.pop()
        ma = max(t)
        for j in range(1,ma+2):
            type.append(t + [j])
type.sort()
char = " abcdefghijklmnopqrstuvwxyz"
for a in type:
    print("".join(map(lambda x: char[x], a)))

Solution (Python):
input = raw_input

alphas = "abcdefghijklmnopqrs"

n = int(input())

if n == 1:
    print("a")
elif n == 2:
    for out in ["aa", "ab"]:
        print(out)

elif n >= 3:
    former_prefixs = ["aa", "ab"]
    next_i = 3
    while True:
        cur_prefixs = []
        for prefix in former_prefixs:
            prefix_nc = len(set(prefix))
            for c in alphas[:prefix_nc+1]:
                out = prefix + c
                if next_i == n:
                    print(out)
                cur_prefixs.append(out)

        if next_i == n:
            break
        next_i += 1
        former_prefixs = cur_prefixs

Solution (Python):
n = int(input())
def all_search(array):
    if len(array) == n:
        print(array)
    else:
        kind = len(set(array))
        fin = min(kind + 1, len(array) + 1)
        for i in range(fin):
            res = array + chr(i + ord('a'))
            all_search(res)
all_search("")

Solution (Python):
N = int(input())
n = [[] for i in range(11)]
s = [[] for i in range(11)]
s[0].append('a')
n[0].append(1)
for i in range(10):
    for j in range(len(s[i])):
        for k in range(n[i][j]+1):
            temp = s[i][j]
            s[i+1].append(temp + chr(97+k))
            if k == n[i][j]:
                n[i+1].append(n[i][j]+1)
            else:
                n[i+1].append(n[i][j])

for i in range(len(s[N-1])):
    print(s[N-1][i])

Solution (Python):
import sys, math

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

prev = ["a"]
cands = "abcdefghijklmnopqrstuvwxyz"
for i in range(1, n):
    current = []
    
    for one in prev:
        count = len(set(list(one)))
        for j in range(count+1):
            current.append(one + cands[j])
    prev = current

for one in prev:
    print(one)

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def dfs(k,l):
    if k==n+1:
        print(''.join(l))
    else:
        m = len(set(l))
        for i in range(m+1):
            c = chr(ord('a')+i)
            l.append(c)
            dfs(k+1,l)
            l.pop()

n = inn()
dfs(2,['a'])

Solution (Python):
N = int(input())
S = [['a',1]]
import copy

for i in range(N-1):
    tmp = []
    for j in S:
        s = j[0]
        n = j[1]
        for k in range(n+1):
            tmp.append([''.join([s,chr(k+97)]), max(n,k+1)])
    S = copy.deepcopy(tmp)
for i in S:
    s = i[0]
    print(s)

Solution (Python):
import collections
import copy

ans = ["a"]
now = ["a"]
N=int(input())
for i in range(1,N):
    ans=[]
    for c in now:
        mojisuu = len(collections.Counter(c).values())
        for j in range(mojisuu+1):
            ans.append(c+chr(j+97))
    now = copy.deepcopy(ans)

for c in ans:
    print(c)

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

def dfs(N, s, c):
    if N == n:
        s = "".join([chr(int(i) + 97) for i in s])
        print(s)

    else:
        for i in range(c+1):
            dfs(N + 1, s+str(i), c+1 if i == c else c)

dfs(0, "", 0)

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


def max2(s):
    return max(map(lambda c: ord(c) - ord('a'), s))


ans = ['a']
for _ in range(n - 1):
    ans2 = []
    for a in ans:
        for i in range(max2(a) + 2):
            ans2.append(a + chr(i + ord('a')))
    ans = ans2

for a in ans:
    print(a)

Solution (Python):
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7





def solve(chars, char):
    idx = []
    for i, c in enumerate(chars):
        if not c:
            idx.append(i)
    if not idx:
        if chars == ['a', 'a', 'b']:
            pass
        return [''.join(chars)]
    ret = []
    d = chr(ord(char) + 1)
    chars[idx[0]] = char
    ret += solve(chars, d)
    for cnt in range(1, len(idx)):
        for choices in itertools.combinations(idx[1:], r=cnt):
            for i in choices:
                chars[i] = char
            ret += solve(chars, d)
            for i in choices:
                chars[i] = ''
    chars[idx[0]] = ''
    return ret


N = int(sys.stdin.buffer.readline())
ans = solve([''] * N, 'a')
ans.sort()
print(*ans, sep='\n')

Solution (Python):
n=int(input())
from collections import deque
d=deque()
e=deque()
d.append(("a",0))

alpha=list("abcdefghijklmnopqrstuvwxyz")
dic={alpha[i]:i for i in range(26)}
for i in range(n-1):
    while d:
        x,y=d.popleft() 
        for j in range(y+2):
            e.append((x+alpha[int(j)],max(y,j)))
    d=e
    e=deque()
d=list(d)
if n==1:
    print("a")
else:
    d=sorted(d,key=lambda x:x[0])
    for some in d:
        print(some[0])

Solution (Python):
ALPHA = 'abcdefghij'
N = int(input())
ans = [('', 0)]
for _ in range(N):
    temp = []
    for s, num in ans:
        for a in ALPHA[:num]:
            t = s + a
            temp.append((t, num))
        temp.append((s + ALPHA[num], num + 1))
    ans = temp
for a, _ in ans: print(a)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
res = set()
a = ord("a")
def dfs(s, x):
  global res
  if len(s) == N:
    res.add(s)
    return
  for i in range(x + 1):
    dfs(s + chr(a + i), x)
  dfs(s + chr(a + x + 1), x + 1)

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

Solution (Python):

from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"




def main():
    a,b,c = mi()
    if c-a-b<=0:
        print(no)
        exit()
    else:
        if (c-a-b)**2 > 4*a*b:
            print(yes)
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "YES"
no = "NO"

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


def makealpha(n,depth,tmp,maxtmp):
    if depth == n:
        tmpalpha = ''
        for i in tmp:
            tmpalpha+=alpha[i]
        print(tmpalpha)
    else:
        
        for i in range(maxtmp+2):
            tmptmp = deepcopy(tmp)
            tmptmp.append(i)
            maxtmp = max(maxtmp,i)
            makealpha(n,depth+1,tmptmp,maxtmp)
    return 0


def main():
    n = ii()
    makealpha(n,1,[0],0)

    


main()

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

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

ans = [[0]]

for i in range(n-1):
  new_ans = [
    i + [j]
    for i
    in ans
    for j
    in range(min(10, max(i) + 2))
  ]
  ans = new_ans

for i in ans:
  print("".join(d[j] for j in i))

Solution (Python):
def dfs(gen,naga,saidai):
    global n,ans
    if(naga==n):
        ans.append(gen)
        return
    gen*=10
    for i in range(saidai+2):
        dfs(gen+i,naga+1,max(saidai,i))

n=int(input())

ans=[]
dfs(0,1,0)
alpha=["a","b","c","d","e","f","g","h","i","j"]

retu=["a"]*n
for a in ans:
    s=str(a)
    for i in range(n):
        if(i<n-len(s)):
            retu[i]="a"
        else:
            retu[i]=alpha[int(s[i-n+len(s)])]
    print("".join(retu))

Solution (Python):
alpha = ['a','b','c','d','e','f','g','h','i','j']
N=int(input())
res=['a']
if N >1:
    for i in range(N-1):
        length=len(res)
        new = []
        for x in range(length):
            kind = len(set(res[x]))
            for y in range(kind+1):
                new.append(str(res[x]+alpha[y]))
        res=new
for i in range(len(res)):
    print(res[i])

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


Z = 'abcdefghijklmn'
def solve(N):
    if N == 1:
        return [(1, "a")]
    result = []
    for n, s in solve(N-1):
        for i in range(n+1):
            result.append((max(n, i+1), s+Z[i]))
    return result

for s in sorted(s for i, s in solve(N)):
    print(s)

Solution (Python):
mem = [([0],0)]
N = int(input().strip())
for i in range(1,N):
  next_mem = []
  for seq, n_max in mem:
    next_mem += [(seq+[n], max(n_max, n)) for n in range(n_max+2)]
  mem = next_mem
    
S = 'abcdefghij'
for seq, n_max in mem:
  print(''.join(S[n] for n in seq))

Solution (Python):
N=int(input())
l=["a","b","c","d","e","f","g","h","i","j"]
def hu(t,c,n):
    if n<N:
        for i in range(0,c):
            hu(t+[i],c,n+1)
        hu(t+[c],c+1,n+1)
    else:
        pr(t)
def pr(t):
    for i in t:
        print(l[i],end="")
    print()
hu([0],1,1)

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

l = [[1,0]]

for _ in range(n - 1):
    l1 = []
    for i in range(len(l)):
        l2 = l[i]
        for j in range(l2[0]+1):
            l3 = l2 + [j]
            if j == l2[0]:
                l3[0] = j + 1
            l1.append(l3)
    l = l1
w = ["a","b","c","d","e","f","g","h","i","j"]
ls = []
for i in range(len(l)):
    s = "a"
    for j in range(2,len(l[i])):
        s += w[l[i][j]]
    ls.append(s)

ls.sort()

for i in range(len(l)):
    print(ls[i])

Solution (Python):
N = int(input())
lex = [chr(i) for i in range(97,123)]

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

def equiv(s, n, pat) :
    if n == N-1 :
        for i in range(pat+1) :
            print(s + lex[i])
    else :
        for i in range(pat+1) :
            if i == pat :
                equiv(s+lex[i], n+1, pat+1)
            else :
                equiv(s+lex[i], n+1, pat)
    return True

equiv("a", 1, 1)

Solution (Python):
n=int(input())
def f(s):
  return len(set([s[i] for i in range(len(s))]))
alphabet = [chr(i) for i in range(97, 97+26)]
for i in range(1,n+1):
  if i==1:
    iso=["a"]
  else:
    iso_new=[]
    for s in iso:
      for j in range(f(s)+1):
        iso_new.append(s+alphabet[j])
    iso = list(set(iso_new))

iso.sort()
for s in iso:
  print(s)

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input().strip())

    path = []

    def backtrack(seen):
        if len(path) == n:
            print("".join(path))
            return
        for i in range(seen + 1):
            path.append(chr(ord("a") + i))
            backtrack(max(seen, i + 1))
            path.pop()
    
    backtrack(0)




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

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

def dfs(s):
    l = len(Counter(list(s)))
    if len(s) == N:
        print(s)
    else:
        for i in range(l+1):
            dfs(s+chr(i+97))
    return 
dfs("a")

Solution (Python):
N = int(input())
def func(X,n):
    if len(X) == N:
        return [X]
    ans = []
    for i in range(n):
        ans += func(X+chr(ord('a')+i),n)
    ans += func(X+chr(ord('a')+n) , n+1)

    return ans

for ans in func('a',1):
    print(ans)

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



ans=[[] for i in range(10)]


for i in range(n):
    if i==0:
        ans[i].append(["a",1])
    else:
        for moji,index in ans[i-1]:
            for plus in range(index):
                new=moji+chr(plus+97)
                ans[i].append([new,index])
            new=moji+chr(index+97)
            ans[i].append([new,index+1])

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

Solution (Python):
A = [ [ ] for i in range(11)]
A[1].append('a')
n = 1
for i in range(1,10):
    B = A[i]
    for b in B:
        x = 0
        for k in range(i):
            c = b[k]
            x = max(ord(c),x)
        for j in range(97,x+2):
            d = b + chr(j)
            A[i+1].append(d)
N = int(input())
for a in A[N]:
    print(a)

Solution (Python):
n = int(input())
def f(l):
	return "".join([chr(x+97) for x in l])

ans = [[] for _ in range(n)]
ans[0] = [[0]]
for i in range(1, n):
	for a in ans[i-1]:
		for j in range(max(a)+2):
			ans[i].append(a+[j])

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

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

A = ord("a")
a2z = [chr(A + i) for i in range(26)]

all_patterns = []

def fill(values, c, i, n):

	if i == N:
		if n == N:
			all_patterns.append("".join(values))
		else:
			for i in range(N):
				if values[i] == None:
					values[i] = a2z[c + 1]
					fill(values, c + 1, i + 1, n + 1)
					values[i] = None
					break
	else:
		if values[i] == None:
			values[i] = a2z[c]
			fill(values, c, i + 1, n + 1)
			values[i] = None
		fill(values, c, i + 1, n)

fill([a2z[0]] + [None] * (N - 1), 0, 1, 1)


all_patterns.sort()
for pattern in all_patterns:
	print(pattern)

Solution (Python):
N = int(input())
char = "abcdefghij"
prev = ["a"]
results = []
for i in range(N-1):
  results = []
  for p in prev:
    for j in range(len(set(p))+1):
      results.append(p+char[j])
  prev = results
if N == 1:
  print("\n".join(prev))
else:
  print("\n".join(results))

Solution (Python):
def main():
    from functools import lru_cache
    from string import ascii_lowercase
    import sys
    sys.setrecursionlimit(10 ** 7)

    @lru_cache(maxsize=None)
    def dfs(curr: '0-indexed' = 0, max_char_index: int = -1):
        if curr == N:
            return ['']

        ret = []
        for i, c in enumerate(ascii_lowercase):
            if i > max_char_index + 1: break
            for d in dfs(curr + 1, max_char_index + (1 if i == max_char_index + 1 else 0)):
                ret.append(c + d)

        return ret

    N = int(input())
    res = dfs()
    print(*res, sep='\n')


if __name__ == '__main__':
    main()

Solution (Python):
import bisect, collections

def helper(n, d, cur):
    if (n, cur) in d:
        return d[(n, cur)]
    if n == 1:
        return [chr(ord('a')+i) for i in range(0, min(25, cur+1)+1)]
    res = []
    for i in range(0, min(25, cur+1)+1):
        for x in helper(n-1, d, max(cur, i)):
            res.append(chr(ord('a')+i)+x)
    d[(n, cur)] = res
    return res

def solution():
    N = int(input().strip())
    res = []
    d = collections.defaultdict(list)
    for x in helper(N, d, -1):
        print(x)
    


def main():    
    
    for _ in range(1):
        solution()
    

main()

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]


def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n = int(input())
ord_a = ord("a")
ans = []
def dfs(s,k):
    if n == len(s):
        ans.append(s)
        return
    for i in range(k+1):
        dfs(s+chr(ord_a + i), k if i!=k else k+1)

dfs("a", 1)

ans.sort()
print("\n".join(ans))

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


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


dfs(1, 'a')

Solution (Python):
n = int(input())
s = [('', 0)]
cnt = 0
ans = []
while s:
    t, k = s.pop()
    if len(t) == n:
        ans.append(t)
    else:
        s.append((t + chr(k + 97), k + 1))
        for i in range(k - 1, -1, -1):
            s.append((t + chr(i + 97), k))
ans.sort()
for row in ans:
    print(row)

Solution (Python):

import sys
import copy

def int2char(x):
    return chr(ord('a')+x)


N = int(input())
dp = ['a']
for i in range(N-1):
    nxt = []
    for s in dp:
        sets = set()
        for t in s:
            sets.add(t)
        for i in range(len(list(sets))+1):
            nxt.append(s+int2char(i))
    dp = copy.copy(nxt)

for s in dp:
    print(s)

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


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


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


def add(S):
    S2 = []
    for n, s in S:
        for m in range(0, n + 1):
            w = chr(ord("a") + m)
            if m == n:
                S2.append((n + 1, s + w))
            else:
                S2.append((n, s + w))
    return S2


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

    S = [(0, "")]
    for _ in range(N):
        S = add(S)
    
    for _, s in S:
        print(s)
    

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] += [''.join([x, chr(97+j)]) for j in range(i+1) for x in w[i]]
        nw[i+1] += [''.join([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):
N = int(input())
k = "abcdefghij"
A = []
Q = [(1,1,"a")]
while Q:
    q = Q.pop()
    if q[0]==N:
        A.append(q[2])
        continue
    for i in range(q[1]+1):
        Q.append((q[0]+1,max(q[1],i+1),q[2]+k[i]))
A.sort()
for a in A:print(a)

Solution (Python):
li = ['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']
n = int(input())
ans = ['a']
for i in range(1,n):
    ans_new = []
    for j in range(len(ans)):
        s = ans[j]
        ma = 0
        for l in range(len(s)):
            ma = max(ma,li.index(s[l]))
        for k in range(ma+2):
            ans_new.append(s+li[k])
    ans = ans_new
for a in ans:
    print(a)

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


def rec(d, now, kind):
    if d == N:
        print(now)
        return
    for i in range(kind):
        rec(d + 1, now + a[i], kind)
    rec(d + 1, now + a[kind], kind + 1)

rec(1, 'a', 1)

Solution (Python):
import sys

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

if N==1:
    print('a')
    sys.exit()

def rank(l):
    return len(set(list(l)))

for i in range(N-1):
    L.append([])
    for j in L[i]:
        for k in range(rank(j)+1):
            
            
            L[i+1].append(j+moji[k])



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

Solution (Python):
alphabet = [chr(i) for i in range(97, 97+26)]
ans = []
N = int(input())


def makeS(S, now):
    if len(S) == N:
        ans.append(S)
        return
    for i, c in enumerate(alphabet[:now+1]):
        if i == now:
            makeS(S+c, now + 1)
        else:
            makeS(S+c, now)


makeS('a', 1)
for s in sorted(ans):
    print(s)

Solution (Python):
n = int(input())
al = "abcdefghijklmn"
s = [("a", 1)]
for i in range(n-1):
    ss = []
    for j in range(len(s)):
        for k in range(s[j][1]+1):
            ss.append((s[j][0] + al[k], s[j][1] + (k == s[j][1])))
    s = ss
for i in range(len(s)):
    print(s[i][0])

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

lst = [['a']]
for i in range(N - 1):
    n = len(lst)
    tmp_lst = []
    tmp_append = tmp_lst.append
    for j in range(n):
        tmp = lst[j]
        count = len(set(tmp))
        for k in range(count + 1):
            tmp_append(tmp + [chr(k + 97)])
    lst = tmp_lst
lst.sort()

for tmp in lst:
    print (*tmp, sep = '')

Solution (Python):
n = int(input())
anstmp = ["a"]
cnt = 0
for i in anstmp:
  t = max(ord(k) for k in i)-95
  if cnt > 100000:
    break
  for j in range(1,t+1):
    anstmp.append(i+chr(j+96))
  cnt += 1
ans = set()
for i in anstmp:
  if len(i) == n:
    ans.add(i)
ans = list(ans)
ans.sort()
print(*ans,sep="\n")

Solution (Python):
n=int(input())
ans=[]
def b(s):
  if len(s)==n:
    ans.append(s)
    return
  for i in "abcdefghijklmnopqrstuvwxyz":
    b(s+i)
    if max(list(s))==chr(ord(i)-1):return
b("a")
ans.sort()
for i in ans:print(i)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
INF = 500000
mod = 10**9+7

cs = atoz = [chr(i) for i in range(97,97+10)]

N = int(input())

def Str(i, m, S):
    if i == N:
        print(S)
        return
    for c in cs[:m]:
        Str(i+1, m, S+c)
    Str(i+1, m+1, S+cs[m])

Str(0, 0, '')

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

al = [chr(ord('a') + i) for i in range(26)]

def dfs(idx, tmp):
    if idx == n:
        return [tmp]
    else:
        ret = []
        nexts = list(set(list(tmp)))
        nexts.sort()
        nexts.append(chr(ord(nexts[-1]) + 1))
        for x in nexts:
            ret += dfs(idx + 1, tmp + x)
        return ret

ans = dfs(1, 'a')
ans.sort()
for a in ans:
    print(a)

Solution (Python):
def dfs(n,N,s):
    L=[]
    if n==N:
        return s
    alps='abcdefghijklmnopqrstuvwxyz'
    
    for alp in alps[:len(set(list(s)))+1]:
        out=dfs(n+1,N,s+alp)
        if n+1==N:
            L.append(out)
        else:
            L+=out
    return L

def main():
    import sys
    import math
    N=int(sys.stdin.readline())

    for s in dfs(0,N,''):
        print(s)

if __name__ == '__main__':
    main()

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


ans = [['a']]
for i in range(1, N):
  ans.append([])
  for s in ans[i-1]:
    n = len(set(s))
    for j in range(n+1):
      ans[i].append(s+strlist[j])

ans.sort()
print(*ans[-1], sep='\n')