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: Runtime Error

Solution code:
#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int N;

void dfs(string s, char mx){
	if(s.length() == N){
		cout << s << "\n";
	}
	else{
		for(char c = 'a'; c <= mx; c++){
			dfs(s + c, ((c == mx)? (char)(mx + 1) : mx));
		}
	}
}

int main(void){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	cin >> N;

	dfs("",'a');

	return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int N;

void dfs(string s, char mx){
	if(s.length() == N){
		cout << s << "\n";
	}
	else{
		for(char c = 'a'; c <= mx; c++){
			if(c == mx){
				dfs(s + c, (char)(mx + 1));
			}
			else{
				dfs(s + c, mx);
			}
		}
	}
}

int main(void){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	cin >> N;

	dfs("",'a');

	return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int N;

void dfs(string s, char mx){
	if(s.length() == N){
		cout << s << "\n";
	}
	else{
		for(char c = 'a'; c <= mx; c++){
			if(c == mx){
				dfs(s + c, (char)(mx + 1));
			}
			else{
				dfs(s + c, mx);
			}
		}
	}
}

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	cin >> N;

	dfs("",'a');

	return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int char_num[10];
int now_char = 0;
stack<int> str;
string out;

int N;

void dfs(string s, char mx){
	if(s.length() == N){
		cout << s << "\n";
	}
	else{
		for(char c = 'a'; c <= mx; c++){
			if(c == mx){
				dfs(s + c, (char)(mx + 1));
			}
			else{
				dfs(s + c, mx);
			}
		}
	}
}

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	cin >> N;

	dfs("",'a');

	return 0;
}

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

min_char = "abcdefghij"

def dtype_tree(tree, start, num):
    for i in range(start+1):
        if num > 0:
            tgt_tree = [i]
            new_tree = dtype_tree([], i+1, num-1)
            tgt_tree.append(new_tree)
            if tree == None:
                tree = tgt_tree
            else:
                tree.append(tgt_tree)
        else:
            tree.append([i])
    return tree

def print_tree(tree, prefix):
    new_prefix = prefix
    if len(tree) == 1:
        print(prefix + min_char[tree[0]])
    else:
        for elem in tree:
            if type(elem) != list:
                new_prefix += min_char[elem]
#                print(new_prefix)
            else:
                print_tree(elem, new_prefix)

    return


def abc_XXX(num):
    tree = dtype_tree(None, 0, num-1)
#    print(tree)
    print_tree(tree, "")
    return

###
# main
if(__name__ == '__main__'):
    # input
    n = int(input())
    
    abc_XXX(n)
    
    # output

# else:
    # do nothing

Submission status: Runtime Error

Solution code:
al=[chr(ord('a') + i) for i in range(26)]
def dfs2(N, f):
    if len(f) == N:
        return f
    else:
        result = ""
        f_index = [al.index(i) for i in f]
        for i in range(max(f_index) +1 + 1):#追加できるのは(f+1) + 1
            result +=dfs(N,  f + al[i])
        return result

N = int(input())
ans = dfs2(N, 'a')
for i in range(int(len(ans) / N)):
    print(ans[N*i : N * (i+1)])

Submission status: Runtime Error

Solution code:
from collections import deque
N=int(input())
X=[chr(i+97) for i in range(N)]
q=deque(["a"])
while(len(q)>0):
    r=q.popleft()
    k=len(set(r))
    for i in range(k+1):
        p=r+X[i]
        if len(p)==N:
            print(p)
        else:
            q.append(p)

Submission status: Runtime Error

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

alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
unvisited = deque(alphabet[0 : N])
visited = deque()
st = deque([["a", visited, unvisited]]) # stack

while len(st) > 0:
    str, visited, unvisited = st.popleft()

    if str[-1] not in visited:
        visited.append(str[-1])
        unvisited.popleft()

    if len(str) == N:
        print(str)
    else:
        # すでに使った文字を使う
        for x in visited:
            st.append([str + x, visited.copy(), unvisited.copy()])
        # まだ使っていない文字を使う
        if len(unvisited) > 0:
            x = unvisited[0]
            st.append([str + x, visited.copy(), unvisited.copy()])

Submission status: Runtime Error

Solution code:
n=int(input())
s='abcdefghijklmnopqrstuvwxyz'
bottom=[[] for i in range(10)]
bottom[0]=['a']

def solve(n):
    num=0
    while num<=n:
        num=num+1
        for base in bottom[num-1]:
            for i in s[:num+1]:
                if ord(i)-ord(base[-1])>1:continue
                bottom[num].append(base+i)

solve(n-1)
print(*bottom[n-1],sep='\n')

Submission status: Runtime Error

Solution code:
n=int(input())
s='abcdefghij'
bottom=[[] for i in range(10)]
bottom[0]=['a']

def solve(n):
    num=0
    while num<=n:
        num=num+1
        for base in bottom[num-1]:
            for i in s[:num+1]:
                if ord(i)-ord(base[-1])>1:continue
                bottom[num].append(base+i)

solve(n-1)
print(*bottom[n-1],sep='\n')

Submission status: Runtime Error

Solution code:
n = int(input())
ans = []
def dfs(line, mx):
    if len(line) == n:
        ans.append(line)
    else:
        for i in range(mx+1):
            line_copy = line.copy()
            line_copy.append(i)
            dfs(line_copy, mx)
        line_copy = line.copy()
        line_copy.append(mx+1)
        dfs(line_copy, mx+1)

dfs([0], 0)

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

for a in ans:
    for i in a:
        print(figures[i], end="")
    print()

Submission status: Runtime Error

Solution code:
n=int(input())
ans=[]
def rec(i,s):
    if i == n:
        print(s)
        return
    else:
        for j in range(len(set(s)) + 1):
            rec(i+1,s+chr(old("a")+j))
rec(1,"a")

Submission status: Runtime Error

Solution code:
N = int(input())
a_ch = [chr(ch) for ch in range(ord('a'), ord('j'))]

def DFS(s, mx):
  if len(s) == N:
    print(s)
  else:
    for i in range(mx + 1):
      if i == mx:
        DFS(s + a_ch[i], mx + 1)
      else:
        DFS(s + a_ch[i], mx)

DFS('', 0)

Submission status: Runtime Error

Solution code:
from string import ascii_lowercase
from functools import lru_cache
n = int(input())

@lru_cache
def make(n):
    if n == 1:
        return ['a']
    else:
        lst = []
        for s in make(n-1):
            for c in ascii_lowercase[:len(set(s))+1]:
                lst.append(s + c)
        return lst
for s in make(n):
    print(*s, sep='')

Submission status: Runtime Error

Solution code:
from string import ascii_lowercase
n = int(input())

@lru_cache
def make(n):
    if n == 1:
        return ['a']
    else:
        lst = []
        for s in make(n-1):
            for c in ascii_lowercase[:len(set(s))+1]:
                lst.append(s + c)
        return lst
for s in make(n):
    print(*s, sep='')

Submission status: Runtime Error

Solution code:
n = int(input())

def dfs(s, mx):
    if len(s) == n:
        print(s)
    else:
        for c in [chr(ord('a') + i) for i in range(ord(mx) - ord('a') + 1)]:
            dfs(s + c, chr(ord(mx) + 1) if c == mx else mx)

dfx('', 'a')

Submission status: Runtime Error

Solution code:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.math.BigInteger;
    import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = c - a - b;
    if (d > 0 && 4 * a * b < d * d) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Submission status: Runtime Error

Solution code:
k = "a",
for _ in range(int(input()) - 1):
  k = {a + b for a in r for b in a + chr(ord(max(a)) + 1)}
print(*sorted(k), sep='\n')

Submission status: Runtime Error

Solution code:
N = input()
mojis = ["a","b","c","d","e","f","g","h","i","j"]
def append_m(moji):
    arr = []
    for i in mojis[:len(set(moji))+1]:
        arr.append(moji+i)
    return arr
arr = ["a"]
for i in range(N-1):
    tmp = []
    for j in arr:
        tmp += append_m(j)
    arr = tmp
for i in arr:
    print(i)

Submission status: Runtime Error

Solution code:
from decimal import Decimal, getcontext
a, b, c = map(int, input().split())
getcontext().prec = 20
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)
l = []
def calc3(s, N):
    if len(s) == N:
        l.append(s)
        return
    if len(s) > 0:
        c = s[-1]
        s2 = s[:]
        z = ord(c) - ord('a') + 2
        for i in range(z):
            st = s[:]
            st += chr(ord('a')+i)
            calc3(st[:], N)
    else:
        c = 'a'
        s += chr(ord(c))
        calc3(s[:], N)
def main():
    N = int(input())
    s = ''
    calc3(s[:], N)
    l = sorted(set(l))
    for i in l:
        print(i)
main()

Submission status: Runtime Error

Solution code:
a,b,c = map(int, input().split())
 
if (c-a-b) **2 - 4*a*b > 0 and c-a-b > 0:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
n = int(input())
a = ord('a')

def f(x: int) -> str:
  return chr(x + a)

for i in range(2 * 10 ** (n-2)):
  x = list(map(int, str(i).zfill(n)))
  maximum = 0
  flag = True
  for j, digit in enumerate(x):
    if digit > maximum + 1:
      flag = False
      break
    elif digit == maximum + 1:
      maximum = digit
  if flag:
    print(''.join(map(f, x)))
  else:
    d = 10 ** (n - j)
    i = (i // d + 1) * d

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())


first = 0
last = 0

for i in range(n):
    first += 1 * 10 ** (n - i - 1)
for i in range(n):
    last += (i + 1) * 10 ** (n - i - 1)

array = np.arrange(first, last + 1)

edited_array = np.array([])
ans_array = np.array([])

for num in array:
    for i in range(n):
        tmp = num // 10 ** ( n - i - 1)
        if tmp > n:
            break
        else:
            if i == n - 1:
                edited_array = np.append(edited_array, num)

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

for num in edited_array:
    tmp_str = str(num)
    for i in range(n):
        tmp_str.replace(str(i + 1), alphabet_array[i])
    ans_array = np.append(ans_array, tmp_str)

for char in ans_array:
    print(char)

Submission status: Runtime Error

Solution code:
import string

def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n = iinp()
a = string.ascii_lowercase

k = n

while k != 0:
  for i in range(int(2**(k-1))):
    d = []
    p = len(bin(i))
    q = bin(i)
    for j in range(p-2):
      q = bin(i>>j)
      if int(q[len(q)-1]) == 1:
        d.append(k-j-2)

    for i in range(n-k+1):
      print(a[i],end="")
    for j in range(k-1):
      if k != n and (j == 0 or j == k-1-1):
      elif j in d:
        print(a[n-k+1],end="")
      else:
        print(a[n-k],end="")
    print("")
  k -= 1

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
vector<string>ans;
bool check(string s,int n)
{
    if(ans.size()==0)
        return true;
    for(auto all:ans)
    {
        int flag=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(s[i]==s[j]&&all[i]==all[j])
                    continue;
               	if(s[i]!=s[j]&&all[i]!=all[j])
                    continue;
                flag=1;break;
            }
            if(flag==1)
                break;
        }
        if(flag==0)
            return false;
    }
    return true;
   
}
void sol(vector<char> v,int val,vector<string> vc,int n)
{
    if(val==n||v.size()==n)
    {
        string s;
        for(auto all:v)
            s+=all;
        if(check(s,n))
        ans.push_back(s);
        return;}
        for(char c:vc[val])
        {
            v.push_back(c);
            sol(v,val+1,vc,n);
            v.pop_back();
        }
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
	int n;
    cin>>n;
    vector<string>vc;
    for(int i=0;i<n;i++){
        string s;
        char c='a';
    	for(int j=0;j<=i;j++)
            s+=c,c++;
        vc.push_back(s);
        //cout<<"12 "<<s<<endl;
    }
    vector<char> v;
    sol(v,0,vc,n);
    for(auto all:ans)
        cout<<all<<endl;
}

Submission status: Runtime Error

Solution code:
from collections import Counter

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

temp = []
for n in range(N):
  result = []
	for i in temp:
    	temp_list = list(i)
  		type = len(Counter(temp_list))
  
  			for j in range(type):
    			result.append(i + alpha[j])
	temp = result.copy()
    
print('\n'.join(result))

Submission status: Runtime Error

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

l = list()
c = 0

def dp(w,c):
    if len(w) == N:
        if w not in l:
            l.append(w)
        return
    for v in range(N):
        if str(v) not in w:
            c += 1
        dp(w+str(c),c)

dp('0',c)
for i in l:
    ans = ''
    for j in i:
        ans = ans + lst[int(j)]
    print(ans)

Submission status: Runtime Error

Solution code:
from itertools import permutations
from itertools import product

N=int(input())

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

num=[i for i in range(2,10)]

st=st[:N]

st2=[""]

ans_ls=["b","c","d","e","f","g","h","i","j"]
ans=["x"]*N

ind=0

if N==1:
    print("a")
else:
    print("a"*N)
    for i in range(2,len(st)):
        for num_ls in product(num_ls,i):
            for j in num_ls:
                ans[j]="a"
            for _ in range(len(ans)):
                if ans[j]!="a":
                    ans[ind]=st2[ind]
                    ind+=1
            print(ans)

  
    print("".join(st))

Submission status: Runtime Error

Solution code:
num = int(input())
word = "a" * num
while (True):
	print(word)
	if word == (("b" * (num - 1)) + "a"):
		print(word)
		break
	else:
		word = list(word)
		for i in [num:0:-1]:
			if word[i] == "a":
				word[i] == "b"
				for j in range(i + 1, num):
					word[j] == "a"
				word = "".join(word)
				break

Submission status: Runtime Error

Solution code:
A = ["a","b","c","d","e","f","g","h","i","j"]
n = int(input())
l = ["a"]

def L(n):
  if n == 1:
    return l
  else:
    m = len(L(n-1))
    N = []
    for i in range(m):
      M = []
      k = len(set(L(n-1)[i]))
      for j in range(k+1):
        M = M.append(L(n-1)[i]+A[j]) 
      N += M
    return N

for s in range(len(L(n))):
  print(L(n)[s])

Submission status: Runtime Error

Solution code:
import sys,math
sys.setrecursionlimit(10**9)
import itertools
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())

n=int(input())
temp=[]
num=0
x=1
for i in range(1,n+1):
  x*=2
for st in itertools.permutations(a,n):
    temp.append(st)
    num+=1
    if num==x-i:break

for x in temp:
  for i in x:
    print(x[i],end="")
  print()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    s = 'abcdefghijkl'
    ans = []
    from heapq import heapify, heappop, heappush

    def f(t: str):
        if len(t) == N:
            heappush(ans, t)
            return
        
        if len(t) >= 2:
            x = s.index(max(list(t)))+3
        else:
            x = len(t)+1
        for i in range(x):
            f(t+s[i])


    
    f('')
    # print(ans)
    c = 0
    # print(len(ans))
    while len(ans):
        print(heappop(ans))
        c += 1


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a = int(input())
b = [1]*a
c = [1,2,3,4,5,6,7,8,9,10]
d = 0
core = c[0:a]
print("a"*a)
while b != core:
    b[-1] = b[-1] + 1
for i in range(10):
    if  b[-i-1]-1 > b[-i-2]:
        b[-i-2] = b[-i-2] + 1
        b[-i-1] = 1
    else:
        break
answer = ""
for j in range(a):
    answer = answer +chr(b[j]+96)
print(answer)

Submission status: Runtime Error

Solution code:
n = int(input())
chars = ["a","b","c","d","e","f","g","h","i","j"]
def ds(s,depth,ind):
    for i in range(ind): #初回→1個
        if depth == n:
            print(s)
            return
        next_chr = chars[i]
        # for j in range(ind + 1):
        ds(s + next_chr, depth + 1,n - ( 1 - i ))
    return
ds("",0,1)


# for i in range(n):



# k = (n - 1)
# # n 桁 → 関係は nC2 * 2個の関係がありうる
# # abc とあったら a = b とか a =cとか
# while k != 0:
#
#     for i in range(2 ** k):  # 2**k個の制約がある k回目 → 2 ** (k) の束縛がある
#         for i1 in range(n - k - 1, n):  # i1番目のアルファベット
#             #着目する文字が0文字目 = 1文字目  0文字目 = 2文字目 って感じになっていく
#             for i2 in range(i1 + 1, n):  # i2番目のアルファベット
#                 ans = ""
#                 # 1→等しい 0 → 等しくない
#                 # 等しくない場合 chr + 1をする
#                 next_chr = "a"
#                 for j in range(1 , n): #追加する 番目 1番目に追加とか
#                     ralation = i2 - i1 -1 #番目の関係
#                     if ralation < 0:
#                         pass
#                     elif  ((ralation  >> j) & 1): #束縛されていたら
#                         next_chr = chr(ord(next_chr) + 1)
#                 ans += next_chr
#             print(ans)#
#
#     k -=1
#
#

Submission status: Runtime Error

Solution code:
import copy
N=int(input())
ans = [0]

if N > 1:
  ans1 = []
  a = max(ans)+1
  for i in range(a+1):
    c = copy.copy(ans)
    c.append(i)
    ans1.append(c)
    
if N > 2:
  ans2 = []
  for j in range(len(ans1)):
    a = max(ans1[j])+1
    for i in range(a+1):
      c = copy.copy(ans1[j])
      c.append(i)
      ans2.append(c)

if N > 3:
  ans3 = []
  for j in range(len(ans2)):
    a = max(ans2[j])+1
    for i in range(a+1):
      c = copy.copy(ans2[j])
      c.append(i)
      ans3.append(c)
      

if N > 4:
  ans4 = []
  for j in range(len(ans3)):
    a = max(ans3[j])+1
    for i in range(a+1):
      c = copy.copy(ans3[j])
      c.append(i)
      ans4.append(c)


if N > 5:
  ans5 = []
  for j in range(len(ans4)):
    a = max(ans4[j])+1
    for i in range(a+1):
      c = copy.copy(ans4[j])
      c.append(i)
      ans5.append(c)

      
if N > 6:
  ans6 = []
  for j in range(len(ans5)):
    a = max(ans5[j])+1
    for i in range(a+1):
      c = copy.copy(ans5[j])
      c.append(i)
      ans6.append(c)

if N > 7:
  ans7 = []
  for j in range(len(ans6)):
    a = max(ans6[j])+1
    for i in range(a+1):
      c = copy.copy(ans6[j])
      c.append(i)
      ans7.append(c)

if N > 8:
  ans8 = []
  for j in range(len(ans7)):
    a = max(ans7[j])+1
    for i in range(a+1):
      c = copy.copy(ans7[j])
      c.append(i)
      ans8.append(c)

if N > 9:
  ans9 = []
  for j in range(len(ans8)):
    a = max(ans8[j])+1
    for i in range(a+1):
      c = copy.copy(ans8[j])
      c.append(i)
      ans9.append(c)
      
ans9.sort()
aaa = "abcdefghij"
if N == 1:
  print("a")    
    
elif N ==2:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==3:
  for i in ans2:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==4:
  for i in ans3:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans4:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==5:
  for i in ans1:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==7:
  for i in ans6:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==8:
  for i in ans7:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
  
elif N ==9:
  for i in ans8:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)
    
elif N ==10:
  for i in ans9:
    S = ""
    for j in i:
      S = S + aaa[j]
    print(S)

Submission status: Runtime Error

Solution code:
N = int(input())

print('a'*N)

for a in range(N, 0, -1):
    for b in range(N-a, 0 ,-1):
        for c in range(N-a-b, 0 ,-1):
            for d in range(N-a-b-c, 0 ,-1):
                for e in range(N-a-b-c-d, 0 ,-1):
                    for f in range(N-a-b-c-d-e, 0 ,-1):
                        for g in range(N-a-b-c-d-e-f, 0 ,-1):
                            for h in range(N-a-b-c-d-e-f-g, 0 ,-1):
                                for i in range(N-a-b-c-d-e-f-g-h, 0 ,-1):
                                    for j in range(N-a-b-c-d-e-f-g-h-i, 0 ,-1):
                                        print('a'*a+'b'*(b)+'c'*c+'d'*d+'e'*e+'f'*f+'g'*g+'h'*h*'i'*i+j*(N-a-b-c-d-e-f-g-h-i))

Submission status: Runtime Error

Solution code:
n=int(input())
patterns = ["a"]
for _ in range(n-1):
    last_patterns = patterns.copy()
    patterns = []
    for string in last_patterns:
        useful_str = alpha[:len(set(string))+1]
        for str_ in useful_str:
            patterns.append(string + str_)

for pat in patterns:
    print(pat)

Submission status: Runtime Error

Solution code:
N=int(input())
ans = []
def same(c):
    if len(c)==N:
        ans.append(c)
        return
    else:
        for i in range(ord('a'),ord(c[-1])+2):
            same(c+chr(i))
same('a')
for i in ans:
    print(ans)

Submission status: Runtime Error

Solution code:
import math

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

N = int(input())
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)

Submission status: Runtime Error

Solution code:
n = int(input())
a = ord('a')

def f(x: int) -> str:
  return chr(x + a)

for i in range(2 * 10 ** (n-2)):
  x = list(map(int, str(i).zfill(n)))
  maximum = 0
  flag = True
  for y in x[1:]:
    if y > maximum + 1:
      flag = False
      break
    elif y == maximum + 1:
      maximum = y
  if flag:
    print(''.join(map(f, x)))

Submission status: Runtime Error

Solution code:
import string

def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n = iinp()
a = string.ascii_lowercase

k = n

while k != 0:
  for i in range(2**(k-1)):
    d = []
    p = len(bin(i))
    q = bin(i)
    for j in range(p-2):
      q = bin(i>>j)
      if int(q[len(q)-1]) == 1:
        d.append(k-j-2)

    for i in range(n-k+1):
      print(a[i],end="")
    for j in range(k-1):
      if j in d:
        print(a[n-k+1],end="")
      else:
        print(a[n-k],end="")
    print("")
    k -= 1

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import itertools
N = int(input())

ans_list = []

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

for i in range(base10fromn(str(N - 1) * N, N)):
    n_num = base10ton(i, N)
    ans_cand = ["0"] * (N - len(str(n_num)))
    ans_cand.extend(list(n_num))
    replace_num = 97
    ans_cand_rep = ans_cand
    for j in ans_cand:
        if j in ans_cand_rep:
            ans_cand_rep = [chr(replace_num) if k == j else k for k in ans_cand_rep]
            replace_num += 1
    ans_cand_str = "".join([str(l) for l in ans_cand_rep])
    ans_list.append(ans_cand_str)

ans = list(set(ans_list))
ans.sort()
print("\n".join(ans))

Submission status: Runtime Error

Solution code:
n = int(input())

base = ['a' for i in range(n)]

end = ['z' for i in range(n)]

def sorted_k_partitions(seq, k):
    """Returns a list of all unique k-partitions of `seq`.

    Each partition is a list of parts, and each part is a tuple.

    The parts in each individual partition will be sorted in shortlex
    order (i.e., by length first, then lexicographically).

    The overall list of partitions will then be sorted by the length
    of their first part, the length of their second part, ...,
    the length of their last part, and then lexicographically.
    """
    n = len(seq)
    groups = []  # a list of lists, currently empty

    def generate_partitions(i):
        if i >= n:
            yield list(map(tuple, groups))
        else:
            if n - i > k - len(groups):
                for group in groups:
                    group.append(seq[i])
                    yield from generate_partitions(i + 1)
                    group.pop()

            if len(groups) < k:
                groups.append([seq[i]])
                yield from generate_partitions(i + 1)
                groups.pop()

    result = generate_partitions(0)

    # Sort the parts in each partition in shortlex order
    result = [sorted(ps, key = lambda p: (len(p), p)) for ps in result]
    # Sort partitions by the length of each part, then lexicographically.
    result = sorted(result, key = lambda ps: (*map(len, ps), ps))

    return result

seq = [i+1 for i in range(n)]

# print(seq)

res = []

for k in seq:
    for groups in sorted_k_partitions(seq, k):
        temp = ['a' for i in range(n)]
        tmp = []
        tmp = list(groups)
        tmp.sort()
        # print(tmp)
        counter = 0
        for t in tmp:
            for e in t:
                temp[e-1] = chr(ord('a') + counter)
            counter += 1
        # print('after')
        # print(temp)
        res.append(''.join(temp))

res.sort()

for r in res:
    print(r)

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())

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


#print(l)
if n>10:
	l = lis[:n]
	c = list(itertools.product(l, repeat=n-1))
	cand = []

	for i in range(len(c)):
		an = "a"
		for j in range(n-1):
			an += c[i][j]
		cand.append(an)
	#print(len(cand))
	#print(len(cand[0]))
else:
	l = lis[:n]
	cand = list(itertools.product(l, repeat=n))

#print(cand)

count = 0
for i in range(len(cand)):#何セットあるか
	temp = []
	temp.append(cand[i][0])
	cand[i] = list(cand[i])
	cand[i][0] = l[len(temp)-1]

	for j in range(1,n):#要素の数n
		for k in range(len(temp)):
			if cand[i][j] == temp[k]:#tempに入ってたら
				cand[i][j] = l[k]
			else:#未知なら
				temp.append(cand[i][j])
				cand[i][j] = l[len(temp)-1]


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

				
ans = get_unique_list(cand)
for i in range(len(ans)):
	p = ""
	for j in range(n):
		p += ans[i][j]
	print(p)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = ["a"] * N


def next_chr(ch):
    res = []
    for i in range(-1, 2):
        if ord(ch) + i >= ord("a") and ord(ch) + i <= ord("z"):
            res.append(chr(ord(ch)+i))
    return res


def answer(s, i):
    if i == N:
        ch = next_chr(s[-1])
        for m in ch:
            print("".join([s, m]))
    else:
        i += 1
        ch = next_chr(s[-1])
        for m in ch:
            answer("".join([s, m]), i)


answer("a", 2)