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

Submission status: Wrong Answer

Solution code:
alphabet=[chr(i+97) for i in range(0,26)]
S=input()
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-2]:
                        S[m-2]=chr(i)
                        S=S[:m-1]
                        string=""
                        for s in S:
                            string+=s
                        print(string)
                        exit()

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
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    ans = '-1'
else:
    l = list(a)
    l.sort(reverse=True)
    l = ''.join(l)
    ele = 0
    for i in range(len(s)):
        if l[:i] == s[-i:]:
            ele = i
    if ele < 25:
        t = s[:-(ele+1)]
        for w in a:
            if not w in t and t + w != s[:-ele]:
                ans = t + w
                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
else:
    l = list(a)
    l.sort(reverse=True)
    l = ''.join(l)
    ele = 0
    for i in range(len(s)):
        if l[:i] == s[-i:]:
            ele = i
    if ele < 25:
        t = s[:-(ele+1)]
        for w in a:
            if not w in t and t + w != s[:-ele]:
                ans = t + w
                break
    else:
        ans = '-1'
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
alpha=list("abcdefghijklmnopqrstuvwxyz")
alpha_dict={a:i for i,a in enumerate(alpha)}
alpha = set(alpha)

string = input()

can_use_str = alpha - set(list(string))

if string == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)

elif len(can_use_str)==0:
    k = 0
    for i in reversed(range(25)):
        if string[i] < string[i + 1]:
            k = i
            break
    last = sorted(string[k:])
    for i in last:
        if string[k] < i:
            print(string[:k] + i)

else:
    string+=sorted(list(can_use_str))[0]
    print(string)

Submission status: Wrong Answer

Solution code:
import copy
alpha=list("abcdefghijklmnopqrstuvwxyz")
alpha_dict={a:i for i,a in enumerate(alpha)}
alpha = set(alpha)

string = input()

can_use_str = alpha - set(list(string))

if string == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)

elif len(can_use_str)==0:
    string_len=len(string)-1
    can=[string[-1]]
    nokori = copy.deepcopy(string[:-1])
    for i in string[::-1][1:]:
        temp = copy.deepcopy(can)
        temp.append(i)
        nokori=nokori[:-1]
        
        if min(temp) == i:
            break
        else:
            can.append(i)
        
    can = sorted(can)[0]
    print(nokori+can)

else:
    string+=sorted(list(can_use_str))[0]
    print(string)

Submission status: Wrong Answer

Solution code:
alpha=list("abcdefghijklmnopqrstuvwxyz")
alpha_dict={a:i for i,a in enumerate(alpha)}
alpha = set(alpha)

string = input()

can_use_str = alpha - set(list(string))

if string == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)

elif len(can_use_str)==0:
    string_len=len(string)-1
    can=""
    for i in range(1,string_len):
        if string[string_len-i] > string[string_len-i-1]:
            break
    can = sorted(list(string[string_len - i:]))[0]
    print(string[:string_len - i-1]+can)

else:
    string+=sorted(list(can_use_str))[0]
    print(string)

Submission status: Wrong Answer

Solution code:
alpha=list("abcdefghijklmnopqrstuvwxyz")
alpha_dict={a:i for i,a in enumerate(alpha)}
alpha = set(alpha)

string = input()

can_use_str = alpha - set(list(string))

if string == "zyxwvutsrqponmlkjihgfedcba":
    print(1)

elif len(can_use_str)==0:
    string_len=len(string)-1
    for i in range(1,string_len):
        if string[string_len-i] < string[string_len-i-1]:
            break
    can = sorted(list(string[string_len - i-1:]))[0]
    print(string[:string_len - i-2]+can)

else:
#     string+=sorted(list(can_use_str))[0]
    print(string)

Submission status: Wrong Answer

Solution code:
alpha=list("abcdefghijklmnopqrstuvwxyz")
alpha_dict={a:i for i,a in enumerate(alpha)}
alpha = set(alpha)

string = input()

can_use_str = alpha - set(list(string))

if string == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)

elif len(can_use_str)==0:
    string_len=len(string)-1
    for i in range(1,string_len):
        if string[string_len-i] < string[string_len-i-1]:
            break
    can = sorted(list(string[string_len - i-1:]))[0]
    print(string[:string_len - i-2]+can)

else:
    string+=sorted(list(can_use_str))[0]
    print(string)

Submission status: Wrong Answer

Solution code:
alpha=list("abcdefghijklmnopqrstuvwxyz")
alpha_dict={a:i for i,a in enumerate(alpha)}
alpha = set(alpha)

string = input()

can_use_str = alpha - set(list(string))

if string == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)

elif len(can_use_str)==0:
    string_len=len(string)-1
    for i in range(1,string_len+1):
        if string[string_len-i] < string[string_len-i-1]:
            break
    can = sorted(list(string[string_len - i-1:]))[0]
    print(string[:string_len - i-2]+can)

else:
    string+=sorted(list(can_use_str))[0]
    print(string)

Submission status: Wrong Answer

Solution code:
alpha=list("abcdefghijklmnopqrstuvwxyz")
alpha_dict={a:i for i,a in enumerate(alpha)}
alpha = set(alpha)

string = input()

can_use_str = alpha - set(list(string))

if string == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)

elif len(can_use_str)==0:
    string_len=len(string)-1
    for i in range(1,string_len+1):
        if string[string_len-i] < string[string_len-i-1]:
            break
    can = sorted(list(string[string_len - i:]))[0]
    print(string[:string_len - i-2]+can)

else:
    string+=sorted(list(can_use_str))[0]
    print(string)

Submission status: Wrong Answer

Solution code:
s=str(input())
#print(len(s))
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

Submission status: Wrong Answer

Solution code:
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[25])
            break

Submission status: Wrong Answer

Solution code:
s=str(input())
p='abcdefghijklmnopqrstuvxyz'
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(26):
        if s[i]!=p[i]:
            print(s[:i]+p[i])
            break

Submission status: Wrong Answer

Solution code:
S = input()
character = list('abcdefghijklmnopqrstuvwxyz')

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(S) < 26:
    for i in character:
        if i not in S:
            print(S + i)
            exit()
else:
    k = 0
    for i in range(25):
        if S[i] > S[i + 1]:
            k = i
            break
    last = sorted(list(S[k:]))
    if S[k] == 'z':
        for i in last[:-1]:
            if S[k + 1] < i:
                print(S[:k + 1] + i)
                exit()
        else:
            for i in last:
                if S[k - 1] < i:
                    print(S[:k - 1] + i)
                    exit()
    else:
        for i in last:
            if S[k] < i:
                print(S[:k] + i)
                exit()
        else:
            last = last[-1]
            while S[k] < last[-1]:
                last = max(last, S[k])
                k -= 1
            print(S[:k] + last[-1])

Submission status: Wrong Answer

Solution code:
S = input()
character = list('abcdefghijklmnopqrstuvwxyz')

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(S) < 26:
    for i in character:
        if i not in S:
            print(S + i)
            exit()
else:
    k = 0
    for i in range(25):
        if S[i] > S[i + 1]:
            k = i
            break
    last = sorted(list(S[k:]))
    if S[k] == 'z':
        for i in last:
            if S[k + 1] < i:
                print(S[:k + 1] + i)
                exit()
        else:
            for i in last:
                if S[k - 1] < i:
                    print(S[:k + 1] + i)
                    exit()
    else:
        for i in last:
            if S[k] < i:
                print(S[:k] + i)
                exit()
        else:
            last = last[-1]
            while S[k] < last[-1]:
                last = max(last, S[k])
                k -= 1
            print(S[:k] + last[-1])

Submission status: Wrong Answer

Solution code:
S = input()
character = list('abcdefghijklmnopqrstuvwxyz')

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(S) < 26:
    last = 'a'
    for i in character:
        if i not in S:
            last = i
            break
    print(S + last)
else:
    k = 0
    for i in range(25):
        if S[i] > S[i + 1]:
            k = i
            break
    last = sorted(list(S[k:]))
    if S[k] == 'z':
        for i in last:
            if S[k - 1] < i:
                print(S[:k - 1] + i)
                exit()
    else:
        for i in last:
            if S[k] < i:
                print(S[:k] + i)
                exit()
        else:
            while S[k] < last[-1]:
                k -= 1
            print(S[:k] + last[-1])

Submission status: Wrong Answer

Solution code:
S = input()
character = list('abcdefghijklmnopqrstuvwxyz')

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(S) < 26:
    last = 'a'
    for i in character:
        if i not in S:
            last = i
            break
    print(S + last)
else:
    k = 0
    for i in range(25):
        if S[i] > S[i + 1]:
            k = i
            break
    print(S[:k + 1] + sorted(list(S[k + 1:]))[0])

Submission status: Wrong Answer

Solution code:
S = input()
character = list('abcdefghijklmnopqrstuvwxyz')

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(S) < 26:
    last = 'a'
    for i in character:
        if i not in S:
            last = i
            break
    print(S + last)
else:
    k = 0
    for i in range(25):
        if S[i] > S[i + 1]:
            k = i
            break
    print(S[:k] + sorted(list(S[k:]))[0])

Submission status: Wrong Answer

Solution code:
s=list(input())
if len(s)==26:
    if s[0]=='z':
        for i in range(1,26):
            if i==25:
                print(-1)
                exit()
            if s[-i]==chr(i+96):
                continue

            s=s[:-i-1]+[s[-i]]
            print(''.join(s))
            exit()

    
            
    for i in range(25,-1,-1):
        if s[i]!='z':
            continue
        s_mae=s[:i]
        s_ushiro=s[i+1:]
        mini=123
        for j in range(97,123):
            if chr(j) in s_mae:
                continue
            elif chr(j) in s_ushiro:
                if j>ord(s[i-1]):
                    mini=min(mini,j)
        s=s_mae[:-1]+[chr(mini)]
        break


else:
    s_set=set(s)
    for i in range(97,123):
        if chr(i) in s_set:
            continue
        else:
            s.append(chr(i))
            break
if s[-1]=='{':
    s=s[:-1]+['z']
print(''.join(s))

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
S = input()
if S == ''.join(sorted(ascii_lowercase,reverse=True)):
    print(-1)
    exit()

case = {s:False for s in ascii_lowercase}
for s in S:
    case[s] = True

for k,v in case.items():
    if v is False:
        print(S+k)
        exit()

i = 0
for s,t in zip(S,ascii_lowercase):
    if s != t:
        print(S[:i-1]+t)
        exit()
    i+=1

Submission status: Wrong Answer

Solution code:
s = input()

Alphabet = "zyxwvutsrqponmlkjihgfedcba"

Al_list = list(Alphabet)

if set(Al_list) - set(list(s)):
  s = s + sorted(list((set(Al_list) - set(list(s)))))[0]
  
elif s == Alphabet:
  s = -1
else:
  for i in range(len(s) -2):
    if s[-1] > s[-(i+1)]:
      s = s[:-(1+i)] + s[-1]
      break
print(s)

Submission status: Wrong Answer

Solution code:
s = input()

Alphabet = "zyxwvutsrqponmlkjihgfedcba"

Al_list = list(Alphabet)

if set(Al_list) - set(list(s)):
  s = s + sorted(list((set(Al_list) - set(list(s)))))[0]
  
elif s == Alphabet:
  s = -1
else:
  for i in range(len(s) -2):
    if s[-1] > s[-(i+1)]:
      s = s[:-(2+i)] + s[-1]
      break
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
t=sorted(s)
ans=""
alp=[chr(i) for i in range(97,97+26)]
ex="".join(alp[::-1])
if len(s)<26:
    for i in alp:
        if i not in s:
            ans +=i
    print(s+ans[0])
else:
    if s==ex:
        print(-1)
        exit()
    else:
        add=alp.index(s[-1])
        point=alp[add:]
        t=""
        for i in range(len(point)):
            if s[-(i+1)]==point[i]:
                t +=point[i]
            else:break
        print(s[:-len(t)-1]+sorted(t)[0])

Submission status: Wrong Answer

Solution code:
s=input()
t=sorted(s)
ans=""
ex="".join([chr(i) for i in range(97+26-1,97-1,-1)])
if len(s)<26:
    for i in [chr(i) for i in range(97,97+26)]:
        if i not in s:
            ans +=i
    print(s+ans[0])
else:
    if s==ex:
        print(-1)
        exit()
    else:
        add=0
        for i in range(len(s)):
            if s[i]!=t[i]:
                add=i
                break
        print(s[:add-1]+sorted(s[add:])[0])

Submission status: Wrong Answer

Solution code:

import sys

S = input()
alp = "abcdefghijklmnopqrstuvwxyz"
alpnum = {}

for i in range(26):
    alpnum[alp[i]] = i

dic = {}

for i in S:

    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

if len(dic) < 26:

    for i in range(26):

        if alp[i] not in dic:
            print (S+alp[i])
            break

else:

    now = alpnum[S[-1]]
    for i in range(26):

        if now > alpnum[S[-1]]:
            print ( S[:-1] + alp[now] )
            sys.exit()
        else:
            S = S[:-1]

    
    print (-1)

Submission status: Wrong Answer

Solution code:

import sys

S = input()
alp = "abcdefghijklmnopqrstuvwxyz"
alpnum = {}

for i in range(26):
    alpnum[alp[i]] = i

dic = {}

for i in S:

    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

if len(dic) < 26:

    for i in range(26):

        if alp[i] not in dic:
            print (S+alp[i])
            break

else:

    now = float("inf")
    for i in range(26):

        if now != float("inf") and now > alpnum[S[-1]]:
            print ( S[:-1] + alp[now] )
            sys.exit()
        else:
            now = min( now , alpnum[S[-1]])
            S = S[:-1]

    
    print (-1)

Submission status: Wrong Answer

Solution code:

import sys

S = input()
alp = "abcdefghijklmnopqrstuvwxyz"
alpnum = {}

for i in range(26):
    alpnum[alp[i]] = i

dic = {}

for i in S:

    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

if len(dic) < 26:

    for i in range(26):

        if alp[i] not in dic:
            print (S+alp[i])
            break

else:

    now = -1
    lis = []
    for i in range(26):

        if now > alpnum[S[-1]]:
            lis.sort()
            print ( S[:-1] + lis[0] )
            sys.exit()
        else:
            lis.append(S[-1])
            now = alpnum[S[-1]]
            S = S[:-1]

    
    print (-1)

Submission status: Wrong Answer

Solution code:
import sys
letters = list('abcdefghijklmnopqrstuvwxyz')
letters.sort()

S = input()
list_S = list(S)

i = len(S) - 1
tmp = ''
while True:
    for l in letters:
        if l not in list_S and l > tmp:
            print(''.join(list_S) + l)
            sys.exit()
    i -= 1
    if i == -1:
        print(-1)
        break
        sys.exit()
    tmp = list_S.pop(-1)

Submission status: Wrong Answer

Solution code:
import sys
letters = list('abcdefghijklmnopqrstuvwzyx')
letters.sort()

S = input()
list_S = list(S)

i = len(S) - 1
tmp = ''
while True:
    for l in letters:
        if l not in list_S and l > tmp:
            print(''.join(list_S) + l)
            sys.exit()
    i -= 1
    if i == -1:
        print(-1)
        break
    tmp = list_S.pop(-1)

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			if d[0]==s[-i-1]:
				k=d[1]
			else:
				k=d[0]
			print(s[:-i-1]+k)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			k=d[1]
			print(s[:-i-1]+k)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)==26:
	for i in range(25):
		if s[-i-1]>s[-i-2]:
			print(s[:26-i-1]+s[-i-2]+s[-i-1]+s[-i:])
			exit()
	print(-1)
	exit()
alph=set()
for i in range(len(s)):
	alph.add(s[i])
alph=list(alph)
alph.sort()
for i in range(len(alph)-1):
	if ord(alph[i+1])-ord(alph[i])>=2:
		k=ord(alph[i])+1
		k=chr(k)
		print(s+k)
		exit()
print(s+chr(ord(s[-1])+1))

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)==26:
	for i in range(25):
		if s[-i-1]>s[-i-2]:
			print(s[:26-i-1]+s[-i-2]+s[-i-1]+s[-i:])
			exit()
	print(-1)
	exit()
alph=set()
for i in range(len(s)):
	alph.add(s[i])
alph=list(alph)
alph.sort()
for i in range(len(alph)-1):
	if ord(alph[i+1])-ord(alph[i])>=2:
		k=ord(alph[i])+1
		k=chr(k)
		print(s+k)
		break

Submission status: Wrong Answer

Solution code:
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]:
            print(S[:len(S)-(i+1)-1]+S_rev[0])
            break
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
if len(s) < 26:
  c = min(set("zyxwvutsrqponmlkjihgfedcba")-set(s))
  r = s+c
  print(r)
  exit()
n = len(s)
for i in range(len(s)):
  ok = True
  for j in range(i+1, len(s)):
    if s[j] > s[j-1]:
      ok = False
      break
  if ok:
    n = i
    break
if n == 0:
  print(-1)
  exit()
#print(n, s[:n])
c = min(set("zyxwvutsrqponmlkjihgfedcba")-set(s[:n]))
r = s[:n-1]+c
print(r)

Submission status: Wrong Answer

Solution code:
S=input()
for c in"abcdefghijklmnopqrstuvwxyz":
 if(c in S)^1:print(S+c);quit()
for i in range(1,26):
 for c in sorted(S[-i:]):
  if c>S[-i]:print(S[:-i]+c);quit()
print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
alp = list("abcdefghijklmnopqrstuvwxyz")

if s == "abcdefghijklmnopqrstuvwxyz"[::-1]:
  print(-1)
  exit()

if len(s) < 26:
  for i in s:
    idx = alp.index(i)
    alp.pop(idx)
  print(s + alp[0])
else:
  li = []
  revs = s[::-1]
  for itr, val in enumerate(revs):
    li.sort()
    for litr, lval in enumerate(li):
      if val < lval:
        print(s[:len(s)-litr-2]+lval)
        exit()
    li.append(val)

Submission status: Wrong Answer

Solution code:
s = input()
if len(s) < 26:
  c = min(set("zyxwvutsrqponmlkjihgfedcba")-set(s))
  r = s+c
  print(r)
n = len(s)
for i in range(len(s)):
  ok = True
  for j in range(i+1, len(s)):
    if s[j] > s[j-1]:
      ok = False
      break
  if ok:
    n = i
    break
if n == 0:
  print(-1)
  exit()
#print(n, s[:n])
c = min(set("zyxwvutsrqponmlkjihgfedcba")-set(s[:n]))
r = s[:n-1]+c
print(r)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date
from math import factorial
import functools
from heapq import*
from collections import deque
import collections
import math
from collections import defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float("inf")


def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    s = list(s)
    d = Counter(s)

    c = 0
    for i in range(26):
        if d[chr(ord("a") + i)] > 0:
            c += 1
    if c == 26:
        for i in range(26):
            if s[i] != chr(ord("a") + i):
                dd = Counter(s[:i])
                for j in range(i, 26):
                    if dd[chr(ord("a") + j)] == 0:
                        s[i-1] = chr(ord("a") + j)
                        print("".join(map(str, s[:i])))
                        exit()
    else:
        for i in range(26):
            if d[chr(ord("a") + i)] == 0:
                print("".join(map(str, s)) + chr(ord("a") + i))
                exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date
from math import factorial
import functools
from heapq import*
from collections import deque
import collections
import math
from collections import defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float("inf")


def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    s = list(s)
    d = Counter(s)

    c = 0
    for i in range(26):
        if d[chr(ord("a") + i)] > 0:
            c += 1
    if c == 26:
        for i in range(26):
            if s[i] != chr(ord("a") + i):
                s[i-1] = chr(ord(s[i-1]) +1 )
                print("".join(map(str, s[:i])))
                exit()
    else:
        for i in range(26):
            if d[chr(ord("a") + i)] == 0:
                print("".join(map(str, s)) + chr(ord("a") + i))
                exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
alphabet = [chr(ord("a")+i) for i in range(26)]
if n != 26:
    for i in alphabet:
        if i not in s:
            s += i
            break
    print(s)
else:
    prev = chr(ord("a")-1)
    i = n-1
    while i >= 0:
        if s[i] > prev:
            prev = s[i]
            i -= 1
        else:
            break
    if i == -1:
        print(-1)
        exit()
    #print(i)
    si = s[i]
    m = "z"
    for j in range(i+1, n):
        if si < s[j]:
            m = min(m, s[j])
    s = s[:i+1] + m
    print(s)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
alphabet = [chr(ord("a")+i) for i in range(26)]
if n != 26:
    for i in alphabet:
        if i not in s:
            s += i
            break
    print(s)
else:
    prev = chr(ord("a")-1)
    i = n-1
    while i >= 0:
        if s[i] > prev:
            prev = s[i]
            i -= 1
        else:
            break
    if i == -1:
        print(-1)
        exit()
    print(i)
    si = s[i]
    m = "z"
    for j in range(i+1, n):
        if si < s[j]:
            m = min(m, s[j])
    s = s[:i+1] + m
    print(s)

Submission status: Wrong Answer

Solution code:
s=input()
N=len(s)
alpha="abcdefghijklmnopqrstuvwxyz"
a=[0]*26
for i in range(N):
    for j in range(26):
        if s[i]==alpha[j]:
            a[j]+=1
            break

if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
c=0
lastidx=-1
while True:


    for j in range(lastidx+1,26):
        if a[j]==0 :
            print(s[:c]+alpha[j])
            exit()
    lastidx=alpha.index(s[-1+c])
    a[lastidx] -= 1
    c-=1

Submission status: Wrong Answer

Solution code:
s=input()
al=[chr(ord('a')+i) for i in range(26)]

if all(a in s for a in al):
    ss=list(reversed(list(s)))
    x=len(s)-1
    for i in range(1,len(s)):
        if ss[i]>ss[i-1]:
            pass
        else:
            x=i
            break
    if x==len(s)-1:
        print(-1)
    else:
        ans='z'
        for a in ss[:x]:
            ans=min(ans,a)
        print(s[:25-x]+ans)
else:
    for a in al:
        if not a in s:
            print(s+a)
            exit()

Submission status: Wrong Answer

Solution code:
def main():
    S = str(input())
    if len(S) != 26:
        alpha = [i for i in range(26)]
        for i in S:
            alpha.remove(ord(i)-97)
        n = min(alpha)
        print(S+chr(97+n))
    elif S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        alpha = []
        for i in range(25):
            if ord(S[-i-1]) < ord(S[-i-2]):
                alpha.append(S[-i-1])
            else:
                alpha.sort()
                for j in alpha:
                    if ord(j) > ord(S[-i-2]):
                        print(S[:(-i-2)]+j)
                        exit()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)
from collections import deque


def getN():
    return int(input())


def getList():
    return list(map(int, input().split()))


import math

s = input().strip()
if len(s) == 26:
    tmp = ord("a") - 1
    remain = []
    for i, c in enumerate(s[::-1]):
        if tmp < ord(c):
            tmp = ord(c)
            remain.append(c)
        else:
            # remain.append(c)
            print(s[:26-i-1] + sorted(remain)[0])
            sys.exit()

    print(-1)
    sys.exit()




alph = [0 for i in range(26)]

for c in s:
    alph[ord(c) - ord("a")] = 1

for i, al in enumerate(alph):
    if al == 0:
        print(s + chr(ord("a") + i))
        sys.exit()


 # zyxwvutsrqponmlkjaihgfedcb

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)
from collections import deque


def getN():
    return int(input())


def getList():
    return list(map(int, input().split()))


import math

s = input().strip()
if len(s) == 26:
    tmp = ord("a") - 1
    remain = []
    for i, c in enumerate(s[::-1]):
        if tmp < ord(c):
            tmp = ord(c)
            remain.append(c)
        else:
            remain.append(c)
            print(s[:26-i-1] + "".join(sorted(remain)))
            sys.exit()

    print(-1)
    sys.exit()




alph = [0 for i in range(26)]

for c in s:
    alph[ord(c) - ord("a")] = 1

for i, al in enumerate(alph):
    if al == 0:
        print(s + chr(ord("a") + i))
        sys.exit()


 # zyxwvutsrqponmlkjaihgfedcb