Problem:


Score : 300 points

Problem Statement

Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible diverse words in lexicographical order.

A word is called diverse if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, atcoder, zscoder and agc are diverse words while gotou and connect aren't diverse words.

Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist.

Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Constraints

1 \leq |S| \leq 26

S is a diverse word.

Input

Input is given from Standard Input in the following format:

S

Output

Print the next word that appears after S in the dictionary, or -1 if it doesn't exist.

Sample Input 1

atcoder

Sample Output 1

atcoderb

atcoderb is the lexicographically smallest diverse word that is lexicographically larger than atcoder. Note that atcoderb is lexicographically smaller than b.

Sample Input 2

abc

Sample Output 2

abcd

Sample Input 3

zyxwvutsrqponmlkjihgfedcba

Sample Output 3

-1

This is the lexicographically largest diverse word, so the answer is -1.

Sample Input 4

abcdefghijklmnopqrstuvwzyx

Sample Output 4

abcdefghijklmnopqrstuvx



Sample input:
atcoder


Sample output:
atcoderb

Submission status: Wrong Answer

Solution code:
w="qwertyuiopasdfghjklzxcvbnm"
l=sorted(list(w))
d={}
for i in l:
  d[i]=0
w1=list(input())
for i in w1:
  d[i]=1
for i in l:
  if d[i]==0:
    w1.append(i)
    print("".join(w1))
    exit()
index=-1
for i in range(len(w1)-1):
  b=True
  for j in range(i,len(w1)-1):
    if w1[j]>w1[j+1]:
      pass
    else:
      b=False
  if b:
    index=i
    break
if index==0:
  print(-1)
elif index==-1:
  ans=""
  for i in range(24):
    ans+=w1[i]
  ans+=w1[-1]
  ans+=w1[-2]
  print(ans)
else:
  ans=""
  d={}
  for i in l:
    d[i]=0
  for i in range(index-1):
    ans+=w1[i]
    d[w1[i]]=1
  for i in l:
    if d[i]==0 and i>w1[index-1]:
      ans+=i
      break
  print(ans)

Submission status: Wrong Answer

Solution code:
w="qwertyuiopasdfghjklzxcvbnm"
l=sorted(list(w))
d={}
for i in l:
  d[i]=0
w1=list(input())
for i in w1:
  d[i]=1
for i in l:
  if d[i]==0:
    w1.append(i)
    print("".join(w1))
    exit()
index=-1
for i in range(len(w1)-1):
  b=True
  for j in range(i,len(w1)-1):
    if w1[j]>w1[j+1]:
      pass
    else:
      b=False
  if b:
    index=i
    break
if index==0:
  print(-1)
elif index==-1:
  ans=""
  for i in range(24):
    ans+=w1[i]
  ans+=w1[-1]
  ans+=w1[-2]
  print(ans)
else:
  ans=""
  d={}
  for i in l:
    d[i]=0
  for i in range(index-1):
    ans+=w1[i]
    d[w1[i]]=1
  for i in l:
    if d[i]==0 and i!=w1[index-1]:
      ans+=i
      break
  print(ans)

Submission status: Wrong Answer

Solution code:
w="qwertyuiopasdfghjklzxcvbnm"
l=sorted(list(w))
d={}
for i in l:
  d[i]=0
w1=list(input())
for i in w1:
  d[i]=1
for i in l:
  if d[i]==0:
    w1.append(i)
    print("".join(w1))
    exit()
index=-1
for i in range(len(w1)-1):
  b=True
  for j in range(i,len(w1)-1):
    if w1[i]>w1[i+1]:
      pass
    else:
      b=False
      break
  if b:
    index=i
    break
if index==0:
  print(-1)
else:
  ans=""
  d={}
  for i in l:
    d[i]=0
  for i in range(index-1):
    ans+=w1[i]
    d[w1[i]]=1
  for i in l:
    if d[i]==0 and i!=w1[index-1]:
      ans+=i
      break
  print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
ans = '-1'

l = []
for i in range(97, 97+26):
    l.append(chr(i))

n = 1
for s in range(len(S)):
    head = l[0]
    if S[s] in l:
        i = l.index(S[s])
        l.pop(i)
        if l[0] == head:
            n += 1
        else:
            n = 1
    else:
        print(-1)
        exit()
    if len(l) == 1:
        n += 1
        break

if len(S) == 26:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        ans = -1
    else:
        ans = S[:-n] + l[0]
else:
    ans = S + l[0]

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

if len(s) < 26:
    for i in "abcdefghijklmnopqrstuvwxyz":
        if not i in s:
            ans = s + i
            break

else:
    tmp = ""
    ss = list(s)
    for i in range(len(ss)):
        if i == 0:
            tmp += ss.pop()
            continue

        if ss[-1] > tmp[-1]:
            tmp += ss.pop()
        else:
            ss.pop()
            ans = "".join(ss) + min(tmp)
            break
    else:
        ans = -1

print(ans)

Submission status: Wrong Answer

Solution code:
import string
S = input()
ans = ''
if len(S) != 26:
    for i in string.ascii_lowercase:
        if S.count(i) == 0:
            ans = S + i
            break
else:
    tmp = []
    tmp.append(S[-1])
    for i in range(len(S) - 2, -1, -1):
        if S[i] < tmp[0]:
            ans = S[0:i] + tmp[0]
            break
        else:
            tmp.append(S[i])
            tmp.sort()
if ans == '':
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
lets = 'abcdefghijklmnopqrstuvwxyz'

for let in lets:
  if let not in S:
    print(S+let)
    exit()
    
for j in range(len(S)-1, -1, -1):
  for i in range(j-1, -1, -1):
    for s in sorted(S[j:]):
      if S[i] < s:
        print(S[:i] + s)
        exit()      

print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
lets = 'abcdefghijklmnopqrstuvwxyz'

for let in lets:
  if let not in S:
    print(S+let)
    exit()
    
for j in range(len(S)-1, -1, -1):
  for i in range(j-1, -1, -1):
    if S[i] < S[j]:
      print(S[:i] + S[j])
      exit()
    
print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
lets = 'abcdefghijklmnopqrstuvwxyz'

for let in lets:
  if let not in S:
    print(S+let)
    exit()
    
for j in range(len(S)-1, -1, -1):
  for i in range(j-1, -1, -1):
    if S[i] < S[j]:
      print(S[:i] + S[j])
      exit()
    
print(-1)
print('a'<'b')

Submission status: Wrong Answer

Solution code:
S = input()
lets = 'abcdefghijklmnopqrstuvwxyz'

for let in lets:
  if let not in S:
    print(S+let)
    exit()

for i in range(len(S)-2, -1, -1):
  if S[i] < S[-1]:
    print(S[:i] + S[-1])
    exit()

print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
lets = 'abcdefghijklmnopqrstuvwxyz'

for let in lets:
  if let not in S:
    print(S+let)
    exit()

for i in range(len(S)-2, -1, -1):
  if S[i] < S[-1]:
    print(S[:i+1] + S[-1])
    exit()

print(-1)

Submission status: Wrong Answer

Solution code:
S=str(input())
A={}
c="abcdefghijklmnopqrstuvwxtz"

for i in range(len(S)):
    if S[i] not in A:
        A[S[i]]=1
    else:
        A[S[i]]+=1

if max(A.values())>1:
    print(-1)
else:
    if len(S)<26:
        for i in range(26):
            if c[i] not in A:
                print(S+c[i])
                break
    else:
        d_renzoku=0
        di=0
        for i in range(len(S)-1):
            if S[i]>S[i+1]:
                if d_renzoku==0:
                    di=i
                d_renzoku+=1
            else:
                d_renzoku=0
        if i==0:
            print(-1)
        else:
            print(S[0:di-1]+min(S[di:27]))

Submission status: Wrong Answer

Solution code:
S = input()
lets = 'abcdefghijklmnopqrstuvwxyz'
for let in lets:
  if let not in S:
    print(S+let)
    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
S = [ord(i)-97 for i in str(input())]
appeared = [False for i in range(26)]

if len(S)<26:
    alp="".join([chr(i) for i in range(97,97+26)])
    s = "".join([chr(i+97) for i in S])
    for i in alp:
        if i not in s:
            print(s+i)
            exit()
    """
    for s in S:
    appeared[s] = True
    for i in range(len(appeared)):
        if appeared[i] == False:
            break
    S.append(i)
    print("".join([chr(i+97) for i in S]))
    exit()
    """
    
else:
    prev = -1
    for i in [25-k for k in range(26)]:
        if S[i] < prev:
            break
        prev = S[i]
    if i == 0:
        print("-1")
        exit()
    else:
        for i in range(24,-1,-1):
            for j in range(25,i,-1):
                if S[i]<S[j]:
                    S = S[:i]+[S[j]]
                    print("".join([chr(i+97) for i in S]))
                    exit()
        """
        string = S[i+1:]
        for j in range(len(string)):
            if string[j] < S[i]:
                string[j] = 100
        S = S[:i]+[min(string)]
        """

Submission status: Wrong Answer

Solution code:
S = [ord(i)-97 for i in str(input())]
appeared = [False for i in range(26)]
for s in S:
    appeared[s] = True
worst = False
if len(S)<26:
    for i in range(len(appeared)):
        if appeared[i] == False:
            break
    S.append(i)
    print("".join([chr(i+97) for i in S]))
    exit()
    
else:
    prev = -1
    for i in [25-k for k in range(26)]:
        if S[i] < prev:
            break
        prev = S[i]
    if i == 0:
        print("-1")
        exit()
    else:
        for i in range(24,-1,-1):
            for j in range(25,i,-1):
                if S[i]<S[j]:
                    S = S[:i]+[S[j]]
                    print("".join([chr(i+97) for i in S]))
                    exit()

Submission status: Wrong Answer

Solution code:
S = [ord(i)-97 for i in str(input())]
appeared = [False for i in range(26)]
for s in S:
    appeared[s] = True
worst = False
if len(S)<26:
    for i in range(len(appeared)):
        if appeared[i] == False:
            break
    S.append(i)
    
else:
    prev = -1
    for i in [25-k for k in range(26)]:
        if S[i] < prev:
            break
        prev = S[i]
    if i == 0:
        worst=True
    else:
        string = S[i+1:]
        for j in range(len(string)):
            if string[j] < S[i]:
                string[j] = 100
        S = S[:i]+[min(string)]
    



if worst:
    print("-1")
else:
    print("".join([chr(i+97) for i in S]))

Submission status: Wrong Answer

Solution code:
S = [ord(i)-97 for i in str(input())]
appeared = [False for i in range(26)]
for s in S:
    appeared[s] = True
worst = False
if len(S)<26:
    for i in range(len(appeared)):
        if appeared[i] == False:
            break
    S.append(i)
    
else:
    prev = -1
    for i in [25-k for k in range(26)]:
        if S[i] < prev:
            break
        prev = S[i]
    if i == 0:
        worst=True
    else:
        string = S[i+1:]
        for j in range(len(string)):
            if string[j] < S[i]:
                string[j] = 100
        S = S[:i]+[min(string)]

Submission status: Wrong Answer

Solution code:
M=["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"]
O=input()
S=list(O+"")

if(len(O)!=26):
    for i in range(26):
        if(M[i] not in S):
            print(O,M[i],sep="")
            exit()

for i in range(1,26):
    for j in range(26):
        if(M[j]==S[25-i]):
            t=j
            for k in range(t,25):
                print(S[25-i],M[t+1],S[26-i:26])
                if(M[k+1] in S[26-i:26]):
                    print("".join(S[0:25-i]),M[k+1],sep="")
                    exit()
            break
        
print(-1)

Submission status: Wrong Answer

Solution code:
M=["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"]
O=input()
S=list(O+"")

if(len(O)!=26):
    for i in range(26):
        if(M[i] not in S):
            print(O,M[i],sep="")
            exit()

for i in range(1,26):
    for j in range(26):
        if(M[j]==S[25-i]):
            t=j
            if(t!=25):
                #print(S[25-i],M[t+1],S[26-i:26])
                if(M[t+1] in S[26-i:26]):
                    print("".join(S[0:25-i]),M[t+1],sep="")
                    exit()
print(-1)

Submission status: Wrong Answer

Solution code:
import bisect

M=["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"]
O=input()
S=list(O+"")



if(len(O)!=26):
    for i in range(26):
        if(M[i] not in S):
            print(O,M[i],sep="")
            exit()

for i in range(1,26):
    t=bisect.bisect_left(M,S[25-i])
    if(t!=25):
        #print(S[25-i],M[t+1],S[26-i:26])
        if(M[t+1] in S[26-i:26]):
            print("".join(S[0:25-i]),M[t+1],sep="")
            exit()
print(-1)


"""
ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            for j in range(26-1,i,-1):
                if(S[j-1]<S[j]):
                    for k in range(26):
                        if(M[k] not in S[0:j-1]):
                            if(S[j-1]!=M[k]):
                                print("".join(S[0:j-1]),M[k],sep="")
                                exit()
    
            for j in range(26):
                if(M[j] not in S[0:i-1]):
                    if(S[i-1]!=M[j]):
                        print("".join(S[0:i-1]),M[j],sep="")
                        exit()    
    
    for j in range(26-1,-1,-1):
        if(S[j-1]<S[j]):
            for k in range(26-1,-1,-1):
                if(M[k] not in S[0:j-1]):
                    if(S[j-1]!=M[k]):
                        print("".join(S[0:j-1]),M[k],sep="")
                        exit()

    
    
    print(-1)


else:
    ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            for j in range(26):
                if(M[j] not in S[0:i-1]):
                    if(S[i-1]!=M[j]):
                        print("".join(S[0:i-1]),M[j],sep="")
                        exit()
    print(-1)
"""

Submission status: Wrong Answer

Solution code:
import bisect

M=["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"]
O=input()
S=list(O+"                         ")

dic={}

for I in list(O):
    if(dic.get(I,None)==None):
        dic[I]=1
    else:
        print(-1)
        exit()

if(len(O)!=26):
    for i in range(26):
        if(M[i] not in S):
            print(O,M[i],sep="")
            exit()
else:
    ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            for j in range(26-1,i,-1):
                if(S[j-1]<S[j]):
                    for k in range(26):
                        if(M[k] not in S[0:j-1]):
                            if(S[j-1]!=M[k]):
                                print("".join(S[0:j-1]),M[k],sep="")
                                exit()
    
            for j in range(26):
                if(M[j] not in S[0:i-1]):
                    if(S[i-1]!=M[j]):
                        print("".join(S[0:i-1]),M[j],sep="")
                        exit()    
    
    for j in range(26-1,-1,-1):
        if(S[j-1]<S[j]):
            for k in range(26-1,-1,-1):
                if(M[k] not in S[0:j-1]):
                    if(S[j-1]!=M[k]):
                        print("".join(S[0:j-1]),M[k],sep="")
                        exit()

    
    
    print(-1)


"""
else:
    ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            for j in range(26):
                if(M[j] not in S[0:i-1]):
                    if(S[i-1]!=M[j]):
                        print("".join(S[0:i-1]),M[j],sep="")
                        exit()
    print(-1)
"""

Submission status: Wrong Answer

Solution code:
import bisect

M=["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"]
O=input()
S=list(O+"                         ")

dic={}

for I in list(O):
    if(dic.get(I,None)==None):
        dic[I]=1
    else:
        print(-1)
        exit()

if(len(O)!=26):
    for i in range(26):
        if(M[i] not in S):
            print(O,M[i],sep="")
            exit()
else:
    ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            for j in range(26-1,i,-1):
                if(S[j-1]<S[j]):
                    for k in range(26):
                        if(M[k] not in S[0:j-1]):
                            if(S[j-1]!=M[k]):
                                print("".join(S[0:j-1]),M[k],sep="")
                                exit()
    
            for j in range(26):
                if(M[j] not in S[0:i-1]):
                    if(S[i-1]!=M[j]):
                        print("".join(S[0:i-1]),M[j],sep="")
                        exit()    
    print(-1)


"""
else:
    ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            for j in range(26):
                if(M[j] not in S[0:i-1]):
                    if(S[i-1]!=M[j]):
                        print("".join(S[0:i-1]),M[j],sep="")
                        exit()
    print(-1)
"""

Submission status: Wrong Answer

Solution code:
import bisect

M=["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"]
O=input()
S=list(O+"                         ")

dic={}

for I in list(O):
    if(dic.get(I,None)==None):
        dic[I]=1
        print(-1)
        exit()
    else:
        print(-1)
        exit()
        
if(len(O)!=26):
    for i in range(26):
        if(M[i] not in S):
            print(O,M[i],sep="")
            exit()
else:
    ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            for j in range(26-1,i,-1):
                if(S[j-1]<S[j]):
                    for k in range(26):
                        if(M[k] not in S[0:j-1]):
                            if(S[j-1]!=M[k]):
                                print("".join(S[0:j-1]),M[k],sep="")
                                exit()
    
            for j in range(26):
                if(M[j] not in S[0:i-1]):
                    if(S[i-1]!=M[j]):
                        print("".join(S[0:i-1]),M[j],sep="")
                        exit()    
    print(-1)


"""
else:
    ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            for j in range(26):
                if(M[j] not in S[0:i-1]):
                    if(S[i-1]!=M[j]):
                        print("".join(S[0:i-1]),M[j],sep="")
                        exit()
    print(-1)
"""

Submission status: Wrong Answer

Solution code:
import bisect

M=["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"]
O=input()
S=list(O+"                         ")


if(len(O)!=26):
    for i in range(26):
        if(M[i] not in S):
            print(O,M[i],sep="")
            exit()
else:
    ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            for j in range(26-1,i,-1):
                if(S[j-1]<S[j]):
                    for k in range(26):
                        if(M[k] not in S[0:j-1]):
                            if(S[j-1]!=M[k]):
                                print("".join(S[0:j-1]),M[k],sep="")
                                exit()
    
            for j in range(26):
                if(M[j] not in S[0:i-1]):
                    if(S[i-1]!=M[j]):
                        print("".join(S[0:i-1]),M[j],sep="")
                        exit()    
    print(-1)

Submission status: Wrong Answer

Solution code:
import bisect

M=["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"]
O=input()
S=list(O+"                         ")


if(len(O)!=26):
    for i in range(26):
        if(M[i] not in S):
            print(O,M[i],sep="")
            exit()
else:
    ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            for j in range(26):
                if(M[j] not in S[0:i-1]):
                    if(S[i-1]!=M[j]):
                        print("".join(S[0:i-1]),M[j],sep="")
                        exit()
    print(-1)

Submission status: Wrong Answer

Solution code:
import bisect

M=["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"]
O=input()
S=list(O+"                         ")


if(len(O)!=26):
    for i in range(26):
        if(M[i] not in S):
            print(O,M[i],sep="")
            exit()
else:
    ind=bisect.bisect_left(M,S[0])
    for i in range(26-ind):
        if(S[i]!=M[ind+i]):
            print("".join(S[0:i-1]),M[ind+i],sep="")
            exit()
    print(-1)

Submission status: Wrong Answer

Solution code:
# AGC022
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
N = len(S)        
al_check = [False] * 26
Sal_check = [False] * 26
al=[chr(ord('a') + i) for i in range(26)]

for i in range(N):
    for k in range(26):
        if S[i] == al[k]:
            al_check[k] = True
if N != 26:
    for i in range(26):
        if al_check[i] == False:
            locate = i
            break
    ans = S + al[i]
else:
    locate = S.index('z')
    S = S[0:locate-1]
    for i in range(len(S)):
        for k in range(26):
            if S[i] == al[k]:
                Sal_check[i] = True
    for i in range(26):
        if Sal_check[i] == False:
            locate = i
            break
    ans = S + al[locate+1]
print(ans)

Submission status: Wrong Answer

Solution 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])
      exit(0)
print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
alp = [i for i in "abcdefghijklmnopqrstuvwxyz"]

if len(s) != 26:
    for a in alp:
        if not a in s:
            ans = s + a
            break
elif s == "zyxwvutsrqponmlkjihgfedcba":
    ans = -1
else:
    s_inv = s[::-1]
    x = []
    for i in range(26):
        if i == 0:
            x.append(s_inv[i])
            continue
        if s_inv[i] > max(x):
            x.append(s_inv[i])
        else:
            x.sort()
            for j in x:
                if j > s_inv[i]:
                    ans = s[:-(i+1)] + j
            break
print(ans)

Submission status: Wrong Answer

Solution code:
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, -1, -1):
        if s[i] < max(list(s[i:])):
            ans = s[:i] + min(list(s[i+1:]))
            break

print(ans)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
ans = ''

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

r = ''.join(sorted(a, reverse=True))
if len(s) == 26:
    for i in range(len(s), -1, -1):
        if i == len(s):
            print('-1')
            exit()
        if r[:i] == s[-i:]:
            ele = i
            break
    ans = s[:-(ele+1)] + sorted(r[:ele])[0]

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
ans = ''

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

r = ''.join(sorted(a, reverse=True))
if len(s) == 26:
    for i in range(len(s), -1, -1):
        if i == 0:
            print('-1')
            exit()
        if r[:i] == s[-i:]:
            ele = i
            break
    ans = s[:-(ele+1)] + sorted(r[:ele])[0]

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()

    if len(s) < 26:
        for i in range(ord("a"), ord("z") + 1):
            c = chr(i)
            if c not in s:
                ans = s + c
                break

    else:
        ans = -1
        for i in range(1, 26)[::-1]:
            if s[i-1] < s[i]:
                ans = s[:i-1] + chr(ord(s[i-1]) + 1)
                break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s = input()

    if len(s) < 26:
        for i in range(ord("a"), ord("z") + 1):
            c = chr(i)
            if c not in s:
                ans = s + c
                break

    else:
        ans = -1
        for i in range(1, 26)[::-1]:
            if s[i-1] < s[i]:
                ans = s[:i-1] + s[-1]
                break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
alphabet=[chr(i+97) for i in range(0,26)]
S=input()

#S=    "zyawvutsrqponmlkjihgfedcbx"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:

    for i in S:
        alphabet.remove(i)
    if alphabet:
        print(S+alphabet[0])
    else:
        S=list(S)
        ordlist=[ord(i) for i in list(S)]
        for m in range(len(ordlist)-1,0,-1):
            if ordlist[m-1]>ordlist[m]:
                flag=0
                strings=[]
                for i in range(ordlist[m-2]+1,123):
                    #print(chr(i),S[:m-2])
                    #print(len(ordlist)-(m))

                    for t in range(0,m):

                        _S=S
                        #print(S)
                        if chr(i) not in _S[:m-t] and i>ord(_S[m-t]):
                            flag=1
                            _S[m-t]=chr(i)
                            _S=_S[:m+1-t]
                            string=""
                            for s in _S:
                                string+=s
                            #print(string)
                            strings.append(string)
                if flag:
                    #print(strings)
                    strings.sort()
                    print(strings[0])
                    exit()

Submission status: Wrong Answer

Solution code:
alphabet=[chr(i+97) for i in range(0,26)]
S=input()

#S=    "zyawvutsrqponmlkjihgfedcbx"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:

    for i in S:
        alphabet.remove(i)
    if alphabet:
        print(S+alphabet[0])
    else:
        S=list(S)
        ordlist=[ord(i) for i in list(S)]
        for m in range(len(ordlist)-1,0,-1):
            if ordlist[m-1]>ordlist[m]:
                for i in range(ordlist[m-2]+1,123):
                    #print(chr(i),S[:m-2])
                    #print(len(ordlist)-(m))
                    flag=0
                    strings=[]
                    for t in range(0,m):

                        _S=S
                        #print(S)
                        if chr(i) not in _S[:m-t] and i>ord(_S[m-t]):
                            flag=1
                            _S[m-t]=chr(i)
                            _S=_S[:m+1-t]
                            string=""
                            for s in _S:
                                string+=s
                            #print(string)
                            strings.append(string)
                    if flag:
                        #print(strings)
                        strings.sort()
                        print(strings[0])
                        exit()

Submission status: Wrong Answer

Solution code:
alphabet=[chr(i+97) for i in range(0,26)]
S=input()
#S=    "zyawvutsrqponmlkjihgfedcbx"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:

    for i in S:
        alphabet.remove(i)
    if alphabet:
        print(S+alphabet[0])
    else:
        S=list(S)
        ordlist=[ord(i) for i in list(S)]
        for m in range(len(ordlist)-1,0,-1):
            if ordlist[m-1]>ordlist[m]:
                for i in range(ordlist[m-2]+1,123):
                    #print(chr(i),S[:m-2])
                    for t in range(0,len(ordlist)-(m)):
                        if chr(i) not in S[:m-t] and i>ord(S[m-t]):
                            S[m-t]=chr(i)
                            S=S[:m+1-t]
                            string=""
                            for s in S:
                                string+=s
                            print(string)
                            exit()

Submission status: Wrong Answer

Solution code:
alphabet=[chr(i+97) for i in range(0,26)]
S=input()
#S=    "zyawvutsrqponmlkjihgfedcbx"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:

    for i in S:
        alphabet.remove(i)
    if alphabet:
        print(S+alphabet[0])
    else:
        S=list(S)
        ordlist=[ord(i) for i in list(S)]
        for m in range(len(ordlist)-1,0,-1):
            if ordlist[m-1]>ordlist[m]:
                for i in range(ordlist[m-2]+1,123):
                    #print(chr(i),S[:m-2])
                    if chr(i) not in S[:m] and i>ord(S[m]):
                        S[m]=chr(i)
                        S=S[:m+1]
                        string=""
                        for s in S:
                            string+=s
                        print(string)
                        exit()
                    if chr(i) not in S[:m-1] and i>ord(S[m-1]):
                        S[m-1]=chr(i)
                        S=S[:m]
                        string=""
                        for s in S:
                            string+=s
                        print(string)
                        exit()
                    if chr(i) not in S[:m-2] and i>ord(S[m-2]):
                        S[m-2]=chr(i)
                        S=S[:m-1]
                        string=""
                        for s in S:
                            string+=s
                        print(string)
                        exit()
                    if chr(i) not in S[:m-3] and i>ord(S[m-3]):
                        S[m-3]=chr(i)
                        S=S[:m-2]
                        string=""
                        for s in S:
                            string+=s
                        print(string)
                        exit()