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()
alp = 'abcdefghijklmnopqrstuvwxyz'
if len(s) < 26:
    for a in alp:
        if a not in s:
            print(s + a)
            exit()
else:
    for i in range(25, 0, -1):
        if s[i - 1] < s[i]:
            for j in range(i, 26):
                if s[i - 1] < s[j]:
                    c = s[j]
            print(s[:i-1] + c)
            exit()

Submission status: Wrong Answer

Solution code:
import string
import sys

S = list(input())
l = [x for x in string.ascii_lowercase]


if len(S) == 26:
  if ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
      print(-1)
  else:
    for i in range(1,len(S)):
      if S[-i]>S[-(i+1)]:
        if i==len(S)-1:
          print(S[-i])
          sys.exit()
        a=''.join(S[:-(i+1)])+S[-i]
        b=''.join(S[:-(i+1)])+S[-1]
        if b<a:
          a,b=b,a
        if ''.join(S)<a:
          print(a)
        else:
          print(b)
        sys.exit()
      else:
        continue
else:
  for s in S:
    l.pop(l.index(s))
  else:
    print(''.join(S)+l[0])

Submission status: Wrong Answer

Solution code:
import string
import sys

S = list(input())
l = [x for x in string.ascii_lowercase]


if len(S) == 26:
  if ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
      print(-1)
  else:
    for i in range(1,len(S)):
      if S[-i]>S[-(i+1)]:
        if i==len(S)-1:
          print(S[-i])
          sys.exit()
        print(''.join(S[:-(i+1)])+S[-1])
        sys.exit()
      else:
        continue
else:
  for s in S:
    l.pop(l.index(s))
  else:
    print(''.join(S)+l[0])

Submission status: Wrong Answer

Solution code:
import string
import sys

S = list(input())
l = [x for x in string.ascii_lowercase]


if len(S) == 26:
  if ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
      print(-1)
  else:
    for i in range(1,len(S)):
      if S[-i]>S[-(i+1)]:
        print(''.join(S[:-(i+1)])+S[-1])
        sys.exit()
      else:
        continue
else:
  for s in S:
    l.pop(l.index(s))
  else:
    print(''.join(S)+l[0])

Submission status: Wrong Answer

Solution code:
import string
import sys

S = list(input())
l = [x for x in string.ascii_lowercase]


if len(S) == 26:
  if ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
      print(-1)
  else:
    for i in range(len(S)-1):
      if S[-i]>S[-(i+1)]:
        print(''.join(S[:-(i+1)])+S[-1])
        sys.exit()
      else:
        continue
else:
  for s in S:
    l.pop(l.index(s))
  else:
    print(''.join(S)+l[0])

Submission status: Wrong Answer

Solution code:
import string
import sys

S = list(input())
l = [x for x in string.ascii_lowercase]


if len(S) == 26:
  if S == 'zyxwvutsrqponmlkjihgfedcba':
      print(-1)
  else:
    for i in range(len(S)-1):
      if S[-i]>S[-(i+1)]:
        print(''.join(S[:-(i+1)])+S[-1])
        sys.exit()
      else:
        continue
else:
  for s in S:
    l.pop(l.index(s))
  else:
    print(''.join(S)+l[0])

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)

vari=[0]*26
al = [chr(ord('a') + i) for i in range(26)]
for i in range(N):
    for j in range(26):
        if S[i] == al[j]:
            vari[j] = 1
# print('N,vari:',N,vari)

if N ==26:
    out=-1
else:
    for j in range(26):
        if vari[j]==0:
            S.append(al[j])
            out=''.join(S)
            break
print(out)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = list(input())
    for i1 in range(26):
        if chr(97 + i1) not in s:
            print("".join(s + [chr(97 + i1)]))
            sys.exit()
    print(-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S=input()
l='abcdefghijklmnopqrstuvwxyz'
P=[]
if S==l[::-1]:
    print(-1)
else:
    ans=''
    if len(S)<26:
        for i in range(26):
            if l[i] not in S:
                ans=S+l[i]
                print(ans)
                break
    else:
        m=S[::-1]
        x=m[0]
        for i in range(26):
            if x>m[i]:
                u=m[i]
                for j in S:
                    if j==u:
                        break
                    else:
                        ans+=j
                for j in l:
                    if j not in ans and j!=u:
                        ans+=j
                        print(ans)
                        exit()
                break
            else:
                x=m[i]

Submission status: Wrong Answer

Solution code:
S=input()
l='abcdefghijklmnopqrstuvwxyz'
P=[]
if S==l[::-1]:
    print(-1)
else:
    ans=''
    if len(S)<26:
        for i in range(26):
            if l[i] not in S:
                ans=S+l[i]
                print(ans)
                break
    else:
        m=S[::-1]
        x=m[0]
        for i in range(26):
            if x>m[i]:
                u=m[i]
                for j in S:
                    if j==u:
                        break
                    else:
                        ans+=j
                for j in l:
                    if j not in ans and j!=u:
                        ans+=j
                        print(ans)
                        exit()
            else:
                x=m[i]

Submission status: Wrong Answer

Solution code:
S=input()
alpha='abcdefghijklmnopqrstuvwxyz'
ans=''
P=[]
for i in range(26):
    P.append([alpha[i],1])


cnt=0
if len(S)==26:
    l=[]
    poe=S[::-1]
    for i in range(25):
        if poe[i]<poe[i+1]:
            cnt+=1
            l.append(poe[i])
        else:
            if len(l)>0:
                ans=poe[:i+1:-1]+min(l)
            else:
                pue=poe[0]
                ans=S[:24]+pue
            break
    if cnt==25:
        ans='-1'
else:
    for i in range(len(S)):
        for j in range(26):
            if S[i]==P[j][0]:
                P[j][1]=0
        for i in range(26):
            if P[i][1]==1:
                ans=S+P[i][0]
                break

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
data='abcdefghijklmnopqrstuvwxyz'
if len(s)!=26:
  for i in range(26):
    if data[i] not in s:
      print(s+data[i])
      exit()
else:
  i=0
  while s[25-i]<s[24-i]:
    i+=1
  print(s[:24-i]+s[-1])
  exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s=input()
if s=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
  exit()
data='abcdefghijklmnopqrstuvwxyz'
if len(s)!=26:
  for i in range(26):
    if data[i] not in s:
      print(s+data[i])
      exit()
else:
  i=0
  while s[25-i]<s[24-i]:
    i+=1
  print(s[:24-i]+s[-1])

Submission status: Wrong Answer

Solution code:
S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) < 26:
    for i in range(97,123):
        k = chr(i)
        f = False
        for s in S:
            if s == k:
                f = True
                break
        if f:
            continue
        print(S+k)
        exit()
for i in range(25,-1,-1):
    if S[0:i] +S[-1]> S:
        print(S[0:i]+S[-1])
        exit()

Submission status: Wrong Answer

Solution code:
S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) < 26:
    for i in range(97,123):
        k = chr(i)
        f = False
        for s in S:
            if s == k:
                f = True
                break
        if f:
            continue
        print(S+k)
        exit()
idx = []
for s in S:
    idx.append(ord(s))
for i in range(-2,-27,-1):
    if idx[i] +1 > 122:
        continue
    if  not idx[i]+1 in idx[:i]:
        for j in idx[:i]:
            print(chr(j), end = '')
        print(chr(idx[i]+1))
        exit()

Submission status: Wrong Answer

Solution code:
S = input()
if len(S) == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) < 26:
    for i in range(97,123):
        k = chr(i)
        f = False
        for s in S:
            if s == k:
                f = True
                break
        if f:
            continue
        print(S+k)
        exit()
idx = []
for s in S:
    idx.append(ord(s))
for i in range(-2,-27,-1):
    if idx[i] +1 > 122:
        continue
    if  not idx[i]+1 in idx[:i]:
        for j in idx[:i]:
            print(chr(j), end = '')
        print(chr(idx[i]+1))
        exit()

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
if s=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
  exit()
d={'a':0,'b':0,'c':0,'d':0,'e':0,'f':0,'g':0,'h':0,'i':0,'j':0,'k':0,'l':0,'m':0,'n':0,'o':0,'p':0,'q':0,'r':0,'s':0,'t':0,'u':0,'v':0,'w':0,'x':0,'y':0,'z':0}
for i in range(n):
  d[s[i]]=1
if n!=26:
  for j in d:
    if d[j]==0:
      print(s+j)
      exit()
else:
  d[s[n-1]]=0
  i=1
  ans=s[n-1]
  for l in range(1,n):
    if s[n-1-l]>s[n-l]:
      d[s[n-l-1]]=0
      i+=1
    else:
      break
  print(s[:n-i-1]+s[n-1])
  exit()

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
if s=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
  exit()
d={'a':0,'b':0,'c':0,'d':0,'e':0,'f':0,'g':0,'h':0,'i':0,'j':0,'k':0,'l':0,'m':0,'n':0,'o':0,'p':0,'q':0,'r':0,'s':0,'t':0,'u':0,'v':0,'w':0,'x':0,'y':0,'z':0}
for i in range(n):
  d[s[i]]=1
if n!=26:
  for j in d:
    if d[j]==0:
      print(s+j)
      exit()
else:
  res=s[n-1]
  d[s[n-1]]=0
  i=1
  ans=s[n-1]
  for l in range(1,n):
    if s[n-1-l]>s[n-l]:
      res=s[n-l-1]
      d[s[n-l-1]]=0
      i+=1
    else:
      break
  print(s[:n-i-1]+s[n-1])
  exit()

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
s=input()
res=[0]*26
n=len(s)
if n!=26:
    for c in s:
        res[ord(c)-ord('a')]=1
    for i in range(26):
        if res[i]==0:
            ans=i
            break
    print(s+chr(ans+ord('a')))
else:
    s=list(s)
    res=[]
    for i in range(n-1):
        if ord(s[n-1-i])-ord(s[n-2-i])>0:
            idx=ord(s[n-2-i])
            res.sort()
            if not res:
              s[n-1-i],s[n-2-i]=s[n-2-i],s[n-1-i]
              print("".join(s))
              exit()
            ch=bisect.bisect_right(res,idx)
            if ch==len(res):
                res=[chr(i) for i in res]
                res.append(s[n-2-i])
                ans=[]
                for j in range(n):
                    if j!=n-2-i:
                        ans.append(s[j])
                    else:
                        ans.append(s[n-1-i])
                        break
                print(''.join(ans))
            else:
                minc=chr(res[ch])
                ans=[]
                for j in range(n):
                    if j!=n-2-i:
                        ans.append(s[j])
                    else:
                        ans.append(minc)
                        break
                print(''.join(ans))
            break
        else:
            res.append(ord(s[n-1-i]))
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
s=input()
res=[0]*26
n=len(s)
if n!=26:
    for c in s:
        res[ord(c)-ord('a')]=1
    for i in range(26):
        if res[i]==0:
            ans=i
            break
    print(s+chr(ans+ord('a')))
else:
    s=list(s)
    res=[]
    for i in range(n-1):
        if ord(s[n-1-i])-ord(s[n-2-i])>0:
            idx=ord(s[n-2-i])
            res.sort()
            if not res:
              s[n-1-i],s[n-2-i]=s[n-2-i],s[n-1-i]
              print("".join(s))
              exit()
            ch=bisect.bisect_right(res,idx)
            if ch==len(res):
                res=[chr(i) for i in res]
                res.append(s[n-2-i])
                ans=[]
                for j in range(n):
                    if j!=n-2-i:
                        ans.append(s[j])
                    else:
                        ans.append(s[n-1-i])
                        break
                print(''.join(ans)+''.join(res))
            else:
                minc=chr(res[ch])
                ans=[]
                for j in range(n):
                    if j!=n-2-i:
                        ans.append(s[j])
                    else:
                        ans.append(minc)
                        break
                print(''.join(ans))
            break
        else:
            res.append(ord(s[n-1-i]))
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
s=input()
res=[0]*26
n=len(s)
if n!=26:
    for c in s:
        res[ord(c)-ord('a')]=1
    for i in range(26):
        if res[i]==0:
            ans=i
            break
    print(s+chr(ans+ord('a')))
else:
    s=list(s)
    res=[]
    for i in range(n-1):
        if ord(s[n-1-i])-ord(s[n-2-i])>0:
            idx=ord(s[n-2-i])
            res.sort()
            if not res:
              s[n-1-i],s[n-2-i]=s[n-2-i],s[n-1-i]
              print("".join(s))
              exit()
            ch=bisect.bisect_right(res,idx)
            if ch!=0:
                res=[chr(i) for i in res]
                res.append(s[n-2-i])
                ans=[]
                for j in range(n):
                    if j!=n-2-i:
                        ans.append(s[j])
                    else:
                        ans.append(s[n-1-i])
                        break
                print(''.join(ans)+''.join(res))
            else:
                minc=chr(res[0])
                ans=[]
                for j in range(n):
                    if j!=n-2-i:
                        ans.append(s[j])
                    else:
                        ans.append(minc)
                        break
                print(''.join(ans))
            break
        else:
            res.append(ord(s[n-1-i]))
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
s=input()
res=[0]*26
n=len(s)
if n!=26:
    for c in s:
        res[ord(c)-ord('a')]=1
    for i in range(26):
        if res[i]==0:
            ans=i
            break
    print(s+chr(ans+ord('a')))
else:
    s=list(s)
    res=[]
    for i in range(n-1):
        if ord(s[n-1-i])-ord(s[n-2-i])>0:
            idx=ord(s[n-1-i])
            res.sort()
            ch=bisect.bisect_right(res,idx)
            if ch==0:
                print(''.join(s))
            else:
                minc=chr(res[0])
                ans=[]
                for j in range(n):
                    if j!=n-2-i:
                        ans.append(s[j])
                    else:
                        ans.append(minc)
                        break
                print(''.join(ans))
            break
        else:
            res.append(ord(s[n-1-i]))
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
s=input()
ch={chr(i):0 for i in range(ord('a'),ord('z')+1)}
res=[0]*26
n=len(s)
if n!=26:
    for c in s:
        res[ord(c)-ord('a')]=1
    for i in range(26):
        if res[i]==0:
            ans=i
            break
    print(s+chr(ans+ord('a')))
else:
    s=list(s)
    for i in range(n-1):
        if ord(s[n-1-i])-ord(s[n-2-i])>0:
            s[n-1-i],s[n-2-i]=s[n-2-i],s[n-1-i]
            print(''.join(s))
            break
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
d_memo = [chr(i) for i in range(97, 97+26)]
s_memo = set(list(s))

def next_c(sub_s, b_c):
    c = None
    for d in d_memo:
        if d not in set(list(sub_s)):
            if d > b_c:
                c = d
                break
    return c

if len(s) < len(d_memo):
    c = next_c(s, '')
    ans = s+c
else:
    b_c = ''
    ans = None
    for i in range(len(s)):
        c = next_c(s[:len(s)-i], b_c)
        if c is not None:
            ans = s[:len(s)-i]+c
            break
        else:
            b_c = s[len(s)-i-1]
if ans is None:
    print('-1')
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
d_memo = [chr(i) for i in range(97, 97+26)]
s_memo = set(list(s))

def next_c(sub_s, b_c):
    c = None
    for d in d_memo:
        if d not in set(list(sub_s)):
            if d > b_c:
                c = d
                break
    return c

if len(s) < len(d_memo):
    ans = s+next_c(s, '')
else:
    b_c = ''
    ans = None
    for i in range(len(s)):
        c = next_c(s[:len(s)-i], b_c)
        if c is not None:
            ans = s[:len(s)-i]+c
            break
        else:
            b_c = s[len(s)-i-1]
if ans is None:
    print('-1')
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
d_memo = [chr(i) for i in range(97, 97+26)]
s_memo = set(list(s))

def next_c(sub_s, b_c):
    c = None
    for d in d_memo:
        if d not in set(list(sub_s)):
            if d > b_c:
                c = d
                break
    return c
b_c = ''
ans = None
for i in range(len(s)):
    c = next_c(s[:len(s)-i], b_c)
    if c is not None:
        ans = s[:len(s)-i]+c
        break
    else:
        b_c = s[len(s)-i-1]

if ans is None:
    print('-1')
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    if len(s)<26:
        for char in string.ascii_lowercase:
            if char not in s:
                print(s+char)
                break
    else:
        for i in range(25, -1, -1):
            ex = s[i:]
            late = list(ex)
            late.sort(reverse=True)
            late = "".join(late)
            if ex != late:
                index = string.ascii_lowercase.index(s[i])
                ans = s[:i] + string.ascii_lowercase[index+1]
                print(ans)
                break
        else:
            print(-1)
    

main()

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    for char in string.ascii_lowercase:
        if char not in s:
            print(s+char)
            break
    else:
        print(-1)
main()

Submission status: Wrong Answer

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    S = input()
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        return

    l = [0]*26
    for c in S:
        l[ord(c)-ord('a')] += 1

    if len(S) < 26:
        i = l.index(0)
        print(S+chr(i+ord('a')))
        return

    for i in range(len(S)-1, 0, -1):
        if S[i-1] < S[i]:
            break

    c = min(S[i:])
    print(S[:i-1]+c)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    S = input()
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        return

    l = [0]*26
    for c in S:
        l[ord(c)-ord('a')] += 1

    if len(S) < 26:
        i = l.index(0)
        print(S+chr(i+ord('a')))
        return

    for i in range(len(S)-1):
        if S[i] > S[i+1]:
            break

    c = min(S[i+1:])
    print(S[:i-1]+c)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = list(input())
m = list('zyxwvutsrqponmlkjihgfedcba')
if len(s) < 26:
    for i in m[::-1]:
        if not i in s:
            s.append(i)
            break
    print(''.join(s))
else:
    x = s[-1]

    for i in range(25)[::-1]:
        if x > s[i]:
            y = m.index(s[i]) - 1
            s = s[:i]
            s.append(m[y])
            break
        else:
            x = s[i]
        if i == 0:
            print(-1)
            exit(0)
    print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
m = list('zyxwvutsrqponmlkjihgfedcba')
if len(s) < 26:
    for i in m[::-1]:
        if not i in s:
            s.append(i)
            break
    print(''.join(s))
else:
    x = s[-1]
    for i in range(25)[::-1]:
        if x > s[i]:
            s = s[:i]
            s.append(x)
            break
        if i == 0:
            print(-1)
            exit(0)
    print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
m = list('zyxwvutsrqponmlkjihgfedcba')
if len(s) < 26:
    for i in m[::-1]:
        if not i in s:
            s.append(i)
            break
    print(''.join(s))
else:
    if s == m:
        print(-1)
    else:
        x = s[-1]
        for i in range(25)[::-1]:
            if x > s[i]:
                s = s[:i]
                s.append(x)
                break
            if i == 0:
                z = m.index(s[0])
                s = m[z-1]
                break
        print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = input(); a = []; b = [0]*27; t = ""
for i in range(len(s)): a.append(ord(s[i])); b[a[i]-97] = 1
if s == "zyxwvutsrqponmlkjihgfedcba": print(-1)
else:
    for i in range(27):
        if b[i] == 0: c = i; break
    if c != 26:
        a.append(c+97)
        for i in range(len(a)): t += chr(a[i])
        print(t)
    else:
        d = a[-1]
        for _ in range(25):
            if a[-2] > a[-1]: a.pop()
            else: a.pop(); a.pop(); a.append(d); break
        for i in range(len(a)): t += chr(a[i])
        print(t)

Submission status: Wrong Answer

Solution code:
S = input()
if len(S) == 26:
    done = set()
    for i, s in enumerate(S[::-1]):
        s = ord(s)
        if done:
            if max(done) < s:
                done.add(s)
                if i == 25:
                    print(-1)
            elif i != 25:
                print(S[: -(i + 1)] + chr(min(done)))
                break
            else:
                print(chr(ord(S[0]) + 1))
        else:
            done.add(s)
else:
    for i in range(ord("a"), ord("z") + 1):
        if not (chr(i) in S):
            print(S + chr(i))
            break

Submission status: Wrong Answer

Solution code:
S = input()
if len(S) == 26:
    done = set()
    for i, s in enumerate(S[::-1]):
        s = ord(s)
        if done:
            if max(done) < s:
                done.add(s)
            else:
                print(S[: -(i + 1)] + chr(min(done)))
                break
        else:
            done.add(s)
        if i == 25:
            print(-1)
else:
    for i in range(ord("a"), ord("z") + 1):
        if not (chr(i) in S):
            print(S + chr(i))
            break

Submission status: Wrong Answer

Solution code:
import bisect
S = input()
L = list(map(ord, S))
if len(S) == 26:
    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        pre = [L[-1], ]
        for i, l in enumerate(L[-2::-1]):
            if min(pre) > l:
                x = bisect.bisect(pre, l)
                print(S[: -(i + 2)] + chr(min(pre)))
                break
            bisect.insort(pre, l)
else:
    t = min(L)
    for i in range(30):
        if not (t in L):
            break
        t += 1
    print(S + chr(t))

Submission status: Wrong Answer

Solution code:
import bisect
S = input()
L = list(map(ord, S))
if len(S) == 26:
    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        pre = [L[-1], ]
        for i, l in enumerate(L[-2::-1]):
            if min(pre) < l:
                x = bisect.bisect(pre, l)
                print(S[: -(i + 2)] + chr(min(pre)))
                break
            bisect.insort(pre, l)
else:
    t = min(L)
    for i in range(30):
        if not (t in L):
            break
        t += 1
    print(S + chr(t))

Submission status: Wrong Answer

Solution code:
s = list(input())
m = list('zyxwvuutsrqponmlkjihgfedcba')
if len(s) < 26:
    for _ in m:
        if not _ in s:
            s.append(_)
            break
    print(''.join(s))
else:
    if s == m:
        print(-1)
    else:
        x = s[-1]
        for _ in range(25)[::-1]:
            if x > s[_]:
                s = s[:_]
                s.append(x)
                break
        print(''.join(s))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc022/tasks/agc022_a

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    if len(S) < 26:
        for i in range(ord("a"), ord("z") + 1):
            if chr(i) not in S:
                print(S + chr(i))
                return
    elif len(S) == 26:
        for i in range(25)[::-1]:
            c = S[i]
            ss = S[:i]
            for j in range(ord(c) + 1, ord("z") + 1):
                cc = chr(j)
                if cc not in ss:
                    print(ss + cc)
                    return

    print(-1)

    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
for c in "abcdefghijklmnopqrstuvwxyz":
    if c not in S:
        print(S + c)
        exit()

for i in range(N - 1, -1, -1):
    nxt = ord(S[i]) - ord("a") + 1
    if nxt >= 26:
        continue
    nxt_c = chr(nxt + ord("a"))
    if nxt_c in S[:i]:
        continue
    print(S[:i] + nxt_c)
    break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
S=input()

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

    for j in range(b+1,26):
        if not A[j] in S[:i]:
            print(S[:i]+A[b+1])
            break

Submission status: Wrong Answer

Solution code:
S=input()

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

Submission status: Wrong Answer

Solution code:
S=input()

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

Submission status: Wrong Answer

Solution code:
S=input()

A="abcdefghijklmnopqrstuvwxyz"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(S)!=26:
    A=list(A)
    for i in range(len(S)):
        A.remove(S[i])
    print(S+A[0])
else:
    for i in range(25,-1,-1):
        if S[i]=='z':
            continue
        ind=A.index(S[i])
        if not A[ind+1] in S[:i]:
            break
    print(S[:i]+A[ind+1])

Submission status: Wrong Answer

Solution code:
S=input()

A="abcdefghijklmnopqrstuvwxyz"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(S)!=26:
    A=list(A)
    for i in range(len(S)):
        A.remove(S[i])
    print(S+A[0])
else:
    for i in range(26):
        if A[i]!=S[i]:
            break
    if S[i]=='z':
        print(S[:i-1]+A[i])
    else:
        x=S[i]
        ind=A.index(S[i])
        print(S[:i]+A[ind+1])

Submission status: Wrong Answer

Solution code:
S=input()

A="abcdefghijklmnopqrstuvwxyz"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(S)!=26:
    A=list(A)
    for i in range(len(S)):
        A.remove(S[i])
    print(S+A[0])
else:
    for i in range(26):
        if A[i]!=S[i]:
            break
    if S[i]=='z':
        print(S[:i-1]+A[i])
    else:
        print(S[:i]+A[i])