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())
alphabet = 'abcdefghijk'

def ans(n):
    if n == 1:
        return ['a']
    ret = []
    pre = ans(n-1)
    for s in pre:
        l = len(set(s))
        for i in range(l+1):
            ret.append(s + alphabet[i])
    return ret

for s in ans(n):
    print(s)

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

def f(frm, l, head):
    if l == 0:
        res.append(head)
    for i in range(l, 0, -1):
        for j in range(frm):
            f(frm, l - i, head + chr(ord('a') + j) * i)
        f(frm + 1, l - i, head + chr(ord('a') + frm) * i)
    
f(0, n, '')
print(*sorted(list(set(res))), sep='\n')

Solution (Python):
N = input()

def f(s, c):
  if len(s)>=N:
    print s
  else:
    for i in range(c+1):
      f(s+chr(ord("a")+i), max(i+1, c))
f("", 0)

Solution (Python):
string = []
kind = 0

alphabet = "abcdefghijklmno"

def dfs(n):
    global string, kind
    if n == 0:
        print("".join(string))
        return
    for i in range(kind):
        string.append(alphabet[i])
        dfs(n-1)
        string.pop()
    string.append(alphabet[kind])
    kind += 1
    dfs(n-1)
    kind -= 1
    string.pop()

dfs(int(input()))

Solution (Python):
n = int(input())
l = [[[],0]]
for i in range(n):
    nxt = []
    for li, ma in l:
        for j in range(ma+1):
            lj = li[:]
            lj.append(j)
            if j == ma:
                nxt.append([lj, ma+1])
            else:
                nxt.append([lj, ma])
    l = nxt

ans = []
aa = ord("a")
for li,_ in l:
    ans.append("".join(map(lambda x: chr(x+aa), li)))
ans.sort()
print(*ans, sep="\n")

Solution (Python):

N = int(input())

alp = "abcdefghijklmnopqrstuvwxyz"

ans =  [ ["",0] ]


for i in range(N):

    nex = []

    for s,i in ans:

        for j in range(i+1):

            nex.append([s+alp[j] , max(i,j+1)])

    ans = nex
    

ans.sort()

for s,i in ans:
    print (s)

Solution (Python):
n=int(input())
if n==1:
    print('a')
    exit()
ans=['a']
al=list('abcdefghijklmnopqrsruvwxyz')
for i in range(n-1):
    tmp=[]
    for j in ans:
        sn=len(set(j))
        for k in range(sn+1):
            tmp.append(j+al[k])  
    ans=tmp
ans.sort()
for i in ans:
    print(i)

Solution (Python):
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

oa = ord('a')
n = ni()

def dfs(v, m, cur):
    if v == n:
        s = ''.join(map(lambda x: chr(x+oa), cur))
        return [s]
    ret = list()
    for i in range(m):
        ret.extend(dfs(v+1, m, cur + [i]))
    ret.extend(dfs(v+1, m+1, cur + [m]))
    return ret

l = dfs(0, 0, list())

l.sort()
print(*l, sep='\n')

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

c = ['a' for _ in range(N)]
def f(i, k):
    if i == N:
        print(''.join(c))
        return
    for j in range(k + 1):
        c[i] = chr(ord('a') + j)
        f(i + 1, max(j + 1, k))

f(0, 0)

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

s = ['' for i in range(n)]
def dfs(k, c):
    if k == n:
        print("".join(s))
        return
    for i in range(c):
        s[k] = chr(i+ord('a'))
        dfs(k+1, c)
    s[k] = chr(c+ord('a'))
    dfs(k+1, c+1)

dfs(0, 0)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()

ans = ["a"]
for i in range(N-1):
    nans = []

    for S in ans:
        m = max(S)
        for x in range(ord(m)-95):
            nans.append(S+chr(97+x))

    ans = copy.copy(nans)

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

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

N = int(read())

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

def dfs(S, i):
    if len(S) == N:
        yield ''.join(S)
        return
    for j in range(i):
        for w in dfs(S + [alphabets[j]], i):
            yield w
    for w in dfs(S + [alphabets[i]], i + 1):
        yield w

for w in dfs([],0):
    print(w)