qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def main():
    S = input()
    alpha = "abcdefghijklmnopqrstuvwxyz"
    alpha_rev = alpha[::-1]
    if S == alpha_rev:
        return -1
    Sset = set(list(S))
    if len(Sset) != 26:
        for c in alpha:
            if c not in Sset:
                return S + c
    else:
        for i in range(len(S)-1, 0, -1):
            if S[i] > S[i-1]:
                target = sorted(S[i-1:])
                for c in target:
                    if c > S[i-1]:
                        ref = c
                        break
                t = S[:i-1] + ref + "".join([c for c in target if c != ref])
                return t
        return -1

if __name__ == '__main__':
    print(main())

Fixed code:
def main():
    S = input()
    alpha = "abcdefghijklmnopqrstuvwxyz"
    alpha_rev = alpha[::-1]
    if S == alpha_rev:
        return -1
    Sset = set(list(S))
    if len(Sset) != 26:
        for c in alpha:
            if c not in Sset:
                return S + c
    else:
        for i in range(len(S)-1, 0, -1):
            if S[i] > S[i-1]:
                target = sorted(S[i-1:])
                for j in range(len(target)):
                    if target[j] > S[i-1]:
                        ref = target[j]
                        break
                t = S[:i-1] + ref
                return t
        return -1

if __name__ == '__main__':
    print(main())
Buggy code:
s = input()

ans = s
ansa = s
a = 'abcdefghijklmnopqrstuvwxyz'
a = [a[i] for i in range(26)]
if len(s)<26:
    for i in a:
        if ans.count(i) == 0:
            ans += i
            break
else:
    b = 26
    for i in range(1,26):
        if a.index(s[i]) > a.index(s[i-1]):
            b = i
    if b == 26:
        print(-1)
    else:
        s = s[:b]
        for j in a:
            if a.index(j) > a.index(s[b-1]) and j not in s:
                s = s[:b-1]+j
                break
        print(s)


Fixed code:
s = input()

ans = s
ansa = s
a = 'abcdefghijklmnopqrstuvwxyz'
a = [a[i] for i in range(26)]
if len(s)<26:
    for i in a:
        if ans.count(i) == 0:
            ans += i
            break
    print(ans)
else:
    b = 26
    for i in range(1,26):
        if a.index(s[i]) > a.index(s[i-1]):
            b = i
    if b == 26:
        print(-1)
    else:
        s = s[:b]
        for j in a:
            if a.index(j) > a.index(s[b-1]) and j not in s:
                s = s[:b-1]+j
                break
        print(s)
Buggy code:
s = input()
# print(s[:-1])
if len(s) != 26:
    for c in range(ord('a'), ord('z')+1):
        c = chr(c)
        if not c in s:
            print(s+c)
            exit()
s = list(s)
t = []
while s:
    for c in t:
        if c > s[-1]:
            print(''.join(s[-1]+c))
            exit()
    t.append(s.pop())

print('-1')

Fixed code:
s = input()
# print(s[:-1])
if len(s) != 26:
    for c in range(ord('a'), ord('z')+1):
        c = chr(c)
        if not c in s:
            print(s+c)
            exit()
s = list(s)
t = []
while s:
    for c in t:
        if c > s[-1]:
            print(''.join(s[:-1])+c)
            exit()
    t.append(s.pop())

print('-1')
Buggy code:
import collections
S = input()

if(S == "zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    exit()
    
alp = "abcdefghijklmnopqrstuvwxyz"
r = S[::-1]

c = collections.Counter(S)
c_s = sorted(c.items(), key=lambda x:x[0])
tmp = ""

for i in range(len(c_s)):
    tmp += c_s[i][0]

if(len(S) < 26):
    for i in range(len(alp)):
        if(alp[i] not in tmp):
            print(S+alp[i])
            break
else:
    for i in range(len(S)-1):
        if(r[i] > r[i+1]):
            cha = sorted(r[:(i+1)])[0]
            print(r[:(i+1)])
            print(sorted(r[:(i+1)]))
            print(S[:(len(S)-i-2)]+cha)
            break

Fixed code:
import collections
S = input()

if(S == "zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    exit()
    
alp = "abcdefghijklmnopqrstuvwxyz"
r = S[::-1]

c = collections.Counter(S)
c_s = sorted(c.items(), key=lambda x:x[0])
tmp = ""

for i in range(len(c_s)):
    tmp += c_s[i][0]

if(len(S) < 26):
    for i in range(len(alp)):
        if(alp[i] not in tmp):
            print(S+alp[i])
            break
else:
    for i in range(len(S)-1):
        if(r[i] > r[i+1]):
            cha = sorted(r[:(i+1)])
            for j in range(len(cha)):
                if(cha[j] > r[i+1]):
                    print(S[:(len(S)-i-2)]+cha[j])
                    exit()
Buggy code:
# encoding:utf-8


def main(s):
	alphabet = "abcdefghijklmnopqrstuvwxyz"
	d = {alphabet[i]:i for i in range(26)}
	if s == "zyxwvutsrqponmlkjihgfedcba":
		print("-1")
	elif len(s) < 26:
		for i in range(26):
			if alphabet[i] not in s:
				print(s + alphabet[i])
				break
	else:
		tail = [d[s[25]]]
		for i in range(0, 25):
			if d[s[24 - i]] >= max(tail):
				tail.append(d[s[24 - i]])
				continue
			else:
				tmp = min([x for x in tail if x >= d[s[24-i]]])
				print(s[0:(24-i)] + alphabet[tmp])
				break


if __name__ == '__main__':
	#s = input()
	main("abc")
	main("adc")
	main("zyawvutsrqponmlkjihgfedcbx")
	main("abcdefghijklmnopqrstuvwzyx")

Fixed code:
# encoding:utf-8


def main(s):
	alphabet = "abcdefghijklmnopqrstuvwxyz"
	d = {alphabet[i]:i for i in range(26)}
	if s == "zyxwvutsrqponmlkjihgfedcba":
		print("-1")
	elif len(s) < 26:
		for i in range(26):
			if alphabet[i] not in s:
				print(s + alphabet[i])
				break
	else:
		tail = [d[s[25]]]
		for i in range(0, 25):
			if d[s[24 - i]] >= max(tail):
				tail.append(d[s[24 - i]])
				continue
			else:
				tmp = min([x for x in tail if x >= d[s[24-i]]])
				print(s[0:(24-i)] + alphabet[tmp])
				break


if __name__ == '__main__':
	s = input()
	main(s)
Buggy code:
S=input()
alphabet=[chr(i) for i in range(ord('a'),ord('z')+1)]
if len(S)!=26:
    for x in alphabet: 
        if not(x in set(S)):
            flag=1
            break
    ans=S+x
    print(ans)
else:
    s=ord(S[25])
    j=25
    for i in range(24,-1,-1):
        if s<ord(S[i]):
            j=i
            s=ord(S[i])
        else:
            break

    if j==0:
        print(-1)
    else:
        l=S[j-2:]
        y=300
        for x in list(map(ord,l)):
            if ord(S[j-3])<x:
                y=min(y,x)
        ans=S[:j-3]+chr(y)
        print(ans)

Fixed code:
S=input()
alphabet=[chr(i) for i in range(ord('a'),ord('z')+1)]
if len(S)!=26:
    for x in alphabet: 
        if not(x in set(S)):
            flag=1
            break
    ans=S+x
    print(ans)
else:
    s=ord(S[25])
    j=25
    for i in range(24,-1,-1):
        if s<ord(S[i]):
            j=i
            s=ord(S[i])
        else:
            break

    if j==0:
        print(-1)
    else:
        l=S[j:]
        y=300
        for x in list(map(ord,l)):
            if ord(S[j-1])<x:
                y=min(y,x)
        ans=S[:j-1]+chr(y)
        print(ans)
Buggy code:
S = list(input())

W = list('abcdefghijklmnopqrstuvwxyz')

if len(S) < 26:
    for s in S:
        W.remove(s)
    S += W[0]
    print(*S, sep='')
else:
    s_last = S[-1]
    for i in range(24, -1, -1):
        s = S[i]
        if s > s_last:
            s_last = s
        else:
            idx = i
            break
    if idx == 0:
        print(-1)
    else:
        res = []
        for s in S[idx+1:]:
            if s > S[idx]:
                res.append(s)
        res.sort()
        print(*(S[:idx] + [res[0]]), sep='')


Fixed code:
S = list(input())

if len(S) < 26:
    W = list('abcdefghijklmnopqrstuvwxyz')
    for s in S:
        W.remove(s)
    S += W[0]
    print(*S, sep='')
else:
    s_last = S[-1]
    idx = -1
    for i in range(24, -1, -1):
        s = S[i]
        if s > s_last:
            s_last = s
        else:
            idx = i
            break
    if idx == -1:
        print(-1)
    else:
        res = []
        for s in S[idx+1:]:
            if s > S[idx]:
                res.append(s)
        res.sort()
        print(*(S[:idx] + [res[0]]), sep='')
Buggy code:
import sys
import heapq
from decimal import Decimal

input = sys.stdin.readline
S =  input()
S = S.replace("\n","")
s_list = list(S)
alpha_list = [chr(i) for i in range(97, 97+26)]
flag_list = [False for _ in range(23)]


if len(s_list) == 26:
    for i in range(25, 0, -1):
        if s_list[i - 1] < s_list[i]:
            c = 'ω'
            for j in range(i, 26):
                if s_list[i - 1] < s_list[j]:
                    c = min(c, s_list[j])
            print(s_list[:i-1] + c)
            exit()
    print(-1)

else:
    for i,alpha in enumerate(alpha_list):
        if alpha in s_list:
            flag_list[i] = True
    for i,flag in enumerate(flag_list):
        if not flag:
            print(S + alpha_list[i])
            break

Fixed code:
import sys

input = sys.stdin.readline
S =  input()
S = S.replace("\n","")
s_list = list(S)
alpha_list = [chr(i) for i in range(97, 97+26)]
flag_list = [False for _ in range(26)]


if len(s_list) == 26:
    for i in range(25, 0, -1):
        if s_list[i - 1] < s_list[i]:
            c = 'ω'
            for j in range(i, 26):
                if s_list[i - 1] < s_list[j]:
                    c = min(c, s_list[j])
            print(S[:i-1] + c)
            exit(0)
    print(-1)

else:
    for i,alpha in enumerate(alpha_list):
        if alpha in s_list:
            flag_list[i] = True
    for i,flag in enumerate(flag_list):
        if not flag:
            print(S + alpha_list[i])
            break
Buggy code:
S = list(input())

abc = [chr(ord('a') + i) for i in range(26)]

if len(S) < 26:
    rest_alp = list(set(abc) - set(S))
    rest_alp.sort()
    S.append(rest_alp[0])
    print("".join(S))
    exit()
else:
    for i in reversed(range(25)):
        for j in reversed(range(i+1, 26)):
            print(i, j)
            if S[i] < S[j]:
                ans = S[:i].append(S[j])
                print(ans)
                print("".join(S[:i]) + "".join(S[j]))
                exit()
print(-1) 

Fixed code:
S = list(input())

abc = [chr(ord('a') + i) for i in range(26)]

if len(S) < 26:
    rest_alp = list(set(abc) - set(S))
    rest_alp.sort()
    S.append(rest_alp[0])
    print("".join(S))
    exit()
else:
    for i in reversed(range(25)):
        for j in reversed(range(i+1, 26)):
            if S[i] < S[j]:
                ans = S[:i].append(S[j])
                print("".join(S[:i]) + "".join(S[j]))
                exit()
print(-1)
Buggy code:
from string import*;from itertools import*;b=ascii_lowercase;r=s=input();d=l=len(s);t=s[::-1]
if l>25:d=-[p*len(list(k))for p,k in groupby([i<j for i,j in zip(s[::-1],s[-2::-1])])][0]-2;s,b,o=s[:d],s[d+1:],1
print(-(d<-26)or s+sorted(set(b)-set([s,b[:ord(s[d])-97]][o]))[0])

Fixed code:
from string import*;from itertools import*;b=ascii_lowercase;s=r=input();t=s[::-1];d=0
if len(s)>25:d=-[p*len(list(k))for p,k in groupby([i<j for i,j in zip(t,t[1:])])][0]-2;u=s*2;s,b,r=s[:d],s[d+1:],b[:ord(u[d])-97]
print(-(d<-26)or s+sorted(set(b)-set(r))[0])
Buggy code:
from string import*
from itertools import*
b = ascii_lowercase
s = input()
l = len(s)
if l < 26:
    print(s + sorted(set(b) - set(s))[0])
else:
    d = [p,*len(list(k)) for p, k in groupby([i < j for i, j in zip(s[-1::-1], t[-2::-1])])][0] - 2
    print(-(d < -26) or s[:d] + sorted(set(s[d+1:]) - set(b[:ord(s[d]) - 97]))[0])

Fixed code:
from string import*
from itertools import*
b = ascii_lowercase
s = input()
if len(s) < 26:
    print(s + sorted(set(b) - set(s))[0])
else:
    d = -[p*len(list(k)) for p, k in groupby([i < j for i, j in zip(s[-1::-1], s[-2::-1])])][0] - 2
    print(-(d < -26) or s[:d] + sorted(set(s[d+1:]) - set(b[:ord(s[d]) - 97]))[0])
Buggy code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    count = 0
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(0, len(s) - 1):
        if s[i] > s[i + 1]:
            break
        else:
            count += 1
    if count == 0:
        print(-1)
    else:
        s = s[: count] + chr(ord(s[count-1]) + 1)
        print(s)
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(26):
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()


Fixed code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    count = 1
    for i in range(1, len(s)):
        if s[-i] < s[-i - 1]:
            count += 1
        else:
            break
    if count == 26:
        print(-1)
    else:
        for i in sorted(s[-count:]):
            if s[-count - 1] < i:
                print(s[:-count-1] + i)
                sys.exit()
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(26):
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()
Buggy code:
S = input()

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

tmp = {a: 0 for a in 'abcdefghijklmnopqrstuvwxyz'}

for x in S:
    tmp[x] += 1

tmp2 = []
if all(x == 1 for x in tmp.values()):
    for i in range(len(S)-1, 0, -1):
        tmp2.append(S[i])
        if S[i-1] < S[i]:
            tmp2 = [x for x in tmp2 if x > S[i-1]]
            exit()
else:
    for k, v in tmp.items():
        if v == 0:
            tmp2.append(k)
    print(S+min(tmp2))

Fixed code:
S = input()

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

tmp = {a: 0 for a in 'abcdefghijklmnopqrstuvwxyz'}

for x in S:
    tmp[x] += 1

tmp2 = []
if all(x == 1 for x in tmp.values()):
    for i in range(len(S)-1, 0, -1):
        tmp2.append(S[i])
        if S[i-1] < S[i]:
            tmp2 = [x for x in tmp2 if x > S[i-1]]
            print(S[:i-1]+min(tmp2))
            exit()
else:
    for k, v in tmp.items():
        if v == 0:
            tmp2.append(k)
    print(S+min(tmp2))
Buggy code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
check = [0]*26
if len(S)==26:
    else:
        end = S[-1]
        for i in range(24, -1, -1):
            if ord(S[i])<ord(end):
                S[i] = end
                print(''.join(S[:i+1]))
                break
        else:
            if S[0]=='z':
                print(-1)
            else:
                print(chr(ord(S[0])+1))
else:
    for s in S:
        check[ord(s)-97] = 1
    for i in range(26):
        if not check[i]:
            S.append(chr(i+97))
            break
    print(''.join(S))



Fixed code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
# while 1:
if len(S)==26:
    end = S[-1]
    lis = [end]
    for i in range(24, -1, -1):
        if ord(S[i])<ord(end):
            for s in lis:
                if ord(S[i])<ord(s):
                    S[i] = s
                    break
            S = S[:i+1]
            print(''.join(S))
            break
        else:
            lis.append(S[i])
            end = S[i]
    else:
        if S[0]=='z':
            print(-1)
        else:
            S = [chr(ord(S[0])+1)]
            print(S[0])
else:
    check = [0]*26
    for s in S:
        check[ord(s)-97] = 1
    for i in range(26):
        if not check[i]:
            S.append(chr(i+97))
            break
    print(''.join(S))
Buggy code:
s = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"
ans = -1
for i in range(len(s)):
    t = s[:~i]
    dif = set(map(chr,range(ord(s[~i])+1,123))) - set(t)
    if dif:
        ans = t + min(dif)
        break
print(ans)

Fixed code:
s = input()+chr(ord("a")-1)
ans = -1
for i in range(len(s)):
    t = s[:~i]
    dif = set(map(chr,range(ord(s[~i])+1,123))) - set(t)
    if dif:
        ans = t + min(dif)
        break
print(ans)
Buggy code:
S = input()
li = [chr(ord('a') + i) for i in range(26)]
used = [0] * 26
dic = dict(zip(li, used))
for i in range(len(S)): dic[S[i]] = 1
if(len(S) < 26):
    for i in range(26):
        k = chr(ord('a') + i)
        v = dic[k]
        if(v == 0):
            print(S + k)
            exit(0)

if(len(S) == 26):
    if(S == 'zyxwvutsrqponmlkjihgfedcba'):
        print(-1)
        exit(0)
    else:
        for i in range(25, 0, -1):
            for i in range(26): dic[chr(ord('a') + i)] = 0
            for j in range(i): dic[S[j]] = 1
            for j in range(i, 26):
                if(S[j] > S[i] and dic[S[j]] == 0):
                    print(S[:i] + S[j - 1])
                    exit(0)


Fixed code:
S = input()
li = [chr(ord('a') + i) for i in range(26)]
used = [0] * 26
dic = dict(zip(li, used))
for i in range(len(S)): dic[S[i]] = 1
if(len(S) < 26):
    for i in range(26):
        k = chr(ord('a') + i)
        v = dic[k]
        if(v == 0):
            print(S + k)
            exit(0)

if(len(S) == 26):
    for i in range(25, -1, -1):
        for j in range(26): dic[chr(ord('a') + j)] = 0
        for j in range(i): dic[S[j]] = 1
        add_c = ""
        for j in range(i + 1, 26):
            if(S[j] > S[i]):
                if(add_c == ""): add_c = S[j]
                else: add_c = min(add_c, S[j])
        if(add_c):
            print(S[:i] + add_c)
            exit(0)
print(-1)
Buggy code:
S = str(input())
alp = "abcdefghijklmnopqrstuvwxyz"
s = len(S)
for i in range(s):
  alp = alp.replace(S[i],'')
if alp != '':
  print(S+alp[0])
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    S = "-1"
  else:
    for j in range(s-1,0,-1):
      if S[j] > S[j-1]:
        alp = "abcdefghijklmnopqrstuvwxyz"
        for k in range(len(alp)-1):
          if alp[k] == S[j-1]:
            S = S[:j-1]+alp[k+1]
            print(S)
            exit()
print(S)

Fixed code:
S = str(input())
alp = "abcdefghijklmnopqrstuvwxyz"
s = len(S)
for i in range(s):
  alp = alp.replace(S[i],'')
if alp != '':
  print(S+alp[0])
  exit()
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    S = "-1"
  else:
    for j in range(s-1,0,-1):
      if S[j] > S[j-1]:
        alp = list(S[j-1:])
        alp = sorted(alp)
        for k in range(len(alp)+1):
          if alp[k] == S[j-1]:
            S = S[:j-1]+alp[k+1]
            print(S)
            exit()
print(S)
Buggy code:
alp = 'abcdefghijklmnopqrstuvwxyz'
s = input()
if s == alp[::-1]:
    print(-1)
elif len(s) == 26:
    for i in range(len(s)-1,0,-1):
        if s[i] > s[i-1]:
            s = s[:i-1]+s[i]+s[i-1]+s[i+1:]
            break
    print(s)
else:
    for i in alp:
        if i not in s:
            print(s+i)
            break

Fixed code:
alp = 'abcdefghijklmnopqrstuvwxyz'
s = input()
if s == alp[::-1]:
    print(-1)
elif len(s) == 26:
    for i in range(len(s)-1,0,-1):
        if s[i] > s[i-1]:
            for j in alp:
                if j not in s[:i] and j > s[i-1]:
                    print(s[:i-1]+j)
                    break
            break
else:
    for i in alp:
        if i not in s:
            print(s+i)
            break
Buggy code:
import string
S = input()
if len(S) == 26:
    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        i = len(S) - 1
        while 0 <= i:
            if S[i-1] < S[i]:
                min_val = min(S[i:])
                i -= 1
                break
            i -= 1
        ans = ""
        for x in range(i):
            ans += S[x]
        ans += min_val
        print(ans)

    exit()


# chars_set = set(S)
# for c in string.ascii_lowercase:
#     if c not in chars_set:
#         S += c
#         break
# print(S)

Fixed code:
import string
S = input()
if len(S) == 26:
    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        i = len(S) - 1
        while 0 <= i:
            if S[i-1] < S[i]:
                break
            i -= 1
        ans = ""
        for x in range(i):
            ans += S[x]

        for j in S[i:][::-1]:
            if ans[-1] < j:
                ans = ans[:-1] + j
                break

        print(ans)

    exit()

chars_set = set(S)
for c in string.ascii_lowercase:
    if c not in chars_set:
        S += c
        break
print(S)
Buggy code:
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)


Fixed code:
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 code:
S = input()

abc = list("abcdefghijklmnopqrstuvwxyz")
# ord('a') = 97
n = len(abc)
check = [0] * n
for s in S:
    check[ord(s) - 97] = 1

if sum(check) != n:
    for i in range(n):
        if check[i] == 0:
            S += abc[i]
            break
    print(S)
else:
    check = [0] * n
    c = n - 1
    for i in range(1, n):
        if S[-i] > S[-i-1]:
            c = i
            check[ord(S[-i]) - 97] = 1
            break
        check[ord(S[-i]) - 97] = 1
    if c == 0:
        ans = -1
    else:
        ans = S[:-i-1]
        for i in range(n - 1, ord(S[-i-1]) - 97, -1):
            if check[i] == 1:
                ans += S[i]
                break
    print(ans)


Fixed code:
S = input()

abc = list("abcdefghijklmnopqrstuvwxyz")
# ord('a') = 97
n = len(abc)
check = [0] * n
for s in S:
    check[ord(s) - 97] = 1

if S == ''.join(abc[::-1]):
    print(-1)
    exit()

if sum(check) != n:
    for i in range(n):
        if check[i] == 0:
            S += abc[i]
            break
    print(S)
else:
    check = [0] * n
    for i in range(0, n):
        check[ord(S[::-1][i]) - 97] = 1
        if S[::-1][i] > S[::-1][i + 1]:
            c = 24 - i
            break
    # print(c)
    # print(check)
    # print(S[c])
    ans = S[:c]
    for i in range(ord(S[c]) - 97, n):
        if check[i] == 1:
            ans += abc[i]
            break
    print(ans)
Buggy code:
import string
ABC=list(string.ascii_lowercase)
s=input()
S=s[::-1]

if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    if len(s)==26:
        for i in range(len(s)):
            n=ABC.index(S[i])
            if not set(ABC[n+1:])<=set(S[i+1:]):
                j=i
                break
        L=list(set(ABC[n+1])-set(S[j+1:]))
        L.sort()
        sgyku=L[0:1]+S[j+1:]
        print("".join(sgyku[::-1]))
    else:
        L=list(set(ABC)-set(s))
        L.sort()
        print(s+L[0])

Fixed code:
import string
ABC=list(string.ascii_lowercase)
s=input()
S=list(s[::-1])

if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    if len(s)==26:
        for i in range(len(s)):
            n=ABC.index(S[i])
            if not set(ABC[n+1:])<=set(S[i+1:]):
                j=i
                break
        L=list(set(ABC[n+1:])-set(S[j+1:]))
        L.sort()
        sgyku=L[0:1]+S[j+1:]
        print("".join(sgyku[::-1]))
    else:
        L=list(set(ABC)-set(s))
        L.sort()
        print(s+L[0])
Buggy code:
i = [int(input()) for i in range(4)]

if i[0]<i[1]:
  train = i[0]
elif i[1]<i[0]:
  train = i[1]
  
if i[2]<i[3]:
  bus= i[2]
elif i[3]<i[2]:
  bus= i[3]

print(train+bus)

Fixed code:
i = [int(input()) for i in range(4)]

if i[0]<i[1]:
  train = i[0]
elif i[1]<=i[0]:
  train = i[1]
  
if i[2]<i[3]:
  bus= i[2]
elif i[3]<=i[2]:
  bus= i[3]

print(train+bus)
Buggy code:
a = int(input())
b = int(input())
c = int(input())
d = int(input())

print(min(a,b)+min(c+d))

Fixed code:
a=int(input())
b=int(input())
c=int(input())
d=int(input())


print(min(a,b)+min(c,d))