Problem p03393 (python)

Fixed submission:
from string import ascii_lowercase
s = input()

if s == ascii_lowercase[::-1]:
    print(-1)
elif len(s)!=len(ascii_lowercase):
    s1 = set(list(s))
    s2 = set(list(ascii_lowercase))
    w = min(s2-s1)
    print(s+w)
else:
    back = ''
    tmp = ''
    pos = 0
    for i in range(len(s))[::-1]:
        if i==25:
            back += s[i]
            tmp = s[i]
        elif s[i]>tmp:
            back += s[i]
            tmp = s[i]
        else:
            pos = i
            break
    
    res = s[:pos]
    w = s[pos]
    l = []
    for b in back:
        if b > w:
            l.append(b)
    print(res + min(l))

Buggy submission (verdict: Runtime Error):

from string import ascii_lowercase
s = input()

if s == ascii_lowercase[::-1]:
    print(-1)
elif len(s)!=len(ascii_lowercase):
    s1 = set(list(s))
    s2 = set(list(ascii_lowercase))
    w = min(s2-s1)
    print(s+w)
else:
    back = ''
    tmp = ''
    pos = 0
    for i in range(len(s))[::-1]:
        if i==25:
            back += s[i]
            tmp = s[i]
        elif s[i]>tmp:
            back += s[i]
            tmp = s[i]
        else:
            pos = i
            break

    res = s[:pos]
    l = []
    for b in back:
        if b > w:
            l.append(b)
    print(res + min(l))

Buggy submission (verdict: Runtime Error):
from string import ascii_lowercase
s = input()

if s == ascii_lowercase[::-1]:
    print(-1)
elif len(s)!=len(ascii_lowercase):
    s1 = set(list(s))
    s2 = set(list(ascii_lowercase))
    w = min(s2-s1)
    print(s+w)
else:
    a = ''
    res = ''
    tmp = ''
    back = ''
    for i in range(len(s))[::-1]:
        if i==0:
            tmp = s[i]
            a += s[i]
        else:
            if s[i]>tmp:
                a += s[i]
                tmp = s[i]
            else:
                res = s[:i]
                back = s[i:]
                break
    p = back[0]
    back = list(back)
    back.sort()
    if back[0]==p:
        print(res+back[1])
    else:
        print(res+back[0])

Buggy submission (verdict: Runtime Error):
from string import ascii_lowercase
s = input()

if s == ascii_lowercase[::-1]:
        print(-1)
elif len(s)!=len(ascii_lowercase):
    s1 = set(list(s))
    s2 = set(list(ascii_lowercase))
    w = min(s2-s1)
    print(s+w)
else:
    a = ''
    res = ''
    tmp = ''
    for i in range(len(s))[::-1]:
        if i==0:
            tmp = s[i]
            a += s[i]
        else:
            if s[i]>tmp:
                a += s[i]
                tmp = s[i]
            else:
                res = s[:i]
                break
    
    m = max(list(res))
    
    tmp = []
    for i in range(len(a)):
        if a[i]>m:
            tmp.append(a[i])
    print(res + min(tmp))

Buggy submission (verdict: Runtime Error):
s = input()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    full_lst = [i for i in range(ord('a'), ord('z')+1)]
    lst = []
    for i in range(len(s)):
        lst.append(ord(s[i]))
    
    if len(lst)!=len(full_lst):
        w = chr(min(set(full_lst)-set(lst)))
        print(s+w)
    else:
        res = ''
        for i in range(len(lst)):
            if lst[i]!=full_lst[i]:
                x = s[:i]
                y = lst[i:]
                break
        print(x[:-1] + chr(min(y)))