Problem p03393 (python)

Fixed submission:
S = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
if S == alpha[::-1]:
    print(-1)
else:
    rest = sorted(list(set(alpha) - set(S)))
    if rest:
        print(S + rest[0])
    else:
        for i in range(len(S)-1, 0, -1):
            if S[i-1] < S[i]:
                break
        rest = sorted([s for s in S[i:] if s > S[i-1]])
        print(S[:i-1] + rest[0])

Buggy submission (verdict: Runtime Error):
import string
alphabets = string.ascii_lowercase

S = input()

if len(S) < 26:
    for i in range(26):
        if alphabets[i] not in S:
            char_idx = i
            break
    print(S + alphabets[char_idx])
elif S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    cont_flag = False
    for i in range(26-1):
        if S[i] > S[i+1]:
            if cont_flag == False:
                idx = i
                cont_flag = True
        else:
            cont_flag = False
            
    if idx == 0:
        for i in range(26):
            if alphabets[i] > S[idx]:
                char_idx = i
                break
        print(alphabets[char_idx])
    else:
        st = S[:idx]
        char = S[idx-1]
        len_st = len(st)
        for i in range(26):
            if alphabets[i] not in st and alphabets[i] > char:
                char_idx = i
                break
        print(st[:len_st-1] + alphabets[char_idx])

Buggy submission (verdict: Runtime Error):
import string
alphabets = string.ascii_lowercase

S = input()

if len(S) < 26:
    for i in range(26):
        if alphabets[i] not in S:
            char_idx = i
            break
    print(S + alphabets[char_idx])
elif S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    cont_flag = False
    for i in range(26-1):
        if S[i] > S[i+1]:
            if cont_flag == False:
                idx = i
                cont_flag = True
        else:
            cont_flag = False
            
    if idx == 0:
        for i in range(26):
            if alphabets[i] > S[idx]:
                char_idx = i
                break
        print(alphabets[char_idx])
    else:
        st = S[:idx]
        if S[idx] == 'z':
            char = S[idx-1]
            len_st = len(st)
            for i in range(26):
                if alphabets[i] not in st and alphabets[i] > char:
                    char_idx = i
                    break
            print(st[:len_st-1] + alphabets[char_idx])
        else:
            char = S[idx]
            for i in range(26):
                if alphabets[i] not in st and alphabets[i] > char:
                    char_idx = i
                    break
            print(st + alphabets[char_idx])

Buggy submission (verdict: Runtime Error):
import string
alphabets = string.ascii_lowercase

def alphabet_check(S, checker):
    for i, s in enumerate(S):
        checker[alphabets.index(s)] = i

S = input()
checker = [-1]*26

alphabet_check(S, checker)

if len(S) < 26:
    char_idx = checker.index(-1) 
    print(S + alphabets[char_idx])
elif S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    cont_flag = False
    for i in range(26-1):
        if S[i] > S[i+1]:
            if cont_flag == False:
                idx = i
                cont_flag = True
        else:
            cont_flag = False
            
    checker2 = [-1]*26
    if idx == 0:
        st = ''
        for i in range(26):
            if alphabets[i] > S[idx]:
                char_idx = i
                break
    else:
        st = S[:idx-1]
        alphabet_check(st, checker2)
        for i in range(26):
            if checker2[i] == -1 and alphabets[i] > S[idx-1]:
                char_idx = i
                break
    print(st + alphabets[char_idx])

Buggy submission (verdict: Runtime Error):
import string
alphabets = string.ascii_lowercase

def alphabet_check(S, checker):
    for i, s in enumerate(S):
        checker[alphabets.index(s)] = i

S = input()
checker = [-1]*26

alphabet_check(S, checker)

if len(S) < 26:
    char_idx = checker.index(-1) 
    print(S + alphabets[char_idx])
elif S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    cont_flag = False
    for i in range(26-1):
        if S[i] > S[i+1]:
            if cont_flag == False:
                idx = i
                cont_flag = True
        else:
            cont_flag = False
    string = S[:idx-1]
    checker2 = [-1]*26
    alphabet_check(string, checker2)
    for i in range(26):
        if checker2[i] == -1 and alphabets[i] > S[idx-1]:
            char_idx = i
            break
    print(string + alphabets[char_idx])

Buggy submission (verdict: Runtime Error):
import string
alphabets = string.ascii_lowercase

def alphabet_check(S, checker):
    for i, s in enumerate(S):
        checker[alphabets.index(s)] = i

S = input()
checker = [-1]*26

alphabet_check(S, checker)

if len(S) < 26:
    char_idx = checker.index(-1) 
    print(S + alphabets[char_idx])
elif S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    cont_flag = False
    for i in range(len(S)-1):
        if S[i] > S[i+1]:
            if cont_flag == False:
                idx = i
                cont_flag = True
    string = S[:idx]
    l = len(string)
    checker = [-1]*26
    alphabet_check(string, checker)
    char_idx = checker.index(-1)
    print(string[:l-1] + alphabets[char_idx])