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: Wrong Answer

Solution code:
def main():
    N = int(input())
    from string import ascii_lowercase
    dic = {str(i): a for i, a in enumerate(ascii_lowercase)}
    rdic = {a: i for i, a in enumerate(ascii_lowercase)}

    if N == 1:
        return print("a")
    elif N == 2:
        print("aa")
        print("ab")
    elif N == 3:
        ans = ["aaa", "aab", "aba", "abb", "abc"]
        print(*ans, sep="\n")
    elif N == 4:
        ans = []
        for i in range(1 << (N-1)):
            s = "0" + "{:0>3b}".format(i)
            t = []
            for ss in s:
                t.append(dic[ss])
            ans.append("".join(t))
        pre = ["abbc", "abcb", "abcc", "abcd"]
        ans.extend(pre)
        print(*ans, sep="\n")
    elif N == 5:
        ans = []
        for i in range(1 << (N-1)):
            s = "0" + "{:0>4b}".format(i)
            t = []
            for ss in s:
                t.append(dic[ss])
            ans.append("".join(t))
        pre = ["aaab",
               "aaba",
               "aabb",
               "abaa",
               "abab",
               "abba",
               "abbb",
               "abbc",
               "abcb",
               "abcc",
               "abcd"]
        nex = []
        for i in range(len(pre)):
            t = []
            for p in pre[i]:
                # print(p, rdic[p], dic[str(rdic[p]+1)])
                t.append(dic[str(rdic[p] + 1)])
            nex.append("a"+"".join(t))
        ans.extend(nex)
        print(*ans, sep="\n")
    elif N == 6:
        ans = []
        for i in range(1 << (N-1)):
            s = "0" + "{:0>5b}".format(i)
            t = []
            for ss in s:
                t.append(dic[ss])
            ans.append("".join(t))
        pre = [
            "aaaab",
            "aaaba",
            "aaabb",
            "aabaa",
            "aabab",
            "aabba",
            "aabbb",
            "abaaa",
            "abaab",
            "ababa",
            "ababb",
            "abbaa",
            "abbab",
            "abbba",
            "abbbb",
            "abbbc",
            "abbcb",
            "abbcc",
            "abcbb",
            "abcbc",
            "abccb",
            "abccc",
            "abccd",
            "abcdc",
            "abcdd",
            "abcde"]
        nex = []
        for i in range(len(pre)):
            t = []
            for p in pre[i]:
                # print(p, rdic[p], dic[str(rdic[p]+1)])
                t.append(dic[str(rdic[p] + 1)])
            nex.append("a"+"".join(t))
        ans.extend(nex)
        print(*ans, sep="\n")
    elif N == 7:
        ans = []
        for i in range(1 << (N-1)):
            s = "0" + "{:0>6b}".format(i)
            t = []
            for ss in s:
                t.append(dic[ss])
            ans.append("".join(t))
        pre = [
            "aaaaab",
            "aaaaba",
            "aaaabb",
            "aaabaa",
            "aaabab",
            "aaabba",
            "aaabbb",
            "aabaaa",
            "aabaab",
            "aababa",
            "aababb",
            "aabbaa",
            "aabbab",
            "aabbba",
            "aabbbb",
            "abaaaa",
            "abaaab",
            "abaaba",
            "abaabb",
            "ababaa",
            "ababab",
            "ababba",
            "ababbb",
            "abbaaa",
            "abbaab",
            "abbaba",
            "abbabb",
            "abbbaa",
            "abbbab",
            "abbbba",
            "abbbbb",
            "abbbbc",
            "abbbcb",
            "abbbcc",
            "abbcbb",
            "abbcbc",
            "abbccb",
            "abbccc",
            "abcbbb",
            "abcbbc",
            "abcbcb",
            "abcbcc",
            "abccbb",
            "abccbc",
            "abcccb",
            "abcccc",
            "abcccd",
            "abccdc",
            "abccdd",
            "abcdcc",
            "abcdcd",
            "abcddc",
            "abcddd",
            "abcdde",
            "abcded",
            "abcdee",
            "abcdef", ]
        nex = []
        for i in range(len(pre)):
            t = []
            for p in pre[i]:
                # print(p, rdic[p], dic[str(rdic[p]+1)])
                t.append(dic[str(rdic[p] + 1)])
            nex.append("a"+"".join(t))
        ans.extend(nex)
        print(*ans, sep="\n")
    elif N == 8:
        ans = []
        for i in range(1 << (N-1)):
            s = "0" + "{:0>7b}".format(i)
            t = []
            for ss in s:
                t.append(dic[ss])
            ans.append("".join(t))
        pre = [
            "aaaaaab",
            "aaaaaba",
            "aaaaabb",
            "aaaabaa",
            "aaaabab",
            "aaaabba",
            "aaaabbb",
            "aaabaaa",
            "aaabaab",
            "aaababa",
            "aaababb",
            "aaabbaa",
            "aaabbab",
            "aaabbba",
            "aaabbbb",
            "aabaaaa",
            "aabaaab",
            "aabaaba",
            "aabaabb",
            "aababaa",
            "aababab",
            "aababba",
            "aababbb",
            "aabbaaa",
            "aabbaab",
            "aabbaba",
            "aabbabb",
            "aabbbaa",
            "aabbbab",
            "aabbbba",
            "aabbbbb",
            "abaaaaa",
            "abaaaab",
            "abaaaba",
            "abaaabb",
            "abaabaa",
            "abaabab",
            "abaabba",
            "abaabbb",
            "ababaaa",
            "ababaab",
            "abababa",
            "abababb",
            "ababbaa",
            "ababbab",
            "ababbba",
            "ababbbb",
            "abbaaaa",
            "abbaaab",
            "abbaaba",
            "abbaabb",
            "abbabaa",
            "abbabab",
            "abbabba",
            "abbabbb",
            "abbbaaa",
            "abbbaab",
            "abbbaba",
            "abbbabb",
            "abbbbaa",
            "abbbbab",
            "abbbbba",
            "abbbbbb",
            "abbbbbc",
            "abbbbcb",
            "abbbbcc",
            "abbbcbb",
            "abbbcbc",
            "abbbccb",
            "abbbccc",
            "abbcbbb",
            "abbcbbc",
            "abbcbcb",
            "abbcbcc",
            "abbccbb",
            "abbccbc",
            "abbcccb",
            "abbcccc",
            "abcbbbb",
            "abcbbbc",
            "abcbbcb",
            "abcbbcc",
            "abcbcbb",
            "abcbcbc",
            "abcbccb",
            "abcbccc",
            "abccbbb",
            "abccbbc",
            "abccbcb",
            "abccbcc",
            "abcccbb",
            "abcccbc",
            "abccccb",
            "abccccc",
            "abccccd",
            "abcccdc",
            "abcccdd",
            "abccdcc",
            "abccdcd",
            "abccddc",
            "abccddd",
            "abcdccc",
            "abcdccd",
            "abcdcdc",
            "abcdcdd",
            "abcddcc",
            "abcddcd",
            "abcdddc",
            "abcdddd",
            "abcddde",
            "abcdded",
            "abcddee",
            "abcdedd",
            "abcdede",
            "abcdeed",
            "abcdeee",
            "abcdeef",
            "abcdefe",
            "abcdeff",
            "abcdefg"]
        nex = []
        for i in range(len(pre)):
            t = []
            for p in pre[i]:
                # print(p, rdic[p], dic[str(rdic[p]+1)])
                t.append(dic[str(rdic[p] + 1)])
            nex.append("a"+"".join(t))
        ans.extend(nex)
        print(*ans, sep="\n")
    elif N == 9:
        ans = []
        for i in range(1 << (N-1)):
            s = "0" + "{:0>8b}".format(i)
            t = []
            for ss in s:
                t.append(dic[ss])
            ans.append("".join(t))
        pre = ["aaaaaaab",
               "aaaaaaba",
               "aaaaaabb",
               "aaaaabaa",
               "aaaaabab",
               "aaaaabba",
               "aaaaabbb",
               "aaaabaaa",
               "aaaabaab",
               "aaaababa",
               "aaaababb",
               "aaaabbaa",
               "aaaabbab",
               "aaaabbba",
               "aaaabbbb",
               "aaabaaaa",
               "aaabaaab",
               "aaabaaba",
               "aaabaabb",
               "aaababaa",
               "aaababab",
               "aaababba",
               "aaababbb",
               "aaabbaaa",
               "aaabbaab",
               "aaabbaba",
               "aaabbabb",
               "aaabbbaa",
               "aaabbbab",
               "aaabbbba",
               "aaabbbbb",
               "aabaaaaa",
               "aabaaaab",
               "aabaaaba",
               "aabaaabb",
               "aabaabaa",
               "aabaabab",
               "aabaabba",
               "aabaabbb",
               "aababaaa",
               "aababaab",
               "aabababa",
               "aabababb",
               "aababbaa",
               "aababbab",
               "aababbba",
               "aababbbb",
               "aabbaaaa",
               "aabbaaab",
               "aabbaaba",
               "aabbaabb",
               "aabbabaa",
               "aabbabab",
               "aabbabba",
               "aabbabbb",
               "aabbbaaa",
               "aabbbaab",
               "aabbbaba",
               "aabbbabb",
               "aabbbbaa",
               "aabbbbab",
               "aabbbbba",
               "aabbbbbb",
               "abaaaaaa",
               "abaaaaab",
               "abaaaaba",
               "abaaaabb",
               "abaaabaa",
               "abaaabab",
               "abaaabba",
               "abaaabbb",
               "abaabaaa",
               "abaabaab",
               "abaababa",
               "abaababb",
               "abaabbaa",
               "abaabbab",
               "abaabbba",
               "abaabbbb",
               "ababaaaa",
               "ababaaab",
               "ababaaba",
               "ababaabb",
               "abababaa",
               "abababab",
               "abababba",
               "abababbb",
               "ababbaaa",
               "ababbaab",
               "ababbaba",
               "ababbabb",
               "ababbbaa",
               "ababbbab",
               "ababbbba",
               "ababbbbb",
               "abbaaaaa",
               "abbaaaab",
               "abbaaaba",
               "abbaaabb",
               "abbaabaa",
               "abbaabab",
               "abbaabba",
               "abbaabbb",
               "abbabaaa",
               "abbabaab",
               "abbababa",
               "abbababb",
               "abbabbaa",
               "abbabbab",
               "abbabbba",
               "abbabbbb",
               "abbbaaaa",
               "abbbaaab",
               "abbbaaba",
               "abbbaabb",
               "abbbabaa",
               "abbbabab",
               "abbbabba",
               "abbbabbb",
               "abbbbaaa",
               "abbbbaab",
               "abbbbaba",
               "abbbbabb",
               "abbbbbaa",
               "abbbbbab",
               "abbbbbba",
               "abbbbbbb",
               "abbbbbbc",
               "abbbbbcb",
               "abbbbbcc",
               "abbbbcbb",
               "abbbbcbc",
               "abbbbccb",
               "abbbbccc",
               "abbbcbbb",
               "abbbcbbc",
               "abbbcbcb",
               "abbbcbcc",
               "abbbccbb",
               "abbbccbc",
               "abbbcccb",
               "abbbcccc",
               "abbcbbbb",
               "abbcbbbc",
               "abbcbbcb",
               "abbcbbcc",
               "abbcbcbb",
               "abbcbcbc",
               "abbcbccb",
               "abbcbccc",
               "abbccbbb",
               "abbccbbc",
               "abbccbcb",
               "abbccbcc",
               "abbcccbb",
               "abbcccbc",
               "abbccccb",
               "abbccccc",
               "abcbbbbb",
               "abcbbbbc",
               "abcbbbcb",
               "abcbbbcc",
               "abcbbcbb",
               "abcbbcbc",
               "abcbbccb",
               "abcbbccc",
               "abcbcbbb",
               "abcbcbbc",
               "abcbcbcb",
               "abcbcbcc",
               "abcbccbb",
               "abcbccbc",
               "abcbcccb",
               "abcbcccc",
               "abccbbbb",
               "abccbbbc",
               "abccbbcb",
               "abccbbcc",
               "abccbcbb",
               "abccbcbc",
               "abccbccb",
               "abccbccc",
               "abcccbbb",
               "abcccbbc",
               "abcccbcb",
               "abcccbcc",
               "abccccbb",
               "abccccbc",
               "abcccccb",
               "abcccccc",
               "abcccccd",
               "abccccdc",
               "abccccdd",
               "abcccdcc",
               "abcccdcd",
               "abcccddc",
               "abcccddd",
               "abccdccc",
               "abccdccd",
               "abccdcdc",
               "abccdcdd",
               "abccddcc",
               "abccddcd",
               "abccdddc",
               "abccdddd",
               "abcdcccc",
               "abcdcccd",
               "abcdccdc",
               "abcdccdd",
               "abcdcdcc",
               "abcdcdcd",
               "abcdcddc",
               "abcdcddd",
               "abcddccc",
               "abcddccd",
               "abcddcdc",
               "abcddcdd",
               "abcdddcc",
               "abcdddcd",
               "abcddddc",
               "abcddddd",
               "abcdddde",
               "abcddded",
               "abcdddee",
               "abcddedd",
               "abcddede",
               "abcddeed",
               "abcddeee",
               "abcdeddd",
               "abcdedde",
               "abcdeded",
               "abcdedee",
               "abcdeedd",
               "abcdeede",
               "abcdeeed",
               "abcdeeee",
               "abcdeeef",
               "abcdeefe",
               "abcdeeff",
               "abcdefee",
               "abcdefef",
               "abcdeffe",
               "abcdefff",
               "abcdeffg",
               "abcdefgf",
               "abcdefgg",
               "abcdefgh"
               ]
        nex = []
        for i in range(len(pre)):
            t = []
            for p in pre[i]:
                # print(p, rdic[p], dic[str(rdic[p]+1)])
                t.append(dic[str(rdic[p] + 1)])
            nex.append("a"+"".join(t))
        ans.extend(nex)
        print(*ans, sep="\n")
    elif N == 10:
        ans = []
        for i in range(1 << (N-1)):
            s = "0" + "{:0>9b}".format(i)
            t = []
            for ss in s:
                t.append(dic[ss])
            ans.append("".join(t))
        pre = [
            "aaaaaaaab",
            "aaaaaaaba",
            "aaaaaaabb",
            "aaaaaabaa",
            "aaaaaabab",
            "aaaaaabba",
            "aaaaaabbb",
            "aaaaabaaa",
            "aaaaabaab",
            "aaaaababa",
            "aaaaababb",
            "aaaaabbaa",
            "aaaaabbab",
            "aaaaabbba",
            "aaaaabbbb",
            "aaaabaaaa",
            "aaaabaaab",
            "aaaabaaba",
            "aaaabaabb",
            "aaaababaa",
            "aaaababab",
            "aaaababba",
            "aaaababbb",
            "aaaabbaaa",
            "aaaabbaab",
            "aaaabbaba",
            "aaaabbabb",
            "aaaabbbaa",
            "aaaabbbab",
            "aaaabbbba",
            "aaaabbbbb",
            "aaabaaaaa",
            "aaabaaaab",
            "aaabaaaba",
            "aaabaaabb",
            "aaabaabaa",
            "aaabaabab",
            "aaabaabba",
            "aaabaabbb",
            "aaababaaa",
            "aaababaab",
            "aaabababa",
            "aaabababb",
            "aaababbaa",
            "aaababbab",
            "aaababbba",
            "aaababbbb",
            "aaabbaaaa",
            "aaabbaaab",
            "aaabbaaba",
            "aaabbaabb",
            "aaabbabaa",
            "aaabbabab",
            "aaabbabba",
            "aaabbabbb",
            "aaabbbaaa",
            "aaabbbaab",
            "aaabbbaba",
            "aaabbbabb",
            "aaabbbbaa",
            "aaabbbbab",
            "aaabbbbba",
            "aaabbbbbb",
            "aabaaaaaa",
            "aabaaaaab",
            "aabaaaaba",
            "aabaaaabb",
            "aabaaabaa",
            "aabaaabab",
            "aabaaabba",
            "aabaaabbb",
            "aabaabaaa",
            "aabaabaab",
            "aabaababa",
            "aabaababb",
            "aabaabbaa",
            "aabaabbab",
            "aabaabbba",
            "aabaabbbb",
            "aababaaaa",
            "aababaaab",
            "aababaaba",
            "aababaabb",
            "aabababaa",
            "aabababab",
            "aabababba",
            "aabababbb",
            "aababbaaa",
            "aababbaab",
            "aababbaba",
            "aababbabb",
            "aababbbaa",
            "aababbbab",
            "aababbbba",
            "aababbbbb",
            "aabbaaaaa",
            "aabbaaaab",
            "aabbaaaba",
            "aabbaaabb",
            "aabbaabaa",
            "aabbaabab",
            "aabbaabba",
            "aabbaabbb",
            "aabbabaaa",
            "aabbabaab",
            "aabbababa",
            "aabbababb",
            "aabbabbaa",
            "aabbabbab",
            "aabbabbba",
            "aabbabbbb",
            "aabbbaaaa",
            "aabbbaaab",
            "aabbbaaba",
            "aabbbaabb",
            "aabbbabaa",
            "aabbbabab",
            "aabbbabba",
            "aabbbabbb",
            "aabbbbaaa",
            "aabbbbaab",
            "aabbbbaba",
            "aabbbbabb",
            "aabbbbbaa",
            "aabbbbbab",
            "aabbbbbba",
            "aabbbbbbb",
            "abaaaaaaa",
            "abaaaaaab",
            "abaaaaaba",
            "abaaaaabb",
            "abaaaabaa",
            "abaaaabab",
            "abaaaabba",
            "abaaaabbb",
            "abaaabaaa",
            "abaaabaab",
            "abaaababa",
            "abaaababb",
            "abaaabbaa",
            "abaaabbab",
            "abaaabbba",
            "abaaabbbb",
            "abaabaaaa",
            "abaabaaab",
            "abaabaaba",
            "abaabaabb",
            "abaababaa",
            "abaababab",
            "abaababba",
            "abaababbb",
            "abaabbaaa",
            "abaabbaab",
            "abaabbaba",
            "abaabbabb",
            "abaabbbaa",
            "abaabbbab",
            "abaabbbba",
            "abaabbbbb",
            "ababaaaaa",
            "ababaaaab",
            "ababaaaba",
            "ababaaabb",
            "ababaabaa",
            "ababaabab",
            "ababaabba",
            "ababaabbb",
            "abababaaa",
            "abababaab",
            "ababababa",
            "ababababb",
            "abababbaa",
            "abababbab",
            "abababbba",
            "abababbbb",
            "ababbaaaa",
            "ababbaaab",
            "ababbaaba",
            "ababbaabb",
            "ababbabaa",
            "ababbabab",
            "ababbabba",
            "ababbabbb",
            "ababbbaaa",
            "ababbbaab",
            "ababbbaba",
            "ababbbabb",
            "ababbbbaa",
            "ababbbbab",
            "ababbbbba",
            "ababbbbbb",
            "abbaaaaaa",
            "abbaaaaab",
            "abbaaaaba",
            "abbaaaabb",
            "abbaaabaa",
            "abbaaabab",
            "abbaaabba",
            "abbaaabbb",
            "abbaabaaa",
            "abbaabaab",
            "abbaababa",
            "abbaababb",
            "abbaabbaa",
            "abbaabbab",
            "abbaabbba",
            "abbaabbbb",
            "abbabaaaa",
            "abbabaaab",
            "abbabaaba",
            "abbabaabb",
            "abbababaa",
            "abbababab",
            "abbababba",
            "abbababbb",
            "abbabbaaa",
            "abbabbaab",
            "abbabbaba",
            "abbabbabb",
            "abbabbbaa",
            "abbabbbab",
            "abbabbbba",
            "abbabbbbb",
            "abbbaaaaa",
            "abbbaaaab",
            "abbbaaaba",
            "abbbaaabb",
            "abbbaabaa",
            "abbbaabab",
            "abbbaabba",
            "abbbaabbb",
            "abbbabaaa",
            "abbbabaab",
            "abbbababa",
            "abbbababb",
            "abbbabbaa",
            "abbbabbab",
            "abbbabbba",
            "abbbabbbb",
            "abbbbaaaa",
            "abbbbaaab",
            "abbbbaaba",
            "abbbbaabb",
            "abbbbabaa",
            "abbbbabab",
            "abbbbabba",
            "abbbbabbb",
            "abbbbbaaa",
            "abbbbbaab",
            "abbbbbaba",
            "abbbbbabb",
            "abbbbbbaa",
            "abbbbbbab",
            "abbbbbbba",
            "abbbbbbbb",
            "abbbbbbbc",
            "abbbbbbcb",
            "abbbbbbcc",
            "abbbbbcbb",
            "abbbbbcbc",
            "abbbbbccb",
            "abbbbbccc",
            "abbbbcbbb",
            "abbbbcbbc",
            "abbbbcbcb",
            "abbbbcbcc",
            "abbbbccbb",
            "abbbbccbc",
            "abbbbcccb",
            "abbbbcccc",
            "abbbcbbbb",
            "abbbcbbbc",
            "abbbcbbcb",
            "abbbcbbcc",
            "abbbcbcbb",
            "abbbcbcbc",
            "abbbcbccb",
            "abbbcbccc",
            "abbbccbbb",
            "abbbccbbc",
            "abbbccbcb",
            "abbbccbcc",
            "abbbcccbb",
            "abbbcccbc",
            "abbbccccb",
            "abbbccccc",
            "abbcbbbbb",
            "abbcbbbbc",
            "abbcbbbcb",
            "abbcbbbcc",
            "abbcbbcbb",
            "abbcbbcbc",
            "abbcbbccb",
            "abbcbbccc",
            "abbcbcbbb",
            "abbcbcbbc",
            "abbcbcbcb",
            "abbcbcbcc",
            "abbcbccbb",
            "abbcbccbc",
            "abbcbcccb",
            "abbcbcccc",
            "abbccbbbb",
            "abbccbbbc",
            "abbccbbcb",
            "abbccbbcc",
            "abbccbcbb",
            "abbccbcbc",
            "abbccbccb",
            "abbccbccc",
            "abbcccbbb",
            "abbcccbbc",
            "abbcccbcb",
            "abbcccbcc",
            "abbccccbb",
            "abbccccbc",
            "abbcccccb",
            "abbcccccc",
            "abcbbbbbb",
            "abcbbbbbc",
            "abcbbbbcb",
            "abcbbbbcc",
            "abcbbbcbb",
            "abcbbbcbc",
            "abcbbbccb",
            "abcbbbccc",
            "abcbbcbbb",
            "abcbbcbbc",
            "abcbbcbcb",
            "abcbbcbcc",
            "abcbbccbb",
            "abcbbccbc",
            "abcbbcccb",
            "abcbbcccc",
            "abcbcbbbb",
            "abcbcbbbc",
            "abcbcbbcb",
            "abcbcbbcc",
            "abcbcbcbb",
            "abcbcbcbc",
            "abcbcbccb",
            "abcbcbccc",
            "abcbccbbb",
            "abcbccbbc",
            "abcbccbcb",
            "abcbccbcc",
            "abcbcccbb",
            "abcbcccbc",
            "abcbccccb",
            "abcbccccc",
            "abccbbbbb",
            "abccbbbbc",
            "abccbbbcb",
            "abccbbbcc",
            "abccbbcbb",
            "abccbbcbc",
            "abccbbccb",
            "abccbbccc",
            "abccbcbbb",
            "abccbcbbc",
            "abccbcbcb",
            "abccbcbcc",
            "abccbccbb",
            "abccbccbc",
            "abccbcccb",
            "abccbcccc",
            "abcccbbbb",
            "abcccbbbc",
            "abcccbbcb",
            "abcccbbcc",
            "abcccbcbb",
            "abcccbcbc",
            "abcccbccb",
            "abcccbccc",
            "abccccbbb",
            "abccccbbc",
            "abccccbcb",
            "abccccbcc",
            "abcccccbb",
            "abcccccbc",
            "abccccccb",
            "abccccccc",
            "abccccccd",
            "abcccccdc",
            "abcccccdd",
            "abccccdcc",
            "abccccdcd",
            "abccccddc",
            "abccccddd",
            "abcccdccc",
            "abcccdccd",
            "abcccdcdc",
            "abcccdcdd",
            "abcccddcc",
            "abcccddcd",
            "abcccdddc",
            "abcccdddd",
            "abccdcccc",
            "abccdcccd",
            "abccdccdc",
            "abccdccdd",
            "abccdcdcc",
            "abccdcdcd",
            "abccdcddc",
            "abccdcddd",
            "abccddccc",
            "abccddccd",
            "abccddcdc",
            "abccddcdd",
            "abccdddcc",
            "abccdddcd",
            "abccddddc",
            "abccddddd",
            "abcdccccc",
            "abcdccccd",
            "abcdcccdc",
            "abcdcccdd",
            "abcdccdcc",
            "abcdccdcd",
            "abcdccddc",
            "abcdccddd",
            "abcdcdccc",
            "abcdcdccd",
            "abcdcdcdc",
            "abcdcdcdd",
            "abcdcddcc",
            "abcdcddcd",
            "abcdcdddc",
            "abcdcdddd",
            "abcddcccc",
            "abcddcccd",
            "abcddccdc",
            "abcddccdd",
            "abcddcdcc",
            "abcddcdcd",
            "abcddcddc",
            "abcddcddd",
            "abcdddccc",
            "abcdddccd",
            "abcdddcdc",
            "abcdddcdd",
            "abcddddcc",
            "abcddddcd",
            "abcdddddc",
            "abcdddddd",
            "abcddddde",
            "abcdddded",
            "abcddddee",
            "abcdddedd",
            "abcdddede",
            "abcdddeed",
            "abcdddeee",
            "abcddeddd",
            "abcddedde",
            "abcddeded",
            "abcddedee",
            "abcddeedd",
            "abcddeede",
            "abcddeeed",
            "abcddeeee",
            "abcdedddd",
            "abcdeddde",
            "abcdedded",
            "abcdeddee",
            "abcdededd",
            "abcdedede",
            "abcdedeed",
            "abcdedeee",
            "abcdeeddd",
            "abcdeedde",
            "abcdeeded",
            "abcdeedee",
            "abcdeeedd",
            "abcdeeede",
            "abcdeeeed",
            "abcdeeeee",
            "abcdeeeef",
            "abcdeeefe",
            "abcdeeeff",
            "abcdeefee",
            "abcdeefef",
            "abcdeeffe",
            "abcdeefff",
            "abcdefeee",
            "abcdefeef",
            "abcdefefe",
            "abcdefeff",
            "abcdeffee",
            "abcdeffef",
            "abcdefffe",
            "abcdeffff",
            "abcdefffg",
            "abcdeffgf",
            "abcdeffgg",
            "abcdefgff",
            "abcdefgfg",
            "abcdefggf",
            "abcdefggg",
            "abcdefggh",
            "abcdefghg",
            "abcdefghh",
            "abcdefghi"
        ]
        nex = []
        for i in range(len(pre)):
            t = []
            for p in pre[i]:
                # print(p, rdic[p], dic[str(rdic[p]+1)])
                t.append(dic[str(rdic[p] + 1)])
            nex.append("a"+"".join(t))
        ans.extend(nex)
        print(*ans, sep="\n")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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:
            ans.append("".join([s, m]))
    else:
        i += 1
        ch = next_chr(s[-1])
        for m in ch:
            answer("".join([s, m]), i)

if N == 1:
    print("a")
else:
    answer("a", 2)

    for c in ans:
        print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

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

    alpha = 'abcdefghijk'

    for i in range(1,N):
        res = []
        pre = dp[i-1]
        for s in pre:
            for j in range(i+1):
                temp = s + alpha[j]
                res.append(temp)
        dp[i] = res

    res = dp[N-1]

    for i in res:
        print(i)



main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import itertools
N = int(input())
def base10ton(num, n):
    if (int(num / n)):
        return base10ton(int(num / n), n) + str(num % n)
    return str(num % n)

def base10fromn(num_str, n):
    i = 0
    numlist = list(num_str);
    while (numlist):
        i *= n
        i += int(numlist.pop(0))
    return i

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