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, = map(chr, range(97, 123))
c = set(s)
if len(c) != 26:
    x = sorted(set(alp) - c)[0]
    print(s+x)
else:
    z_idx = s.index("z")
    last_idx = z_idx
    cnt = 0
    for j in range(26-z_idx):
        if s[z_idx+j] == alp[::-1][j]:
            last_idx = z_idx+j
            cnt += 1
            continue
        break

    if cnt == 26:
        print(-1)
    elif last_idx == 25:
        next_idx = alp.index(s[z_idx-1])+1
        print(s[:z_idx-1]+alp[next_idx])
    else:
        ans = s[:last_idx+1]
        tmp = list(s[last_idx+1:])
        loop = len(tmp)-1
        prev = "a"
        for i in range(loop):
            a, b, *c = tmp[::-1]
            if prev > b:
                tmp.pop()
                tp = tmp.pop()
                tmp.append(prev)
                prev = tp
                continue
            elif a > b:
                tmp.pop()
                prev = tmp.pop()
                tmp.append(a)
                continue
            else:
                tmp.pop()
                continue
        print(ans+tmp[0])

Submission status: Wrong Answer

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

def solve(S: str):
    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return

    if len(S) < 26:
        res = sorted(list(set("zyxwvutsrqponmlkjihgfedcba")-set(S)))
        print(S+res[0])
    else:
        prev = None
        for i in range(25,-1,-1):
            if prev == None or prev < S[i]:
                prev = S[i]
                continue
            else:
                res = sorted(list(set("zyxwvutsrqponmlkjihgfedcba")-set(S[:i+1])))
                print(S[:i]+res[0])
                return


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
alpha = set("abcdefghijklmnopqrstuvqxyz")
S = input()
S_set = set(S)
can_use = alpha - S_set
if can_use:
    print(S + sorted(list(can_use))[0])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
invalpha = "zyxwvutsrqponmlkjihgfedcba"
D = {alpha[i]: i for i in range(26)}
E = [0 for i in range(26)]

for i in range(len(S)):
  E[D[S[i]]] = 1
if min(E) == 0:
  for m in range(26):
    if E[m] == 0:
      S = S[:] + alpha[m]
      break
  print(S)
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
else:
  p = 26
  for i in range(25, 0, -1):
    if D[S[i]] < D[S[i-1]]:
      p = i
    else:
      break
  m = D[S[p-2]]
  L = []
  for x in range(p, 26):
    if D[S[x]] >= m + 1:
      L.append(S[x])
  L.sort()
  if L != []:
    S = S[:p-2] + L[0]
  else:
    S = S[:p-2] + 'z'
  print(S)

Submission status: Wrong Answer

Solution code:
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
invalpha = "zyxwvutsrqponmlkjihgfedcba"
D = {alpha[i]: i for i in range(26)}
E = [0 for i in range(26)]
def sugar(s):
  n = len(s)
  q = 0
  for i in range(n):
    if s[i] == 'z':
      q = i
  return i

for i in range(len(S)):
  E[D[S[i]]] = 1
if min(E) == 0:
  for m in range(26):
    if E[m] == 0:
      S = S[:] + alpha[m]
      break
  print(S)
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
else:
  p = 26
  for i in range(25, 0, -1):
    if D[S[i]] < D[S[i-1]]:
      p = i
    else:
      break
  S = S[:p-2] + S[p-1]
  print(S)

Submission status: Wrong Answer

Solution code:
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
invalpha = "zyxwvutsrqponmlkjihgfedcba"
D = {alpha[i]: i for i in range(26)}
E = [0 for i in range(26)]
def sugar(s):
  n = len(s)
  q = 0
  for i in range(n):
    if s[i] == 'z':
      q = i
  return i

for i in range(len(S)):
  E[D[S[i]]] = 1
if min(E) == 0:
  for m in range(26):
    if E[m] == 0:
      S = S[:] + alpha[m]
      break
  print(S)
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
else:
  p = 26
  for i in range(25, 0, -1):
    if D[S[i]] < D[S[i-1]]:
      p = i
    else:
      break
  S = S[:p-2] + S[25]
  print(S)

Submission status: Wrong Answer

Solution code:
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
if len(s)!=26:
    print(s+sorted(list(set(list("zyxwvutsrqponmlkjihgfedcba"))-set(list(s))))[0])
else:
    des=set()
    l=list(s)
    while True:
        pre=l.pop()
        if l[-1]< pre:break
    print("".join(l[:-1])+chr(ord(l[-1])+1))

Submission status: Wrong Answer

Solution code:
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
if len(s)!=26:
    print(s+sorted(list(set(list("zyxwvutsrqponmlkjihgfedcba"))-set(list(s))))[0])
else:
    des=set()
    l=list(s)
    pre=s[-1]
    while chr(ord(pre)+1) not in des:
        pre=l.pop()
        des.add(pre)
    print("".join(l)+chr(ord(pre)+1))

Submission status: Wrong Answer

Solution code:
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
if len(s)!=26:
    print(s+sorted(list(set(list("zyxwvutsrqponmlkjihgfedcba"))-set(list(s))))[0])
else:
    des=set()
    l=list(s)
    pre=s[-1]
    while chr(ord(pre)+1) not in des:
        pre=l.pop()
        des.add(pre)
    q=sorted(list(des))
    print("".join(l)+q[q.index(pre)+1])

Submission status: Wrong Answer

Solution code:
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
if len(s)!=26:
    print(s+sorted(list(set(list("zyxwvutsrqponmlkjihgfedcba"))-set(list(s))))[0])
else:
    des=set()
    l=list(s)
    pre=s[-1]
    while chr(ord(pre)+1) not in des:
        pre=l.pop()
        des.add(pre)
    print("".join(l)+sorted(list(des))[1])

Submission status: Wrong Answer

Solution code:
s=input()
ans=''
err1=1

def nxt_str(string, lust_s):
	l_s=list(string)
	err=1
	for s1 in range(ord(lust_s)+1, ord('z')+1):
		if chr(s1) not in l_s:
			ans = string + chr(s1)
			err = 0
			break
	if err == 0:
		return ans
	else:
		return False


if len(s)==26:
	for i in range(1,27):
		judge = nxt_str(s[:-i], s[-i])
		if judge != False:
			print(judge)
			err1=0
			break
else:
	judge = nxt_str(s, 'a')
	if judge != False:
		print(judge)
		err1=0

if err1==1:
	print(-1)

Submission status: Wrong Answer

Solution code:
s=input()
ans=''
err1=1

def nxt_str(string, lust_s):
	l_s=list(string)
	err=1
	for s1 in range(ord(lust_s)+1, ord('z')+1):
		if chr(s1) not in l_s:
			ans = string + chr(s1)
			err = 0
			break
	if err == 0:
		return ans
	else:
		return False


if len(s)==26:
	for i in range(1,26):
		judge = nxt_str(s[:-i], s[-i])
		if judge != False:
			print(judge)
			err1=0
			break
else:
	judge = nxt_str(s, 'a')
	if judge != False:
		print(judge)
		err1=0

if err1==1:
	print(-1)

Submission status: Wrong Answer

Solution code:
s=input()
ans=''
err1=1

def nxt_str(string, lust_s):
	l_s=list(string)
	err=1
	for s1 in range(ord(lust_s)+1, ord('z')+1):
		if chr(s1) not in l_s:
			ans = string + chr(s1)
			err = 0
			break
	if err == 0:
		return ans
	else:
		return False


if len(s)==26:
	for i in range(1,len(s)+1):
		judge = nxt_str(s[:-i], s[-i])
		if judge != False:
			print(judge)
			err1=0
			break
else:
	judge = nxt_str(s, 'a')
	if judge != False:
		print(judge)
		err1=0

if err1==1:
	print(-1)

Submission status: Wrong Answer

Solution code:
s=input()
ans=''
err=1
s_set=set(list(s))
if len(s_set)==26:
	for s1 in range(ord(s[-1]), ord('z')+1):
		if chr(s1) not in s_set:
			ans=s[:-1]+chr(s1)
			err=0
			break
	if err == 1:
		print(-1)
	else:
		print(ans)
else:
	for i in range(ord('a'),ord('z')+1):
		if chr(i) not in s_set:
			ans=s+chr(i)
			print(ans)
			break

Submission status: Wrong Answer

Solution code:
S=input()
M="zyxwvutsrqponmlkjihgfedcba"
if S==M:
    print(-1)
    exit()
l=[]
for i in range(len(S)):
    l.append(S[i])
for i in range(97,123):
    s=chr(i)
    if s in l:
        continue
    else:
        l.append(s)
        break
if len(l)==len(S):
    for i in range(len(S)):
        if S[i]=="z":
            idx=i
            break
    if idx==(len(S)-1):
        ans=""
        for i in range(len(S)-2):
            ans=ans+S[i]
        t=ord(S[len(S)-2])
        ans=ans+chr(t+1)
    else:
        """
        tmp=124
        for i in range(idx,len(S)):
            t=ord(S[i])
            tmp=min(t,tmp)
        ans=""
        for i in range(idx):
            ans=ans+S[i]
        ans=ans+chr(tmp)
    print(ans)
        """
        ans=""
        r=[]
        r.append(S[idx-1])
        for i in range(idx-1):
            ans=ans+S[i]
            r.append(S[i])
        for i in range(97,123):
            if chr(i) in r:
                continue
            else:
                ans=ans+chr(i)
                break
    print(ans)
else:
    ans=""
    for i in range(len(l)):
        ans=ans+l[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s = [i for i in input()]
if len(s) < 26:
    e = "a"
    c = collections.Counter(s)
    for _ in range(26):
        if e not in c.keys():
            print("".join(s) + e)
            exit()
        else: e = chr(ord(e) + 1)
if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
e = s[-1]
l = [e]
for i in reversed(range(25)):
    s_ = s[:i]
    li = min(l)
    if "".join(s_) + li > "".join(s[:i+1]):
        print("".join(s_) + li)
        exit()
    else: l.append(s[i+1])
print(-1)

Submission status: Wrong Answer

Solution code:
import collections
s = [i for i in input()]
if len(s) < 26:
    c = collections.Counter(s)
    e = "a"
    while True:
        if e not in c.keys():
            print("".join(s) + e)
            exit()
        else: e = chr(ord(e) + 1)
else:
    if s[0] == "a":
        for i in range(len(s)-1):
            if s[i+1] == chr(ord(s[i]) + 1):
                continue
            else:
                print("".join(s[:i]) + chr(ord(s[i])+1))
                exit()
    elif s[0] == "z":
        for i in range(len(s)-1):
            if s[i+1] == chr(ord(s[i]) - 1):
                continue
            else:
                print("".join(s[:i+1]) + chr(ord(s[i+1]) + 1))
                exit()
    else:
        print(chr(ord(s[0])+1))
        exit()
    print(-1)

Submission status: Wrong Answer

Solution code:
S=input()
A=[chr(ord('a') + i) for i in range(26)]
if S=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
else:
  if len(S)<26:
    for i in A:
      if str(i) not in S:
        print(S+str(i))
        exit()
  else:
    G=[]
    for i in range(26):
      G.append(S[25-i])
      G=sorted(G)        
      if len(G)>1 and S[25-i]!=G[-1]:
        print(S[:25-i]+G[-1])
        exit()

Submission status: Wrong Answer

Solution code:
S=input()
A=[chr(ord('a') + i) for i in range(26)]
if S=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
else:
  if len(S)<26:
    for i in A:
      if str(i) not in S:
        print(S+str(i))
        exit()
  else:
    G=[]
    for i in range(26):
      G.append(S[25-i])
      G=sorted(G)
      if len(G)>1 and S[25-i]==G[0]:
        print(S[:25-i]+G[1])
        exit()

Submission status: Wrong Answer

Solution code:
S=input()
A=[chr(ord('a') + i) for i in range(26)]
if S=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
else:
  if len(S)<26:
    for i in A:
      if str(i) not in S:
        print(S+str(i))
        exit()
  else:
    G=[]
    for i in range(26):      
      if S[25-i]!=A[25-i]:
        G.append(S[25-i])
        G=sorted(G)
        if len(G)>1 and S[25-i]==G[0]:
          print(S[:25-i]+G[1])
          exit()

Submission status: Wrong Answer

Solution code:
S=input()
A=[chr(ord('a') + i) for i in range(26)]
if S=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
else:
  if len(S)<26:
    for i in A:
      if str(i) not in S:
        print(S+str(i))
        exit()
  else:
    for i in range(26):
      if S[i]!=A[i]:
        print(S[:i-1]+A[i])
        exit()

Submission status: Wrong Answer

Solution code:
S=input()
alphabet=[chr(i) for i in range(ord('a'),ord('z')+1)]
if len(S)!=26:
    for x in alphabet: 
        if not(x in set(S)):
            flag=1
            break
    ans=S+x
    print(ans)
else:
    s=ord(S[25])
    j=25
    for i in range(24,-1,-1):
        if s<ord(S[i]):
            j=i
            s=ord(S[i])
        else:
            break

    if j==0:
        print(-1)
    else:
        l=S[j-2:]
        y=300
        for x in list(map(ord,l)):
            if ord(S[j-3])<x:
                y=min(y,x)
        ans=S[:j-3]+chr(y)
        print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
alphabet=[chr(i) for i in range(ord('a'),ord('z')+1)]
if len(S)!=26:
    for x in alphabet: 
        if not(x in set(S)):
            flag=1
            break
    ans=S+x
    print(ans)
else:
    inverse_S=list(reversed(S))
    s=ord(inverse_S[0])
    l=[]
    for i in range(26):
        if s>ord(inverse_S[i]):
            break

    if i+1==26:
        print(-1)
    else:
        l=S[-i:]
        y=300
        for x in list(map(ord,l)):
            if ord(S[-(i+1)])<x:
                y=min(y,x)
        ans=S[:-(i+1)]+chr(y)
        print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
alphabet=[chr(i) for i in range(ord('a'),ord('z')+1)]
if len(S)!=26:
    for x in alphabet: 
        if not(x in set(S)):
            flag=1
            break
    ans=S+x
    print(ans)
else:
    inverse_S=list(reversed(S))
    s=ord(inverse_S[0])
    l=[]
    for i in range(1,26):
        if s>ord(inverse_S[i]):
            break

    if i+1==26:
        print(-1)
    else:
        l=S[-(i+1):]
        ans=S[:-(i+1)]+sorted(l)[-1]
        print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
alphabet=[chr(i) for i in range(ord('a'),ord('z')+1)]
flag=0
for x in alphabet: 
    if not(x in set(S)):
        flag=1
        break

if flag==1:
    ans=S+x
    print(ans)
else:
    ans=""
    for x in S:
        if x!='z':
            ans+=x
        else:
            break
    ans=ans[:-1]+sorted(list(set(alphabet)-set(ans)))[0]
    if len(ans)==len(alphabet):
        print(ans)
    else:
        ans=""
        for i in range(len(alphabet)):
            if list(reversed(alphabet))[i]==S[i]:
                ans+=S[i]
            else:
                ans+=chr(ord(S[i])+1)
                break
        if ans!="zyxwvutsrqponmlkjihgfedcba":
            print(ans)
        else:
            print(-1)

Submission status: Wrong Answer

Solution code:
S=input()

alphabet=[chr(i) for i in range(ord('a'),ord('z')+1)]
flag=0
for x in alphabet: 
    if not(x in set(S)):
        flag=1
        break

if flag==1:
    print(S+x)
else:
    ans=""
    for x in S:
        if x!='z':
            ans+=x
        else:
            break
    ans=ans[:-1]+sorted(list(set(alphabet)-set(ans)))[0]
    if len(ans)==len(alphabet):
        print(ans)
    else:
        ans=""
        for i in range(len(alphabet)):
            if list(reversed(alphabet))[i]==S[i]:
                ans+=S[i]
            else:
                ans+=chr(ord(S[i])+1)
                break
        if ans!="zyxwvutsrqponmlkjihgfedcba":
            print(ans)
        else:
            print(-1)

Submission status: Wrong Answer

Solution code:
S=input()

alphabet=[chr(i) for i in range(ord('a'),ord('z')+1)]
flag=0
for x in alphabet: 
    if not(x in set(S)):
        flag=1
        break

if flag==1:
    print(S+x)
else:
    ans=""
    for x in S:
        if x!='z':
            ans+=x
        else:
            break
    ans=ans[:-1]+sorted(list(set(alphabet)-set(ans)))[0]
    print(ans)

Submission status: Wrong Answer

Solution code:
S=input()

alp=[chr(i+97) for i in range(26)]

for item in alp:
    if item not in S:
        print(S+item)
        exit()

if len(S)==26:
    temp=ord(S[-1])
    for i in range(25):
        if ord(S[-i-2])>temp:
            pass
        else:
            print(S[:-i-2]+chr(temp))
            exit()

print(-1)

Submission status: Wrong Answer

Solution code:
def examA():
    S = SI()
    N = len(S)
    if N<26:
        d = defaultdict(bool)
        for s in S:
            d[s] = True
        for a in alphabet:
            if not d[a]:
                ans = S + a
                print(ans)
                return
    keep = []
    for i in range(N-1)[::-1]:
        keep.append(S[i+1])
        if S[i]<S[i+1]:
            break
    #print(keep)
    n = len(keep)
    if n==25:
        print(-1)
        return
    c = "zz"
    for s in keep:
        if s>S[(N-n-1)]:
            c = min(c,s)
    ans = S[:(N-n-1)] + c
    print(ans)
    return

def examB():
    N = I()
    ans = [2*(i+1) for i in range(N)]
    if N%2==0:
        for i in range(4998):
            ans[-3-i] = 3+i*6

    print(" ".join(map(str,ans)))
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()

"""

"""

Submission status: Wrong Answer

Solution code:
def examA():
    S = SI()
    N = len(S)
    if N<26:
        d = defaultdict(bool)
        for s in S:
            d[s] = True
        for a in alphabet:
            if not d[a]:
                ans = S + a
                print(ans)
                return
    keep = []
    for i in range(N-1)[::-1]:
        keep.append(S[i+1])
        if S[i]<S[i+1]:
            break
    #print(keep)
    n = len(keep)
    if n==25:
        print(-1)
        return
    c = "z"
    for s in keep:
        if s>S[(N-n-1)]:
            c = min(c,s)
    ans = S[:(N-n-1)] + c
    print(ans)
    return

def examB():
    N = I()
    ans = [2*(i+1) for i in range(N)]
    if N%2==0:
        for i in range(4998):
            ans[-3-i] = 3+i*6

    print(" ".join(map(str,ans)))
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()

"""

"""

Submission status: Wrong Answer

Solution code:
def examA():
    S = SI()
    N = len(S)
    if N<26:
        d = defaultdict(bool)
        for s in S:
            d[s] = True
        for a in alphabet:
            if not d[a]:
                ans = S + a
                print(ans)
                return
    keep = []
    for i in range(N-1)[::-1]:
        keep.append(S[i+1])
        if S[i]<S[i+1]:
            break
    #print(keep)
    n = len(keep)
    if n==25:
        print(-1)
        return
    ans = S[:(N-n-1)] + min(keep)
    print(ans)
    return

def examB():
    N = I()
    ans = [2*(i+1) for i in range(N)]
    if N%2==0:
        for i in range(4998):
            ans[-3-i] = 3+i*6

    print(" ".join(map(str,ans)))
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()

"""

"""

Submission status: Wrong Answer

Solution code:
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

al=[chr(ord('a') + i) for i in range(26)]
# 出たアルファベットとその場所をチェックする
check =[[0] * 2 for _ in range(26)]
for i in range(len(S)):
    for a in range(26):
        if S[i] == al[a]:
            check[a][0] = 1
            check[a][1] = i
flag = False
for i in range(26):
    if check[i][0] == 0:
        used_al = al[i]
        flag = True
        break
    if i == 25:
        flag = False
if flag:
    print(S + used_al)
else:
    ans = ""
    for i in range(26):
        if S[i] == al[i]:
            ans += al[i]
        else:
            ans = ans[:-1] 
            ans += al[i]
            print(ans)
            exit()
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

if len(s) < 26:
    for i in range(26):
        c = chr(ord('a') + i)
        if not c in s:
            print(s + c)
            exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
else:
    for i in range(len(s)-1):
        if s[i] > s[i+1]:
            for j in range(26):
                c = chr(ord('a') + j)
                if not c in s[:i]:
                    print(s[:i-1] + c)
                    print(exit())

Submission status: Wrong Answer

Solution code:
s = input()

if len(s) < 26:
    for i in range(26):
        c = chr(ord('a') + i)
        if not c in s:
            print(s + c)
            exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
else:
    for i in range(len(s)-1):
        if s[i] > s[i+1]:
            for j in range(26):
                c = chr(ord('a') + i)
                if not c in s[:i]:
                    print(s[:i-1] + c)
                    print(exit())

Submission status: Wrong Answer

Solution code:
berb = ['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']

S = list(input())

for i in range(len(S)):
    S[i] = berb.index(S[i])

S_d = [-1]
S_0 = len(S)
k = 0

while True:
    if k == 26:
        S_d.append(S.pop(-1))
        if S == []:
            print(-1)
            break
        else:
            k = 0
    elif k in S or k <= S_d[-1]:
        k += 1
    else:
        S.append(k)
        for j in range(len(S)):
            S[j] = berb[S[j]]

        print(''.join(S))
        break

Submission status: Wrong Answer

Solution code:
berb = ['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']

S = list(input())

for i in range(len(S)):
    S[i] = berb.index(S[i])

S_d = [-1]
S_0 = len(S)
k = 0

while True:
    if k == 26:
        S_d.append(S.pop(-1))
        if S == []:
            print('-1')
            break
        else:
            k = 0
    elif k in S or k <= S_d[-1]:
        k += 1
    else:
        S.append(k)
        for j in range(len(S)):
            S[j] = berb[S[j]]

        print(''.join(S))
        break

Submission status: Wrong Answer

Solution code:
berb = ['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']

S = list(input())
S_0 = len(S)
i = 0

while len(S) == S_0:
    if i == 26:
        print('-1')
        break
    elif berb[i] in S:
        i += 1
    else:
        S.append(berb[i])
        print(''.join(S))

Submission status: Wrong Answer

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

if len(S)<26:
    for s in S:
        abc.remove(s)
    print(S+abc[0])
else:
    index_z=S.index('z')
    if index_z==0:
        print(-1)
        exit()
    index_=abc.index(S[index_z-1])
    abc_=abc[index_:]
    for s in S[:index_z]:
        if s in abc_:
                abc_.remove(s)
    print(S[:index_z-1]+abc_[0])

Submission status: Wrong Answer

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

if len(S)==26:
    z=S.index('z')
    if z==0:
        print(-1)
    else:
        ans=S[:z]
        for s in ans:
            abc.remove(s)
        for s in abc:
            if S[z-1]<s and s not in ans:
                res=s
                break
        print(ans[:-1]+res)
else:
    for s in S:
        abc.remove(s)
    print(S+abc[0])

Submission status: Wrong Answer

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

if len(S)==26:
    z=S.index('z')
    if z==0:
        print(-1)
    else:
        ans=S[:z-1]
        abc.remove(S[z-1])
        for s in ans:
            abc.remove(s)
        print(ans+abc[0])
else:
    for s in S:
        abc.remove(s)
    print(S+abc[0])

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    dic = ['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 d in dic:
        if d in S:
            continue
        else:
            return print(S + d)
    if S == "zyxwvutsrqponmlkjihgfedcba":
        return print(-1)
    pre = ord(S[0])
    for i, s in enumerate(S[1:]):
        if s == "z":
            c = 1
            while chr(pre + c) in S[:i]:
                c += 1
            return print(S[:i] + chr(pre + c))
        pre = ord(s)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    dic = ['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 d in dic:
        if d in S:
            continue
        else:
            return print(S + d)
    if S == "zyxwvutsrqponmlkjihgfedcba":
        return print(-1)
    pre = ord(S[0])
    for i, s in enumerate(S[1:]):
        if s == "z":
            return print(S[:i] + chr(pre + 1))
        pre = ord(s)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# AGC022 A - Diverse Word
s=input()
n=len(s)
mozi=[0]*26
ans=''
if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif n<26:
    for ss in s:
        mozi[ord(ss)-97]+=1
    for i in range(len(mozi)):
        if mozi[i]==0:
            break
    ans=s
    ans+=chr(97+i)
    print(ans)
elif n==26:
    for i in range(2,27):
        if s[-i]>s[-i-1]:
            break
    ss=sorted(s[-i:])
    for sss in ss:
        if sss>s[-i-1]:
            break
    print(s[:-i-1]+sss)

Submission status: Wrong Answer

Solution code:
alp = 'abcdefghijklmnopqrstuvwxyz'
s = input()
if s == alp[::-1]:
    print(-1)
elif len(s) == 26:
    for i in range(len(s)-1,0,-1):
        if s[i] > s[i-1]:
            for j in alp:
                if j not in s[:i]:
                    print(s[:i-1]+j)
                    break
            break
else:
    for i in alp:
        if i not in s:
            print(s+i)
            break

Submission status: Wrong Answer

Solution code:
alp = 'abcdefghijklmnopqrstuvwxyz'
s = input()
if s == alp[::-1]:
    print(-1)
elif len(s) == 26:
    zind = s.index('z')
    s = s[:zind]
    maxs = max(s)
    for i in alp:
        if i not in s and i > maxs:
            print(s[:-1]+i)
            break    
else:
    for i in alp:
        if i not in s:
            print(s+i)
            break

Submission status: Wrong Answer

Solution code:
alp = 'abcdefghijklmnopqrstuvwxyz'
s = input()
if s == alp[::-1]:
    print(-1)
elif len(s) == 26:
    zind = s.index('z')
    s = s[:zind]
    for i in alp:
        if i not in s:
            print(s[:-1]+i)
            break    
else:
    for i in alp:
        if i not in s:
            print(s+i)
            break

Submission status: Wrong Answer

Solution code:
alp = 'abcdefghijklmnopqrstuvwxyz'
s = input()
if s == alp[::-1]:
    print(-1)
elif len(s) == 26:
    zind = s.index('z')
    s = s[:zind]
    for i in alp:
        if i not in s:
            print(s+i)
            break    
else:
    for i in alp:
        if i not in s:
            print(s+i)
            break

Submission status: Wrong Answer

Solution code:
alp = 'abcdefghijklmnopqrstuvwxyz'
s = input()
if s == alp[::-1]:
    print(-1)
elif len(s) == 26:
    for i in range(len(s)-1,0,-1):
        if s[i] > s[i-1]:
            s = s[:i-1]+s[i]+s[i-1]+s[i+1:]
            break
    print(s)
else:
    for i in alp:
        if i not in s:
            print(s+i)
            break

Submission status: Wrong Answer

Solution code:
S=input()
tmp=("abcdefghijklmnopqrstuvwxyz")
C=len(S)
M=sorted(S)
count=0
if C!=26:
	for i in range (C):
		if M[i]!=tmp[i]:
			print(S,end="")
			print(tmp[i])
			break
		else:
			count+=1
	if count== C:
		print(S,end="")
		print(tmp[C])
else:
	if S == ("zyxwvutsrqponmlkjihgfedcba"):
		print("-1")
	else:
		for i in range (26):
			if S[-i]!=tmp[-i] and tmp[-i]<S[-i]:
				print(S[0:-i-1],end="")
				print(tmp[-i])
				break

Submission status: Wrong Answer

Solution code:
S=input()
tmp=("abcdefghijklmnopqrstuvwxyz")
C=len(S)
M=sorted(S)
count=0
if C!=26:
	for i in range (C):
		if M[i]!=tmp[i]:
			print(S,end="")
			print(tmp[i])
			break
		else:
			count+=1
	if count== C:
		print(S,end="")
		print(tmp[C])
else:
	if S == ("zyxwvutsrqponmlkjihgfedcba"):
		print("-1")
	else:
		for i in range (26):
			if S[i]!=tmp[i] and tmp[i]<S[i]:
				print(S[0:i-1],end="")
				print(tmp[i])
				break