qyliang/CodeNanoFix huggingface dataset:
Buggy code:
ss = input()
ss =list(map(ord, ss))
dic = [i for i in range(97,123)]
# print(dic)
for s in ss:
    dic.remove(s)
# print(dic)
if len(ss)<26:
    ss.append(min(dic))
else:
    for s in ss[::-1]:
        if len(dic)>0 and s < max(dic):
            ss[ss.index(s)] = max(dic)
            break
        dic.append(ss.pop(ss.index(s)))
    else:
        ss = -1
print(ss if ss == -1 else ''.join(list(map(chr,ss))))

Fixed code:
import bisect
ss = input()
ss =list(map(ord, ss))
dic = [i for i in range(97,123)]
# print(dic)
for s in ss:
    dic.remove(s)
# print(dic)
if len(ss)<26:
    ss.append(min(dic))
else:
    for s in ss[::-1]:
        if len(dic)>0 and s < max(dic):
            ss[ss.index(s)] = dic[bisect.bisect_right(dic,s)]
            break
        dic.append(ss.pop(ss.index(s)))
        dic = sorted(dic)
    else:
        ss = -1
print(ss if ss == -1 else ''.join(list(map(chr,ss))))
Buggy code:
s = input() #+ chr(96)
print(s)
 
for j in reversed(range(len(s)-1)):
    sets=set(s[:j])
    #print(sets)
    for i in range(ord(s[j]) + 1,123):
        if chr(i) not in sets:
            #print(s[:j] + chr(i))
            exit()
print(-1)

Fixed code:
s = input()+"`"

for j in reversed(range(len(s))):
    sets=set(s[:j])
    for i in range(ord(s[j])+1,123):
        if chr(i) not in sets:
            print(s[:j] + chr(i))
            exit()
print(-1)
Buggy code:
alp = "abcdefghijklmnopqrstuvwxyz"
s = input()
if len(s) < 26:
  for x in alp:
    if x not in s:
      print(s+x)
elif s == alp[::-1]:
  print(-1)
else:
  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()

Fixed code:
alp = "abcdefghijklmnopqrstuvwxyz"
s = input()
if len(s) < 26:
  for x in alp:
    if x not in s:
      print(s+x)
      break
elif s == alp[::-1]:
  print(-1)
else:
  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()
Buggy code:
s = input()
t = list(s)

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

r = []
for c in t:
    r.append(ord(c))

if len(t) < 26:
    r = sorted(r)

    temp = ord('a')

    for x in r:
        if x == temp:
            temp += 1
        else:
            break

    t.append(chr(temp))

    print(''.join(t))

else:
    temp = r[25]
    for i in range(24, -1, -1):
        if r[i] < temp:
            t[i] = chr(temp)
            break
        else:
            temp = max(temp, r[i])
            t[i] = ''

    t[25] = ''
    print(''.join(t))



Fixed code:
s = input()
t = list(s)

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

r = []
for c in t:
    r.append(ord(c))

if len(t) < 26:
    r = sorted(r)

    temp = ord('a')

    for x in r:
        if x == temp:
            temp += 1
        else:
            break

    t.append(chr(temp))

    print(''.join(t))

else:
    temp = r[25]
    for i in range(24, -1, -1):
        if r[i] < temp:
            hoge = r[i]
            fuga = sorted(r[i + 1:])
            for x in fuga:
                if x > hoge:
                    hoge = x
                    break
            t[i] = chr(hoge)
            break
        else:
            temp = max(temp, r[i])
            t[i] = ''

    t[25] = ''
    print(''.join(t))
Buggy code:
s=input()

ans=""

if len(s)<26:
    cnt_alphabet=[0]*26

    for i in range(len(s)):
        cnt_alphabet[ord(s[i])-97]+=1
    
    moji=""
    for i in range(26):
        if cnt_alphabet[i]<1:
            moji=chr(i+97)
            break
    ans=s+moji

else:
    cnt=25
    
    for i in range(24,-1,-1):
        if ord(s[i])>ord(s[i+1]):
            cnt=i
        else:
            break
    
    if cnt==1:
        ans='-1'
    else:
        min_chr=ord('{')
        for m in s[cnt:]:
            if ord(m)>ord(s[cnt-1]):
                min_chr=min(min_chr,ord(m))
            
        ans=s[:cnt-1]+chr(min_chr)

print(ans)

Fixed code:
s=input()

ans=""

if len(s)<26:
    cnt_alphabet=[0]*26

    for i in range(len(s)):
        cnt_alphabet[ord(s[i])-97]+=1
    
    moji=""
    for i in range(26):
        if cnt_alphabet[i]<1:
            moji=chr(i+97)
            break
    ans=s+moji

else:
    cnt=25
    
    for i in range(24,-1,-1):
        if ord(s[i])>ord(s[i+1]):
            cnt=i
        else:
            break
    
    if cnt==0:
        ans='-1'
    else:
        min_chr=ord('{')
        for m in s[cnt:]:
            if ord(m)>ord(s[cnt-1]):
                min_chr=min(min_chr,ord(m))
            
        ans=s[:cnt-1]+chr(min_chr)

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

Fixed code:
s=input()
if len(s)<26:
  for i in range(97,123):
    if not chr(i) in s:
      print(s+chr(i))
      exit()
else:
  for i in range(25)[::-1]:
    for j in range(i+1,26)[::-1]:
      if s[i]<s[j]:
        print(s[:i]+s[j])
        exit()
  else:
    print(-1)
Buggy code:
def main():
    s = input()
    al = list("abcdefghijklmnopqrstuvwxyz")
    d = set(s)
    n = len(s)
    if s == al[::-1]:
        print(-1)
        return 0
    if n == 26:
        for i in (range(n-1))[::-1]:
            if s[i] < s[i+1]:
                for j in range(i+1,n)[::-1]:
                    if s[i] < s[j]:
                        print(s[:i]+s[j])
                        return 0
    else:
        for i in al:
            if i not in d:
                print(''.join(s)+i)
                return 0

if __name__ == '__main__':
    main()


Fixed code:
def main():
    s = input()
    al = list("abcdefghijklmnopqrstuvwxyz")
    d = set(s)
    n = len(s)
    if list(s) == al[::-1]:
        print(-1)
        return 0
    if n == 26:
        for i in (range(n-1))[::-1]:
            if s[i] < s[i+1]:
                for j in range(i+1,n)[::-1]:
                    if s[i] < s[j]:
                        print(s[:i]+s[j])
                        return 0
    else:
        for i in al:
            if i not in d:
                print(''.join(s)+i)
                return 0

if __name__ == '__main__':
    main()
Buggy code:
s =i nput()
if len(s) < 26:
    for i in range(26):
        c = chr(ord("a")+i)
        if c not in s:
            print(s+c)
            exit()
else:
    for i in reversed(range(1,26)):
        if s[i-1] < s[i]:
            s1 = s[0:i-1]
            for j in range(26):
                c = chr(ord("a")+j)
                if c > s[i-1] and c not in s1:
                    print(s1+c)
                    exit()
    print(-1)

Fixed code:
s = input()
if len(s) < 26:
    for i in range(26):
        c = chr(ord("a")+i)
        if c not in s:
            print(s+c)
            exit()
else:
    for i in reversed(range(1,26)):
        if s[i-1] < s[i]:
            s1 = s[0:i-1]
            for j in range(26):
                c = chr(ord("a")+j)
                if c > s[i-1] and c not in s1:
                    print(s1+c)
                    exit()
    print(-1)
Buggy code:
abc="abcdefghijklmnopqrstuvwxyz"
import collections
table=collections.defaultdict(int)
for i in range(26):
  table[abc[i]]=i
table2=collections.defaultdict(int)
s=input()
for i in reversed(range(len(s)+1)):
  k=0
  if i < len(s):
    k=table[s[i]]
  for j in range(k+1,26):
    if abc[j] in s[:i]:
      continue
    else:
      print(s[:i]+abc[j])
      print(i,j)
      exit(0)
print(-1)

Fixed code:
abc="abcdefghijklmnopqrstuvwxyz"
import collections
table=collections.defaultdict(int)
for i in range(26):
  table[abc[i]]=i
table2=collections.defaultdict(int)
s=input()
for i in reversed(range(len(s)+1)):
  k=0
  if i < len(s):
    k=table[s[i]]+1
  for j in range(k,26):
    if abc[j] in s[:i]:
      continue
    else:
      print(s[:i]+abc[j])
      exit(0)
print(-1)
Buggy code:
s=input()
abc="abcdefghijklmnopqrstuvwxyz"
if len(s)<26:
  print(s+sorted(list(set(abc)-set(s)))[0])
else:
  x=s[-1]
  Tail=[x]
  count,flag=0,0
  for i in range(2,27):
    if s[-i]<x:
      count=i
      flag=1
      break
    else:
      x=s[-i]
      Tail.append(x)
  t="z"
  for tt in Tail:
    if tt>s[26-count]:
       t=min(t,tt)  
  print(s[:-count]+t if flag==1 else -1)

Fixed code:
s=input()
abc="abcdefghijklmnopqrstuvwxyz"
if len(s)<26:
  print(s+sorted(list(set(abc)-set(s)))[0])
else:
  x=s[-1]
  Tail=[x]
  count,flag=0,0
  for i in range(2,27):
    if s[-i]<x:
      count=i
      flag=1
      break
    else:
      x=s[-i]
      Tail.append(x)
  t="z"
  if count!=0:
    for tt in Tail:
      if tt>s[26-count]:
        t=min(t,tt)  
  print(-1 if flag==0 else s[:-count]+t)
Buggy code:
def check():
    S = input()
    s_set = set(S)
    alpha = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) == 26:
        if S == alpha[::-1]:
            return -1
        else:
            for i in range(1,len(S)):
                S1 = S[-i:]
                if S1 != ''.join(sorted(S1, reverse=True)):
                    for s in S1[::-1]:
                        if s > S[-i-1]:
                            return S[:-i-1]+s
    else:
        for a in alpha:
            if a not in s_set:
                return S+a
              
print(check())

Fixed code:
def check():
    S = input()
    s_set = set(S)
    alpha = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) == 26:
        if S == alpha[::-1]:
            return -1
        else:
            for i in range(1,len(S)+1):
                S1 = S[-i:]
                if S1 != ''.join(sorted(S1, reverse=True)):
                    S1 = S1[1:]
                    break
            for s in S1[::-1]:
                if s > S[-i]:
                    return S[:-i]+s
    else:
        for a in alpha:
            if a not in s_set:
                return S+a
print(check())
Buggy code:
from string import ascii_lowercase


def main():
    word = input()
    if len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count_l = list(count.items())
        count_l.sort(key=lambda x: x[0])
        print(count_l)
        add = ""
        for i in range(26):
            if count_l[i][1] == 0:
                add = count_l[i][0]
                break
        print(word + add)
    elif word == ascii_lowercase[::-1]:
        print(-1)
    else:
        is_printed = False
        while len(word) > 0 and not is_printed:
            for c in ascii_lowercase[ascii_lowercase.index(word[-1]) + 1:]:
                if c not in word[:-1]:
                    print(word[:-1] + c)
                    is_printed = True
                    break
            else:
                word = word[:-1]


if __name__ == '__main__':
    main()



Fixed code:
from string import ascii_lowercase


def main():
    word = input()
    if len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count_l = list(count.items())
        count_l.sort(key=lambda x: x[0])
        add = ""
        for i in range(26):
            if count_l[i][1] == 0:
                add = count_l[i][0]
                break
        print(word + add)
    elif word == ascii_lowercase[::-1]:
        print(-1)
    else:
        is_printed = False
        while len(word) > 0 and not is_printed:
            for c in ascii_lowercase[ascii_lowercase.index(word[-1]) + 1:]:
                if c not in word[:-1]:
                    print(word[:-1] + c)
                    is_printed = True
                    break
            else:
                word = word[:-1]


if __name__ == '__main__':
    main()
Buggy code:
import numpy as np
alp = [chr(v) for v in range(ord("a"), ord("z") + 1)]
inp = input()

if inp[::-1] == "".join(alp):
    print(-1)
    exit()

if len(inp) == len(alp):
    prev = inp[0]
    indices = [0]
    for index, char in enumerate(inp[1:]):
        if prev > char:
            indices.append(index)
        prev = char
    # diff = [0] * (len(indices) - 1)
    # for i, (v1, v2) in enumerate(zip(indices[1:], indices[:-1])):
    #     diff[i] = v1 - v2
    # maxv = float("-inf")
    # maxv_index = 0
    # for i, d in enumerate(diff):
    #     if maxv <= d:
    #         maxv = d
    #         maxv_index = i
    index = indices[-1]
    #
    # index = indices[maxv_index + 1]
    print(inp[:index - 1] + min(inp[index:]))

else:
    print(inp + min(set(alp) - set(list(inp))))


Fixed code:
import numpy as np
alp = [chr(v) for v in range(ord("a"), ord("z") + 1)]
inp = input()

if inp[::-1] == "".join(alp):
    print(-1)
    exit()

if len(inp) == len(alp):
    prev = inp[0]
    indices = [0]
    for index, char in enumerate(inp[1:]):
        if prev < char:
            indices.append(index)
        prev = char
    # diff = [0] * (len(indices) - 1)
    # for i, (v1, v2) in enumerate(zip(indices[1:], indices[:-1])):
    #     diff[i] = v1 - v2
    # maxv = float("-inf")
    # maxv_index = 0
    # for i, d in enumerate(diff):
    #     if maxv <= d:
    #         maxv = d
    #         maxv_index = i
    #
    # index = indices[maxv_index + 1]
    index = indices[-1]
    targets = inp[index + 1:]
    for v in sorted(targets):
        if inp[index] < v:
            break
    print(inp[:index] + v)

else:
    print(inp + min(set(alp) - set(list(inp))))
Buggy code:
S = input()
if len(S) < 26:
    for c in string.ascii_lowercase:
        if c not in S:
            break
    print(S + c)
else:
    ret = None
    for i in range(26):
        if max(S[25-i:]) != S[25-i]:
            mc = 'z'
            for c in S[25-i:]:
                if c > S[25-i]:
                    mc = min(c, mc)
            ret = S[:25-i] + mc
            break
            
    if ret is None:
        print(-1)
    else:
        print(ret)

Fixed code:
import string
 
S = input()
if len(S) < 26:
    for c in string.ascii_lowercase:
        if c not in S:
            break
    print(S + c)
else:
    ret = None
    for i in range(26):
        if max(S[25-i:]) != S[25-i]:
            mc = 'z'
            for c in S[25-i:]:
                if c > S[25-i]:
                    mc = min(c, mc)
            ret = S[:25-i] + mc
            break
            
    if ret is None:
        print(-1)
    else:
        print(ret)
Buggy code:
if __name__ == '__main__':
    s = input()
    alpha = list([1 for i in range(26)])
    if len(s) != 26:
        for i in range(len(s)):
            alpha[ord(s[i])-97] = 0
            for i in range(len(alpha)):
                if alpha[i]==1:
                    print(str(s)+chr(i+97))
                    exit()
            print("-1")
            exit()
    else:
        max = 0
        for i in reversed(range(len(s))):
            if ord(s[i]) < max:
                print(s[:i]+chr(max))
                exit()
            if ord(s[i]) > max:
                max = ord(s[i])
        print("-1")
        
                    


Fixed code:
if __name__ == '__main__':
    s = input()
    alpha = list([1 for i in range(26)])
    if len(s) != 26:
        for i in range(len(s)):
            if(alpha[ord(s[i])-97] == 0):
                print("-1")
                exit()
            alpha[ord(s[i])-97] = 0
        for i in range(len(alpha)):
            if alpha[i]==1:
                print(str(s)+chr(i+97))
                exit()
        print("-1")
        exit()
    else:
        max = ord(s[-1])-97
        alpha[ord(s[-1])-97] = 0
        
        for i in reversed(range(len(s)-1)):
            if ord(s[i])-97 <  max:
                for j in range(len(alpha)):
                    if alpha[j] == 0 and ord(s[i])-97<j:
                        print(s[:i]+chr(j+97))
                        exit()
            else:
                max = ord(s[i])-97
            alpha[ord(s[i])-97] = 0
        print("-1")
        exit()
Buggy code:
s = list(input())
m = list('zyxwvutsrqponmlkjihgfedcba')
if len(s) < 26:
    for i in m[::-1]:
        if not j in s:
            s.append(j)
            break
    print(''.join(s))
else:
    if s == m:
        print(-1)
    else:
        x = s[-1]
        for i in range(25)[::-1]:
            if x > s[i]:
                s = s[:i]
                s.append(x)
                break
            if i == 0:
                z = m.index(s[0])
                s = m[z-1]
                break
        print(''.join(s))

Fixed code:
s = list(input())
m = list('zyxwvutsrqponmlkjihgfedcba')
if len(s) < 26:
    for i in m[::-1]:
        if not i in s:
            s.append(i)
            break
    print(''.join(s))
else:
    x = s[-1]

    for i in range(25)[::-1]:
        if x > s[i]:
            y = m.index(s[i])
            s = s[:i]
            for j in range(y)[::-1]:
                if not m[j] in s:
                    s.append(m[j])
                    break
            break
        else:
            x = s[i]
        if i == 0:
            print(-1)
            exit(0)
    print(''.join(s))
Buggy code:
# 2019/08/12

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

st=set(s)
"""
if len(s)<26:
    for i in range(97,97+26+1):
        if chr(i) in st:continue
        print(s+chr(i))
        exit()
"""
s=list(s)
res=[s.pop()]

def solve(s):
    for _ in range(len(s)):
        tmp=s.pop()
        if tmp>res[-1]:
            res.append(tmp)
            res.sort()
        else:            
            for e in res:
                if e<tmp:continue
                s.append(e)
                return s

print(''.join(solve(s)))

Fixed code:
# 2019/08/12

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

st=set(s)

if len(s)<26:
    for i in range(97,97+26+1):
        if chr(i) in st:continue
        print(s+chr(i))
        exit()

s=list(s)
res=[s.pop()]

def solve(s):
    for _ in range(len(s)):
        tmp=s.pop()
        if tmp>res[-1]:
            res.append(tmp)
            res.sort()
        else:            
            for e in res:
                if e<tmp:continue
                s.append(e)
                return s

print(''.join(solve(s)))
Buggy code:
s= input()
V = list(s)
X = [chr(ord('a') + i) for i in range(26)]

if len(s)<26:
  for i in range(26):
    count1 = s.count(X[i])
    if count1 >= 1:
      continue
    else:
      Nasi = X[i]
      break
  ans = s + Nasi
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    ans= -1
  else:
    for i in range(25, 0, -1):
        if V[i] > V[i-1]:
          ans = V[0:i-2]
          ans.append(min(V[i+1:26]))
          ans = ''.join(ans)
          break
        else:
          continue
print(ans)

Fixed code:
s= input()
V = list(s)
X = [chr(ord('a') + i) for i in range(26)]

if len(s)<26:
  for i in range(26):
    count1 = s.count(X[i])
    if count1 >= 1:
      continue
    else:
      Nasi = X[i]
      break
  ans = s + Nasi
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    ans= -1
  else:
    for i in range(25, 0, -1):
        if V[i] > V[i-1]:
          ans = V[0:i-1]
          if ans == []:
            ans = chr(ord(V[0]) + 1)
          else:
              B = min(V[i:26])
              while B <= V[i-1]:
                  B = chr(ord(B) + 1)
              while B in ans:
                  B = chr(ord(B) + 1)
              ans.append(B)
              ans = ''.join(ans)
              break
        else:
            continue
print(ans)
Buggy code:
s=input()
a='abcdefghijklmnopqrstuvwxyz'
r='zyxwvutsrqponmlkjihgfedcba'
if len(s)!=26:
  for i in a:
    if i not in s:
      s=s+i
      break
elif s==r:
  s=-1
else:
  for i in range(25,0,-1):
    if i==1:
      s=chr(ord(s[0])+1)
      break
    if s[i]>s[i-1]:
      l=sorted(s[i:])
      for i in l:
        if i>s[i-1]:
          m=i
          break
      s=s[:i-1]+m
      break
print(s)

Fixed code:
s=input()
a='abcdefghijklmnopqrstuvwxyz'
r='zyxwvutsrqponmlkjihgfedcba'
if len(s)!=26:
  for i in a:
    if i not in s:
      s=s+i
      break
elif s==r:
  s=-1
else:
  for i in range(25,0,-1):
    if i==1:
      s=chr(ord(s[0])+1)
      break
    if s[i]>s[i-1]:
      l=sorted(s[i:])
      for j in l:
        if j>s[i-1]:
          m=j
          break
      s=s[:i-1]+m
      break
print(s)
Buggy code:
s=input()
l=[chr(i) for i in range(97,97+26)]
if len(s)!=26:
  for i in l:
    if i not in s:
      print(s+i)
      break
else:
  for j in range(26):
    S=s[j:26]
    c=0
    for k in range(len(S)-1):
      if S[k]>S[k+1]:c+=1
    if c==len(S)-1:
      x=j
      break
  if j==0:print(-1)
  else:
    for m in range(l.index(s[x-1])+1,26):
      if l[m] not in s[0:x-1]:y=l[m]
    print(s[0:x-1]+y)

Fixed code:
s=input()
l=[chr(i) for i in range(97,97+26)]
if len(s)!=26:
  for i in l:
    if i not in s:
      print(s+i)
      break
else:
  for j in range(26):
    S=s[j:26]
    c=0
    for k in range(len(S)-1):
      if S[k]>S[k+1]:c+=1
    if c==len(S)-1:
      x=j
      break
  if x==0:print(-1)
  else:
    for m in range(l.index(s[x-1])+1,26):
      if l[m] not in s[0:x-1]:
        y=l[m]
        break
    print(s[0:x-1]+y)
Buggy code:
def solv(S):
    for i in range(25, 0, -1):
        for j in range(i-1, -1, -1):
            if ord(S[i]) > ord(S[j]):
                print(S[:j]+S[i])
                return


alph = "abcdefghijklmnopqrstuvwxyz"
S = input()
for c in S:
    alph = alph.replace(c, "")
if alph != "":
    print(S+alph[0])
else:
    if S == alph[::-1]:
        print(-1)
    else:
        solv(S)


Fixed code:
def solv(S):
    c = []
    for i in range(25, 0, -1):
        for j in range(i-1, -1, -1):
            if S[i] > S[j]:
                c.append(S[:j]+S[i])
    print(sorted(c)[0])
    return


alph = "abcdefghijklmnopqrstuvwxyz"
S = input()
for c in S:
    alph = alph.replace(c, "")
if alph != "":
    print(S+alph[0])
else:
    alph = "abcdefghijklmnopqrstuvwxyz"
    if S == alph[::-1]:
        print(-1)
    else:
        solv(S)
Buggy code:
s = input()
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(True):
    for c in t:
        if(c > s[-1]):
            print(''.join(s[:-1]) + c)
            exit()
    t.append(s.pop())


Fixed code:
s = input()
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:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    for i in range(25):
        if ord(inp[-1 - i]) > ord(inp[-2 - i]):
            an = inp[:-2-i]
            ls = inp[-2-i]
            for char in map(ord,list(inp[-1-i:])):
                dic[char] = "exist"
            break
    for j in range(26):
        if  97 + j in dic and 97+ j  >  ord(ls):
            an =  an + chr(97+j)
            break
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Fixed code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
if inp_len == 26:
    for i in range(25):
        if ord(inp[-1 - i]) > ord(inp[-2 - i]):
            an = inp[:-2-i]
            ls = inp[-2-i]
            for char in map(ord,list(inp[-1-i:])):
                dic[char] = "exist"
            break
    for j in range(26):
        if  97 + j in dic and 97+ j  >  ord(ls):
            an =  an + chr(97+j)
            break
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)