qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
 
 
alph="abcdefghijklmnopqrstuvwxyz"
allis=list(alph)
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()
 
for i in alph:
    if(i not in S):
        print(S)
        sys.exit()
        
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()

Fixed code:
import sys
 
 
alph="abcdefghijklmnopqrstuvwxyz"
allis=list(alph)
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()
 
for i in alph:
    if(i not in S):
        print(S+i)
        sys.exit()
        
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()
Buggy code:
s = input()

abc = ['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 s == ''.join(abc)[::-1]:
    print(-1)
    exit()
if len(s) <26:
    for a in abc:
        if a not in abc:
            print(s+a)
            exit()
i = 25
while s[i-1] > s[i]:
    i -= 1
    #print(s[i-1], s[i])
#print(s[i-1], s[i])
tt = s[i-1]
ss = list(s[i-1:])
ss.sort()
print(s[:i-1]+ss[ss.index(tt)+1])


Fixed code:
s = input()

abclist = ['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']
abcstr = ''.join(abclist)
if s == abcstr[::-1]:
    print(-1)
    exit()
if len(s) != 26:
    for a in abclist:
        if a not in s:
            print(s+a)
            exit()

else:
    i = 25
    while s[i-1] > s[i]:
        i -= 1
        #print(s[i-1], s[i])
    #print(s[i-1], s[i])
    tt = s[i-1]
    ss = list(s[i-1:])
    ss.sort()
    print(s[:i-1]+ss[ss.index(tt)+1])
Buggy code:
s = list(input())
a = [chr(ord('a') + i) for i in range(26)]
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) != 26:
    for i in range(len(a)):
        if a[i] not in s:
            s.append(a[i])
            print("".join(s))
            exit()
else:
    used = [s[25]]
    for i in range(25, 0, -1):
        if a.index(s[i-1]) > a.index(s[i]):
            used.append(s[i-1])
        else:
            for j in range(a.index(s[i-1])+1, 26):
                if a[j] in used:
                    s[i-1] = a[j]
                    print("".join(s[:i]))
                    exit()






Fixed code:
sa = input()
s = list(sa)
a = [chr(ord('a') + i) for i in range(26)]
if sa == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) != 26:
    for i in range(len(a)):
        if a[i] not in s:
            s.append(a[i])
            print("".join(s))
            exit()
else:
    used = [s[25]]
    for i in range(25, 0, -1):
        if a.index(s[i-1]) > a.index(s[i]):
            used.append(s[i-1])
        else:
            for j in range(a.index(s[i-1])+1, 26):
                if a[j] in used:
                    s[i-1] = a[j]
                    print("".join(s[:i]))
                    exit()
Buggy code:
s = input()

if len(s) > 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans) 


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()

print(-1)

Fixed code:
s = input()

if len(s) < 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans)
    exit()


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()

print(-1)
Buggy code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[-i + 1]:
            break
        if i == 26:
            print(-1)
    s_ = sorted(s[-i + 1:])
    for j in s_:
        if j > s[-i]:
            break
    print(s[:-i] + j)

Fixed code:
s=input()
a=list("abcdefghijklmnopqrstuvwxyz")
if len(s)!=26:nokori=sorted(set(a)-set(s),key=a.index);print(s+nokori[0])
else:
 for i in range(2,27):
  if s[-i]<s[-i+1]:
    break
  if i==26:
   print(-1)
   exit()
 t=sorted(s[-i+1:])
 for j in t:
  if j>s[-i]:break
 print(s[:-i]+j)
Buggy code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
elif len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[-i + 1]:
            break
    if i == 26:
        print(-1)
    else:
        s_ = sorted(s[-i + 1:])
        for j in s_:
            if j > s[-i]:
                break
        print(s[:-i] + j)

Fixed code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[-i + 1]:
            break
        if i == 26:
            print(-1)
            exit()
    s_ = sorted(s[-i + 1:])
    for j in s_:
        if j > s[-i]:
            break
    print(s[:-i] + j)
Buggy code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(1, 27):
        if s[-i] > s[-i - 1]:
            break
    print(i)
    s_ = sorted(s[-i:])
    for j in s_:
        if j > s[-i - 1]:
            break
    print(s[:-i - 1] + j)

Fixed code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(1, 27):
        if s[-i] > s[-i - 1]:
            break
    s_ = sorted(s[-i:])
    for j in s_:
        if j > s[-i - 1]:
            break
    print(s[:-i - 1] + j)
Buggy code:
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    for i, s1 in enumerate(s[::-1]):
        if i != 0 and s1 < old[-1]:
            for o in sorted(old):
                if o > s1:
                    out = s[:len(s)-i-1] + o
                    flag = 1
                    break
        old += s1
        if flag == 0:
            out = -1
else:
    out = s + min(set(sample)-set(s))

print(out)

Fixed code:
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    for i, s1 in enumerate(s[::-1]):
        if i != 0 and s1 < old[-1]:
            for o in sorted(old):
                if o > s1:
                    out = s[:len(s)-i-1] + o
                    print(out)
                    exit()
        old += s1
    if flag == 0:
        out = -1
else:
    out = s + min(set(sample)-set(s))

print(out)
Buggy code:
import string

S = input()
N = len(S)

if S == string.ascii_lowercase[::-1]:
    print(-1)
elif N <= 25:
    for l in string.ascii_lowercase:
        if l not in S:
            print(S + l)
            break
else:
    ret = string.ascii_lowercase[::-1]
    for i in range(N):
        for c in string.ascii_lowercase:
            if c in S[:i]:
                continue
            s = S[:i] + c
            if S[i] == 'z' or c in S[:i] or S > s:
                continue
            ret = min(ret, s)
    print(ret)


Fixed code:
import string

S = input()
N = len(S)

if S == string.ascii_lowercase[::-1]:
    print(-1)
elif N <= 25:
    for l in string.ascii_lowercase:
        if l not in S:
            print(S + l)
            break
else:
    ret = string.ascii_lowercase[::-1]
    for i in range(N):
        for c in string.ascii_lowercase:
            if c in S[:i]:
                continue
            s = S[:i] + c
            if S >= s:
                continue
            ret = min(ret, s)
    print(ret)
Buggy code:
a={chr(i) for i in range(ord(a),ord(a)+25)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(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={chr(i) for i in range(ord("a"),ord("a")+26)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(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)
Buggy code:
s=input()
from bisect import bisect_left as bl,bisect_right as br
if len(s)==26:
  if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
  f=s[-1]
  p=[s[-1]]
  for i in range(2,26):
    if s[-i]>f:
      f=s[-i];p.append(f)
    else:print("!",s[:-i]+p[bl(p,s[-i])]);exit()
  print(p[bl(p,s[-i])])
else:
  f=sorted(list(set(list("aqzxswedcvfrtgbnhyujmkilop"))-set(list(s))))
  print(s+f[0])

Fixed code:
s=input()
from bisect import bisect_left as bl,bisect_right as br
if len(s)==26:
  if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
  f=s[-1]
  p=[s[-1]]
  for i in range(2,26):
    if s[-i]>f:
      f=s[-i];p.append(f)
    else:print(s[:-i]+p[bl(p,s[-i])]);exit()
  print(chr(ord(s[0])+1))
else:
  f=sorted(list(set(list("aqzxswedcvfrtgbnhyujmkilop"))-set(list(s))))
  print(s+f[0])
Buggy code:
#print([chr(ord('a') + i) for i in range(26)])
#print([chr(i) for i in range(97, 97+26)])
import sys
import bisect
li = [chr(i) for i in range(97, 97+26)]
s = input()
if len(s)<26:
    for l in li:
        if l not in s:
            print(s+l)
            sys.exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    r = s[::-1]
    tmp = ''
    kabe = ''
    for i,rr in enumerate(r):
        if i == 0:
            continue
        if rr < r[i-1]:
            tmp = r[:i+1][::-1]
            kabe = rr
            break
    print(tmp) #wzyx

    tmp_li = list(tmp)
    tmp_li.sort()
    ind = bisect.bisect_left(tmp_li, kabe)
    s0 = tmp_li[ind+1]
    #s0 = tmp_li[1]
    print(s.replace(tmp, s0))


Fixed code:
#print([chr(ord('a') + i) for i in range(26)])
#print([chr(i) for i in range(97, 97+26)])
import sys
import bisect
li = [chr(i) for i in range(97, 97+26)]
s = input()
if len(s)<26:
    for l in li:
        if l not in s:
            print(s+l)
            sys.exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    r = s[::-1]
    tmp = ''
    kabe = ''
    for i,rr in enumerate(r):
        if i == 0:
            continue
        if rr < r[i-1]:
            tmp = r[:i+1][::-1]
            kabe = rr
            break
    #print(tmp) #wzyx

    tmp_li = list(tmp)
    tmp_li.sort()
    ind = bisect.bisect_left(tmp_li, kabe)
    s0 = tmp_li[ind+1]
    #s0 = tmp_li[1]
    print(s.replace(tmp, s0))

    #print(tmp_li)
    #print(s - tmp + tmp[-1])
    #xx = list(tmp[1:])
    #xx.sort()
    #print(s[:26-len(tmp)] + xx[0])
Buggy code:
s = str(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
if len(s) < 26:
    toappend = ""
    for i in alpha:
        if i not in s:
            toappend = i
            break
    s += toappend
    print(s)
else:
    s = s[::-1]
    ckd = []
    for i in range(26):
        for j, it in enumerate(ckd):
            if s[i] < it:
                temp = ckd[j] + s[i+1:]
                print(temp[::-1])
                exit()
        ckd.append(s[i])





Fixed code:
s = str(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
if len(s) < 26:
    toappend = ""
    for i in alpha:
        if i not in s:
            toappend = i
            break
    s += toappend
    print(s)
else:
    if s == alpha[::-1]:
        print(-1)
    else:
        s = s[::-1]
        ckd = []
        for i in range(26):
            for j, it in enumerate(ckd):
                if s[i] < it:
                    temp = ckd[j] + s[i+1:]
                    print(temp[::-1])
                    exit()
            ckd.append(s[i])
Buggy code:
check='abcdefghijklmnopqrstuvwxyz'
s=input()
l=len(s)
if l<=25:
  for i in range(25):
    if check[i] not in s:
      print(s+check[i])
      break
else:
  s2=''.join(map(str,sorted(s,reverse=True)))
  if s==s2:
    print(-1)
  else:
    for i in range(25):
      if s[-(i+1)]>s[-(i+2)]:
        tmp1=s[:-(i+2)]
        tmp2=s[-(i+2):]
        break
    base=tmp2[0]
    minc=0
    for i in range(1,len(tmp2)):
      tmpv=ord(tmp2[i])-ord(base)
      if tmpv>0 and tmpv<minc:
        minc=tmpv
    print(tmp1+chr(ord(base)+minc))

Fixed code:
check='abcdefghijklmnopqrstuvwxyz'
s=input()
l=len(s)
if l<=25:
  for i in range(25):
    if check[i] not in s:
      print(s+check[i])
      break
else:
  s2=''.join(map(str,sorted(s,reverse=True)))
  if s==s2:
    print(-1)
  else:
    for i in range(25):
      if s[-(i+1)]>s[-(i+2)]:
        tmp1=s[:-(i+2)]
        tmp2=s[-(i+2):]
        break
    base=tmp2[0]
    minc=10**9
    for i in range(1,len(tmp2)):
      tmpv=ord(tmp2[i])-ord(base)
      if tmpv>0 and tmpv<minc:
        minc=tmpv
    print(tmp1+chr(ord(base)+minc))
Buggy code:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
temp1 = []
for i in range(26):
    temp1 = []
    temp.append(S[-1-i])
    # print(S[-1-i])
    for i, v in enumerate(temp):
        if S[-1-i-1] < v:
            temp1.append(v)
    if len(temp1) > 0:
        print(S[:-1-i-1]+min(temp1))
        sys.exit()

Fixed code:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
temp1 = []

for i in range(25):
    temp1 = []
    temp.append(S[-1-i])
    # print(S[-1-i], S[-1-i-1])
    for k, v in enumerate(temp):
        # print("v="+v)
        # print(S[-1-i-1], ord(S[-1-i-1]), ord(v))
        if S[-1-i-1] < v:
            temp1.append(v)
    # print(temp, temp1)
    if len(temp1) > 0:
        temp1.sort()
        print(S[:-1-i-1]+temp1[0])
        sys.exit()
Buggy code:
S = input()
S_set = set(list(S))
C_set = set([chr(ord("a") + i) for i in range(26)])

if len(S_set) == len(C_set):
    S = list(S)
    p = None
    for i in range(len(S) - 2, -1, -1):
        if S[i] < S[i + 1]:
            p = i
            break

    if p == 0:
        print(-1)
    else:
        ans = S[:p].copy()
        rest = C_set - set(S[: p + 1])
        rest = sorted(rest)
        ans.append(rest[0])
        print(*ans, sep="")
else:
    diff = C_set - S_set
    diff = sorted(diff)
    print(S + diff[0])


Fixed code:
def main():
    S = input()
    S_set = set(list(S))
    C_set = set([chr(ord("a") + i) for i in range(26)])

    if len(S_set) == len(C_set):
        S = list(S)
        p = None
        for i in range(len(S) - 2, -1, -1):
            if S[i] < S[i + 1]:
                p = i
                break
        else:
            print(-1)
            return

        ans = S[:p].copy()
        rest = C_set - set(S[: p + 1])
        rest = sorted(rest)
        for r in rest:
            if S[p] < r:
                ans.append(r)
                break
        print(*ans, sep="")
    else:
        diff = C_set - S_set
        diff = sorted(diff)
        print(S + diff[0])
        return


main()
Buggy code:
# coding: utf-8
# Your code here!

N = input()
p = list("abcdefghijklmnopqrstuvwxyz")

if len(N) != 26:
    for i in N:
        p.pop(p.index(i))
    if p == []:
        print(-1)
        exit()
    print(N+p[0])
else:
    tmp = 0
    a = list("zyxwvutsrqponmlkjihgfedcba")
    if a == N:
        print("-1")
        exit()
    for i in range(25,-1,-1):
        for c in N:
            if c not in N[:i] and c > N[i]:
                print(N[:i]+c)
                exit()

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

N = input()
p = list("abcdefghijklmnopqrstuvwxyz")

if len(N) != 26:
    for i in N:
        p.pop(p.index(i))
    if p == []:
        print(-1)
        exit()
    print(N+p[0])
else:
    tmp = 0
    a = list("zyxwvutsrqponmlkjihgfedcba")
    if a == list(N):
        print("-1")
        exit()
    for i in range(24,-1,-1):
        for c in p:
            if c not in N[:i] and c > N[i]:
                print(N[:i]+c)
                exit()
Buggy code:
S = input()
chr_list = [1] * 26

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for s in S:
        chr_list[ord(s) - ord("a")] = 0

    if all(map(lambda c: c == 0, chr_list)):
        c_set = [S[-1]]
        for i in range(24, -1, -1):
            print(S[i])
            if not ord(S[i]) > ord(S[i+1]):
                print(S[:i] + min(c_set))
                break
            c_set.append(S[i])
            tail = s
    else:
        for i, v in enumerate(chr_list):
            if v == 1:
                print(S + chr(ord("a") + i))
                break

Fixed code:
S = input()
chr_list = [1] * 26

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for s in S:
        chr_list[ord(s) - ord("a")] = 0

    if all(map(lambda c: c == 0, chr_list)):
        c_set = [S[-1]]
        for i in range(24, -1, -1):
            if not ord(S[i]) > ord(S[i+1]):
                c_set = [c for c in c_set if c >= S[i]]
                print(S[:i] + min(c_set))
                break
            c_set.append(S[i])
    else:
        for i, v in enumerate(chr_list):
            if v == 1:
                print(S + chr(ord("a") + i))
                break
Buggy code:
S = input()
l = len(S)
if l != 26:
    colors = [0]*26
    for i in range(26):
        colors[ ord(S[i]) - ord('a')]
    for i in range(26):
        if colors[i] == 0:
            ans = S + chr( i + ord('a'))
            break
    print(ans)
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for i in range(25,0,-1):
        if S[i] > S[i-1]:
            now = i
            break
    print(S[:i-1] + S[-1])

Fixed code:
S = input()
l = len(S)
if l != 26:
    colors = [0]*26
    for i in range(l):
        colors[ ord(S[i]) - ord('a')] = 1
    for i in range(26):
        if colors[i] == 0:
            ans = S + chr( i + ord('a'))
            break
    print(ans)
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for i in range(25,0,-1):
        if S[i] > S[i-1]:
            now = i
            break
    colors = [0]*26
    for i in range(now-1):
        colors[ ord(S[i]) - ord('a')] = 1
    c = 'z'
    for i in range(now-1,26):
        if S[now-1] < S[i]:
            c = min(c, S[i])
    print(S[:now-1]+c)
Buggy code:
s=input()
t="abcdefghijklmnopqrstuvwxyz"
if s==t[::-1]:print(-1);exit()
if len(s)<26:
  for i in t:
    if not i in s:print(s+i);exit()
else:
  for i in range(25):
    if s[-i-2]<s[-1-i]:
      t=s[:-i-1]
      a=sorted(list(s[-1-i:]))
      print(t+a[0]);exit()

Fixed code:
s=input()
t="abcdefghijklmnopqrstuvwxyz"
if s==t[::-1]:print(-1);exit()
if len(s)<26:
  for i in t:
    if not i in s:print(s+i);exit()
else:
  for i in range(25):
    if s[-i-2]<s[-1-i]:
      t=s[:-i-2]
      a=sorted(list(s[-2-i:]))
      print(t+a[a.index(s[-2-i])+1]);exit()
Buggy code:
def f(s, i, d):
  if len(s) == i:
    d.sort()
    return d[0]
  if len(d) == 0:
    return "_"
  d.remove(s[i])
  r = f(s, i+1, d)
  if r == "_":
    d.sort()
    for i in d:
      if s[i] < i:
        return i
    d.append(s[i])
    return "_"
  return "".join(s[i], r)

def main():
  d = list("abcdefghijklmnopqrstuvwxyz")
  t = input()
  r = f(t, 0, d)
  print(r)
  
main()

Fixed code:
def f(s, i, d):
  if len(d) == 0:
    return "-1"
  if len(s) == i:
    d.sort()
    return d[0]
  d.remove(s[i])
  r = f(s, i+1, d)
  if r == "-1":
    d.sort()
    for j in d:
      if s[i] < j:
        return j
    d.append(s[i])
    return "-1"
  return "".join([s[i], r])

def main():
  d = list("abcdefghijklmnopqrstuvwxyz")
  t = input()
  r = f(t, 0, d)
  print(r)

main()
Buggy code:
# https://atcoder.jp/contests/agc022/tasks/agc022_a

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    if len(S) < 26:
        for i in range(ord("a"), ord("z") + 1):
            if chr(i) not in S:
                print(S + chr(i))
                return
    elif len(S) == 26:
        for i in range(25)[::-1]:
            c = S[i]
            ss = S[:i]
            for j in range(ord(c) + 1, ord("z") + 1):
                cc = chr(j)
                if cc not in ss:
                    print(ss + cc)
                    return

    print(-1)

    return


if __name__ == "__main__":
    main()


Fixed code:
# https://atcoder.jp/contests/agc022/tasks/agc022_a

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    if len(S) < 26:
        for i in range(ord("a"), ord("z") + 1):
            if chr(i) not in S:
                print(S + chr(i))
                return
    elif len(S) == 26:
        for i in range(25)[::-1]:
            c = S[i]
            ss = S[:i]
            for j in range(ord(c) + 1, ord("z") + 1):
                cc = chr(j)
                if cc not in ss:
                    print(ss + cc)
                    return
        print(-1)

    return


if __name__ == "__main__":
    main()
Buggy code:
s = list(input())
n = len(s)

if n!=26:
  for i in [chr(ord('a') + i) for i in range(26)]:
    if not i in s:
      tmp=i
      break
  s.append(tmp)
  print("".join(s))

elif n==26:
  if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)

  else:
    for j in range(n)[::-1]:
      for k in range(1,122-ord(s[j])+1):
        tmp = chr(ord(s[j])+k)
        if tmp not in s[:j]:
          s[j]=tmp
          del s[j+1:]
          print("".join(s))
          exit()

Fixed code:
s = list(input())
n = len(s)

if n!=26:
  for i in [chr(ord('a') + i) for i in range(26)]:
    if not i in s:
      tmp=i
      break
  s.append(tmp)
  print("".join(s))

else:
  if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)

  else:
    for j in range(n)[::-1]:
      for k in range(1,122-ord(s[j])+1):
        tmp = chr(ord(s[j])+k)
        if tmp not in s[:j]:
          s[j]=tmp
          del s[j+1:]
          print("".join(s))
          exit()
Buggy code:
def main():
    S = input()
    if S == "zyxwvutsrqponmlkjihgfedcba":
        ans = -1
    elif len(S) != 26:
        for i in range(26):
            a = chr(ord('a') + i)
            if a not in S:
                print(S + a)
                return
    else:
        while len(S) > 1:
            S = S[:-1]
            last = S[-1]
            while ord(last) < ord('z'):
                last = chr(ord(last) + 1)
                if last not in S:
                    print(S[:-1] + last)
                    return
if __name__ == '__main__':
    main()

Fixed code:
def main():
    S = input()
    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    elif len(S) != 26:
        for i in range(26):
            a = chr(ord('a') + i)
            if a not in S:
                print(S + a)
                return
    else:
        while len(S) > 1:
            S = S[:-1]
            last = S[-1]
            while ord(last) < ord('z'):
                last = chr(ord(last) + 1)
                if last not in S:
                    print(S[:-1] + last)
                    return
if __name__ == '__main__':
    main()