Buggy python submission (verdict: Runtime Error):
from string import ascii_lowercase


def main():
    word = input()
    if len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count_l = list(count.items())
        add = ""
        for i in range(26):
            if count_l[i][1] == 0:
                add = count_l[i][0]
                break
        print(word + add)
    else:
        stop = ascii_lowercase[::-1]
        final_permutation_index = 26
        for i in range(-2, -27, -1):
            if word[i:] not in stop:
                final_permutation_index = 26 + i
                break
        if final_permutation_index == 26:
            print(-1)
        else:
            add = sorted(list(word[final_permutation_index:]))
            final = ""
            for i in range(len(add)):
                if add[i] == word[final_permutation_index]:
                    final = add[i + 1]
                    break
            print(word[:final_permutation_index] + final)


if __name__ == '__main__':
    main()



Fixed submission:
from string import ascii_lowercase


def main():
    word = input()
    if len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count_l = list(count.items())
        count_l.sort(key=lambda x: x[0])
        add = ""
        for i in range(26):
            if count_l[i][1] == 0:
                add = count_l[i][0]
                break
        print(word + add)
    elif word == ascii_lowercase[::-1]:
        print(-1)
    else:
        is_printed = False
        while len(word) > 0 and not is_printed:
            for c in ascii_lowercase[ascii_lowercase.index(word[-1]) + 1:]:
                if c not in word[:-1]:
                    print(word[:-1] + c)
                    is_printed = True
                    break
            else:
                word = word[:-1]


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
from string import ascii_lowercase


def main():
    word = input()
    if word == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    elif len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count = count.items()
        add = ""
        for i in range(26):
            if count[i][1] == 0:
                add = count[i][0]
                break
        print(word + add)
    else:
        stop = ascii_lowercase[::-1]
        final_permutation_index = 25
        for i in range(-2, -27, -1):
            if word[i:] not in stop:
                final_permutation_index = 26 + i
                break
        if final_permutation_index != 25:
            print(word[:final_permutation_index] + word[-1])
        else:
            word = list(word)
            if word[-2] == "z":
                word[-1], word[-3] = word[-3], word[-1]
            else:
                word[-1], word[-2] = word[-2], word[-1]
            print("".join(word))



if __name__ == '__main__':
    main()



Fixed submission:
from string import ascii_lowercase


def main():
    word = input()
    if len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count_l = list(count.items())
        count_l.sort(key=lambda x: x[0])
        add = ""
        for i in range(26):
            if count_l[i][1] == 0:
                add = count_l[i][0]
                break
        print(word + add)
    elif word == ascii_lowercase[::-1]:
        print(-1)
    else:
        is_printed = False
        while len(word) > 0 and not is_printed:
            for c in ascii_lowercase[ascii_lowercase.index(word[-1]) + 1:]:
                if c not in word[:-1]:
                    print(word[:-1] + c)
                    is_printed = True
                    break
            else:
                word = word[:-1]


if __name__ == '__main__':
    main()