Problem p03393 (python)

Fixed submission:
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + chr(X)
else:
    T = []
    x = S[-1]
    T.append(x)
    for i in range(2,27):
        y = S[-i]
        if y > x:
            x = y
            T.append(y)
        else:
            break
    m = 26 - len(T)
    if m > 1:
        ans = S[0]
        for i in range(1,m-1):
            ans += S[i]
        for t in T:
            if t > S[m-1]:
                ans += t
                break
    elif m == 0:
        ans = -1
    else:
        for t in T:
            if t > S[m-1]:
                ans = t
                break
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + X
else:
    T = []
    x = S[-1]
    T.append(x)
    for i in range(2,27):
        y = S[-i]
        if y > x:
            x = y
            T.append(y)
        else:
            break
    m = 26 - len(T)
    if m != 0:
        ans = S[0]
        for i in range(1,m-1):
            ans += S[i]
        for t in T:
            if t > S[m-1]:
                ans += t
                break
    else:
        ans = -1
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + chr(X)d
else:
    T = []
    x = S[-1]
    T.append(x)
    for i in range(2,27):
        y = S[-i]
        if y > x:
            x = y
            T.append(y)
        else:
            break
    m = 26 - len(T)
    if m != 0:
        ans = S[0]
        for i in range(1,m-1):
            ans += S[i]
        for t in T:
            if t > S[m-1]:
                ans += t
                break
    else:
        ans = -1
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + chr(X)
else:
    T = []
    p = 0
    q,r = -1,-1
    for i in range(n):
        j = S[i]
        if ord(j) > p:
            q = i
            T = []
        else:
            if len(T) == 0:
                r = i
                T.append(S[i-1])
            T.append(j)
        p = ord(j)
    if len(T) == 0:
        T.append(S[n-1])
        r = n
    if (r == 1) & (S[r-1] == 'z'):
        ans = -1
    else:
        ans = S[0]
    for i in range(1,r-2):
         ans += S[i]
    for i in range(1,len(T)+1):
            if S[r-2] < T[-i]:
                ans += T[-i]
                break
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + chr(X)
else:
    T = []
    p = 0
    q,r = -1,-1
    for i in range(n):
        j = S[i]
        if ord(j) > p:
            q = i
            T = []
        else:
            if len(T) == 0:
                r = i
            T.append(j)
        p = ord(j)
    if q < r:
        if S[r-1] == 'z':
            if r == 1:
                ans = -1
            else:
                ans = S[0]
                for i in range(1,r-2):
                    ans += S[i]
                ans += T[-1]
    else:
        ans = S[0]
        for i in range(1,n-2):
            ans += S[i]
        ans += S[n-1]
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + chr(X)
else:
    T = []
    p = 0
    q,r = -1,-1
    for i in range(n):
        j = S[i]
        if ord(j) > p:
            q = i
            T = []
        else:
            if len(T) == 0:
                r = i
            T.append(j)
        p = ord(j)
    if q < r:
        if S[r-1] == 'z':
            if r == 1:
                ans = -1
            else:
                ans = S[0]
                for i in range(1,r-2):
                    ans += S[i]
                ans += T[-1]
    else:
        ans = S[0]
        for i in range(1,n-2):
            ans += S[i]
        ans += S[n-1]
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + ord(X)
else:
    A = []
    B = []
    p = 0
    d,e = -1,-1
    for i in range(n):
        j = ord(s[i])
        if ord(j) > p:
            d = i
            A.append(j)
            B = []
        else:
            if len(B) == 0:
                e = i
            B.append(j)
            A = []
    if d < e:
        if S[e-1] == 'z':
            if e == 1:
                ans = -1
            else:
                ans = S[0]
                for i in range(1,e-2):
                    ans += S[i]
                ans += B[-1]
    else:
        ans = S[0]
        for i in range(1,n-2):
            ans += S[i]
        ans += S[n]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = []
n = N//2
if N == 3:
    ans = [2,3,63]
elif 4 <= N <= 15000:
    for i in range(1,n):
        ans.append(2*i)
        x = 30000 - 2*i
        ans.append(x)
    if N % 2 == 1:
        ans.append(30000)
    ans.append(3)
    ans.append(9)
else:
    for i in range(1,15000):
        ans.append(2*i)
    x = N - 14999
    for j in range(x-1):
        y = 6*j + 3
        ans.append(y)
    if x % 2 == 1:
        ans.append(30000)
    else:
        ans.append(6*x - 3)
print(*ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = []
n = N//2
if N == 3:
    ans = [2,3,63]
elif 4 <= N <= 15000:
    for i in range(1,n):
        ans.append(2*i)
        x = 30000 - 2*i
        ans.append(x)
    if N % 2 == 0:
        ans.append(30000)
    ans.append(3)
    ans.append(9)
else:
    for i in range(1,15000):
        ans.append(2*i)
    x = N - 14999
    for j in range(x):
        y = 6*x + 3
        if y <= 30000:
            ans.append(y)
    if N == 20000:
        ans.append(30000)
print(*ans)