peterverebics/CodeNet_Python_118 huggingface dataset:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
alphabets = string.ascii_lowercase

N = int(input())
ans = ["0"]
for i in range(1, N):
    ans2 = copy.deepcopy(ans)
    ans = []
    for l in ans2:
        for k in range(int(l[-1]) + 2):
            ans.append(l + str(k))
for i in ans:
    s = ""
    for l in range(N):
        s += alphabets[int(i[l])]
    print(s)
n=int(input())
l = ['a','b','c','d','e','f','g','h','i','j','k','l']
arr = ['a']
for i in range(2,n+1):
    temp = []
    for x in l[:i]:
        for y in arr:
            temp.append(y+x)
    arr = temp
arr.sort()
for x in arr:
    print(x)
n = int(input())
al = ['a','b','c','d','e','f','g','h','i','j']

dpn = ['']
dpp = []
for i in range(n):
    for j in dpn:
        for k in al[0:i+1]:
            if i != n-1:
                dpp.append(j+k)
            else:
                print(j+k)
    if i!= n-1:
        dpn = dpp
        dpp = []
n = int(input())
from copy import copy

L = ["a"]
if n == 1:
    print(L[0])
    exit()
    
for i in range(n-1):
    li = []
    for s in L:
        max1 = s[-1]
        S = ""
        for j in range(ord(max1)-95):
            S = s + chr(97+j)
            #print(ord(max1)-95,chr(ord(max1)+j))
            li.append(S)
    L = copy(li)
    
for i in range(len(L)):
    print(L[i])
n = int(input().strip())
dic = {0: "a",
       1: "b",
       2: "c",
       3: "d",
       4: "e",
       5: "f",
       6: "g",
       7: "h",
       8: "i",
       9: "j",
       }

prev = [""]
for i in range(n):
    curr = []
    for elem in prev:
        for j in range(0, i + 1):
            curr.append(elem + dic[j])
    prev = curr
for e in prev:
    print(e)
# Problem D - String Equivalence

from collections import deque

# input
N = int(input())

char_list = [chr(i) for i in range(97, 97+26)]

def dfs(a_list, a_len, char_count):
    if a_len==N:
        print("".join(a_list))
    else:
        for i in range(char_count):
            a_list.append(char_list[i])
            dfs(a_list, a_len+1, i + 2)
            a_list.pop()

# initialization
a_nums = deque([])

# dfs search
dfs(a_nums, 0, 1)
import sys
sys.setrecursionlimit(100000000)
readline = sys.stdin.readline
from collections import deque

N = int(readline())

alph = 'abcdefghij'

seq = deque()

def dfs(a):
    seq.append(a)
    if len(seq) == N:
        print(''.join([alph[i] for i in seq]))
    else:
        dfs(a)
        if a < N - 1:
            dfs(a + 1)
    seq.pop()

dfs(0)
N = int(input())

def n(s):
    tail = s[-1]
    tails = [chr(i) for i in range(ord('a'), ord(tail)+2)]
    return [s + t for t in tails]

def nn(li):
    r = []
    for l in li:
        r += n(l)
    return r
  
li = ['a']
for i in range(N-1):
    li = nn(li)
for i in li:
    print(i)
def create_li(li):
  if len(li) >= n:
    lis.append(li)
    return
  p = li[-1]
  ret = []
  for i in range(1, p + 2):
    cp = li[:]
    cp.append(i)
 #   print(cp)
    create_li(cp)

lis = []
  
n = int(input())
pre = [1]
create_li(pre)
lis.sort()
al = ["a","b","c","d","e","f","g","h","i","j"]
for i in lis:
  ans = "".join([al[id-1] for id in i])
  print(ans)
n=int(input())

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

ans=[]

st='a'

temp=0
now=0

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

for h in ans:
  print(h)
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):
            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)
N = int(input())

for i in range(2**(N-1)):
  S = ["a"]*N
  a=format(i,"b").zfill(N)
  for j in range(N-1,0,-1):
    if a[j] == "1":
      S[j]="b"
  print("".join(S))
N = int(input())

dp = [[] for _ in range(N)]
dp[0].append('a')

for i in range(1, N):
    for strings in dp[i-1]:
        j = 97
        while j <= ord(strings[-1])+1:
            nextstr = strings
            nextstr += chr(j)
            dp[i].append(nextstr)
            j += 1

dp[N-1].sort()

for strings in dp[N-1]:
    print(strings)
n = int(input())
ans = []
def all_search(array):
    if len(array) == n:
        ans.append(array)
    else:
        for i in range(len(array) + 1):
            res = array + chr(i + ord('a'))
            all_search(res)
all_search("")
for i in range(len(ans)):
    print(ans[i])
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N = int(input())

def rec(i, m, ar) :
  if i == N :
    print(''.join(chr(s + 97) for s in ar))
    return 
  for j in range(min(m + 1, N)) :
    rec(i + 1, j + 1, ar + [j])


rec(0, 0, [])
N = int(input())
if N==1:
    print('a')
    exit()
if N==2:
    print('aa')
    print('ab')
    exit()

ans = []
st = set()
import itertools
for ptn in itertools.product('abc', repeat=N):
    h = 0
    for i in range(N-1):
        for j in range(i+1,N):
            h <<= 1
            if ptn[i]==ptn[j]:
                h += 1
    if h in st: continue
    st.add(h)
    ans.append(''.join(ptn))

print(*sorted(ans), sep='\n')
i = input()
 
if int(i) == 1:
  print('a')
elif int(i) == 2:
  print('aa')
  print('ab')
else:
  x = (int(i) - 2)
  y = 3 ** x
  z = 2 ** x
  print(y + z)
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]:
        for k in range(ord(j[-1])-ord("a")+2):
            an = j + l[k]
            ans[i].append(an)
count = ans[-1]
count.sort()

for i in count:
    print(i)
n = int(input())
anstmp = ["a"]
cnt = 0
for i in anstmp:
  t = ord(i[-1])-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")
chars = ['a','b','c','d','e','f','g','h','i','j']
length = int(input())
def cals(words, num, length):
  work = words
  for val in range(0, length):
    temp = work + chars[val]
    if num + 1 == length:
      print(temp)
    else:
      cals(temp, num + 1, length)
      break
cals('',0 , length)
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d

n = int(input())

def dfs(s, n, path):
    if n == 0:
        path.append(s)
        return
    for i in range(n):
        dfs(chr(i + ord('a')) + s, n - 1, path)


path = []
dfs('', n, path)
for ans in path:
    print(ans)
N = int(input())
S = "abcdefghijklmn"
Q = [(1,1,"a")]
A = []
while Q:
    q = Q.pop(-1)
    if q[0]==N:
        A.append(q[2])
        continue
    for i in range(q[1]+1):
        Q.append((q[0]+1,i+1,q[2]+S[i]))
for a in sorted(A):print(a)
import math

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

N = int(input())
if N == 1:
  print(al[0])
else:
  S = [[""] * math.factorial(i+1) for i in range(N-1)]
  S[0][0] = al[0]

  for i in range(1, N-1):
    prev_S = S[i-1]
    al_use = al[:i+1]
    S[i] = [s + a for s in prev_S for a in al_use]

  prev_S = S[N-2]
  al_use = al[:N]
  for s in prev_S:
    for a in al_use:
      print(s + a)
N = int(input())

#from collections import deque

#Q = deque()

S = "a"

def printer(S):
    if len(S)==N:
        print(S)
    else:
        for i in range(ord('a'),ord(S[-1])+2):        
            printer(S + chr(i))
        
printer(S)
# -*- coding: utf-8 -*-

alphabets = list('abcdefghijklmnopqrstuvwxyz')

N = int(input())

if N == 1:
    print('a')
else:
    tmp = ['a']
    for i in range(1, N):
        result = []
        for s in tmp:
            for alphabet in set(list(s)):
                result.append(s+alphabet)
            result.append(s+alphabets[len(set(list(s)))])
            tmp = result
    print('\n'.join(result))
alp = [chr(i) for i in range(97, 97+26)]

def dfs(s, mx):
    if len(s)==N:
        print(s)
    else:
        for i in range(mx+1):
            dfs(s+alp[i], i+1)
        
N = int(input())
dfs('',0)
n = int(input())

def dfs(s,mx):
    if len(s)==n:
        print(s)
        return None
    for i in range(ord('a'),(mx+1)+1):
        dfs(s+chr(i),max(mx,i))
dfs('',ord('a'))
N = int(input())

answer = [(97, 'a')]
for _ in range(N - 1):
    new_answer = []
    for i, j in answer:
        for k in range(97, i + 1):
            new_answer.append((k, j + chr(k)))
        new_answer.append((i+1,j+chr(i+1)))
    answer = new_answer[:]

answer = [j for _, j in answer]
answer.sort()
print('\n'.join(answer))
import string
N = int(input())
abc = string.ascii_lowercase
ans = ['a']
for i in range(2, N):
    ans2 = []
    for a in ans:
        for b in abc[:i]:
            ans2 += [a + b]
    ans = ans2
print('\n'.join(ans))
import itertools

n = int(input())

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


rs=set()
for i in range(n):
    s= ["a"]*(n-i)
    #右からi+1桁目以降のパターンを抽出
    rs |= set(["".join(s + list(l)) for l in itertools.product(cl[:n-1], repeat=i)])
    # for l in  itertools.product(cl[:n],repeat=i):
    #     s+list(l)
rl=list(rs)
rl.sort()
rl.append("".join(cl[:n]))

for r in rl:
    print(r)
def search(s):
    global ans_li
    if len(s) > max_length:
        ans_li.append(s)
    else:
        temp = s+"a"
        search(temp)
        temp = s+"b"
        search(temp)

global ans_li
ans_li = []
n = int(input())
max_length = n-1

search("a")
ans_li.sort()
for i in ans_li:
    print(i)
s = ["a","b","c","d","e","f","g","h","i","j"]
n=int(input())
l = ["a"]

x = 1
while(x <= n):
    ll = l
    l = []
    for i in ll:
        for j in s[:x-1]:
            l.append(i + j)
    l.append("".join(s[:x]))
    x = x + 1
for i in l:
    print(i)
n = int(input())
a = [0]*n

def print_str():
    for i in reversed(a):
        print(chr(97+i), end='')
    print()

print_str()
while True:
    for i in range(n-1):
        if a[i] <= a[i+1]:
            a[i] += 1
            for j in range(i):
                a[j] = 0
            print_str()
            break
    else:
        break
n=int(input())
abc='abcdefghih'
def dfs(i,a,s):
    if i==n:
        print(s)
    else:
        for j in range(0,a+1):
            dfs(i+1,j+1,s+abc[j])
dfs(0,0,'')
import itertools
alp = [chr(ord('a') + i) for i in range(26)]
N = int(input())
allS = list(itertools.combinations_with_replacement(alp[0:N], N))
answers = []
PatternList = []
for s in allS:
    pattern = []
    letters = []
    num = 0
    for l in s:
        if not(l in letters):
            letters.append(l)
        pattern.append(letters.index(l))
    if not(pattern in PatternList):
        PatternList.append(pattern)
        answers.append(s)
for answer in answers:
    print(' '.join(answer))
n = int(input())
A = "abcdefghijklmnopqrstuvwxyz"
for i in range(n):
    print("a"*(n-i) + A[1:1+i])
alpha = "abcdefghijklmnopqrstuvwxyz"
ans = []
n = int(input())
def saiki(s):
    global ans
    if len(s) == n:
        ans.append(s)
    else:
        i = alpha.index(s[-1])
        for j in range(i+2):
            saiki(s+alpha[j])
saiki("a")
print("\n".join(ans))
N = int(input())
char = "abcdefghij"
prev = ["a"]
results = []
for i in range(N-1):
  results = []
  for p in prev:
    for j in range(i+2):
      results.append(p+char[j])
  prev = results
if N == 1:
  print("\n".join(prev))
else:
  print("\n".join(results))
import itertools
n =int(input())
alp = [chr(i+64) for i in range(1,n+1)]
cmbs = list(itertools.combinations_with_replacement(alp,n))
for cmb in cmbs:
    flg = False
    for i, al in enumerate(alp):
        if al in cmb:
            for a in alp[0:i]:
                if a not in cmb:
                    flg = True
                    break
            if flg:
                break
    if not flg:
        print(''.join(cmb))
from itertools import product
n=int(input())
s='abcdefghijklmnopqrstuvwxyz'
use_s=s[:n]
#print(use_s,1)
for i in product(list(use_s), repeat=n):
    ans=''.join(i)
    if use_s<ans:continue
    print(ans)
from itertools import combinations_with_replacement as cb

N = int(input())
al = [chr(i) for i in range(97, 97 + 26)]

ans = []
for C in cb(al[:N], N):
    if C[0] != 'a': continue
    cur = 'a'
    flag = True

    for i in range(1, N):
        if ord(cur) >= ord(C[i]): continue
        if ord(cur) + 1 == ord(C[i]):
            cur = C[i]
        else: flag = False
    if flag:
        ans.append(''.join(C))

ans.sort()
print(*ans, sep='\n')
alf = 'abcdefghijklmnopqrstuvwxyz'
d = {c:i+1 for i,c in enumerate(alf)}
d['z']=25
def dfs(n):
    lst = []
    lst.append(['a'])
    while lst:
        a = lst.pop()
        if len(a) == n:
            print(''.join(a))
            continue
        for i in range(d[a[-1]]+1)[::-1]:
            lst.append(a + [alf[i]])

n= int(input())
dfs(n)
n = int(input())
lets = [chr(i) for i in range(ord("a"), ord("a") + n)]
d = {e: i for i, e in enumerate(lets)}

s = ["a"]
for i in range(1, n):
    nxt = []
    for e in s:
        let = e[-1]
        for j in range(d[let] + 2):
            nxt.append(e + lets[j])
    s = nxt

print(*s, sep="\n")
import sys
sys.setrecursionlimit(100000000)
readline = sys.stdin.readline
from collections import deque

N = int(readline())

alph = 'abcdefghij'

seq = deque()

def dfs(a):
    seq.append(a)
    if len(seq) == N:
        print(''.join([alph[i] for i in seq]))
    else:
        m = min(N - 1, a + 1)
        for i in range(m + 1):
            dfs(i)
    seq.pop()

dfs(0)
n = int(input())
cs = 'abcdefghijklmn'
cm = {cs[i]:i for i in range(len(cs))}

def rec(string, l):
    if (l >= n):
        print(string)
        return 0
    now = string[-1]
    k = cm[now] + 2
    for c in cs[:k]:
        rec(string + c,l+1)

rec('a',1)
import sys
input = sys.stdin.readline

n = int(input())

a_ord = ord('a')

s = ["a"]

ans = []

def dfs(s):
    last_ord = a_ord + len(s)
    for i in range(a_ord, last_ord + 1):
        t = s[:]
        t.append(chr(i))
        if len(t) == n:
            ans.append("".join(t))
        else:
            dfs(t)
if n == 1:
    print('a')
else:
    dfs(s)
    ans.sort()
    for w in ans:
        print(w)
n=int(input())
lst=('a','ab','abc','abcd','abcde','abcdef','abcdefg','abcdefgh','abcdefghi', 'abcdefghij')
for i in range(n):
    print(lst[i])
n = int(input())

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

ans = ['a'] * n

print(''.join(ans))

# 桁 最後 to 1
count = 1
for i in reversed(range(1, n)):
    temp = ans[:]
    for j in range(i, n):
        current = a[j - i]
        for k in range(j, n):
            temp[k] = current
            print(''.join(temp))
def dfs(ans, n, l):
    if len(ans) == n:
        print(ans)
        return ans
    for x in l:
        dfs(ans + x, n, l)


n = int(input())
s = 'abcdefghij'
l = [s[i] for i in range(n)]

ans = 'a'
dfs(ans, n, l)
import sys
sys.setrecursionlimit(500000)

N = int(input())
global ans
ans = []
def dfs(now,rank,root_):
    root = root_[:]
    if rank == N:
        root.append(now)
        ans.append(''.join([chr(i+ord('a')) for i in root]))
    else:
        root.append(now)
        for i in range(now+2):
            dfs(i,rank+1,root)

dfs(0,1,[])
print(*ans,sep='\n')
n = int(input())
def dfs(i,s):
    if i == n:
        print(s)
        return
    for j in range(i+1):
        if ord(s[-1]) == 97+j or ord(s[-1]) + 1 == 97+j:
            dfs(i+1,s+chr(97+j))
    return
dfs(1,"a")
import sys

N=int(input())
def num2alpha(num):
    return chr(97+num)
print(''.join(['a']*N))
for i in range(N-1):
  a=['0']*N
  while True:
    a=[j for j in str(int(''.join(a))+1).zfill(N)]
    print(''.join([num2alpha(int(i)) for i in a]))   
    
    if a[N-i-1]>max(a[:N-i-1]):
      break
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n = int(readline())
bit = list(itertools.product([0, 1], repeat=(n - 1)))
if n == 1:
    print('a')
    exit()
for i in range(2 ** (n - 1)):
    ans = ''
    for j in range(n - 1):
        if bit[i][j] == 0:
            ans += 'a'
        else:
            ans += 'b'
    print('a' + ans)
n=int(input())

abc='abcdefghijklmnopqrstuvwxyz'

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

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

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

for i in ans:
  print(i)
n = int(input())
def dfs(i,s):
    if i == n:
        print(s)
        return
    for j in range(n):
        if ord(s[-1]) <= 97+j:
            dfs(i+1,s+chr(97+j))
    return
dfs(1,"a")
print('''aaaa
aaab
aaba
aabb
aabc
abaa
abab
abba
abbb
abbc
abca
abcb
abcc
abcd''')
import sys
sys.setrecursionlimit(10**7)
n = int(input())

def dfs(s, mx):
  if len(s) == n:
    print(s)
  else:
    dfs(s+chr(ord("a")+mx), mx)
    dfs(s+chr(ord("a")+mx+1), mx+1)

dfs("", 0)
N = int(input())
a= "0" + str(N) + "b"

for i in range(2**(N-1)):
    x = format(i, a)
    print(x.replace('0', 'a').replace('1', 'b'))
from heapq import heappush, heappop

N = int(input())

q = []

for i in range(1 << N):  
  s = ''.join('b' if i & (1 << x) else 'a' for x in range(N))
  heappush(q, s)
  
                 
for _ in range((1 << N) // 2):
  s = heappop(q)
  print(s)
from collections import deque

def dfs(q):
    if len(q)==N:
        print(''.join(q))
        return
    
    for i in range(min(26, ord(q[-1])-ord('a')+2)):
        q.append(alpha[i])
        dfs(q)
        q.pop()
    
N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
dfs(deque(['a']))
n=int(input())


A='abcdefghijklmnopqrstuvwxyz'

def dfs(s,mx):
    if len(s)==n:
        print(s)
    else:
        for c in range(mx):
            if c==mx-1:
                dfs(s+A[c],mx+1)
            else:
                dfs(s+A[c],mx)



print(dfs('',1))
# coding: utf-8
# Your code here!
N=int(input())

cand=["a"]

for i in range(N-1):
    temp=[]
    for item in cand:
        temp.append(item+item[-1])
        temp.append(item+chr(ord(item[-1])+1))
    cand=temp[:]

for item in cand:
    print(item)
# coding: utf-8
# Your code here!
N=int(input())

cand=["a"]


for i in range(N-1):
    temp=[]
    for item in cand:
        for i in range(ord(item[-1])-95):
            temp.append(item+chr(i+97))
    cand=temp[:]

for item in cand:
    print(item)
import itertools
A =[chr(ord('a') + i) for i in range(26)]
N = int(input())
for i in itertools.combinations_with_replacement(A[:N],N):
    if i[0] != "a":
        continue
    
    for j in range(1,N):
        if ord(i[j]) -ord(i[j-1])>1:
            break
        
    else:
        print(*i,sep="")
n = int(input())
alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
def doukei(n):
  if n == 1:
    return ["a"]
  k = doukei(n-1)
  ans = []
  for i in range(len(k)):
    key = k[i][-1]
    ans.append(k[i]+"a")
    for j in range(1, 10):
      ans.append(k[i]+alpha[j])
      if key == alpha[j-1]:
        break
  return ans
answer = doukei(n)
for i in range(len(answer)):
  print(answer[i])
import itertools as iters

N = int(input())
alpha = "abcdefghijk"
S = [list(range(1,n+2)) for n in range(N)]

for s in iters.product(*S):
    #print(s)
    r = [alpha[ss-1] for ss in s]
    print("".join(r))
n = int(input())


def dfs(s, d, n):
    if d == n:
        print(s)
        return

    dfs(s + "a", d + 1, n)
    dfs(s + "b", d + 1, n)

    return


dfs("a", 1, n)
N = int(input())
a = [[[0]]]
k = 0
while k < N-1:
  c = a[k]
  a.append([])
  for r in c:
    for i in range(r[-1]+2):
      x = r + [i]
      a[k+1].append(x)
  
  k += 1
A = a[-1]
for s in A:
  ans = ""
  for i in range(N):
    ans += chr(s[i]+97)
  print(ans)
import itertools
import sys

n = int(input())
S = ['a']*n
while True:
    print("".join(S))
    for i in range(n-1,0,-1):
        if(S[i-1]>=S[i]):
            S[i] = chr(ord(S[i])+1)
            for j in range(i+1,n):
                S[j] = 'a'
            break
    else:
        break
def dfs(s):
    if len(s)>n:
        return
    t.append(s)
    for c in 'abcdefghij':
        if -1<=ord(c)-ord(s[-1])<=1:
            dfs(s+c)

n=int(input())
if n==1:
    print('a')
    exit(0)
t=[]
ans=[]
dfs('a')

for tt in t:
    if len(tt)==n:
        ans.append(tt)
ans.sort()
print(*ans,sep='\n')
import itertools

n = int(input())

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

rs = set()
for i in range(n):
    s = ["a"] * (n - i)
    # 右からi+1桁目以降のパターンを抽出
    rs |= set(["".join(s + list(l)) for l in itertools.product(cl[:n - 1], repeat=i)])
    # for l in  itertools.product(cl[:n],repeat=i):
    #     s+list(l)
rl = list(rs)
rl.sort()
if n != 1:
    rl.append("".join(cl[:n]))

for r in rl:
    print(r)
n = int(input())


def f(s, I):
    if len(s) >= n:
        print(s)
    else:
        for i in range(I+1):
            f(s + chr(ord('a') + i), i+1)


f('a', 1)
N = int(input())

def dfs(s):
    if(len(s) == N):
        print(s)
        return
    else:
        next_str = chr(ord(s[-1]) + 1)
        pre_str = chr(ord(s[-1]) - 1)
        dfs(s + s[-1])
        dfs(s + next_str)
        if(s[-1] != "a"):
            dfs(s + pre_str)

dfs("a")
n = int(input())
if n == 1:
    print("a")
if n == 2:
    print("aa")
    print("ab")
elif n == 3:
    print("aaa")
    print("aab")
    print("aac")
    print("abb")
    print("abc")
elif n == 4:
    print("aaaa")
    print("aaab")
    print("aabb")
    print("abbb")
else:
    print("hoge")
N = int(input())

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

que = ['a']
res = []
for i in range(1, N):
    for q in que:
        res.append(q + 'a')
        res.append(q + 'b')
    que = res
    res = []

que.sort()
for q in que:
    print(q)
N = int(input())

alphabets = 'abcdefghijklmnopqrstuvwxyz'

def dfs(s, max_idx):
  if len(s) == N:
    print(s)
    return
  else:
    for i in range(0, max_idx+1):
      t = s
      t = t + alphabets[i]
      dfs(t, max(i, max_idx))
    
dfs("a", 1)
def solve(n):
    s = ["a"] * n
    for i in range(n):
        print("".join(s))
        s[-i-1] = "b"

n = int(input())
solve(n)
N = int(input())

A = [0] * N

ED = [chr(i + 97) for i in range(N)]
ED = ''.join(ED)

while True:
    for i in range(N - 1, 0, -1):
        if A[i] == A[i - 1] + 2:
            A[i] = 0
            A[i - 1] += 1
    ret = ['' for _ in range(N)]
    for i in range(N):
        ret[i] = chr(A[i] + 97)

    ret = ''.join(ret)
    print(ret)

    if ret == ED: break
    else: A[-1] += 1
n = int(input())

strings = ["a"]

for i in range(n-1):
    newstrings = []
    for s in strings:
        mx = ord('a')
        for char in s:
            mx = max(mx, ord(char))
        
        for c in range(ord('a'),mx+2):
            newstrings.append(s+chr(c))
    
    strings = newstrings

print(strings)
N = int(input())
ans_list = ["a"]  # 生成元の初期状態 (N = 1 の答え)
alphabet = [chr(ord("a") + i) for i in range(N)]  # 使用するアルファベット

for i in range(N - 1):
    ans_list = [ans + x for ans in ans_list for x in alphabet[:len(ans) + 1]]

for ans in ans_list:
    print(ans)
from itertools import product
n = int(input())
alph = 'abcdefghij'
al = [alph[i] for i in range(n)]
for p in product(al, repeat=n):
    if p[0] == 'b':
        break
    print(''.join(p))
import sys
sys.setrecursionlimit(10 ** 7)


N = int(input())
L = list("abcdefghij")

def nasu(x, n, e):
  if n == N:
    print(x)
    return
  for i in range(e + 1):
    if i == n:
      nasu(x + L[i], n + 1, e + 1)
    else:
      nasu(x + L[i], n + 1, e)

nasu("", 0, 0)
a_list = ["a","b","c","d","e","f","g","h","i","j","k"]
n = int(input())
def dfs(s,n,a_list):
  if len(s) == n:
    print(s)
  else:
    for i in range(a_list.index(s[-1]) + 2):
      s_1 =s +  a_list[i]
      dfs(s_1,n,a_list)
      
dfs("a",n,a_list)
import sys
sys.setrecursionlimit(10**9)

N = int(input())

def bfs(s, cnt):
	if cnt == N:
		print(s)
		return

	for i in range(97,ord(s[-1])+2):
		bfs(s+chr(i), cnt+1)

bfs('a',1)
N = int(input().rstrip())
zumi = []
for i in range(1, N + 1):
    ret = 'a' * i + 'b' * (N - i)
    # print(f'origin: {ret}')
    for j in range(i, N + 1):
        # print(f'1: {ret[:j-1]}, 2: {ret[j:]}')
        tmp = ret[:j - 1] + 'a' + ret[j:]
        if tmp not in zumi:
            zumi.append(tmp)
for x in sorted(zumi):
    print(x)