qyliang/CodeNanoFix huggingface dataset:
Buggy code:
s = input()

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

def youngest(str):
    cnt = [0]*26
    for c in str:
        cnt[ord(c)-ord('a')] += 1
    return chr(ord('a')+cnt.index(0))

if len(s)<26:
    print(s+youngest(s))
    exit()

# len(s)==26
suffix = ''
for i,c in enumerate(s[::-1]):
    if len(suffix)==0:
        suffix += c
    else:
        if suffix[i-1]>c:
            break
        else:
            suffix += c

print(s[:25-len(suffix)]+sorted(suffix)[-1])


Fixed code:
s = input()

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

def youngest(str):
    cnt = [0]*26
    for c in str:
        cnt[ord(c)-ord('a')] += 1
    return chr(ord('a')+cnt.index(0))

if len(s)<26:
    print(s+youngest(s))
    exit()

# len(s)==26
suffix = ''
for i,c in enumerate(s[::-1]):
    if len(suffix)==0:
        suffix += c
    else:
        if suffix[i-1]>c:
            break
        else:
            suffix += c

c = 'z'
for i in suffix:
    if i>s[25-len(suffix)]:
        c = min(c,i)

print(s[:25-len(suffix)]+c)
Buggy code:
#0. setting
CHR_A = ord("a") #97
NUM_CHR = 26
CHR_LIST = [chr(CHR_A+i) for i in range(NUM_CHR)]

def addChar(s, chr_list):
    for char in chr_list:
        if not(char in s):
            s = s+char
            break
    return s

def removeTail(s):
    for i in range(1,NUM_CHR):
        if ord(s[-1])<ord(s[-2]):
            s = s[:-1]
        else:
            s = s[:-1]
            last_s = s[-1]
            s = s[:-1:1]
            candidate = [chr(i) for i in range(ord(last_s)+1, CHR_A+NUM_CHR)]
            s = addChar(s, candidate)
            break
    return s

def main():
    #1. input
    s = input()

    #sp. output -1 if S='zyx...a'
    if s == ','.join(CHR_LIST[::-1]):
        print(-1)
    
    
    #2. add next char if |S| <= 25
    elif len(s) <= 25:
        s = addChar(s, CHR_LIST)
        print(s)
    
    
    #3. jump next step if |S| == 26
    else:
        s = removeTail(s)
        print(s)
    
if __name__ == "__main__":
    main()

Fixed code:
#0. setting
CHR_A = ord("a") #97
NUM_CHR = 26
CHR_LIST = [chr(CHR_A+i) for i in range(NUM_CHR)]

def addChar(s, chr_list):
    for char in chr_list:
        if not(char in s):
            s = s+char
            break
    return s

def removeTail(s):
    for i in range(1,NUM_CHR):
        if ord(s[-1])<ord(s[-2]):
            s = s[:-1]
        else:
            s = s[:-1]
            last_s = s[-1]
            s = s[:-1:1]
            candidate = [chr(i) for i in range(ord(last_s)+1, CHR_A+NUM_CHR)]
            s = addChar(s, candidate)
            break
    return s

def main():
    #1. input
    s = input()

    #sp. output -1 if S='zyx...a'
    if s == ''.join(CHR_LIST[::-1]):
        print(-1)
    
    
    #2. add next char if |S| <= 25
    elif len(s) <= 25:
        s = addChar(s, CHR_LIST)
        print(s)
    
    
    #3. jump next step if |S| == 26
    else:
        s = removeTail(s)
        print(s)
    
if __name__ == "__main__":
    main()
Buggy code:
def next(x):
    return chr(ord(x)+1)

import sys

A=set([chr(ord("a")+k) for k in range(26)])
S=input()

if len(S)!=26:
    u=min(A-set(S))
    print(S+u)
    exit()

p=-1
for i in range(25):
    if S[i]<S[i+1]:
        p=i

if p==-1:
    print(-1)
else:
    T=S[:p-1]
    a=next(S[p])

    while a in T:
        a=next(a)
    print(T+a)


Fixed code:
def next(x):
    return chr(ord(x)+1)

import sys

A=set([chr(ord("a")+k) for k in range(26)])
S=input()

if len(S)!=26:
    u=min(A-set(S))
    print(S+u)
    exit()

p=-1

for i in range(25):
    if S[i]<S[i+1]:
        p=i

if p==-1:
    print(-1)
else:
    T=S[:p]
    a=next(S[p])

    while a in T:
        a=next(a)
    print(T+a)
Buggy code:
s=str(input())
s=list(s)
t=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
if len(s)!=26:
  for i in range(26):
    if t[i] not in s:
      s.append(t[i])
      break
  print("".join(s))
else:
  if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    ans=[]
    for i in range(24):
      ans.append(s[i])
    ans.append(s[25])
    ans.append(s[24])
    print("".join(ans))

Fixed code:
s=str(input())
t=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
if len(s)!=26:
  s=list(s)
  for i in range(26):
    if t[i] not in s:
      s.append(t[i])
      break
  print("".join(s))
else:
  if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    a=[]
    for i in range(26):
      a.append(s[25-i])
      for j in a:
        if s<s[:25-i]+j:
          print(s[:25-i]+j)
          exit()
Buggy code:


def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    elif len(temp)==26:
        temp=list(temp)
        p=0
        for i in range(25):
            if temp[25-i]>temp[25-i-1]:
                p=25-i        
        print("".join(temp[:p-1])+min(temp[p:]))
        exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()


Fixed code:


def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    elif len(temp)==26:
        temp=list(temp)
        p=0
        for i in range(25):
            if temp[25-i]>temp[25-i-1]:
                p=25-i-1
                # print(p)
                # print(temp[p:])
                q=[k for k in temp[p:] if k>temp[p]] 
                print("".join(temp[:p])+min(q))
                exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()
Buggy code:
S = input()
alphabets = set(chr(ord("a") + x) for x in range(26))

def F_short(S):
  se = alphabets - set(S)
  x = min(se)
  return S + x

def F_long(S):
  if S == "".join(sorted(alphabets, reverse=True)):
    return "-1"
  
  cand = []
  S = list(S)
  while True:
    x = S[-1]
    if not cand or (x > max(cand)):
      cand.append(S.pop())
      print(cand)
      continue
    y = min(ch for ch in cand if ch > x)
    return "".join(S[:-1]) + y

L = len(S)
ans = F_short(S) if L < 26 else F_long(S)
print(ans)

Fixed code:
S = input()
alphabets = set(chr(ord("a") + x) for x in range(26))

def F_short(S):
  se = alphabets - set(S)
  x = min(se)
  return S + x

def F_long(S):
  if S == "".join(sorted(alphabets, reverse=True)):
    return "-1"
  
  cand = []
  S = list(S)
  while True:
    x = S[-1]
    if not cand or (x > max(cand)):
      cand.append(S.pop())
      continue
    y = min(ch for ch in cand if ch > x)
    return "".join(S[:-1]) + y

L = len(S)
ans = F_short(S) if L < 26 else F_long(S)
print(ans)
Buggy code:
s=input()
if len(s)<26:
    al=[chr(ord('a') + i) for i in range(26)]
    for i in al:
        if not(i in s):
            print(s+i)
            exit()
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
a=[]
for i in range(25,-1,-1):
    for j in range(24-(25-i),-1,-1):
        if s[j]<s[i]:
            a.append(s[:j]+s[i])
min(a)

Fixed code:
s=input()
if len(s)<26:
    al=[chr(ord('a') + i) for i in range(26)]
    for i in al:
        if not(i in s):
            print(s+i)
            exit()
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
a=[]
for i in range(25,-1,-1):
    for j in range(24-(25-i),-1,-1):
        if s[j]<s[i]:
            a.append(s[:j]+s[i])
print(min(a))
Buggy code:
alp=[chr(ord('a') + i) for i in range(26)]
unused=set(alp)
     
S=input()
print("len",len(S))

if len(S)<26:
    for i in range(len(S)):
        if S[i] in unused:
            unused.remove(S[i])
    unused=sorted(unused)
    print(S+unused[0])
else:
    for j in range(len(S)-1,-1,-1):
        p=set(S[j:])
        #print(p)
        q=sorted(p)
        if S[j]==q[-1]:
            pass
        else:
            idx=q.index(S[j])
            print(S[:j]+q[idx+1])
            break
    else:
        print(-1)

Fixed code:
alp=[chr(ord('a') + i) for i in range(26)]
unused=set(alp)
     
S=input()
#print("len",len(S))

if len(S)<26:
    for i in range(len(S)):
        if S[i] in unused:
            unused.remove(S[i])
    unused=sorted(unused)
    print(S+unused[0])
else:
    for j in range(len(S)-1,-1,-1):
        p=set(S[j:])
        #print(p)
        q=sorted(p)
        if S[j]==q[-1]:
            pass
        else:
            idx=q.index(S[j])
            print(S[:j]+q[idx+1])
            break
    else:
        print(-1)
Buggy code:
# coding: utf-8
# Your code here!

S=list(input())


S=list(map(lambda x : ord(x)-97,S))

alpha=[0]*26
for s in S:
    alpha[s]=1

if len(S)!=26:
    for i in range(26):
        if alpha[i] == 0:
            S.append(i)
            ans=S[:]
            ans=list(map(lambda x :chr(x+97), ans))
            print("".join(ans))
            exit()
else:
    for i in range(26)[::-1]:
        if alpha[S[i]:].count(0)>0:
            print(chr(S[i]+97))
            for j in range(S[i],26):
                if alpha[j]==0:
                    ans=S[:i]+[j]
                    ans=list(map(lambda x :chr(x+97), ans))
                    print("".join(ans))
                    exit()
        else:
            alpha[S[i]]=0

print(-1)


Fixed code:
# coding: utf-8
# Your code here!

S=list(input())


S=list(map(lambda x : ord(x)-97,S))

alpha=[0]*26
for s in S:
    alpha[s]=1

if len(S)!=26:
    for i in range(26):
        if alpha[i] == 0:
            S.append(i)
            ans=S[:]
            ans=list(map(lambda x :chr(x+97), ans))
            print("".join(ans))
            exit()
else:
    for i in range(26)[::-1]:
        if alpha[S[i]:].count(0)>0:
            for j in range(S[i],26):
                if alpha[j]==0:
                    ans=S[:i]+[j]
                    ans=list(map(lambda x :chr(x+97), ans))
                    print("".join(ans))
                    exit()
        else:
            alpha[S[i]]=0

print(-1)
Buggy code:
a = set(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"])
s = input()
for i in range(len(s)):
    a.remove(s[i])
b = list(a).sort()
if b:
    print(s[i]+s[0])
else:
    for i in range(2,27):
        if s[-i] < s[-i+1]:
            break
        if i == 26:
            print(-1)
            exit()
    for j in sorted(s[-i+1:]):
        if j > s[-i]:break
    print(s[:-i]+j)

Fixed code:
a = set(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"])
s = input()
if len(s)<26:
    b = list(a-set(s))
    b.sort()
    print(s+b[0])
else:
    for i in range(2,27):
        if s[-i] < s[-i+1]:
            break
        if i == 26:
            print(-1)
            exit()
    for j in sorted(s[-i+1:]):
        if j > s[-i]:break
    print(s[:-i]+j)
Buggy code:
S = input()
n = len(S)

import string
def f(x):
    for c in string.ascii_lowercase:
        if c in x: continue
        return c
    return None

if n < 26:
    print(S + f(S))
    exit()

i = n-2
while i >= 0:
    if S[i] < S[i+1]: break
    i -= 1
else:
    print(-1)
    exit()

t = S[:i+1]
print(t + f(t))

Fixed code:
S = input()
n = len(S)

import string
def f(x, mn=None):
    for c in string.ascii_lowercase:
        if c in x: continue
        if mn and c <= mn: continue
        return c
    return None

if n < 26:
    print(S + f(S))
    exit()

i = n-2
while i >= 0:
    if S[i] < S[i+1]: break
    i -= 1
else:
    print(-1)
    exit()

t = S[:i]
print(t + f(t, S[i]))
Buggy code:
s = input()
l = len(s)
backet = [0] * 26
if l != 26:
  for i in s:
    backet[ord(i) - 97] = 1
  for i in range(26):
    if not backet[i]:
      print(s + chr(i + 97))
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    d = []
    for i in s[::-1]:
      s = s[:-1]
      d.sort()
      for j in d:
        if j > ord(i)-97:
          print(s + chr(j+97))
      d.append(ord(i)-97)


Fixed code:
s = input()
l = len(s)
backet = [0] * 26
if l != 26:
  for i in s:
    backet[ord(i) - 97] = 1
  for i in range(26):
    if not backet[i]:
      print(s + chr(i + 97))
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    d = []
    for i in s[::-1]:
      s = s[:-1]
      d.sort()
      for j in d:
        if j > ord(i)-97:
          print(s + chr(j+97))
          exit()
      d.append(ord(i)-97)
Buggy code:
S = input()

ans = ''

if len(S) != 26:
    a_z = [chr(i) for i in range(97, 123)]
    for s in S:
        a_z.remove(s)
    ans = S + a_z[0]
    print(ans)
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        ans = -1
        print(ans)
    else:
        a_z = [int(i) for i in range(97, 123)]
        inputs = list(map(ord, list(S)))
        buf = [inputs[-1]]
        for i in range(1, len(S)):
            if inputs[25-i] > inputs[25-(i-1)]:
                buf.append(inputs[25-i])
            else:
                buf.sort()
                for item in buf:
                    if inputs[25-i] < item:
                        last = item
                print(''.join(list(map(chr, inputs[:25-i]+[last]))))
                break


Fixed code:
S = input()

ans = ''

if len(S) != 26:
    a_z = [chr(i) for i in range(97, 123)]
    for s in S:
        a_z.remove(s)
    ans = S + a_z[0]
    print(ans)
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        ans = -1
        print(ans)
    else:
        a_z = [int(i) for i in range(97, 123)]
        inputs = list(map(ord, list(S)))
        buf = [inputs[-1]]
        for i in range(1, len(S)):
            if inputs[25-i] > inputs[25-(i-1)]:
                buf.append(inputs[25-i])
            else:
                buf.sort()
                for item in buf:
                    if inputs[25-i] < item:
                        last = item
                        break
                print(''.join(list(map(chr, inputs[:25-i]+[last]))))
                break
Buggy code:
import sys


alph="abcdefghijklmnopqrstuvwxyz"
allis=list(alph)
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()

"""
if(S=="abcdefghijklmnopqrstuvwxyz"):
    print("b")
    sys.exit()
"""
for i in alph:
    if(i not in S):
        print(S+i)
        sys.exit()
        
"""
outp=""
for i in range(len(S)):
    if(S[i]==alph[i]):
        outp+=S[i]
    else:
        outp=outp[:-1]
        outp=outp+alph[i]
        break
"""
l=-1
for i in range(len(S)-1)[::-1]:
    if(ord(S[i])<ord(S[i+1])):
        l=i
        break
        
x=sorted(S[i+1:])
for i in x:
    if(i>S[l]):
        print(S[:l-1]+i)
        sys.exit()
print("b")


Fixed code:
import sys


alph="abcdefghijklmnopqrstuvwxyz"
allis=list(alph)
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()

"""
if(S=="abcdefghijklmnopqrstuvwxyz"):
    print("b")
    sys.exit()
"""
for i in alph:
    if(i not in S):
        print(S+i)
        sys.exit()
        
"""
outp=""
for i in range(len(S)):
    if(S[i]==alph[i]):
        outp+=S[i]
    else:
        outp=outp[:-1]
        outp=outp+alph[i]
        break
"""
l=-1
for i in range(len(S)-1)[::-1]:
    if(ord(S[i])<ord(S[i+1])):
        l=i
        break
        
x=sorted(S[i+1:])
for i in x:
    if(i>S[l]):
        print(S[:l]+i)
        sys.exit()
print("b")
Buggy code:
s = input()
abc = [chr(i) for i in range(ord('a'), ord('z')+1)]

if len(s) == 26:
  for i in range(24, -1, -1):
    cand = list(s[i+1:])
    for c in cand:
      if ord(c) > ord(s[i]):
        print(s[:i] + c)
        exit()
  print(-1)
else:
  for l in abc:
    if l not in s:
      print(s + l)
      exit()

Fixed code:
s = input()
abc = [chr(i) for i in range(ord('a'), ord('z')+1)]

if len(s) == 26:
  for i in range(24, -1, -1):
    cand = list(s[i+1:])
    cand.sort()
    for c in cand:
      if ord(c) > ord(s[i]):
        print(s[:i] + c)
        exit()
  print(-1)
else:
  for l in abc:
    if l not in s:
      print(s + l)
      exit()
Buggy code:
import sys

N = input()
a = []
b = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
c = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
l = list(N)
if N =='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
elif len(N) != 26:
  for i in range(len(N)):
    c.remove(l[i])
  N = N[0: i+1] + c.pop(0)
  print(N)
else:
  for i in range(len(N)):
    if l[i] != b[i] and l[i] =='z':
      d = c[0]
      for j in range(i,len(N)-1):
        if l[j+1] != c[0]:
          N = N[0: i+1] + c.pop(1)
          print(N)
          sys.exit()
      N = N[0: i-1] + d
      print(N)
      sys.exit()
    elif l[i] != b[i]:
      N = N[0:i] + chr(ord(l[i]) + 1)
      print(N)
      sys.exit()
    c.remove(l[i])

Fixed code:
import sys

N = input()
a = []
b = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
c = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
l = list(N)
if N =='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
elif len(N) != 26:
  for i in range(len(N)):
    c.remove(l[i])
  N = N[0: i+1] + c.pop(0)
  print(N)
else:
  for i in range(len(N)-1,0,-1):
    a.append(l[i])
    if ord(l[i]) > ord(l[i-1]):
      for j in range(len(a)):
        if l[i-1] < a[j]:
          print(N[0:i-1]+a[j])
          sys.exit()
Buggy code:
import bisect
s=input()
n=len(s)
if n!=26:
  alp=[1]*26
  for i in s:
    alp[ord(i)-ord('a')]=0
  for i in range(26):
    if alp[i]:break
  ans=s+chr(ord('a')+i)
else:
  alp=[]
  for i in range(n-1,-1,-1):
    if bisect.bisect_left(alp,ord(s[i]))==len(alp):
      bisect.insort_left(alp,ord(s[i]))
    else:
      ans=s[:i+1]+chr(alp[bisect.bisect_left(alp,ord(s[i]))])
      break
  else:ans=-1
print(ans)

Fixed code:
import bisect
s=input()
n=len(s)
if n!=26:
  alp=[1]*26
  for i in s:
    alp[ord(i)-ord('a')]=0
  for i in range(26):
    if alp[i]:break
  ans=s+chr(ord('a')+i)
else:
  alp=[]
  for i in range(n-1,-1,-1):
    if bisect.bisect_left(alp,ord(s[i]))==len(alp):
      bisect.insort_left(alp,ord(s[i]))
    else:
      ans=s[:i]+chr(alp[bisect.bisect_left(alp,ord(s[i]))])
      break
  else:ans=-1
print(ans)
Buggy code:
S = input()

s_sort = sorted(list(S))

new_character = "?"

if len(S) < 26:
  for  s in range(97,123,1):
    if S.count(chr(s))==0:
      new_character = chr(s)
      print(S + new_character)
      break
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    letter = S[25]
    for x in range(25,0,-1):
      if ord(S[x-1]) > ord(S[x]):
        letter = chr(min(ord(S[x-1]),ord(S[x]),ord(letter)))
      else:
        letter = chr(min(ord(S[x-1]),ord(S[x]),ord(letter)))
        ans = S[:x-1] + letter
        print(ans)
        break
      


Fixed code:
S = input()

s_sort = sorted(list(S))

new_character = "?"

if len(S) < 26:
  for  s in range(97,123,1):
    if S.count(chr(s))==0:
      new_character = chr(s)
      print(S + new_character)
      break
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    for x in range(25,0,-1):
      if ord(S[x-1]) < ord(S[x]):
        letters = sorted([ord(n) for n in list(S[x:])])
        letter = chr([l for l in letters if l >= ord(S[x-1])][0])
        ans = S[:x-1] + letter
        print(ans)
        break
Buggy code:
s=list(input())
al=[chr(ord('a') + i) for i in range(26)]
al=[i for i in al if i not in s]
if al:
    print(s+al[0])
    exit()
for i in range(25,0,-1):
    if s[i-1]<s[i]:
        s=s[:i-1]+[s[-1]]
        print(''.join(s))
        exit()
else:print(-1)

Fixed code:
s=list(input())
al=[chr(ord('a') + i) for i in range(26)]
al=[i for i in al if i not in s]
if al:
    print(''.join(s)+al[0])
    exit()
for i in range(25,0,-1):
    if s[i-1]<s[i]:
        a=[j for j in s[i-1:] if s[i-1]<j]
        s=s[:i-1]+[sorted(a)[0]]
        print(''.join(s))
        break
        exit()
else:print(-1)
Buggy code:
import collections
s = input()


cnt = collections.Counter(s)
used = set(cnt.keys())
c = -1
if len(used) < 26:
    for i in range(26):
        if not chr(i+ord("a")) in used:
            c = chr(i+ord("a"))
            break
if c != -1:
    print(s+c)
else:
    i = 25
    while s[i-1] > s[i]:
        i -= 1
        lused = sorted(s[i-1:])
        print(s[:i-1]+lused[lused.index(s[i-1])+1])
        break
    else:
        print("-1")


Fixed code:
import collections
s = input()


cnt = collections.Counter(s)
used = set(cnt.keys())
c = -1
if len(used) < 26:
    for i in range(26):
        if not chr(i+ord("a")) in used:
            c = chr(i+ord("a"))
            break
if c != -1:
    print(s+c)
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print("-1")
        exit()
    i = 25
    while i > 1 and s[i-1] > s[i]:
        i -= 1
    lused = sorted(s[i-1:])
    print(s[:i-1]+lused[lused.index(s[i-1])+1])
Buggy code:
S=input()
if len(S)<26:
    for char in range(ord("a"),ord("z")):
        if chr(char) not in S:
            break
    print(S+chr(char))
else:
    stack=list(S[-1])
    for s in S[len(S)-2::-1]:
        if s>stack[-1]:
            stack.append(s)
        else:
            break
    if len(stack)==26:
        print(-1)
    else:
        print(S[0:len(S)-len(stack)-1]+sorted(stack)[-1])

Fixed code:
S=input()
if len(S)<26:
    for char in range(ord("a"),ord("z")):
        if chr(char) not in S:
            break
    print(S+chr(char))
else:
    stack=list(S[-1])
    for s in S[len(S)-2::-1]:
        if s>stack[-1]:
            stack.append(s)
        else:
            break
    if len(stack)==26:
        print(-1)
    else:
        print(S[:-len(stack)-1]+min(s for s in stack if s>S[-len(stack)-1]))
Buggy code:
import collections
S = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
dic = collections.defaultdict(int)
ans = -1
if len(S) <= 25:
    for i in S:
        dic[i] += 1
    for i in alp:
        if dic[i] == 0:
            ans = S + i
            break
else:
    dic2 = {}
    dic3 = {}
    lst = []
    tmp = 0
    for i, j in zip(alp, range(1, 27)):
        dic2[i] = j
        dic3[j] = i
    for i in range(1, 27):
        a = S[-i]
        idx = dic2[a]
        if idx < tmp:
            lst.sort()
            for j in lst:
                if j > idx:
                    ans = S[:-i] + dic3[j]
                    flag = True
                    break
        
        else:
            tmp = idx
            lst.append(idx)
        if flag:
            break


print(ans)

Fixed code:
import collections
S = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
dic = collections.defaultdict(int)
ans = -1
if len(S) <= 25:
    for i in S:
        dic[i] += 1
    for i in alp:
        if dic[i] == 0:
            ans = S + i
            break
else:
    dic2 = {}
    dic3 = {}
    lst = []
    tmp = 0
    flag = False
    for i, j in zip(alp, range(1, 27)):
        dic2[i] = j
        dic3[j] = i
    for i in range(1, 27):
        a2 = S[-i]
        idx = dic2[a2]
        if idx < tmp:
            lst.sort()
            for j in lst:
                if j > idx:
                    ans = S[:-i] + dic3[j]
                    flag = True
                    break
        
        else:
            tmp = idx
            lst.append(idx)
        if flag:
            break

print(ans)
Buggy code:
s = input()
al = [chr(i) for i in range(97, 97+26)]
l = list(s)
if len(s) == 26:
    for i in range(24, -1, -1):
        for j in range(25, i, -1):
            if s[i] < s[j]:
                print(s[:i] + s[j])
                exit()
elif s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for i in al:
        if not i in s:
            print(s + i)
            exit()

Fixed code:
s = input()
al = [chr(i) for i in range(97, 97+26)]
l = list(s)
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) == 26:
    for i in range(24, -1, -1):
        for j in range(25, i, -1):
            if s[i] < s[j]:
                print(s[:i] + s[j])
                exit()
else:
    for i in al:
        if not i in s:
            print(s + i)
            exit()