Problem p03393 (python)

Fixed submission:
import string

S = input()
reversedS = ''.join(list(S)[::-1])
alphabets = list(string.ascii_lowercase)
lastWord = ''.join(alphabets[::-1])
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        found = False
        for i in range(len(reversedS)):
            s = reversedS[i]
            largeS = alphabets[ord(s)-ord('a')+1:]
            tailS = list(S)[26-i-1:]
            for lS in largeS:
                if lS in tailS:
                    print(S[:26-i-1]+lS)
                    found = True
                    break
            if found: break
else:
    for j in range(26):
        if cnt[j] == 0:
            S += chr(ord('a')+j)
            print(S)
            break

Buggy submission (verdict: Runtime Error):
import string

S = input()
alphabets = list(string.ascii_lowercase)
lastWord = ''.join(alphabets[::-1])
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i in S:
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
else:
    print('test')

Buggy submission (verdict: Runtime Error):
import string

S = input()
alphabets = list(string.ascii_lowercase)
lastWord = ''.join(alphabets[::-1])
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i in S:
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
else:
    for j in range(26):
        if cnt[j] == 0:
            S += chr(ord('a')+j)
            print(S)
            break

Buggy submission (verdict: Runtime Error):
import string

S = input()
alphabetsStr = string.ascii_lowercase
alphabets = list(map(lambda x: x, string.ascii_lowercase))
lastWord = ''.join(alphabets[::-1])
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i in S:
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
else:
    for j in range(26):
        if cnt[j] == 0:
            S += chr(ord('a')+j)
            print(S)
            break

Buggy submission (verdict: Runtime Error):
import string

S = input()
alphabetsStr = string.ascii_lowercase
alphabets = list(map(lambda x: x, string.ascii_lowercase))
lastWord = ''.join(alphabets[::-1])

if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i  in S:
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
# else:
#     for s in alphabets:
#         if s not in S:
#             print(S + s)
#             break

print(-1)

Buggy submission (verdict: Runtime Error):
import string

S = input()
alphabetsStr = string.ascii_lowercase
alphabets = list(map(lambda x: x, string.ascii_lowercase))
lastWord = ''.join(alphabets[::-1])

if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i  in S:
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
else:
    for s in alphabets:
        if s not in S:
            print(S + s)
            break

Buggy submission (verdict: Runtime Error):
import string


S = input()
retS = ''
alphabetsStr = string.ascii_lowercase
alphabets = list(map(lambda x: x, string.ascii_lowercase))
lastWord = ''.join(alphabets[::-1])

if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i  in S:
            if alphabets[i] != S[i]:
                retS = S[:i] + alphabets[i]
                break
else:
    for s in alphabets:
        if s not in S:
            retS = S + s
            break
print(retS)

Buggy submission (verdict: Runtime Error):
import string

S = input()

if len(S) == 26: print(-1)
retS = ''
alphabetsStr = string.ascii_lowercase
alphabets = list(map(lambda x: x, string.ascii_lowercase))
found = False
lenS = len(S)
if S[0] == 'a':
    for i in range(len(S)):
        if S[i] != alphabets[i]:
            retS = string.ascii_lowercase[:i+1]
            found = True
            break
else:
    idx = alphabets.index(S[0])
    for i in range(1, idx+1):
        if S[i] != alphabets[i-1]:
            retS = S[:i] + alphabets[i-1]
            found = True
            break
    if not found:
        for i in range(idx+1, len(S)):
            if S[i] != alphabets[i]:
                retS = string.ascii_lowercase[:i+1]
                found = True
                break
    
if not found: retS = S + alphabets[len(S)]
print(retS)