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 = input()

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

Submission status: Wrong Answer

Solution code:
S = input()

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

Submission status: Wrong Answer

Solution code:
S = input()

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

Submission status: Wrong Answer

Solution code:
S = input()

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

Submission status: Wrong Answer

Solution code:
S = input()
N = [chr(i) for i in range(97,123) if chr(i) not in S]
ABC = [chr(i) for i in range(97,123)]

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

Submission status: Wrong Answer

Solution code:
import sys
s = input()

counts = [0] * 26
for i in range(len(s)):
    num = ord(s[i]) - 97
    counts[num] += 1
   
for i in range(26):
    if counts[i] == 0:
        print(s + chr(i + 97))
        sys.exit()

print(-1)

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    count = 1
    for i in range(1, len(s) - 1):
        if s[-i] < s[-i - 1]:
            count += 1
        else:
            break
    if count == 26:
        print(-1)
    else:
        for i in sorted(s[-count:]):
            if s[-count - 1] < i:
                print(s[:-count-1] + i)
                break
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(26):
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    count = 1
    for i in range(0, len(s) - 1):
        if s[-i] < s[-i - 1]:
            count += 1
        else:
            break
    if count == 26:
        print(-1)
    else:
        for i in sorted(s[-count:]):
            if s[-count - 1] < i:
                print(s[:-count-1] + i)
                break
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(26):
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    count = 0
    for i in range(0, len(s) - 1):
        if s[-i] < s[-i - 1]:
            count += 1
        else:
            break
    if count == 26:
        print(-1)
    else:
        for i in sorted(s[-count:]):
            if s[-count - 1] < i:
                print(s[:-count-1] + i)
                break
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(26):
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    count = 0
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(0, len(s) - 1):
        if s[i] > s[i + 1]:
            break
        else:
            count += 1
    if count == 0:
        print(-1)
    else:
        s = s[: count] + chr(ord(s[count-1]) + 1)
        print(s)
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(26):
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    count = 0
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(1, len(s)):
        if s[i] < s[i - 1]:
            break
        else:
            count += 1
    if count == 0:
        print(-1)
    else:
        s = s[:count-1] + chr(ord(s[count - 1]) + 1)
        print(s)
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(26):
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    for i in range(len(s) - 1, 0, -1):
        if s[i] > s[i - 1]:
            s = list(s)
            s = s[: i - 1] + [min(s[i:])]
            print(''.join(s))
            sys.exit()
    print(-1)
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in range(26):
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    N=len(S)
    alps=[chr(i) for i in range(97,97+26)]
    flags=[False]*26
    if N<26:
        for i in range(N):
            flags[ord(S[i])-97]=True
        for i in range(26):
            if flags[i]==False:
                s=alps[i]
                break
        print(S+s)

    else:
        if S=="zyxwvutsrqponmlkjihgfedcba":
            print(-1)
        else:
            k=0
            for i in range(26):
                if i==0:
                    j=ord(S[i])-97
                else:
                    if j<ord(S[i])-97:
                        k=i
                        j=ord(S[i])-97

            target1=S[k-1]
            for i in range(k,26):
                if i==k:
                    target2=S[k]
                else:
                    if ord(target1)-97<ord(S[i])-97<ord(target2)-97:
                        target2=S[i]

            print(S[:k-1]+target2)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def main():
    S = input()
    T = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) < 26:
        U = set(T) - set(S)
        print(S + sorted(U)[0])
    else:
        if S == T[::-1]:
            print(-1)
        else:
            count = 1
            for i in range(25):
                if S[25-i] > S[24-i]:
                    break
                else:
                    count += 1
                    for s in sorted(S[25-count:]):
                        if s > S[24-count]:
                            print(S[:24-count] + s)
                            exit()

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def main():
    S = input()
    T = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) < 26:
        U = set(T) - set(S)
        print(S + sorted(U)[0])
    else:
        if S == T[::-1]:
            print(-1)
        else:
            count = 1
            for i in range(25):
                if S[25-i] > S[24-i]:
                    break
                else:
                    count += 1
            t = T.index(S[25-count])
            print(S[:25-count] + T[t+1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
alp = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
buf = ''
for i in alp:
    if not i in set(s):
        buf = i
        break
if buf:
    print(s+buf)
else:
    c = 1
    for i in range(1,len(s)):
        if s[-i-1]>s[-i]:
            c += 1
        else:break
    if c==26:
        print(-1)
    else:
        buf = chr(ord(s[-c-1])+1)
        print(s[:-c-1]+buf)

Submission status: Wrong Answer

Solution code:
s = input()
alp = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
buf = ''
for i in alp:
    if not i in set(s):
        buf = i
        break
if buf:
    print(s+buf)
else:
    c = 1
    for i in range(len(s)-1):
        if s[-i]<s[-i-1]:
            c += 1
        else:break
    if c==1:
        print(-1)
    else:
        for i in alp:
            if not i in s[:-c+1]:
                buf = i
                break
        print(s[:-c]+buf)

Submission status: Wrong Answer

Solution code:
import sys
from string import ascii_lowercase as AL
input = sys.stdin.readline


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

    if len(S) < 26:
        for a in AL:
            if a not in S:
                ans = S + a
                break
    else:
        i = 25
        while True:
            if i == 0:
                ans = -1
                break
            if S[i-1] > S[i]:
                i -= 1
            else:
                ans = S[:i-1] + min(S[i:])
                break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
c = len(s)-1
r = 0
x = 97
while -1 < c:
    for i in range(x, 97+26):
        if chr(i) not in s:          
            s = s+chr(i)
            r = 1
            break
    if r == 1:
        break
    else:
        x = ord(s[c]) +1
        c -= 1
        s = s[:len(s)-1]

if c==-1:
    s = '-1'
print(s)

Submission status: Wrong Answer

Solution code:
s = input()
c = len(s)-1
r = 0
x = 97
while -1 < c:
    for i in range(x, 97+26):
        if chr(i) not in s:
            s = s+chr(i)
            r = 1
            break
    if r == 1:
        break
    else:
        c -= 1
        x = ord(s[-1]) +1
        s = s[:len(s)-1]

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

Submission status: Wrong Answer

Solution code:
s = input()
r = ''
for i in range(97, 97+26):
    if chr(i) in s:
        continue
    else:
        r = chr(i)
        break
if r == '':
    s = '-1'
print(s+r)

Submission status: Wrong Answer

Solution code:
s = input()
str_list = [chr(i) for i in range(97, 97+26)]
if s == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
elif len(s) != 26:
  for _ in s:
    str_list.remove(_)
  str_list.sort()
  print(s+str_list[0])
  
else:
  for i in range(25,0,-1):
    if ord(s[i]) > ord(s[i-1]):
      q = chr(ord(s[i-1]) + 1)
      print(s[:i-1] + q)
      break

Submission status: Wrong Answer

Solution code:
s = input()
str_list = [chr(i) for i in range(97, 97+26)]
if s == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
elif len(s) != 26:
  for _ in s:
    str_list.remove(_)
  str_list.sort()
  print(s+str_list[0])
  
else:
  for i in range(25,0,-1):
    if ord(s[i]) > ord(s[i-1]):
      q = chr(ord(s[i-1]) + 1)
      print(s[:i-2] + q)
      break

Submission status: Wrong Answer

Solution code:
s=str(input())
a=list("zyxwvutsrqponmlkjihgfedcba")
a=a[::-1]
#print(a)


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


if len(s)==26:
    s=s[::-1]#後ろから見ていく
    for i in range(len(s)):
        for j in range(i+1):
           # print(i,j,s[i+1],s[j+1])
            if s[i+1]<s[j+1]:#xyzの降順の流れが切れたところを変える
                s=s[::-1]
                print(s[:-(i+2)]+s[-(j+1)])
                exit()
else:
    for i in a:
        if i not in s:
            s+=i
            break
    print(s)

Submission status: Wrong Answer

Solution code:
s=str(input())
a=list("zyxwvutsrqponmlkjihgfedcba")
a=a[::-1]
#print(a)


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


if len(s)==26:
    s=s[::-1]#後ろから見ていく
    for i in range(len(s)):
        for j in range(i+1):
           # print(i,j,s[i+1],s[j+1])
            if s[i+1]<s[j+1]:#xyzの降順の流れが切れたところを変える
                s=s[::-1]
                print(s[:-(i+1)]+s[-(j+1)])
                exit()
else:
    for i in a:
        if i not in s:
            s+=i
            break
    print(s)

Submission status: Wrong Answer

Solution code:
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
x=len(s)

al=[0]*26

if x!=26:
    for i in s:
        al[ord(i)-97]=1
    
    for i in range(26):
        if al[i]==0:
            s+=chr(97+i)
            print(s)
            exit()

else:
    option=[]
    
    for i in reversed(range(26)):
        option=sorted(option)
        num=ord(s[i])
        if i==25:
            option.append(num)
        else:
            if num>max(option):
                option.append(num)
            else:
                s=s[:26-len(option)-1]
                s+=chr(option[0])
                print(s)
                exit()

Submission status: Wrong Answer

Solution code:
s=input()
a=97
if s=="zyxwvutsrqponmlkjihgfedcba":
    print("-1")
elif len(s)!=26:
    for i in range(26):
        if chr(a+i) not in s:
            print(s+chr(a+i))
            exit()
else:
    for i in range(26):
        if s[-(i+1)]<s[-1]:
            print(s[:-(i+1)]+s[-1])
            exit()

Submission status: Wrong Answer

Solution code:
s = list(input())

abc = list('abcdefghijklmnopqrstuvwxyz')

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

if len(s) == 26:
    for i in range(26)[::-1]:
        if s[i] == 'z':
            continue
        temp = abc[abc.index(s[i])+1]
        if temp in s[:i+1]:
            continue
        
        else:
            s[i] = temp
            print(''.join(s[:i+1]))
            exit()


else:
    for i in abc:
        if not i in s:
            print(''.join(s)+i)
            break

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
cha=["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 n<26:
    for i in range(26):
        if s.count(cha[i])==0:
            print(s+cha[i])
            exit()
else:
    for j in range(n-1,0,-1):
        if s[j]>s[j-1]:
            memo=j-1
            break
        if j==1:
            print(-1)
            exit()
    s2=s[:j]
    for i in range(26):
        if s2.count(cha[i])==0:
            memo2=cha[i]
            break
    print(s[:j-1]+memo2)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
cha=["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 n<26:
    for i in range(26):
        if s.count(cha[i])==0:
            print(s+cha[i])
else:
    for j in range(n-1,0,-1):
        if s[j]>s[j-1]:
            memo=j-1
            break
        if j==1:
            print(-1)
            exit()
    s2=s[:j]
    for i in range(26):
        if s2.count(cha[i])==0:
            memo2=cha[i]
            break
    print(s[:j-1]+memo2)

Submission status: Wrong Answer

Solution code:
S = input()

alf = set([chr(i) for i in range(ord('a'), ord('z')+1)])

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(S) < 26:
    not_used_alf = list(alf - set(S))
    ans = S + min(not_used_alf)
    print(ans)
else:
    tmp = S[-1]
    for i in reversed(range(26)):
        if S[i] >= tmp:
            continue
        else:
            break
    tmp = set(S[i+1:])
    for x in [chr(i) for i in range(ord('a'), ord('z')+1)]:
        if x in tmp and x > S[i]:
            ans = S[:i] + x
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

S=list(input())


S=list(map(lambda x : ord(x)-97,S))

alpha=[0]*26
for s in S:
    alpha[s]=1

if len(S)!=26:
    for i in range(26):
        if alpha[i] == 0:
            S.append(i)
            ans=S[:]
            ans=list(map(lambda x :chr(x+97), ans))
            print("".join(ans))
            exit()
else:
    for i in range(26)[::-1]:
        if alpha[S[i]:].count(0)>0:
            print(chr(S[i]+97))
            for j in range(S[i],26):
                if alpha[j]==0:
                    ans=S[:i]+[j]
                    ans=list(map(lambda x :chr(x+97), ans))
                    print("".join(ans))
                    exit()
        else:
            alpha[S[i]]=0

print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
al = ['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']
for i in al:
    if i not in S:
        print(S+i)
        exit()
N = len(S)
tmp = S[-1]
for i in range(N-1):
    if al.index(S[-2]) > al.index(S[-1]):
        S = S[:-1]
        tmp = S[-1] + tmp
    else:
        print(S[:-1]+tmp[-1])
        exit()
print(-1)
exit()

Submission status: Wrong Answer

Solution code:
S = input()
al = ['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']
for i in al:
    if i not in S:
        print(S+i)
        exit()
N = len(S)
tmp = []
for i in range(N-1):
    if S[-1] != 'z' and al[al.index(S[-1])+1] in tmp:
        print(S[:-1]+al[al.index(S[-1])+1])
        exit()
    else:
        tmp.append(S[-1])
        S = S[:-1]
print(-1)
exit()

Submission status: Wrong Answer

Solution code:
s = input()
cnt = [0]*26
ans = ""
if s[0] == "z":
    print(-1)
    exit(0)
for i in range(len(s)):
    if cnt[int(ord(s[i])-ord("a"))] == 1:
        min = chr(ord("z")+1)
        for j in range(26):
            if cnt[j] == 0:
                if ord(chr(j+ord("a"))) < ord(min) and int(ord(s[i])) < ord(chr(j+ord("a"))):
                    min = chr(j+ord("a"))
        ans += min
        print(ans)
        exit(0)
    else :
        ans += s[i]
        cnt[int(ord(s[i])-ord("a"))] = 1
if ans == s :
    min = chr(ord("z") + 1)
    for j in range(26):
        if cnt[j] == 0:
            if ord(chr(j+ord("a"))) < ord(min):
                min = chr(j+ord("a"))
    if min == chr(ord("z") + 1):
        if s[0] == "z":
            print(-1)
            exit(0)
        else:
            for k in range(len(s)-1,-1,-1):
                ans = ans.strip(s[k])
                cnt[int(ord(s[k])-ord("a"))] -= 1
                if ord(s[k]) > ord(s[k-1]):
                    ans = ans.strip(s[k-1])
                    min = chr(ord("z") + 1)
                    for j in range(26):
                        if cnt[j] == 0:
                            if ord(chr(j + ord("a"))) < ord(min):
                                min = chr(j + ord("a"))
                    ans += min
                    break
    else:
        ans += min
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = [0]*26
ans = ""
for i in range(len(s)):
    if cnt[int(ord(s[i])-ord("a"))] == 1:
        min = chr(ord("z")+1)
        for j in range(26):
            if cnt[j] == 0:
                if ord(chr(j+ord("a"))) < ord(min):
                    min = chr(j+ord("a"))
        ans += min
        print(ans)
        exit(0)
    else :
        ans += s[i]
        cnt[int(ord(s[i])-ord("a"))] = 1
if ans == s :
    min = chr(ord("z") + 1)
    for j in range(26):
        if cnt[j] == 0:
            if ord(chr(j+ord("a"))) < ord(min):
                min = chr(j+ord("a"))
    if min == chr(ord("z") + 1):
        if s[0] == "z":
            print(-1)
            exit(0)
        else:
            for k in range(len(s)-1,-1,-1):
                ans = ans.strip(s[k])
                cnt[int(ord(s[k])-ord("a"))] -= 1
                if ord(s[k]) > ord(s[k-1]):
                    ans = ans.strip(s[k-1])
                    min = chr(ord("z") + 1)
                    for j in range(26):
                        if cnt[j] == 0:
                            if ord(chr(j + ord("a"))) < ord(min):
                                min = chr(j + ord("a"))
                    ans += min
                    break
    else:
        ans += min
print(ans)

Submission status: Wrong Answer

Solution code:
d="zyxwvutsrqponmlkjihgfedcba"
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1)
else:
    if len(s)!=26:
        for i in range(1,1+26):
            if d[-i] not in s:print(s+d[-i]);exit()
    else:
        de=[s[-1]]
        for i in range(2,27):

            if de[-1]<s[-i]:de.append(s[-i]);de.sort()
            else:print(s[:-i]+de[0]);exit()

Submission status: Wrong Answer

Solution code:
d="zyxwvutsrqponmlkjihgfedcba"
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1)
else:
    if len(s)!=26:
        for i in range(1,1+26):
            if d[-i] not in s:print(s+d[-i]);exit()
    else:
        de=[s[-1]]
        for i in range(2,27):

            if de[0]<s[-i]:de.insert(0,s[-i])
            else:print(s[:-i]+de[0]);exit()

Submission status: Wrong Answer

Solution code:
d="zyxwvutsrqponmlkjihgfedcba"
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1)
else:
    if len(s)!=26:
        for i in range(1,1+26):
            if d[-i] not in s:print(s+d[-i]);exit()
    else:
        de=[s[-1]]
        for i in range(2,27):
            print(de)
            if de[0]<s[-i]:de.insert(0,s[-i])
            else:print(s[:-i]+de[0]);exit()

Submission status: Wrong Answer

Solution code:
d="zyxwvutsrqponmlkjihgfedcba"
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1)
else:
    if len(s)!=26:
        for i in range(1,1+26):
            if d[-i] not in s:print(s+d[-i]);exit()
    else:
        de=[s[-1]]
        for i in range(2,27):
            if de[0]<s[-i]:de.insert(0,s[-1])
            else:print(s[:-i]+de[0]);exit()

Submission status: Wrong Answer

Solution code:
d="zyxwvutsrqponmlkjihgfedcba"
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1)
else:
    if len(s)!=26:
        for i in range(1,1+26):
            if d[-i] not in s:print(s+d[-i]);exit()
    else:
        de=set()
        for i in range(1,27):
            if chr(ord(s[-i])+1) not in de:de.add(chr(ord(s[-i])))
            else:print(s[:-i]+chr(ord(s[-i])+1));break

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    if len(s)==26:
        for i in range(25,1,-1):
            if s[i]<s[i-1]:
                continue
            else:
                sx=s[i-1]
                for j in range(1,25):
                    sy=chr(ord(sx)+j)
                    if sy in s[i:]:
                        print(s[:i-1]+sy)
                        sys.exit()
        else:
            print(-1)
    else:
        for i in range(26):
            if chr(ord('a')+i) in s:
                continue
            print(s+chr(ord('a')+i))
            break
    
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    zyx="zyxwvutsrqponmlkjihgfedcba"
    if s==zyx:
        print(-1)
        sys.exit()
    if len(s)==26:
        for i,sx in enumerate(zyx):
            if s[i]!=sx:
                sxi=s.index(sx)
                s=s[:sxi]
                sy=s[-1]
                for j in range(26):
                    sz=chr(ord(sy)+j+1)
                    if not(sz in s):     
                        print(s[:-1]+sz)
                        sys.exit()
    else:
        for i in range(26):
            if chr(ord('a')+i) in s:
                continue
            print(s+chr(ord('a')+i))
            break
    


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    s=input()
    zyx="zyxwvutsrqponmlkjihgfedcba"
    if s==zyx:
        print(-1)
        sys.exit()
    ss=set(s)
    if len(ss)==26:
        for i,sx in enumerate(zyx):
            if s[i]!=sx:
                sxi=s.index(sx)
                s=s[:sxi-1]+chr(ord(s[sxi-1])+1)
                print(s)
                break
    else:
        for i in range(26):
            if chr(ord('a')+i) in s:
                continue
            print(s+chr(ord('a')+i))
            break
    


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    s=input()
    zyx="zyxwvutsrqponmlkjihgfedcba"
    if s==zyx:
        print(-1)
        sys.exit()
    ss=set(s)
    if len(ss)==26:
        for sx in zyx:
            sxi=s.index(sx)
            if sxi!=0:
                s=s[:sxi-1]+chr(ord(s[sxi-1])+1)
                print(s)
                break
    else:
        for i in range(26):
            if chr(ord('a')+i) in s:
                continue
            print(s+chr(ord('a')+i))
            break
    


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    s=input()
    zyx="zyxwvutsrqponmlkjihgfedcba"
    if s==zyx:
        print(-1)
        sys.exit()
    ss=set(s)
    if len(ss)==26:
        for sx in zyx:
            print(s,sx)
            sxi=s.index(sx)
            if sxi!=0:
                s=s[:sxi-1]+chr(ord(s[sxi-1])+1)
                break
    else:
        for i in range(26):
            if chr(ord('a')+i) in s:
                continue
            print(s+chr(ord('a')+i))
            break
    
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = str(input())
alp = "abcdefghijklmnopqrstuvwxyz"
s = len(S)
for i in range(s):
  alp = alp.replace(S[i],'')
if alp != '':
  print(S+alp[0])
  exit()
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    S = "-1"
  else:
    for j in range(s-1,0,-1):
      if S[j] > S[j-1]:
        alp = list(S[j-1:])
        for k in range(len(alp)+1):
          if alp[k] == S[j-1]:
            S = S[:j-1]+alp[k+1]
            print(S)
            exit()
print(S)

Submission status: Wrong Answer

Solution code:
S = str(input())
alp = "abcdefghijklmnopqrstuvwxyz"
s = len(S)
for i in range(s):
  alp = alp.replace(S[i],'')
if alp != '':
  print(S+alp[0])
  exit()
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    S = "-1"
  else:
    for j in range(s-1,0,-1):
      if S[j] > S[j-1]:
        alp = "abcdefghijklmnopqrstuvwxyz"
        for k in range(len(alp)-1):
          if alp[k] == S[j-1]:
            S = S[:j-1]+alp[k+1]
            print(S)
            exit()
print(S)

Submission status: Wrong Answer

Solution code:
S = str(input())
alp = "abcdefghijklmnopqrstuvwxyz"
s = len(S)
for i in range(s):
  alp = alp.replace(S[i],'')
if alp != '':
  print(S+alp[0])
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    S = "-1"
  else:
    for j in range(s-1,0,-1):
      if S[j] > S[j-1]:
        alp = "abcdefghijklmnopqrstuvwxyz"
        for k in range(len(alp)-1):
          if alp[k] == S[j-1]:
            S = S[:j-1]+alp[k+1]
            print(S)
            exit()
print(S)

Submission status: Wrong Answer

Solution code:
s=input()
# アルファベット(a〜z)→数値(1〜26)小文字限定
a2n = lambda c: ord(c) - ord('a') + 1
# 数値(1〜26)→アルファベット(a〜z)
n2a = lambda c: chr(c+64).lower()

if len(s)<26:
  for i in range(1,27):
    if n2a(i) not in s:
      print(s+n2a(i))
      exit()
f=False
for i in range(1,26):
  if a2n(s[-i-1])>a2n(s[-i]):
    continue
  else:
    f=True
    break
if f==False:
  print(-1)
  exit()
ans=s[:-i-1]+s[-1]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    for i in range(len(s) - 1, 0, -1):
        if s[i] > s[i - 1]:
            s = list(s)
            s = s[: i - 1] + [min(s[i:])]
            print(''.join(s))
            sys.exit()
            break
    print(-1)
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in d:
        if d[i] == 0:
            s += chr(i + 97)
            print(s)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    if s == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        ind = len(s)
        for i in range(len(s) - 1, 0, -1):
            if s[i] > s[i - 1]:
                ind = i - 1
                break
        s = list(s)
        s = s[: i - 1] + [min(s[i:])]
        print(''.join(s))
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in d:
        if d[i] == 0:
            s += chr(i+97)
            print(s)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
if len(s) == 26:
    for i in range(len(s)-1, -1, -1):
        for j in range(len(s) - 1, -1, -1):
            sc = s
            sc = list(sc)
            tmp = sc[i]
            sc[i] = sc[j]
            sc[j] = tmp
            sc = ''.join(sc)
            if sc > s:
                print(sc)
                sys.exit()
    print(-1)
    sys.exit()
else:
    d = {}
    for i in range(26):
        d.update({i: 0})
    for si in s:
        d[ord(si) - 97] += 1
    for i in d:
        if d[i] == 0:
            s += chr(i+97)
            print(s)
            sys.exit()