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



Sample input:
1


Sample output:
a

Submission status: Accepted

Solution code:
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("")

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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 # and False
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'])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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


# MOD = 998244353


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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#gcdは3.4.3だとfractionsにある
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)#gcdは3.4.3だとfractionsにある
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()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env 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)


# region fastio

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

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
N = int(input())

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

all_patterns = []

def fill(values, c, i, n):
#	print(values, a2z[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)
#fill([None] * N, 0, 0, 0)

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

Solution code:
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():    
    # T = int(input().strip())
    for _ in range(1):
        solution()
    

main()

Submission status: Accepted

Solution code:
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(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
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))

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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):
            #print(i,j,k,rank(j))
            #print(j+moji[k])
            L[i+1].append(j+moji[k])

#print(L)

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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 = '')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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, '')

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    c = 'abcdefghij'
    a = [-1] * N
    a[0] = 0
    def f(a):
        for i in range(N):
            if a[i] == -1:
                break
        else:
            return [a[:]]
        b = max(a[:i])
        ans = []
        for j in range(b+2):
            a[i] = j
            ans.extend(f(a))
            a[i] = -1
        return ans

    for b in f(a):
        print(''.join([c[i] for i in b]))




def main():
    N = read_int()
    (slv(N))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

def main():

    N = int(input())
    cur = [['a', set(['a'])]]
    for _ in range(N-1):
        temp = []
        for s, u in cur:
            for c in 'abcdefghij':
                 if c not in u:
                     temp.append([s + c, u | {c}])
                     break
                 else:
                    temp.append([s + c, u])
        cur = temp
    for s, _ in cur:
        print(s)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

ordA = ord('a')

N = int(input())

def dfs(i, sSt):
    if i == N:
#        print(Ss)
        ans = ''.join([chr(ordA+S) for S in Ss])
        anss.append(ans)
    else:
        for s in range(0, sSt+2):
            Ss[i] = s
            dfs(i+1, max(s, sSt))

anss = []
Ss = [0] * N
dfs(1, 0)

print('\n'.join(anss))

Submission status: Accepted

Solution code:
N = int(input())

alphabet = ['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']

def norm(n, prev_list):
	out_list = []
	for line in prev_list:
		for i in range(len(set(line))+1):
			new_line = line + alphabet[i]
			out_list.append(new_line)
	return out_list

init_line = ['a']

for _ in range(N-1):
	init_line = norm(1, init_line)
for line in init_line:
	print(line)

Submission status: Accepted

Solution code:
n = int(input())
ans = [[['a']]] + [[] for _ in range(9)]
alp = ['a','b','c','d','e','f','g','h','i','j']
for i in range(n-1):
    for j in ans[i]:
        x = len(set(j))
        for k in range(x+1):
            ans[i+1].append(j+[alp[k]])
for i in ans[n-1]:
    print("".join(i))

Submission status: Accepted

Solution code:
n=int(input())
s=set()
s.add('a')
l='abcdefghijkl'
for i in range(n-1):
  s1=set()
  for t in s:
    for j in range(12):
      if l[j] in t:
        u=t+l[j]
        s1.add(u)
      else:
        u=t+l[j]
        s1.add(u)
        break
  s=s1
m=list(s)
m.sort()
for i in m:
  print(i)

Submission status: Accepted

Solution code:
# ret = []
N = int(input())
newL = [[0]]
# ret.append(L.copy())

for _ in range(N - 1):
    L = newL.copy()
    newL = []
    for s in L:
        for i in range(max(s) + 2):
            newL.append(s.copy() + [i])
#     ret.append(newL.copy())
    
di = {i: chr(ord('a') + i) for i in range(10)}
print('\n'.join([''.join(list(map(lambda x: di[x], newL[i]))) for i in range(len(newL))]))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
q = deque()
q.append(['0',1])
qq = []
while q:
    a,b = q.popleft()
    if b >= n: 
        qq.append(a)
        continue
    ln = len(a)
    mx = 0
    for i in a:
        mx = max(mx, int(i))
    for i in range(mx+2):
        tmp = a + str(i)
        q.append([tmp,b+1])
qq.sort()
lr = len(qq)
for i in range(lr):
    a = qq[i]
    res = []
    for j in a:
        res.append(chr(ord('a') + int(j)))
    print(''.join(res))

Submission status: Accepted

Solution code:
from collections import deque
import copy
N = int(input())

q = deque()

a = ord("a")

q.append([0, 0])

while len(q) > 0:
    task = q.popleft()
    if len(task) == N + 1:
        for i in task[1:]:
            print(chr(a + i), end="")
        print()
    else:
        for i in range(task[0] + 1):
            newtask = copy.copy(task)
            newtask.append(i)
            q.append(newtask)
        newtask = copy.copy(task)
        newtask.append(task[0] + 1)
        newtask[0] = task[0] + 1
        q.append(newtask)