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:
S = list(input())
Z = sorted(S)
G = ["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"]
ans = []
for s in S:
    if s not in ans:
        ans.append(s)
    else:
        i = G.index()
        j = 0
        while j < 27:
            if G[(i+j)%26] not in ans:
                ans.append(G[(i+j)%26])
                break
            j += 1
        else:
            print(-1)
            exit()

ans = "".join(ans)
S = "".join(S)
if ans == S:
    ans = list(ans)
    aaa = sorted(list(ans))
    i = G.index(aaa[0])
    j = 0
    while j < 27:
        if G[(i + j) % 26] not in ans:
            ans.append(G[(i + j) % 26])
            break
        j += 1
    else:
        for i in range(len(S)-1, -1, -1):
            for j in range(i, -1, -1):
                if S[i] > S[j]:
                    print(S[:j] + S[i])
                    exit()
ans = "".join(ans)
if ans > S:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:


def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    
    elif len(temp)==26:
        t1,t2=temp.split("z")
        # print(t1)
        # print(t2)
        st=t1[-1]
        temp=t1[:-1]
        mt="z"
        for t in t2:
            if t>st and mt>t:
                mt=t
                #print(t)
        temp+=mt
        print(temp)
        exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()

D = ord('z') - ord('a')

def to_integer(s):
    sum = 0
    for i in range(len(s)):
        sum *= D
        sum += ord(s[i]) - ord('a') + 1
    return sum

def inc(s):
    s = list(s)
    if s[-1] != 'z':
        s[-1] = chr(ord(s[-1]) + 1)
    else:
        if len(s) == 1:
            s = ['a', 'a']
        else:
            s = inc(s[:-1]) + 'a'
    return ''.join(s)

def is_xx(s):
    xx = set()
    for c in s:
        if c in xx:
            return False
        else:
            xx.add(c)
    return True

max_s = to_integer('zyxwvutsrqponmlkjihgfedcba')

x = to_integer(s)

if x >= max_s:
    print('-1')
else:
    s = inc(s)
    while not is_xx(s):
        s = inc(s)
    print(inc(s))

Submission status: Wrong Answer

Solution code:
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_=[]
        num=0
        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_))
                num+=1
                break
            if num>0:
                break

Submission status: Wrong Answer

Solution code:
s=list(raw_input())
l=len(s)-1
al={}
for i in s:
    al[i]=1
while(l>=0):
    for i in range(97,97+26):
        x=chr(i)
        if al.get(x,-1)==-1 and x>s[l]:
            ans=s[:l+1] +[x]
            if len(s)==26:
                ans[-2]=''
            print ''.join(ans)
            exit()
    al[s[l]]=-1
    l-=1
print -1

Submission status: Wrong Answer

Solution code:
def nextword(s):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print("-1")
    s_set = set(s)
    for c in alphabet:
        if c not in s:
            nexts = s + c
            return nexts
    s_length = len(s)
    for i in range(1, s_length+1):
        nexts = s[:]
        c = s[-i]
        k = alphabet.find(c)
        if k == 25:
            continue
        for j in range(k+1,26):
            if alphabet[j] not in s:
                nexts=s.replace(alphabet[k],alphabet[j])
                return nexts
        
s = input()
print(nextword(s))

Submission status: Wrong Answer

Solution code:
s=input()

ss=[0 for i in range(26)]
for i in range(len(s)):
    for j in range(26):
        if s[i]==chr(97+j):
            ss[j]=1

if len(s)!=26:
        for i in range(26):
            if ss[i]==0:
                s=s+chr(97+i)
                break
        print(s)
else:
    if s=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        for i in range(25):
            if s[24-i] < s[25-i]:
                s=s[:25-i]
                break

        sss=[0 for i in range(26)]
        for i in range(len(s)):
            for j in range(26):
                if s[i]==chr(97+j):
                    sss[j]=1

        for i in range(26):
            if sss[i]==0:
                s=s[:len(s)-1]+chr(97+i)
                break

        print(s)

Submission status: Wrong Answer

Solution code:
s = list(input())
import collections
import sys
dic = collections.defaultdict(lambda: 0)
min_word = '{'

if len(list(set(s))) == 26:
    if (ord(s[1]) - ord(s[0])) == -1:
        print(-1)
        sys.exit(0)

    before_str = s[0]
    for index, i in enumerate(s[1:]):
        if ord(i) - ord(before_str) != 1:
            if chr(ord(s[index]) + 1) == '{':
                print(-1)
                sys.exit(0)

            print(''.join(s[0:index]) + chr(ord(s[index]) + 1))
            sys.exit(0)
        before_str = i

else:
    min_word = s[0]
    for i in s[1:]:
        # min_word = min(min_word, i)
        if ord(i) - ord(min_word) == 1:
            min_word = i
    print(''.join(s) + chr(ord(min_word) + 1))

Submission status: Wrong Answer

Solution code:
s = input()

lst = ['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']

dic = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6,
       'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13,
       'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19,
       'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

if len(s) < 26:
    for x in s:
        lst.remove(x)
    print(s + lst[0])
    
else:
    tmp = ''
    cnt = 0
    cond = False
    for i in range(26):
        if cnt <= dic[s[-1]]:
            tmp += s[-1]
            cnt = dic[s[-1]]
            s = s[:-1]
        else:
            tmp += s[-1]
            s = s[:-1]
            cond = True
            break
            
    if cond:
        print(s + sorted(tmp)[1])
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
import sys
s = input()
ss = list(s)

if len(ss) > 26:
    print(-1)
else:
    ngchar = ''
    while len(ss) > 0:
        res = -1
        for i in range(97, 122):
            if chr(i) not in ss:
                if chr(i) != ngchar:
                    print(''.join(ss) + chr(i))
                    sys.exit(0)
        if res == -1:
            ngchar = ss.pop(-1)
        else:
            break

Submission status: Wrong Answer

Solution code:
ascii_lowercase='abcdefghijklmnopqrstuvwxyz'

s=input()

if(len(s)<26):
    for c in ascii_lowercase:
        if(s.find(c)<0):
            print(s+c)
            break
elif(s==ascii_lowercase[::-1]):
    print(-1)
else:
    for i in range(25):
        if(s[-i-2]<s[-i-1]):
            print(s[:-i-2]+ascii_lowercase[ascii_lowercase.find(s[-i-2])+1])
            break

Submission status: Wrong Answer

Solution code:
import sys
S = []

S = input()

Len = len(S)

Cnt = [0 for i in range(26)]
Chk = 0

S2 = 'abcdefghijklmnopqrstuvwxyz'

if Len == 26:
    for i in range(26):
        TmpI2 = 25 - i
        TmpI1 = 25 - i - 1
        if TmpI2 < 0:
            print('-1')
            sys.exit()
            
        TmpS2 = S[TmpI2]
        TmpS1 = S[TmpI1]
        
        TmpS1N = 26
        TmpS2N = 26
        for j in range(26):
            if TmpS2 == S2[j]:
                TmpS2N = j

            if TmpS1 == S2[j]:
                TmpS1N = j
            
            if (TmpS1N < 26) and (TmpS1N < 26):
                break
        
        if TmpS1N < TmpS2N:
            S = S[:TmpI1]
            Len = len(S)
            Cnt[TmpS1N] = 1
            break

                
for i in range(Len):
    TmpS = S[i]
    
    for j in range(26):
        if S2[j] == TmpS:
            Cnt[j] += 1
            if Cnt[j] > 1:
                Chk = 1
            break
    
    if (Chk==1):
        print('-1')
        sys.exit()
        
for i in range(26):
    
    if Cnt[i] == 0:
        S = S + S2[i]
        break

print(S)

Submission status: Wrong Answer

Solution code:
S=input()
if len(S)==26:
  max_code='zyxwvutsrqponmlkjihgfedcba'
  if S==max_code:
    print('-1')
    exit()
  for i in range(26):
    if max_code[i]!=S[i]:
      maxw=max_code[i]
      head=S[0:i]
      S=S[i:]
      break
  minw=maxw
  for i in range(len(S)):
    if S[i]==maxw:
      for j in range(len(S)-i-1):
        jtmp=j+i+1
        if S[jtmp]<minw:
          minw=S[jtmp]
      print('aaaaaa'+head+S[0:i-1]+minw)
      exit()
alp='abcdefghijklmnopqrstuvwxyz'
for i in S:
  for j in range(len(alp)):
    if i==alp[j]:
      alp=alp[0:j]+alp[j+1:]
      break
print(S+alp[0])

Submission status: Wrong Answer

Solution code:
import sys


alph="abcdefghijklmnopqrstuvwxyz"
allis=list(alph)
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()


if(S=="abcdefghijklmnopqrstuvwxyz"):
    print("b")
    sys.exit()
for i in alph:
    if(i not in S):
        print(S+i)
        sys.exit()
        
"""
outp=""
for i in range(len(S)):
    if(S[i]==alph[i]):
        outp+=S[i]
    else:
        outp=outp[:-1]
        outp=outp+alph[i]
        break
"""
for i in range(len(S)-1):
    if(ord(S[i])-ord(S[i+1])<-1):
        for j in alph:
            if(j not in S[:i+1]):
                outp=S[:i]+j
                print(S[:i]+j)
                sys.exit()
    elif(ord(S[i+1])-ord(S[i])<-1):
        for j in alph:
            if(j not in S[:i+2]):
                outp=S[:i+1]+j
                print(S[:i+1]+j)
                sys.exit()

Submission status: Wrong Answer

Solution code:
import sys


s = input()
alpha = [chr(i) for i in range(97, 97+26)]
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    res = ""
    for i in alpha:
        if i not in s:
            res = i
            break
    if res != "":
        print(s+res)
        sys.exit()

    tmp_res = s
    for i in s[::-1]:
        if i != "z":
            for j in alpha[alpha.index(i)+1:]:
                if tmp_res.count(j) == 0:
                    print(tmp_res+j)
                    sys.exit()
            tmp_res = tmp_res[:-2]

Submission status: Wrong Answer

Solution code:
A = input()

check = [True for _ in range(30)]
emptyCheck = ord('z') - ord('a')
isEmpty = True

for cha in A:
    check[ord(cha) - ord('a')] = False
    if emptyCheck != ord(cha) - ord('a'):
        isEmpty = False
    emptyCheck = emptyCheck - 1
    
if emptyCheck > 0:
    isEmpty = False
    
if isEmpty:
    print(-1)
else:
    isEnd = False
    num = 0
    while num <= ord('z') - ord('a'):
        if check[num]:

            A_list = list(A)
            A_list.append(chr(num + ord('a')))
            A = "".join(A_list)
            print(A)
            isEnd = True
            break
        num = num + 1

    if isEnd:
        pass
    else:
        num = len(A) - 2
        while num >= 0:
            if A[len(A) - 1] > A[num]:
                A_list = list(A[:num])
                A_list.append(A[len(A) - 1])
                A = "".join(A_list)
                print(A)
                break
            num = num - 1

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

ALPHA = sorted([a for a in "zyxwvutsrqponmlkjihgfedcba"])


def main():
    S = input().strip()

    if 'zyxwvutsrqponmlkjihgfedcba' == S:
        return '-1'

    S = [s for s in S]
    ans = []
    for s in S:
        if s in ALPHA:
            ALPHA.remove(s)
            ans.append(s)
        else:
            ans.append(ALPHA.pop(0))
            break
    else:
        if ALPHA:
            ans.append(ALPHA.pop(0))
        else:
            alpha = sorted([a for a in "zyxwvutsrqponmlkjihgfedcba"])
            for i in range(len(ans) - 1, 0, -1):
                if ans[i - 1] < ans[i]:
                    break
            diff = sorted(list(set(alpha) - set(ans[:i])))
            ans = ans[:i - 1]
            ans.append(diff.pop(0))
    return "".join(ans)


if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
A = input()

check = [True for _ in range(30)]
emptyCheck = ord('z') - ord('a')
isEmpty = True

for cha in A:
    check[ord(cha) - ord('a')] = False
    if emptyCheck != ord(cha) - ord('a'):
        isEmpty = False
    emptyCheck = emptyCheck - 1

if isEmpty:
    print(-1)
else:
    isEnd = False
    num = 0
    while num <= ord('z') - ord('a'):
        if check[num]:

            A_list = list(A)
            A_list.append(chr(num + ord('a')))
            A = "".join(A_list)
            print(A)
            isEnd = True
            break
        num = num + 1

    if isEnd:
        pass
    else:
        num = len(A) - 2
        while num >= 0:
            if A[len(A) - 1] > A[num]:
                A_list = list(A[:num])
                A_list.append(A[len(A) - 1])
                A = "".join(A_list)
                print(A)
                break
            num = num - 1

Submission status: Wrong Answer

Solution code:
s = input()

lst = ['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']

dic = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6,
       'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13,
       'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19,
       'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

if len(s) < 26:
    for x in s:
        lst.remove(x)
    print(s + lst[0])

elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    
else:
    tmp = ''
    cnt = 0
    for i in range(26):
        if cnt <= dic[s[-1]]:
            tmp += s[-1]
            cnt = dic[s[-1]]
            s = s[:-1]
        else:
            tmp += s[-1]
            s = s[:-1]
            print(s + sorted(tmp)[1])
            break

Submission status: Wrong Answer

Solution code:
S = input()
alp = "abcdefghijklmnopqrstuvwxyz"

if len(S) < 26:
  for i in range(len(alp)):
    c = alp[i]
    index = S.find(c)
    if index <0 :
      print(S,c,sep='')
      exit()

stack=[]
c_pre=""
for j in range(len(S)):
  c_now = S[25-j]
  #print(c_now)
  if c_now < c_pre :
    S = S[:-j-1]
    print(S)
    c_min = "z"
    for cx in stack:
      if c_now < cx and cx <= c_min :
        c_min = cx
        #print(c_min)
    print(S,c_min,sep='')
    exit()
  else :
    stack.append(c_now)
    c_pre = c_now

print("-1")

Submission status: Wrong Answer

Solution code:
S = input()
ss= set(S)

def itoc(i): return chr(ord('a') + i)
def ctoi(c): return ord(c) - ord('a')

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(ss) == 26:
    cands = []
    tmp = ''
    for i,c in enumerate(S):
        if c == 'z': continue
        ti = ctoi(c) + 1
        while ti <= ctoi('z'):
            tc = itoc(ti)
            if tc not in tmp:
                cands.append(tmp + tc)
                break
            ti += 1
        tmp += c
    for cand in sorted(cands):
        if cand > S:
            print(cand)
            exit()
else:
    for i in range(26):
        c = itoc(i)
        if c in S: continue
        print(S + c)
        break

Submission status: Wrong Answer

Solution code:
s=list(raw_input())
l=len(s)-1
al={}
for i in s:
    al[i]=1
while(l>=0):
    for i in range(97+26):
        x=chr(i)
        if al.get(x,-1)==-1 and x>s[l]:
            ans=s[:l+1] +[x]
            print ''.join(ans)
            exit()
    al[s[l]]=-1
    l-=1
print -1

Submission status: Wrong Answer

Solution code:
S = input()
T = "abcdefghijklmnopqrstuvwxyz"
if len(S) != 26:
    for i in T:
        if i not in S:
            print(S+i)
            exit()
else:
    if S == "zyxwvutsrqponmlkjihgfedcba" :
        print(-1)
    else:
        dic = []
        kouho = 25
        for i in range(25,-1,-1):
                if S[i] != T[kouho]:
                    dic.append(S[i])
                else:
                    if len(dic) == 0 and i != 0:
                        kouho -= 1
                    elif i == 0:
                        for j in range(26):
                            if T[j] == S[0]:
                                print(T[j+1])
                                exit()
                    else:
                        dic = sorted(dic)
                        print(S[0:i-1]+dic[0])
                        exit()

Submission status: Wrong Answer

Solution code:
S=input()
if len(S)==26:
  max_code='zyxwvutsrqponmlkjihgfedcba'
  if S==max_code:
    print('-1')
    exit()
  for i in range(26):
    if max_code[i]!=S[i]:
      maxw=max_code[i]
      head=S[0:i]
      S=S[i:]
      break
  minw=maxw
  for i in range(len(S)):
    if S[i]==maxw:
      for j in range(len(S)-i-1):
        jtmp=j+i+1
        if S[jtmp]<minw:
          minw=S[jtmp]
      print(head+S[0:i-1]+minw)
      exit()
alp='abcdefghijklmnopqrstuvwxyz'
for i in S:
  for j in range(len(alp)):
    if i==alp[j]:
      alp=alp[0:j]+alp[j+1:]
      break
print(S+alp[0])

Submission status: Wrong Answer

Solution code:
s = list(input())
if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) <= 25:
    for i in range(ord("a"), ord("a") + 26):
        if chr(i) not in s:
            s += chr(i)
            break
    print("".join(s))
else:
    i = 25
    while s[i] != "z":
        i -= 1
    if i == 25:
        print(chr(ord(s[0]) + 1))
    else:
        i -= 1
        for j in range(ord("a"), ord("a") + 26):
            if chr(j) not in s[:i + 1]:
                s[i] = chr(j)
                break
        print("".join(s[:i + 1]))

Submission status: Wrong Answer

Solution code:
import sys
if __name__ == "__main__":
    S = str(input())
    tmp = 0
    flag = {}
    for i in range(97, 97 + 26):
        flag[chr(i)] = 0
    for i,ele in enumerate(S):
        if flag[ele] == 0:
            flag[ele] = i+1
    if len(S) < 26:
        for i in range(97, 97 + 26):
            if flag[chr(i)] == 0:
                print(S+chr(i))
                sys.exit()
    else:
        error = 1
        for i in range(25, -1, -1):
            if flag[chr(97+i)] != (26 - i):
                error = 0
        if error == 1:
            print('-1')
            sys.exit()
        for i in range(25, -1, -1):
            if flag[chr(97+i)] != 0:
                tmp = ''
                for j,ele in enumerate(S):
                    if j != flag[chr(97+i)]-2:
                        tmp += ele
                    else:
                        tmp += chr(ord(ele)+1)
                        print(tmp)
                        sys.exit()

Submission status: Wrong Answer

Solution code:
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]:
            print(s[:-i] + chr(ord(s[-i:][0]) + 1))
            break
    else:
        print(s[1000])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

ALPHA = sorted([a for a in "zyxwvutsrqponmlkjihgfedcba"])


def main():
    S = input().strip()

    if 'zyxwvutsrqponmlkjihgfedcba' == S:
        return '-1'

    S = [s for s in S]
    ans = []
    for s in S:
        if s in ALPHA:
            ALPHA.remove(s)
            ans.append(s)
        else:
            ans.append(ALPHA.pop(0))
            break
    else:
        if ALPHA:
            ans.append(ALPHA.pop(0))
        else:
            alpha = sorted([a for a in "zyxwvutsrqponmlkjihgfedcba"])
            for i in range(len(ans) - 1, 0, -1):
                if ans[i - 1] < ans[i]:
                    break
            ans = ans[:i - 1]
            ans.append(sorted(list(set(alpha) - set(ans[:i - 1]))).pop(0))
    return "".join(ans)


if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    quit()
if S == 'abcdefghijklmnopqrstuvwxyz':
    print('abcdefghijklmnopqrstuvwxz')
    quit()

ans = None
alphabet = [chr(c) for c in range(97, 97 + 26)]
if len(S) == 26:
    for i in range(24, -1, -1):
        if S[i] < S[25]:
            print(S[0:i] + S[25])
            quit()


used_c = set()
for c in S:
    used_c.add(c)
for c in alphabet:
    if not c in used_c:
        ans = S + c
        break;
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
frag = False
for i in range(97, 123):
    if chr(i) not in S:
        print("".join([S, chr(i)]))
        frag = True
        break
if frag == False:
    for i in range(2, len(S)):
        for j in range(97, 123):
            if chr(j) not in S[:1-i] and j > ord(S[1-i]):
                frag = True
                break
        if frag:
            break
    if frag:
        print("".join([S[:1-i], chr(j)]))
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
s = list(input())
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) <= 25:
    for i in range(ord("a"), ord("a") + 26):
        if chr(i) not in s:
            s += chr(i)
            break
    print("".join(s))
else:
    i = 25
    while s[i] != "z":
        i -= 1
    if i == 25:
        print(chr(ord(s[0]) + 1))
    else:
        i -= 1
        for j in range(ord("a"), ord("a") + 26):
            if chr(j) not in s[:i + 1]:
                s[i] = chr(j)
                break
        print("".join(s[:i + 1]))

Submission status: Wrong Answer

Solution code:
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]:
                break
            for j in range(i-3):
                S_.append(S[j])
            S_.append(S[25])
            S_=''.join(S_)
            print(str(S_))
            break

Submission status: Wrong Answer

Solution code:
import numpy as np

s = input()

text = "abcdefghijklmnopqrstuvwxyz"
count = []

for i in range(len(text)):
    count.append(0)

if(len(s) != len(text)):
    for i in s:
        for j in range(len(text)):
            if(i == text[j]):
                count[j] = 1
                break

    for i in range(len(text)):
        if(count[i] == 0):
            print((s + text[i]))
            exit()
else:
    for i in range(1, len(text) + 1, 1):
        for j in s[0:-i]:
            for k in range(len(text)):
                if(j == text[k]):
                    count[k] = 1
                    break

        for j in range(len(text)):
            if(s[-i] == text[j]):
                num = j

        for j in range(num+1, len(text), 1):
            if(count[j] == 0):
                print((s[0:-i] + text[j]))
                exit()

print("-1")

Submission status: Wrong Answer

Solution code:
S = input()
T = "abcdefghijklmnopqrstuvwxyz"
if len(S) != 26:
    for i in T:
        if i not in S:
            print(S+i)
            exit()
else:
    if S == "zyxwvutsrqponmlkjihgfedcba" :
        print(-1)
    else:
        dic = []
        kouho = 25
        for i in range(25,-1,-1):
                if S[i] != T[kouho]:
                    dic.append(S[i])
                else:
                    if len(dic) == 0:
                        kouho -= 1
                    if kouho >= -1:
                        for j in range(26):
                            if T[j] == S[0]:
                                print(T[j+1])
                                exit()
                    else:
                        dic = sorted(dic)
                        print(S[0:i-1]+dic[0])
                        exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from string import ascii_lowercase


def main():
    word = stdin.readline().rstrip()
    if word == ascii_lowercase[::-1]:
        print(-1)
        return

    spam = sorted(list(set(ascii_lowercase) - set(word)))
    if 1 <= len(spam):
        print(word + spam[0])
        return

    rword = word[::-1]
    tmp = []
    for x in rword:
        if len(tmp) != 0 and x < tmp[-1]:
            print(word[:-len(tmp) - 1] + tmp[0])
            return
        tmp.append(x)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

abc = "abcdefghijklmnopqrstuvwxyz"
s = S()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
ans = ""
if len(s) < 26:
    for a in abc:
        if not a in s:
            print(s+a)
            exit()
else:
    for i in range(len(s)-1):
        if s[i] > s[i+1]:
            for a in abc:
                if not a in s[:i]:
                    print(s[:i-1]+a)
                    exit()

Submission status: Wrong Answer

Solution code:
S=input()
row='abcdefghijklmnopqrstuvwxyz'
row=list(row)
if len(S)!=26:
    for letter in S:
        row.remove(letter)
    print(S+row[0])
    
else:
    if list(S)==row.sort(reverse=True):
        print(-1)
    else:
        S_=[]
        for i in range(25,0,-1):
            if S[i-1]<S[i]:
                break
            for j in range(i-3):
                S_.append(S[j])
            S_.append(S[25])
            S_=''.join(S_)
            print(str(S_))
            break

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase


def solve(s):
    if len(s) < 26:
        for c in ascii_lowercase:
            if c not in s:
                return s + c

    while True:
        pi = ascii_lowercase.index(s[-1])
        s = s[:-1]
        if not s:
            return -1
        for c in ascii_lowercase[pi + 1:]:
            if c not in s:
                return s + c


s = input()
print(solve(s))

Submission status: Wrong Answer

Solution code:
ascii_lowercase='abcdefghijklmnopqrstuvwxyz'

s=input()

if(len(s)<26):
    for c in ascii_lowercase:
        if(s.find(c)<0):
            print(s+c)
            break
elif(s==ascii_lowercase[::-1]):
    print(-1)
else:
    for i in range(25):
        if(s[-i-2]<s[-i-1]):
            print(s[:-i-2]+s[-1])
            break

Submission status: Wrong Answer

Solution code:
import sys
s = raw_input()
check_list = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
if s == "zyxwvutsrqponmlkjihgfedcba":
    print("-1")
else:
    # not all alphabet 
    for i in check_list:
        if i not in s:
            print(s+i)
            sys.exit()
    # all alphabet 
    if len(s)==26:
        for i,cl in enumerate(check_list):
            if s[i] != cl:
                print(s[:i]+cl)
                sys.exit()

Submission status: Wrong Answer

Solution code:
s = list(input())
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) <= 25:
    for i in range(ord("a"), ord("a") + 26):
        if chr(i) not in s:
            s += chr(i)
            break
    print("".join(s))
else:
    i = 25
    while s[i] != "z":
        i -= 1
    if i == 25:
        print(chr(ord(s[0]) + 1))
    else:
        i -= 1
        s[i] = chr(ord(s[i]) + 1)
        print("".join(s[:i + 1]))

Submission status: Wrong Answer

Solution code:
S=input()
if len(S)==26:
  max_code='zyxwvutsrqponmlkjihgfedcba'
  if S==max_code:
    print('-1')
    exit()
  for i in range(26):
    if max_code[i]!=S[i]:
      maxw=max_code[i]
      break
  minw='z'
  for i in range(len(S)):
    if S[i]==maxw:
      for j in range(len(S)-i-1):
        jtmp=j+i+1
        if S[jtmp]<minw:
          minw=S[jtmp]
      print(S[0:i-1]+minw)
      exit()
alp='abcdefghijklmnopqrstuvwxyz'
for i in S:
  for j in range(len(alp)):
    if i==alp[j]:
      alp=alp[0:j]+alp[j+1:]
      break
print(S+alp[0])

Submission status: Wrong Answer

Solution code:
from sys import stdin
from string import ascii_lowercase


def main():
    word = stdin.readline().rstrip()
    if word == ascii_lowercase[::-1]:
        print(-1)
        return

    spam = sorted(list(set(ascii_lowercase) - set(word)))
    if 1 <= len(spam):
        print(word + spam[0])

    rword = word[::-1]
    tmp = []
    for x in rword:
        if len(tmp) != 0 and x < tmp[-1]:
            print(word[:-len(tmp) - 1] + tmp[0])
            break
        tmp.append(x)


if __name__ == '__main__':
    main()