ZhenlongDai/ACPR huggingface dataset:
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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:
    inverse_S=list(reversed(S))
    s=ord(inverse_S[0])
    l=[]
    for i in range(1,26):
        if s>ord(inverse_S[i]):
            break

    if i+1==26:
        print(-1)
    else:
        l=S[-(i+1):]
        ans=S[:-(i+1)]+sorted(l)[-1]
        print(ans)

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
-1


Fixed submission (verdict: Accepted):
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)

Problem: p03393
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
dic = [False for i in range(26)]
txt = input()
for i in txt:
  dic[ord(i) - 97] = True
for i in range(26):
  if not dic[i]:
    print(txt + chr(i + 97))
    break
else:
  for j in range(25):
    
    if txt[24 - j] < txt[25 - j]:
      txt = txt[:25 - j]
      temp = ord(txt[-1]) + 1
      txt = txt[:-1]
      txt += chr(temp)
      dic = [False for i in range(26)]
      print(txt)
      break

Failing test case input:
zyxwvutsrqponmlkjihgfedcba

Expected output:
-1

Actual output:

Fixed submission (verdict: Accepted):
dic = [False for i in range(26)]
txt = input()
for i in txt:
  dic[ord(i) - 97] = True
for i in range(26):
  if not dic[i]:
    print(txt + chr(i + 97))
    break
else:
  for j in range(25):
    if txt[24 - j] < txt[25 - j]:
      
      last = txt[24-j] 
      txt = txt[:24 - j]
      
      dic = [False for i in range(26)]
      for k in txt:
        dic[ord(k) - 97] = True
      txt += chr(dic[ord(last) - 96:].index(False) + ord(last) + 1)

      print(txt)
      break

  else:
    print(-1)
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import sys
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 = ''
    for i,rr in enumerate(r):
        if i == 0:
            continue
        if rr < r[i-1]:
            tmp = r[:i+1][::-1]
            break
    
    tmp_li = list(tmp)
    tmp_li.sort()
    s0 = tmp_li[1]
    print(s.replace(tmp, s0))

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xb


Fixed submission (verdict: Accepted):


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
    

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

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
d=list("abcdefghijklmnopqrstuvwxyz")
s=input()
ss=list(s)
unused=list(set(d)^set(ss))
unused.sort()
if len(s)==26:
    cnt=1
    l=d.index(s[-1])
    for i in range(2,27):
        if d.index(s[-i])>l:
            l=d.index(s[-i])
            cnt+=1
        else:
            ans=ss[:26-cnt-1]+[s[-1]]
            print("".join(ans))
            exit()
    print(-1)
else:
    ans=ss+[unused[0]]
    print("".join(ans))

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
d=list("abcdefghijklmnopqrstuvwxyz")
s=input()
ss=list(s)
unused=list(set(d)^set(ss))
unused.sort()
if len(s)==26:
    cnt=1
    l=d.index(s[-1])
    for i in range(2,27):
        if d.index(s[-i])>l:
            l=d.index(s[-i])
            cnt+=1
        else:
            i=ss[-cnt-1]
            j=1
            while True:
                if d.index(i)>d.index(ss[-j]):
                    j+=1
                else:
                    break
            ans=ss[:-cnt-1]+[ss[-j]]
            print("".join(ans))
            exit()
    print(-1)
else:
    ans=ss+[unused[0]]
    print("".join(ans))
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
s_set = set(S)
ind = len(S)

if len(S) == 26:
    s_set.remove(S[-1])
    s_set.remove(S[-2])
    for i in range(23, -1, -1):
        if ord(S[i]) > ord(S[i+1]):
            s_set.remove(S[i])
            continue
        else:
            ind = i
            break
    if len(s_set) == 0:
        print(-1)
        exit()

        
for i in range(26):
    if chr(i+97) in s_set:
        continue
    else:
        print(S[:ind] + chr(i+97))
        break

Failing test case input:
abcdefghijklmnopqrytuvwzsx

Expected output:
abcdefghijklmnopqrytuvwzx


Actual output:
abcdefghijklmnopqrytuvs


Fixed submission (verdict: Accepted):
S = input()
s_set = set(S)
ind = len(S)

if len(S) == 26:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        exit()
    for i in range(24, -1, -1):
        if ord(S[i]) <= ord(S[i+1]):
            ind = i
            break
    ans = S[:ind]
    for s in reversed(S[ind+1:]):
        if ord(s) > ord(S[ind]):
            print(ans + s)
            exit()

else:        
    for i in range(26):
        if chr(i+97) in s_set:
            continue
        else:
            print(S + chr(i+97))
            break

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
abcdefghijklmnopqrstuvwzyx

Expected output:
abcdefghijklmnopqrstuvx

Actual output:
abcdefghijklmnopqrstuvwx


Fixed submission (verdict: Accepted):
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]))
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
alp = ['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']
buf = ''
for i in alp:
    if not i in set(s):
        buf = i
        break
if buf:
    print(s+buf)
else:
    c = 1
    for i in range(1,len(s)):
        if s[-i-1]>s[-i]:
            c += 1
        else:break
    if c==26:
        print(-1)
    else:
        buf = chr(ord(s[-c-1])+1)
        print(s[:-c-1]+buf)

Failing test case input:
azcdefghijklmnopqrstuvwbyx

Expected output:
azcdefghijklmnopqrstuvwx


Actual output:
azcdefghijklmnopqrstuvwc


Fixed submission (verdict: Accepted):
s = input()
alp = ['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']
buf = ''
for i in alp:
    if not i in set(s):
        buf = i
        break
if buf:
    print(s+buf)
else:
    c = 1
    for i in range(1,len(s)):
        if s[-i-1]>s[-i]:
            c += 1
        else:break
    if c==26:
        print(-1)
    else:
        for i in sorted(s[-c:]):
            if ord(s[-c-1])<ord(i):
                buf = i
                break
        print(s[:-c-1]+buf)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import string

alp = string.ascii_lowercase

def main():
    s = input()
    if len(s) < 26:
        for i in alp:
            if i not in s:
                print (s + i)
                return
    if s == alp[::-1]:
        print(-1)
        return
    L = len(s)
    for i, ss in enumerate( s ):
        if s[L-i-1] > s[L-i-2]:
            print ( s[:L-i-2] + s[-1] )
            break

main()



Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
import string

alp = string.ascii_lowercase

def main():
    s = input()
    if len(s) < 26:
        for i in alp:
            if i not in s:
                print (s + i)
                return
    if s == alp[::-1]:
        print(-1)
        return
    L = len(s)
    tmp = []
    tt = ''
    for i, ss in enumerate( s ):
        tmp += [ s[L-i-1] ]
        if s[L-i-1] > s[L-i-2]:
            ans = s[:L-i-2]
            tt = s[L-i-2] 
            break
    tmp.sort()
    for i in tmp:
        if i > tt:
            print (ans + i)
            break
main()
Problem: p03393
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
s = input()

if len(s) < 26:
    for i in range(ord('a'), ord('z')+1):
        if not chr(i) in s:
            print(s+chr(i))
            break
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    for i in range(1, 26):
        if ord(s[-i]) > ord(s[-i-1]):
            val = ord('z')+1
            for j in s[-i:]:
                val = min(ord(j), val)
            print(s[:-i-1]+chr(val))
            break



Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
import sys
s = input()

if len(s) < 26:
    for i in range(ord('a'), ord('z')+1):
        if not chr(i) in s:
            print(s+chr(i))
            break
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    a = set()
    for i in range(26):
        a.add(s[25-i])
        for j in sorted(a):
            if s < s[:25-i]+j:
                print(s[:25-i]+j)
                sys.exit()

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = str(input())

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(s) == 26:
    tmp = ord(s[-1])
    for i in range(len(s))[::-1]:
        if ord(s[i]) > tmp:
            ans = sorted(s[i - 2:])
            for j in ans:
                if ord(j) > ord(s[i - 2]):
                    print(s[:i - 2] + j)
                    exit()
        tmp = ord(s[i])
    
else:
    alpha = [chr(i) for i in range(97, 97 + 26)]
    for i in alpha:
        if i not in s:
            print(s + i)
            break


Failing test case input:
azcdefghijklmnopqrstuvwbyx

Expected output:
azcdefghijklmnopqrstuvwx


Actual output:
azcdefghijklmnopqrstuvx


Fixed submission (verdict: Accepted):
s = str(input())

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(s) == 26:
    tmp = ord(s[-1])
    for i in range(len(s))[::-1]:
        if ord(s[i]) < tmp:
            ans = sorted(s[i:])
            for j in ans:
                if ord(j) > ord(s[i]):
                    print(s[:i] + j)
                    exit()
        tmp = ord(s[i])
else:
    alpha = [chr(i) for i in range(97, 97 + 26)]
    for i in alpha:
        if i not in s:
            print(s + i)
            break
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import string

S = input()
V = set(S)

for s in string.ascii_lowercase:
    if not s in V:
        print(S + s)
        exit()

for s, t in zip(S[:: -1], string.ascii_lowercase):
    if s != t:
        break
else:
    print(-1)
    exit()

for i, (s, t) in enumerate(zip(S, string.ascii_lowercase)):
    if s < t:
        print(S[:i] + t)
        break
    elif s > t:
        print(S[: i - 1] + t)
        break

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xyzwvutsrqponmlkjihgfedcba


Fixed submission (verdict: Accepted):
import string

S = input()
V = set(S)

for s in string.ascii_lowercase:
    if not s in V:
        print(S + s)
        exit()

for s, t in zip(S[:: -1], string.ascii_lowercase):
    if s != t:
        break
else:
    print(-1)
    exit()

for i in range(len(S))[:: -1]:
    A = []
    for j in range(i + 1, len(S)):
        if S[i] < S[j]:
            A.append(S[j])
    if A:
        A.sort()
        print(S[: i] + A[0])
        break

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
if sorted(s, reverse=True) == s and len(s) == 26:
    print(-1)
    quit()
sn = []
for i in s:
    sn.append(ord(i)-97)
for i in range(1, 26+1):
    if chr(97+i) not in s:
        if len(s) != 26:
            print(''.join(s) + chr(97+i))
            quit()
        else:
            ans = []
            for j in range(len(s)):
                ans.append(chr(97 + j))
                if sn[j] != j:
                    print(''.join(ans))
                    quit()

Failing test case input:
dfrocbt

Expected output:
dfrocbta


Actual output:
dfrocbte


Fixed submission (verdict: Accepted):
s = list(input())
if sorted(s, reverse=True) == s and len(s) == 26:
    print(-1)
    quit()
for i in range(0, 26):
    if chr(97 + i) not in s and len(s) != 26:
        print(''.join(s) + chr(97+i))
        quit()

while len(s) > 0:
    while ord(s[-1]) < ord('z'):
        s[-1] = chr(ord(s[-1])+1)
        if len(s) == len(set(s)):
            print(''.join(s))
            quit()
    del s[-1]
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict
S = input()
alphabet= "abcdefghijklmnopqrstuvxyz"

dict = defaultdict(int)
for s in S:
    dict[s] += 1

if len(S) < len(alphabet):
    for a in alphabet:
        if dict[a] == 0:
            print(S + a)
            exit()
else:
    ans = ""
    for s,a in zip(S, alphabet):
        if s != a:
            print(ans + chr(ord(s)+1))
            exit()
        ans += s
print(-1)

Failing test case input:
abcdefghijklmnopqrytuvwzsx

Expected output:
abcdefghijklmnopqrytuvwzx


Actual output:
abcdefghijklmnopqrz


Fixed submission (verdict: Accepted):
from collections import defaultdict
S = input()
alphabet = "abcdefghijklmnopqrstuvxyz"

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

dict = defaultdict(int)
for s in S:
    dict[s] += 1

if len(S) < len(alphabet):
    for a in alphabet:
        if dict[a] == 0:
            print(S + a)
            exit()
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()
print(-1)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
ans = '-1'

if len(s) < 26:
    for w in a:
        if not w in s:
            ans = s + w
            break

if len(s) == 26:
    for i in range(len(s)-1, 0, -1):
        if s[i] > s[i-1]:
            ans = s[:i-1] + sorted(s[i-1:])[1]
            break

print(ans)

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xb


Fixed submission (verdict: Accepted):
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'

if len(s) < 26:
    for w in a:
        if not w in s:
            print(s + w)
            exit()

if len(s) == 26:
    for i in range(len(s)-2, -1, -1):
        for j in range(len(s)-1, i, -1):
            if s[i] < s[j]:
                print(s[:i]+s[j])
                exit()

print('-1')

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
al = "abcdefghijklmnopqrstuvwxyz"
s = input()
if len(s)<26:
  for i in al:
    if i not in s:
      print(s+i)
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    k = set()
    for i in range(25, 0, -1):
      if s[i-1] < s[i]:
        for j in k:
          if j > s[i-1]:
            print(s[:i-1] + j)
            exit()
      k.add(s[i])

Failing test case input:
abcdefghijklmnopqrytuvwzsx

Expected output:
abcdefghijklmnopqrytuvwzx


Actual output:
abcdefghijklmnopqrytuvx


Fixed submission (verdict: Accepted):
al = "abcdefghijklmnopqrstuvwxyz"
s = input()
if len(s)<26:
  for i in al:
    if i not in s:
      print(s+i)
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    k = []
    for i in range(25, 0, -1):
      k.append(s[i])
      if s[i-1] < s[i]:
        for j in sorted(k):
          if j > s[i-1]:
            print(s[:i-1] + j)
            exit()
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()
row='abcdefghijklmnopqrstuvwxyz'
row=list(row)
if len(S)!=26:
    for letter in S:
        row.remove(letter)
    print(S+row[0])
    
else:
    if S=='zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        S_=[]
        for i in range(25,1,-1):
            if S[i-1]<S[i]:
                for j in range(i-1):
                    S_.append(S[j])
                S_.append(S[25])
                S_=''.join(S_)
                print(str(S_))
                break
        else:
            print(row[row.index(S[0])+1])


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
S=input()
row='abcdefghijklmnopqrstuvwxyz'
row=list(row)
if len(S)!=26:
    for letter in S:
        row.remove(letter)
    print(S+row[0])
    
else:
    if S=='zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        S_=[]
        for i in range(25,1,-1):
            if S[i-1]<S[i]:
                for j in range(i-1):
                    S_.append(S[j])
                x=row.index(S[i-1])
                for j in range(x+1,27,1):
                    if row[j] not in S_:
                        S_.append(row[j])
                        break
                S_=''.join(S_)
                print(str(S_))
                break
        else:
            print(row[row.index(S[0])+1])

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()
abc=[chr(ord('a')+i) for i in range(26)]

if len(S)==26:
    z=S.index('z')
    if z==0:
        print(-1)
    else:
        ans=S[:z-1]
        abc.remove(S[z-1])
        for s in ans:
            abc.remove(s)
        print(ans+abc[0])
else:
    for s in S:
        abc.remove(s)
    print(S+abc[0])


Failing test case input:
abcpefghijklmnodqrytuvwzsx

Expected output:
abcpefghijklmnodqrytuvwzx


Actual output:
abcpefghijklmnodqrytuvs


Fixed submission (verdict: Accepted):
S=input()
abc=[chr(ord('a')+i) for i in range(26)]

if len(S)<26:
    for s in S:
        abc.remove(s)
    print(S+abc[0])
    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)
Problem: p03393
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = str(input())
N = len(S)
L = list(S)
L = set(L)
if N != 26: 
  for i in range(26):
    temp = chr(i+97)
    if temp not in L:
      ans = S+temp
      print(ans)
      exit()
M = []
All = [chr(97+i) for i in range(26)]
print(All)
for i in range(25):
  now = 25-i
  M.append(S[now])
  if S[now] > S[now-1]:
    M.sort()
    for x in M:
      if x > S[now-1]:
        temp = x
        ans = S[:now-1]+temp
        print(ans)
        exit()
  
print(-1)  

Failing test case input:
abcdefghijklmnopqrytuvwzsx

Expected output:
abcdefghijklmnopqrytuvwzx


Actual output:
['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']
abcdefghijklmnopqrytuvwzx


Fixed submission (verdict: Accepted):
S = str(input())
N = len(S)
L = list(S)
L = set(L)
if N != 26: 
  for i in range(26):
    temp = chr(i+97)
    if temp not in L:
      ans = S+temp
      print(ans)
      exit()
M = []
All = [chr(97+i) for i in range(26)]

for i in range(25):
  now = 25-i
  M.append(S[now])
  if S[now] > S[now-1]:
    M.sort()
    for x in M:
      if x > S[now-1]:
        temp = x
        ans = S[:now-1]+temp
        print(ans)
        exit()
  
print(-1)

Problem: p03393
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S=input()

A="abcdefghijklmnopqrstuvwxyz"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(S)!=26:
    A=list(A)
    for i in range(len(S)):
        A.remove(S[i])
    print(S+A[0])
else:
    a=A.index(S[25])
    for i in range(24,-1,-1):
        b=A.index(S[i])
        if a>b:
            break
        a=b
    print(S[:i]+A[b+1])


Failing test case input:
abcpefghijklmnodqrytuvwzsx

Expected output:
abcpefghijklmnodqrytuvwzx


Actual output:
abcpefghijklmnodqrytuvwzt


Fixed submission (verdict: Accepted):
S=input()

A="abcdefghijklmnopqrstuvwxyz"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(S)!=26:
    A=list(A)
    for i in range(len(S)):
        A.remove(S[i])
    print(S+A[0])
else:
    a=A.index(S[25])
    for i in range(24,-1,-1):
        b=A.index(S[i])
        if a>b:
            break
        a=b

    for j in range(b+1,26):
        if not A[j] in S[:i]:
            print(S[:i]+A[j])
            break
Problem: p03393
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
if len(N) < 26:
    for d in D:
        if not d in setN:
            N.append(d)
            print(''.join(N))
            exit()
else:
    N.reverse()
    for i in range(25):
        if N[i] < N[i+1]:
            continue
        else:
            tmp = N[i+1]
            ans = N[i+2:]
            ans.reverse()
            ans.append(chr(ord(tmp)+1))
            print(''.join(ans))
            exit()
print(-1)

Failing test case input:
azcdefghijklmnopqrstuvwbyx

Expected output:
azcdefghijklmnopqrstuvwx


Actual output:
azcdefghijklmnopqrstuvwc


Fixed submission (verdict: Accepted):
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
if len(N) < 26:
    for d in D:
        if not d in setN:
            N.append(d)
            print(''.join(N))
            exit()
else:
    N.reverse()
    for i in range(25):
        if N[i] < N[i+1]:
            continue
        else:
            tmp = N[i+1]
            ans = N[i+2:]
            ans.reverse()
            cand = N[:i+2]
            cand.sort()
            for n in N[:i+2]:
                if ord(n) - ord(tmp) > 0:
                    ans.append(n)
                    print(''.join(ans))
                    exit()
print(-1)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
if len(S) < 26:
    for i in range(26):
        c = chr(i + ord('a'))
        if c not in S:
            print(S + c)
            break
else:
    while len(S) > 0:
        if (S[-1] == 'z'):
            S = S[:-1]
        else:
            c = chr(ord(S[-1]) + 1)
            if c not in S[:-1]:
                print(S[:-1] + c)
                break
            else:
                S = S[:-1]





Failing test case input:
abcpefghijklmnodqrytuvwzsx

Expected output:
abcpefghijklmnodqrytuvwzx


Actual output:
abcpefghijklmnodqrytuvx


Fixed submission (verdict: Accepted):
S = input()
if len(S) < 26:
    for i in range(26):
        c = chr(i + ord('a'))
        if c not in S:
            print(S + c)
            break
else:
    tmp = 26
    for i in range(len(S) - 1, 0, -1):
        if ord(S[i - 1]) < ord(S[i]):
            break
        tmp = i
    tmp -= 1
    if tmp == 0:
        print(-1)
    else:
        c = ord(S[:tmp][-1])
        suf = S[tmp:]
        print(S[:tmp - 1] + chr(min([ord(si) for si in suf if ord(si) > c])))
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
alp = "abcdefghijklmnopqrstuvwxyz"
s = input()
if len(s) < 26:
  for x in alp:
    if x not in s:
      print(s+x)
      exit()
if s == alp[::-1]:
  print(-1)
  exit()
i = 25
while i and s[i-1] > s[i]:
  i -= 1
print(s[:i-1]  + s[-1])
  

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
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()

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


alp = 'abcdefghijklmnopqrstuvwxyz'
S = input()
if S == alp[::-1]:
    print(-1)
else:
    if len(S) == len(alp):
        l = list(S)
        for i in range(1, len(S))[::-1]:
            if l[i-1] > l[i]:
                l = l[:i-1] + [l[i]]
        print(''.join(l))
    else:
        for i in S : alp = alp.replace(i, '')
        print(S+alp[0])

Failing test case input:
azcdefghijklmnopqrstuvwbyx

Expected output:
azcdefghijklmnopqrstuvwx


Actual output:
ab


Fixed submission (verdict: Accepted):


alp = 'abcdefghijklmnopqrstuvwxyz'
S = input()
if S == alp[::-1]:
    print(-1)
else:
    if len(S) == len(alp):
        l = list(S)
        s = []
        for i in range(1, len(S))[::-1]:
            s += [l[i]]
            r = sorted(x for x in s if x > l[i-1])
            if r:
                l = l[:i-1] + [r[0]]
                break
        print(''.join(l))
    else:
        for i in S : alp = alp.replace(i, '')
        print(S+alp[0])

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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()

Failing test case input:
rfdcpsb

Expected output:
rfdcpsba


Actual output:
rfdcpsba
rfdcpsbe
rfdcpsbg
rfdcpsbh
rfdcpsbi
rfdcpsbj
rfdcpsbk
rfdcpsbl
rfdcpsbm
rfdcpsbn
rfdcpsbo
rfdcpsbq
rfdcpsbt
rfdcpsbu
rfdcpsbv
rfdcpsbw
rfdcpsbx
rfdcpsby
rfdcpsbz


Fixed submission (verdict: Accepted):
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()
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
a='abcdefghijklmnopqrstuvwxyz'
b=[i for i in a if i not in s]
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif b:
    print(s + b[0])
else:
    for i in range(1, len(s)+1):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            b=[str(j) for j in a if j not in s[:-i] + s[-i:][0]]
            print(s[:-i] + b[0])
            break


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
b = [i for i in a if i not in s]
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif b:
    print(s + b[0])
else:
    for i in range(1, len(s) + 1):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            b = [j for j in a if j not in s[:-i+1] and j > s[-i:][0]][0]
            if i == 26:
                print(chr(ord(s[0]) + 1))
            else:
                print(s[:-i] + b)
            break

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()
row='abcdefghijklmnopqrstuvwxyz'
row=list(row)
if len(S)!=26:
    for letter in S:
        row.remove(letter)
    print(S+row[0])
    
else:
    if S=='zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        S_=[]
        for i in range(25,0,-1):
            if S[i-1]<S[i]:
                for j in range(i-1):
                    S_.append(S[j])
                S_.append(S[25])
                S_=''.join(S_)
                print(str(S_))
                break


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
S=input()
row='abcdefghijklmnopqrstuvwxyz'
row=list(row)
if len(S)!=26:
    for letter in S:
        row.remove(letter)
    print(S+row[0])
    
else:
    if S=='zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        S_=[]
        for i in range(25,1,-1):
            if S[i-1]<S[i]:
                for j in range(i-1):
                    S_.append(S[j])
                x=row.index(S[i-1])
                for j in range(x+1,27,1):
                    if row[j] not in S_:
                        S_.append(row[j])
                        break
                S_=''.join(S_)
                print(str(S_))
                break
        else:
            print(row[row.index(S[0])+1])
Problem: p03393
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S=list(input())
A='abcdefghijklmnopqrstuvwxyz'

ans='-1'
if len(S)<26:
    for a in A:
        if a not in S:
            ans=''.join(S)+a
            break
else:
    i=0
    ss=S[::-1]
    while i+1<26:
        if ss[i]>ss[i+1]:
            ss[i],ss[i+1]='',chr(ord(ss[i+1])+1)
            ans=''.join(ss[::-1])
            break
        else:
            ss[i]=''
        i+=1

print(ans)

Failing test case input:
abcdefghijklmnopqrytuvwzsx

Expected output:
abcdefghijklmnopqrytuvwzx


Actual output:
abcdefghijklmnopqrytuvwzt


Fixed submission (verdict: Accepted):
S=input()
A='abcdefghijklmnopqrstuvwxyz'
N=len(S)

ans='-1'
if N<26:
    for a in A:
        if a not in S:
            ans=S+a
            break
else:
    rs=S[::-1]
    i=1
    while i<26:
        srt=sorted(rs[:i+1])
        if srt[-1]!=rs[i]:
            ans=rs[i+1:][::-1]+srt[srt.index(rs[i])+1]
            break
        i+=1

print(ans)

Problem: p03393
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
for d in D:
    if not d in setN:
        N.append(d)
        print(''.join(N))
        exit()
ans = []
for i in range(0, 25):
    if N[i] < N[i+1]:
        ans.append(N[i])
if len(ans) == 0:
    print(-1)
else:
    del(ans[-1])
    for d in D:
        if not d in ans:
            ans.append(d)
            print(''.join(ans))
            exit()

Failing test case input:
abcdefghijklmnopqrytuvwzsx

Expected output:
abcdefghijklmnopqrytuvwzx


Actual output:
abcdefghijklmnopqrtuvws


Fixed submission (verdict: Accepted):
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
if len(N) < 26:
    for d in D:
        if not d in setN:
            N.append(d)
            print(''.join(N))
            exit()
else:
    N.reverse()
    for i in range(25):
        if N[i] < N[i+1]:
            continue
        else:
            tmp = N[i+1]
            ans = N[i+2:]
            ans.reverse()
            cand = N[:i+2]
            cand.sort()
            for n in N[:i+2]:
                if ord(n) - ord(tmp) > 0:
                    ans.append(n)
                    print(''.join(ans))
                    exit()
print(-1)
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
A = "abcdefghijklmnopqrstuvwxyz"
if len(S)<26:
    for c in A:
        if c not in S:
            print(S+c)
            break
elif S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    c = S[25]                
    for i in range(25,-1,-1):
        if ord(c)>ord(S[i]):
            print(S[:i]+chr(min(map(ord,S[i+1:]))))
            break  


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:

Fixed submission (verdict: Accepted):
S = input()
A = "abcdefghijklmnopqrstuvwxyz"
if len(S)<26:
    for c in A:
        if c not in S:
            print(S+c)
            break
elif S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for i in range(24,-1,-1):
        for c in A:
            if c not in S[:i] and c>S[i]:
                print(S[:i]+c)
                break
        else:
            continue
        break

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
if len(s)<26:
    seen = set()
    for c in s:
        seen.add(c)
    for i in range(26):
        tmp = chr(i+ord('a'))
        if tmp not in seen:
            print(s+tmp)
            break
else:
    pre = 'a'
    for i, c in enumerate(reversed(s)):
        if c < pre:
            print(s[:25-i]+s[-1])
            break
        pre = c
    else:
        print(-1)

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
s = input()
if len(s)<26:
    seen = set()
    for c in s:
        seen.add(c)
    for i in range(26):
        tmp = chr(i+ord('a'))
        if tmp not in seen:
            print(s+tmp)
            break
else:
    pre = 'a'
    seen = set()
    for i, c in enumerate(reversed(s)):
        if c < pre:
            for j in range(26):
                tmp = chr(j+ord(c)+1)
                if tmp in seen:
                    print(s[:25-i]+tmp)
                    break
            break
        seen.add(c)
        pre = c
    else:
        print(-1)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
if len(S) == 26:
    idx = -1
    for i in range(len(S)-1, 0, -1):
        if S[i-1] < S[i]:
            idx = i
            break
    if idx == -1:
        print(-1)
    else:
        if idx != 1:
            print(S[:idx-1]+S[-1])
        else:
            print(chr(ord(S[0])+1))
else:
    for i in range(97, 97+26):
        if chr(i) not in S:
            key = chr(i)
            break
    print(S+key)


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
import sys
S = input()
if len(S) < 26:
    for i in range(97, 97 + 26):
        if chr(i) not in S:
            print(S+chr(i))
            break
else:
    S_rev = S[::-1]
    for i in range(len(S_rev)-1):
        if S_rev[i] > S_rev[i+1]:
            for j in range(len(S_rev)):
                if S_rev[j] > S[-(i+2)]:
                    print(S[:len(S)-(i+1)-1]+S_rev[j])
                    sys.exit(0)
    print(-1)
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



def main():
	s = input()
	alphabet = "abcdefghijklmnopqrstuvwxyz"
	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
	elif s == alphabet:
		print("ac")
	else:
		for i in range(26):
			if s[i] != alphabet[i]:
				print(s[0:(i-1)] + alphabet[i])
				break


if __name__ == '__main__':
	main()

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xyzwvutsrqponmlkjihgfedcba


Fixed submission (verdict: Accepted):



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)

Problem: p03393
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
S = input()
N = len(S)

D = [0 for i in range(26)]
for i in range(N):
    D[ord(S[i]) - 97] = 1

if N != 26:
    for i in range(26):
        if D[i] == 0:
            s = chr(97 + i)
            break
    print(S + s)

else:
    if S == "abcdefghijklmnopqrstuvwxyz"[::-1]:
        print(-1)
    else:
        c = 2
        for i in range(N):
            if ord(S[-2 - i]) - ord(S[-1 - i]) == 1:
                c += 1
            else:
                break
        print(S[:26 - c] + S[-1])


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xya


Fixed submission (verdict: Accepted):
S = input()
N = len(S)

D = [0 for i in range(26)]
for i in range(N):
    D[ord(S[i]) - 97] = 1

if N != 26:
    for i in range(26):
        if D[i] == 0:
            s = chr(97 + i)
            break
    print(S + s)

else:
    if S == "abcdefghijklmnopqrstuvwxyz"[::-1]:
        print(-1)
    else:
        c = 2
        for i in range(N):
            if ord(S[-2 - i]) - ord(S[-1 - i]) >= 1:
                c += 1
            else:
                break
        s = sorted(list(S[26 - c:]))
        for i in s:
            if ord(i) > ord(S[-c]):
                key = i
                break

        print(S[:26 - c] + key)
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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:
    print(s[0:j-1]+l[l.index(s[j-1])+1])

Failing test case input:
azcdefghijklmnopqrstuvwbyx

Expected output:
azcdefghijklmnopqrstuvwx


Actual output:
azcdefghijklmnopqrstuvwc


Fixed submission (verdict: Accepted):
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)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
if len(S)<26:
    for i in range(26):
        ans = S + chr(97+i)
        if len(ans) == len(list(set(ans))):
            print(ans)
            break
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        for i in range(1,26):
            if S[25-i] < S[25]:
                print(S[0:25-i]+S[25])
                break

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:

Fixed submission (verdict: Accepted):
import sys
S = input()
if len(S)<26:
    for i in range(26):
        ans = S + chr(97+i)
        if len(ans) == len(list(set(ans))):
            print(ans)
            break
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        SS = S[0:-1]
        while True:
            SS = SS[0:-1]
            for i in range(26):
                ans = SS + chr(97+i)
                if len(ans) == len(list(set(ans))) and S < ans:
                    print(ans)
                    sys.exit()
Problem: p03393
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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:
    lused = []
    for i in range(1, len(s)):
        lused.append(s[-i])
        if s[-i-1] < min(lused):
            print(s[:-i-1]+min(lused))
            break
    else:
        print("-1")


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
-1


Fixed submission (verdict: Accepted):
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])

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()

if len(S) < 26:
  N = [chr(i) for i in range(97,123) if chr(i) not in S]
  print(S + N[0])
else:
  for i in range(25,0,-1):
    if S[i] > S[i - 1]:
      N = sorted(S[i:])
      print(S[:i - 1] + N[0])
      break
  else:
    print(-1)
      

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
S = input()

if len(S) < 26:
  N = [chr(i) for i in range(97,123) if chr(i) not in S]
  print(S + N[0])
else:
  for i in range(26):
    for j in range(i+1):
      if S[-(i + 1)] < S[-(j + 1)]:
          print(S[:-(i+1)]+S[-(j+1)])
          exit()
  else:
    print(-1)

Problem: p03393
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
s = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
c = Counter(s)
if len(s) < 26:
    for a in alp:
        if c[a] == 0:
            print(s + a)
            exit()
else:
    
    
    s = list(s)
    ita = -1
    for i in range(len(s) - 2, -1, -1):
        if s[i] < s[-1]:
            ita = i
            break
    if ita == -1:
        print(-1)
    else:
        s[ita], s[-1] = s[-1], s[ita]
        print(''.join(s[:ita + 1]))


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
-1


Fixed submission (verdict: Accepted):
s = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
if len(s) < 26:
    for a in alp:
        if a not in s:
            print(s + a)
            exit()
else:
    for i in range(25, 0, -1):
        if s[i - 1] < s[i]:
            c = 'ω'
            for j in range(i, 26):
                if s[i - 1] < s[j]:
                    c = min(c, s[j])
            print(s[:i-1] + c)
            exit()

    print(-1)
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
if S == alpha[::-1]:
    print(-1)
else:
    rest = sorted(list(set(alpha) - set(S)))
    if rest:
        print(S + rest[0])
    else:
        for i, s in enumerate(S):
            if s == 'z':
                break
        rest = sorted(S[i:])
        print(S[:i-1] + rest[0])

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
S = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
if S == alpha[::-1]:
    print(-1)
else:
    rest = sorted(list(set(alpha) - set(S)))
    if rest:
        print(S + rest[0])
    else:
        for i in range(len(S)-1, 0, -1):
            if S[i-1] < S[i]:
                break
        rest = sorted([s for s in S[i:] if s > S[i-1]])
        print(S[:i-1] + rest[0])

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import deque


alphs = set("abcdefghijklmnopqrstuvwxyz")
S = input()
remaining = alphs - set(S)
if remaining:
    print(S + min(remaining))
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    q = deque(S[-1])
    prev = S[-1]
    for i in range(1, 25):
        c = S[25 - i]
        if c < prev:
            print(S[: 25 - i] + q.popleft())
            break
        q.append(c)
        prev = c


Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xa


Fixed submission (verdict: Accepted):
S = input()
remaining = set("abcdefghijklmnopqrstuvwxyz") - set(S)
if remaining:
    print(S + min(remaining))
else:
    prev = S[25]
    for i in range(24, -1, -1):
        c = S[i]
        if c < prev:
            print(S[:i] + min(c for c in S[i + 1 :] if c > S[i]))
            break
        prev = c
    else:
        print(-1)

Problem: p03393
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s=str(input())

p='abcdefghijklmnopqrstuvwxyz'
p=list(p)
if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(s)!=26:
    for i in range(26):
        if p[i] not in s:
            print(s+p[i])
            break
elif len(s)==26:
    for i in range(24,-1,-1):
        if s[i]<s[i+1]:
            print(s[:i]+s[i+1])
            break

Failing test case input:
azcdefghijklmnopqrstuvwbyx

Expected output:
azcdefghijklmnopqrstuvwx


Actual output:
azcdefghijklmnopqrstuvwy


Fixed submission (verdict: Accepted):
s=str(input())

p='abcdefghijklmnopqrstuvwxyz'
p=list(p)
if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(s)!=26:
    for i in range(26):
        if p[i] not in s:
            print(s+p[i])
            break
elif len(s)==26:
    for i in range(24,-1,-1):
        if s[i]<s[i+1]:
            z=list(s[i+1:])
            z.sort()
            for j in range(len(z)):
                if s[i]<z[j]:
                    print(s[:i]+z[j])
                    break
            else:
                continue
            break
Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a=input().strip()
if len(a)<26:
  for i in range(97, 97+26):
    if chr(i) not in list(a):
      print(a+chr(i))
      break
else:
  for i in range(26):
    t0=a[25-i:]
    ts=list(t0)
    ts.sort(reverse=True)
    t1="".join(ts)
    if t0 != t1:
      print(a[:25-i]+t1[len(t1)-2])
      break
  else:
    print(-1)

Failing test case input:
xyzwvutsrqponmlkjihgfedcba

Expected output:
xz


Actual output:
xb


Fixed submission (verdict: Accepted):
a=input().strip()
if len(a)<26:
  for i in range(97, 97+26):
    if chr(i) not in list(a):
      print(a+chr(i))
      break
else:
  f=False
  for i in range(26):
    t0=a[25-i:]
    ts=list(t0)
    ts.sort(reverse=True)
    t1="".join(ts)
    
    if t0 != t1 :
      for j in range(len(ts)):
        if ts[len(ts)-1-j]==t0[0]:
          print(a[:25-i]+ts[len(ts)-1-j-1])
          f=True
          break
    if f == True:
      break
  else:
    print(-1)

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
l = list('abcdefghijklmnopqrstuvwxyz')
for s_ in s:
    l.remove(s_)
if l==[]:
    for i in range(len(s)-1):
        for j in range(i+1,len(s)):
            if s[i]>s[j]:
                key = s[i-1]
                z = sorted(s[i:])
                for z_ in z:
                    if z_>key:
                        print(s[:i-1]+z_)
                        exit()
    print(-1)
else:
    print(s+l[0])

Failing test case input:
azcdefghijklmnopqrstuvwbyx

Expected output:
azcdefghijklmnopqrstuvwx


Actual output:
b


Fixed submission (verdict: Accepted):
s = input()
l = list('abcdefghijklmnopqrstuvwxyz')
for s_ in s:
    l.remove(s_)
if l==[]:
    l.append(s[-1])
    for i in range(len(s)-2,-1,-1):
        if s[i]<max(l):
            for k in l:
                if k>s[i]:
                    print(s[:i]+k)
                    exit()
        l.append(s[i])
    print(-1)
else:
    print(s+l[0])

Problem: p03393
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      S=S[:24-i]+chr((ord(S[24-i])+1-97)%26+97)
      print(S)
      break
    if i==24:
      print(-1)
else:
  print(S+s[0])

Failing test case input:
abcdefghijklmnopqrytuvwzsx

Expected output:
abcdefghijklmnopqrytuvwzx


Actual output:
abcdefghijklmnopqrytuvwzt


Fixed submission (verdict: Accepted):
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      q=S[25-i:]
      q2=[]
      for j in q:
        if ord(j)<ord(S[24-i]):
          pass
        else:
          q2+=[ord(j)]
      q2.sort()
      
      S=S[:24-i]+chr(q2[0])
      print(S)
      break
    if i==24:
      print(-1)
    
else:
  print(S+s[0])