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()
A = "abcdefghijklmnopqrstuvwxyz"
if len(S)<26:
    for c in A:
        if c not in S:
            print(S+c)
            break
elif S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for i in range(24,-1,-1):
        if ord(S[25])>ord(S[i]):
            break
    for c in A: 
        if ord(c)>ord(S[i]) and c in S[i+1:]:   
            print (S[:i]+c)
            break

Submission status: Wrong Answer

Solution code:
S = input()
A = "abcdefghijklmnopqrstuvwxyz"
if len(S)<26:
    for c in A:
        if c not in S:
            print(S+c)
            break
elif S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    c = S[25]                
    for i in range(25,-1,-1):
        if ord(c)>ord(S[i]):
            print(S[:i]+chr(min(map(ord,S[i+1:]))))
            break

Submission status: Wrong Answer

Solution code:
S = input()
A = "abcdefghijklmnopqrstuvwxyz"
if len(S)<26:
    for c in A:
        if c not in S:
            print(S+c)
            break
elif S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    c = S[25]                
    for i in range(25,-1,-1):
        if ord(c)>ord(S[i]):
            print(S[:i]+c)
            break

Submission status: Wrong Answer

Solution code:
s = input()
L = []
alp = [chr(ord('a') + i) for i in range(26)]
TF = [False]*26
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
    TF[ord(s[i])-97] = True
if len(L) != 26:
  for i in range(26):
    if TF[i] == False:
      k = alp[i]
      break
  print(s+k)
else:
  if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
  elif s == 'abcdefghijklmnopqrstuvwxyz':
    print('b')
  else:
    for i in range(25,-1,-1):
      if s[i] > s[i-1]:
        break
    print(s[0:i-1]+s[25])

Submission status: Wrong Answer

Solution code:
s = input()
L = []
alp = [chr(ord('a') + i) for i in range(26)]
TF = [False]*26
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
    TF[ord(s[i])-97] = True
if len(L) != 26:
  for i in range(26):
    if TF[i] == False:
      k = alp[i]
      break
  print(s+k)
else:
  if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
  elif s == 'abcdefghijklmnopqrstuvwxyz':
    print('b')
  else:
    for i in range(25,-1,-1):
      if s[i] > s[i-1]:
        break
    print(s[0:i-1]+alp[ord(s[i-1])-96])

Submission status: Wrong Answer

Solution code:
s = input()
L = []
alp = [chr(ord('a') + i) for i in range(26)]
TF = [False]*26
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
    TF[ord(s[i])-97] = True
if len(L) != 26:
  for i in range(26):
    if TF[i] == False:
      k = alp[i]
      break
  print(s+k)
else:
  if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
  elif s == 'abcdefghijklmnopqrstuvwxyz':
    print('b')
  else:
    saityou = 0
    cur = 0
    start = 0
    for i in range(25):
      if cur == 0:
        start = i
      else:  
        if s[i] > s[i+1]:
          cur += 1
        else:
          if cur > saityou:
            saityou = cur
          cur = 0
    k = ord(s[start])-97
    print(s[0:start-2]+alp[ord(s[start])-98])

Submission status: Wrong Answer

Solution code:
s = input()
L = []
alp = [chr(ord('a') + i) for i in range(26)]
TF = [False]*26
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
    TF[ord(s[i])-97] = True
if len(L) != 26:
  for i in range(26):
    if TF[i] == False:
      k = alp[i]
      break
  print(s+k)
else:
  if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
  elif s == 'abcdefghijklmnopqrstuvwxyz':
    print('b')
  else:
    for i in range(25):
      if ord(s[i+1])-ord(s[i]) != 1:
        break
    if ord(s[i+1])-97 != 25:
      print(s[0:i+1]+alp[ord(s[i+1])-97+1])
    else:
      print(s[0:i]+alp[ord(s[i])-97+1])

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
S = sorted(list(set(s)))
al=[chr(ord('a') + i) for i in range(26)]
for j in S:
    if j in al:
        del al[al.index(j)]
if len(al) != 0:
    print("".join(S)+al[0])
else:
    al=sorted([chr(ord('a') + i) for i in range(26)],reverse=True)
    for j in range(len(s)-1,0,-1):
        if s[j-1] in al:
            del al[al.index(s[j-1])]
        if s[j] > s[j-1]:
            #print(al)
            s[j],s[j-1] = s[j-1],s[j]
            print("".join(s[:j-1])+al[0])
            exit()

    print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
l = list('abcdefghijklmnopqrstuvwxyz')
for s_ in s:
    l.remove(s_)
if l==[]:
    l.append(s[-1])
    for i in range(len(s)-2,-1,-1):
        if s[i]<min(l):
            for k in l:
                if k>s[i]:
                    print(s[:i]+k)
                    exit()
        l.append(s[i])
    print(-1)
else:
    print(s+l[0])

Submission status: Wrong Answer

Solution code:
s = input()
l = list('abcdefghijklmnopqrstuvwxyz')
for s_ in s:
    l.remove(s_)
if l==[]:
    l.append(s[-1])
    for i in range(len(s)-2,-1,-1):
        if s[i]<min(l):
            print(s[:i]+min(l))
            exit()
        l.append(s[i])
    print(-1)
else:
    print(s+l[0])

Submission status: Wrong Answer

Solution code:
s = input()
l = list('abcdefghijklmnopqrstuvwxyz')
if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
for s_ in s:
    l.remove(s_)
if l==[]:
    for i in range(len(s)-1):
        for j in range(i+1,len(s)):
            if s[i]<s[j]:
                break
            if j==len(s)-1:
                key = s[i-1]
                z = sorted(s[i:])
                for z_ in z:
                    if z_>key:
                        print(s[:i-1]+z_)
                        exit()
    print(-1)
else:
    print(s+l[0])

Submission status: Wrong Answer

Solution code:
s = input()
l = list('abcdefghijklmnopqrstuvwxyz')
for s_ in s:
    l.remove(s_)
if l==[]:
    for i in range(len(s)-1):
        for j in range(i+1,len(s)):
            if s[i]>s[j]:
                key = s[i-1]
                z = sorted(s[i:])
                for z_ in z:
                    if z_>key:
                        print(s[:i-1]+z_)
                        exit()
    print(-1)
else:
    print(s+l[0])

Submission status: Wrong Answer

Solution code:
s = input()
l = list('abcdefghijklmnopqrstuvwxyz')
for s_ in s:
    l.remove(s_)
if l==[]:
    for i in range(len(s)-1,0,-1):
        for j in range(i-1,-1,-1):
            if s[i]>s[j]:
                print(s[:j]+s[i])
                exit()
    print(-1)
else:
    print(s+l[0])

Submission status: Wrong Answer

Solution code:
import numpy as np
alpha = list('abcdefghijklmnopqrstuvwxyz')
alpha_num = [num for num in range(26)]

d = {char:num for (char, num) in zip(alpha, range(26))}
d_reverse = {num:char for (num, char) in zip(range(26), alpha)}

S = input()
S_num = np.array([d[char] for char in S])
last = S_num[-1]

flag = True

if len(S) < 26:
  S_num.sort()
  for k in range(last):
      if S_num[k] != alpha_num[k]:
        print(S + alpha[k])
        flag = False
        break
  if flag:
    print(S + alpha[len(S)])
    
else:
  for k in reversed(range(1, 26)):
    if S_num[k] > S_num[k-1]:
      A = S_num[k:]
      A = A[A > S_num[k-1]]
      A.sort()
      print(S[:k-1] + d_reverse[A[0]])
      flag = False
      break
  if flag:
    print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
alpha = list('abcdefghijklmnopqrstuvwxyz')
alpha_num = [num for num in range(26)]

d = {char:num for (char, num) in zip(alpha, range(26))}
d_reverse = {num:char for (num, char) in zip(range(26), alpha)}

S = input()
S_num = np.array([d[char] for char in S])
last = S_num[-1]

flag = True

if len(S) < 26:
  S_num.sort()
  for k in range(last):
      if S_num[k] != alpha_num[k]:
        print(S + alpha[k])
        flag = False
        break
  if flag:
    print(S + alpha[len(S)])

else:
  for k in reversed(range(1, 26)):
    if S_num[k] > S_num[k-1]:
      A = S_num[S_num > S_num[k-1]]
      print(S[:k-1] + d_reverse[A[-1]])
      flag = False
      break
  if flag:
    print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
alpha = list('abcdefghijklmnopqrstuvwxyz')
alpha_num = [num for num in range(26)]

d = {char:num for (char, num) in zip(alpha, range(26))}
d_reverse = {num:char for (num, char) in zip(range(26), alpha)}

S = input()
S_num = np.array([d[char] for char in S])
last = S_num[-1]

flag = True

if len(S) < 26:
  S_num.sort()
  for k in range(last):
      if S_num[k] != alpha_num[k]:
        print(S + alpha[k])
        flag = False
        break
  if flag:
    print(S + alpha[len(S)])

else:
  for k in reversed(range(1, 26)):
    if S_num[k] > S_num[k-1]:
      A = S_num[S_num > S_num[k-1]]
      char = d_reverse[A[-1]]
      char_rest_sorted = [d_reverse[num] for num in np.sort(S_num[k-1:])]
      char_rest_sorted.remove(char)
      char_rest = ''.join(char_rest_sorted)
      print(S[:k-1] + char + char_rest)
      flag = False
      break
  if flag:
    print(-1)

Submission status: Wrong Answer

Solution code:
S = input()

alph = [0] * 26
record = -1

for index, i in enumerate(S):
    pointer = ord(i) - ord("a")
    alph[pointer] += 1

    if((alph[index] == 0) and (record == -1)):
        record = index
#    print(alph)
#print(record)

if(len(S) == 26):
    if(S == "zyxwvutsrqponmlkjihgfedcba"):
        print(-1)
    else:
        print(S[0:record - 1] + chr(record + ord("a")))
else:
    if(record == -1):
        print(S + chr(index + ord("a") + 1))
    else:
        print(S + chr(record + ord("a")))

Submission status: Wrong Answer

Solution code:
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'}
dic1=['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']
n=len(s)
d=set()
for x in s:
    d.add(x)
c=sorted(dic-d)
if c==[]:
    k=0
    for i in range(n):
        if s[i]=='z':
            k=i
    if k==0:
        print(-1)
    else:
        y=s[k-1]
        z=0
        for i in range(26):
            if dic1[i]==y:
                z=dic1[i+1]
        print(s[:k-1]+z)
else:
    print(s+c[0])

Submission status: Wrong Answer

Solution code:
s=input()
b="abcdefghijklmnopqrstuvwxyz"
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      print(s[:i]+mn)
      exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s=input() 
b="".join(list(reversed("zyxwvutsrqponmlkjihgfedcba")))
if s=="zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      print(s[:i]+mn)
      exit()

Submission status: Wrong Answer

Solution code:
S = input()

A = [chr(i) for i in range(ord("a"),ord("z")+1)]

if len(S) < 26 :
    for i in range(len(A)) :
        if A[i] not in S :
            ans = S + A[i]
            break
elif S == "".join(A[::-1]) :
    ans = -1
else :
    for i in range(len(S)-2,-1,-1) :
        if S[i] < S[i+1] :
            ans = S[:i] + chr(ord(S[i])+1)
            break

    
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 c not in S:
            print(S + c)
            exit()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

cs = set()
for i in range(25):
    t,tt = S[-i-1],S[-i-2]
    cs.add(t)
    if tt < t:
        print(S[:-i-2] + min(cs))
        exit()

Submission status: Wrong Answer

Solution code:
import string

alp = string.ascii_lowercase

def main():
    s = input()
    if len(s) < 26:
        for i in alp:
            if i not in s:
                print (s + i)
                return
    if s == alp[::-1]:
        print(-1)
        return
    L = len(s)
    for i, ss in enumerate( s ):
        if s[L-i-1] > s[L-i-2]:
            print ( s[:L-i-2] + s[-1] )
            break

main()

Submission status: Wrong Answer

Solution code:
import string

alp = string.ascii_lowercase

def main():
    s = input()
    if len(s) < 26:
        for i in alp:
            if i not in s:
                print (s + i)
                return
    if s == alp[::-1]:
        print(-1)
        return
    for i, ss in enumerate( s[::-1] ):
        if  s[-(i+2)] < s[-(i+1)]:
            print ( s[:(-i-2)] + s[-1] )
            break

main()

Submission status: Wrong Answer

Solution code:
import string

alp = string.ascii_lowercase

def main():
    s = input()
    if len(s) < 26:
        for i in alp:
            if i not in s:
                print (s + i)
                return
    if s == alp[::-1]:
        print(-1)
        return
    for i, ss in enumerate( s[::-1] ):
        if s[-(i)] > ss:
            print ( s[:(-i-1)] + s[-1] )
            break

main()

Submission status: Wrong Answer

Solution code:
import string

alp = string.ascii_lowercase

def main():
    s = input()
    if s == alp[::-1]:
        print(-1)
        return
    for i, ss in enumerate( s[::-1] ):
        if s[-(i)] > ss:
            print ( s[:(-i-1)] + s[-1] )
            break

main()

Submission status: Wrong Answer

Solution code:
S = input()

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

tmp = {a: 0 for a in 'abcdefghijklmnopqrstuvwxyz'}

for x in S:
    tmp[x] += 1

tmp2 = []
if all(x == 1 for x in tmp.values()):
    for i in range(len(S)-1, 0, -1):
        tmp2.append(S[i])
        if S[i-1] < S[i]:
            tmp2 = [x for x in tmp2 if x > S[i-1]]
            print(S+min(tmp2))
            exit()
else:
    for k, v in tmp.items():
        if v == 0:
            tmp2.append(k)
    print(S+min(tmp2))

Submission status: Wrong Answer

Solution code:
S = input()

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

tmp = {a: 0 for a in 'abcdefghijklmnopqrstuvwxyz'}

for x in S:
    tmp[x] += 1

tmp2 = []
if all(x == 1 for x in tmp.values()):
    for i in range(len(S)-1, 0, -1):
        tmp2.append(S[i])
        if S[i-1] < S[i]:
            tmp2 = [x for x in tmp2 if x > S[i-1]]
            exit()
else:
    for k, v in tmp.items():
        if v == 0:
            tmp2.append(k)
    print(S+min(tmp2))

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            ans = ""
            c = 0
            for j in s:
                if chr(ord(j)+c) != "z":
                    c += 1
                    print (ans+ chr(ord(j)+1))
                    return
                ans += j

            break
        if s.count(i) == 0:
            print (s + i)
            break

main()

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            ans = ""
            for j in s:
                if j != "z":
                    print (ans+ chr(ord(j)+1))
                    return
                ans += j

            break
        if s.count(i) == 0:
            print (s + i)
            break

main()

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            ans = ""
            for i in s:
                if i != "z":
                    print (ans+ chr(ord(i)+1))
                    return
                ans += i

            break
        if s.count(i) == 0:
            print (s + i)
            break

main()

Submission status: Wrong Answer

Solution code:
S = input()

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

tmp = {a: 0 for a in 'abcdefghijklmnopqrstuvwxyz'}

for x in S:
    tmp[x] += 1

tmp2 = []
if all(x == 1 for x in tmp.values()):
    for i in range(len(S)-1, 0, -1):
        if S[i-1] < S[i]:
            if tmp2 == []:
                print(S[:i-1] + S[i])
                exit()
            print(S[:i-1] + min(tmp2))
            exit()
        tmp2.append(S[i])
else:
    for k, v in tmp.items():
        if v == 0:
            tmp2.append(k)
    print(S+min(tmp2))

Submission status: Wrong Answer

Solution code:
s = input()
for i in "abcdefghijklmnopqrstuvwxyz@":
    if i == "@":
        print(-1)
        break
    if s.count(i) == 0:
        print (s + i)
        break

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    if len(s) > 25:
        print(-1)
    else:
        for i in "abcdefghijklmnopqrstuvwxyz":
            if s.count(i) == 0:
                print (s + i)
                return
main()

Submission status: Wrong Answer

Solution code:
S = input()
import sys

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit(0)

atoz = list(map(chr,range(97,123)))
charmap = dict()
for c in atoz:
    charmap[c] = 0

for s in S:
    charmap[s] += 1

flag = 0
for c in atoz:
    if charmap[c] == 0:
        flag = 1
        S = S + c
        break

if flag == 0:
    index = 0
    for i in range(len(S)-1):
        if S[-1-i] > S[-2-i]:
            index = -2-i
            break
    tmp = sorted(list(S[index+1:]))
    S = S[:index]+tmp[0]

print(S)

Submission status: Wrong Answer

Solution code:
S = input()
import sys

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit(0)

atoz = list(map(chr,range(97,123)))
charmap = dict()
for c in atoz:
    charmap[c] = 0

for s in S:
    charmap[s] += 1

flag = 0
for c in atoz:
    if charmap[c] == 0:
        flag = 1
        S = S + c
        break

if flag == 0:
    index = 0
    last = ''
    for i in range(len(S)-1):
        S[-1+i] > S[-2+i]
        index = -2+i
    tmp = sorted(list(S[index+1:]))
    S = S[:index]+tmp[0]

print(S)

Submission status: Wrong Answer

Solution code:
S = list(input())

if len(S) != 26:
    AL = [chr(i) for i in range(97, 123)]
    for i in range(len(S)):
        AL.remove(S[i])
    ans = ''.join(S) + AL[0]
elif ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
    ans = -1
else:
    for i in range(24, -1, -1):
        if S[i] < S[i+1]:
            S[i] = min(S[i+1:])
            ans = ''.join(S[:i+1])
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
MAX = 'zyxwvutsrqponmlkjihgfedcba'
lst_s = list(s)

if len(s) != 26:
    AL = [chr(i) for i in range(97, 123)]
    for i in range(len(s)):
        AL.remove(lst_s[i])
    ans = s + AL[0]
elif s == MAX:
    ans = -1
else:
    for i in range(24, -1, -1):
        if s[i] < lst_s[i+1]:
            lst_s[i] = min(lst_s[i+1:])
            ans = ''.join(lst_s[:i+1])
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
MAX = 'zyxwvutsrqponmlkjihgfedcba'
lst_s = list(s)

if len(s) != 26:
    AL = [chr(i) for i in range(97, 123)]
    for i in range(len(s)):
        AL.remove(lst_s[i])
    ans = s + AL[0]
elif s == MAX:
    ans = -1
else:
    for i in range(24, -1, -1):
        if s[i] < lst_s[i+1]:
            lst_s[i] = lst_s[i+1]
            ans = ''.join(lst_s[:i+1])
            break
print(ans)

Submission status: Wrong Answer

Solution code:
a=input()
abc="abcdefghijklmnopqrstuvwxvyz"
k=[]
for i in a:
  k.append(i)
k.sort()
I =""
for j, l in zip(k,abc):
  if j!=l:
    I+=a+l
    break
if I ==a:print(-1)
else:print(I)

Submission status: Wrong Answer

Solution code:
a=input()+"5"
abc="abcdefghijklmnopqrstuvwxvyz"
k=[]
for i in a:
  k.append(i)
k.sort()
I =""
for j, l in zip(abc,a):
  if j!=l:
    I+=a+l
    break
if I ==a:print(-1)
else:print(I)

Submission status: Wrong Answer

Solution code:
a=input()
abc="abcdefghijklmnopqrstuvwxvyz"
k=[]
for i in a:
  k.append(i)
k.sort()
I =""
for j, l in zip(a,abc):
  if j!=l:
    I+=a+l
    break
if I ==a:print(-1)
else:print(I)

Submission status: Wrong Answer

Solution code:

a=input()
abc="abcdefghijklmnopqrstuvwxvyz"
k=[]
for i in a:
  k.append(i)
k.sort()
I =""
for j, l in zip(a,abc):
  if j!=l:
    I+=a+l
    break
if I ==a:print(-1)
else:print(I)

Submission status: Wrong Answer

Solution code:
alphabet = "abcdefghijklmnopqrstuvwxyz"
S = raw_input()
if len(S) < 26:
  for ab in alphabet:
    if not ab in S:
      print S+ab
      break
else:
  i = -1
  s = "Z"
  while i > -27 and s < S[i]:
    s = S[i]
    i -= 1
  if i == -27:
    print "-1"
  else:
    for ab in alphabet:
      if not ab in S[:i+1]:
        print S[:i]+ab
        break

Submission status: Wrong Answer

Solution code:
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()

abc = "abcdefghijklmnopqrstuvwxyz"
num = [i for i in range(26)]
dic = {"null":-1}
for i in range(26):
    dic[abc[i]] = num[i]+1

l = []
tmp = "null"
if len(s) == 26:
    for i in range(25,-1,-1):
        if dic[tmp] < dic[s[i]]:
            tmp = s[i]
            l.append(s[i])
        else:
            for j in l:
                if dic[j] < dic[s[i-1]]:
                    continue
                else:
                    print(s[:i]+j)
                    exit()
                    break
    else:
        print(-1)
else:
    for i in range(26):
        if abc[i] in s:
            continue
        else:
            print(s+abc[i])
            break

Submission status: Wrong Answer

Solution code:
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()

abc = "abcdefghijklmnopqrstuvwxyz"
num = [i for i in range(26)]
dic = {"null":-1}
for i in range(26):
    dic[abc[i]] = num[i]+1


tmp = "null"
if len(s) == 26:
    for i in range(25,-1,-1):
        if dic[tmp] < dic[s[i]]:
            tmp = s[i]
        else:
            print(s[:i]+s[-1])
            break
    else:
        print(-1)
else:
    for i in range(26):
        if abc[i] in s:
            continue
        else:
            print(s+abc[i])
            break

Submission status: Wrong Answer

Solution code:
l=['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())
if ''.join(s)=='zyxwvutsrqponmlkjihgfedcba':
  print(-2)
  exit()
for i in range(len(s)):
  l.remove(s[i])
if len(l)==0:
  a=s[-1]
  rs=s[:]
  rs.reverse()
  l2=[]
  l2.append(a)
  b=0
  for i in range(1,len(s)):
    if a>rs[i]:
      b=i
      break
    else:
      l2.append(rs[i])
  print(''.join(s[:(b+1)*(-1)]+[min(l2)]))
else:
  print(''.join(s+[l[0]]))

Submission status: Wrong Answer

Solution code:
S = list(input())

D = list("abcdefghijklmnopqrstuvwxyz")

if len(S) == 26:
  cnt = 0
  for i in range(25, -1, -1):
    Flag = True
    for j in range(cnt, 26):
      if S[i] == D[j]:
        cnt = j
        Flag = False
        break
    if Flag:
      S[i] = S[-1]
      #print("".join(S[:i+1]))
      exit()
  print("-1")      
else:
  for i in S:
    D.remove(i)
  print("".join(S) + D[0])

Submission status: Wrong Answer

Solution code:
S = list(input())

D = list("abcdefghijklmnopqrstuvwxyz")

if len(S) == 26:
  L = []
  cnt = 0
  for i in range(25, -1, -1):
    Flag = True
    for j in range(cnt, 26):
      if S[i] == D[j]:
        cnt = j
        Flag = False
        break
    if Flag:
      S[i] = S[-1]
      print("".join(S[:i+1]))
      exit()
  print("-1")      
else:
  for i in S:
    D.remove(i)
  print("".join(S) + D[0])

Submission status: Wrong Answer

Solution code:
def stoi(s):
    return ord(s)-97
def itos(i):
    return chr(97+i)

s = input()

if len(s) < 26:
    X = [0] * 26
    for ss in s:
        X[stoi(ss)] = 1
    for i in range(26):
        if X[i] == 0:
            print(s + itos(i))
            break
elif s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    i = 25
    A = []
    while stoi(s[i-1]) > stoi(s[i]):
        A.append(stoi(s[i]))
        i -= 1
    A.append(stoi(s[i]))
    i -= 1
    
    print(s[:i]+itos(min(A)))

Submission status: Wrong Answer

Solution code:
from collections import deque

alphabet = set('abcdefghijklmnopqrstuvwxyz')

if __name__ == '__main__':
    s = input()
    l = [c for c in alphabet - set(s)]
    if l != []:
        print(s + min(l))
        quit(0)

    deq = deque()
    small = s[-1]
    for i in range(24, -1, -1):
        if s[i] < s[i + 1]:
            print(s[:i] + small)
            quit(0)
    print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
S = list(S)
li = ['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 s in S:
    if s in li:
        li.remove(s)

if len(li) == 0:
    li = ['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']
    max = 26
    m = []
    for i in range(2,len(S)):
        m.append(li.index(S[-i+1]))
        if li.index(S[-i]) < li.index(S[-i+1]):
            for p in m:
                if p < li.index(S[-i]):
                    m.remove(p)
            S[-i] = li[min(m)]
            S = S[:-i+1]
            for s in S:
                print(s,end='')
            exit()
    print(-1)
else:
    S += li[0]
    for s in S:
        print(s,end='')

Submission status: Wrong Answer

Solution code:
ss = input()
ss =list(map(ord, ss))
dic = [i for i in range(97,123)]
# print(dic)
for s in ss:
    dic.remove(s)
# print(dic)
if len(ss)<26:
    ss.append(min(dic))
else:
    for s in ss[::-1]:
        if len(dic)>0 and s < max(dic):
            ss[ss.index(s)] = max(dic)
            break
        dic.append(ss.pop(ss.index(s)))
    else:
        ss = -1
print(ss if ss == -1 else ''.join(list(map(chr,ss))))

Submission status: Wrong Answer

Solution code:
ss = input()
ss =list(map(ord, ss))
dic = [i for i in range(97,123)]
print(dic)
for s in ss:
    dic.remove(s)
print(dic)
if len(ss)<26:
    ss.append(min(dic))
else:
    for s in ss[::-1]:
        if len(dic)>0 and s < max(dic):
            ss[ss.index(s)] = max(dic)
            break
        dic.append(ss.pop(ss.index(s)))
    else:
        ss = -1
print(ss if ss == -1 else ''.join(list(map(chr,ss))))

Submission status: Wrong Answer

Solution code:
ss = input()
ss =list(map(ord, ss))
dic = [i for i in range(97,123)]
for s in ss:
    dic.remove(s)
if len(ss)<26:
    ss.append(min(dic))
else:
    last = ss[-1]
    for s in ss[::-1]:
        if s < last:
            ss = ss[:ss.index(s)] + [last]
            break
    else:
        ss = -1
if ss == -1:
    print(ss)
else:
    print(''.join(list(map(chr,ss))))

Submission status: Wrong Answer

Solution code:
ss = input()
ss =list(map(ord, ss))
print(ss)
dic = [i for i in range(97,123)]
for s in ss:
    dic.remove(s)
if len(ss)<26:
    ss.append(min(dic))
else:
    last = ss[-1]
    for s in ss[::-1]:
        if s < last:
            ss = ss[:ss.index(s)] + [last]
            break
    else:
        ss = -1
if ss == -1:
    print(ss)
else:
    print(''.join(list(map(chr,ss))))

Submission status: Wrong Answer

Solution code:
import bisect
ss = input()
dic = [i for i in range(97,123)]

ss = list(map(ord, ss))
for s in ss:
    if dic.count(s)>0:
        dic.remove(s)

if len(ss)==26 and len(dic)==0:
    print(-1)
else:
    if len(ss)<26:
        ss.append(min(dic))
    else:
        max_dic = max(dic)
        for i,s in enumerate(ss[::-1]):
            if s < max_dic:
                idx = bisect.bisect_right(dic, s)
                ss[-(i+1)] = dic[idx]
                break
    print(''.join(list(map(chr,ss))))

Submission status: Wrong Answer

Solution code:
s = input()
if len(s)>25:
    print("-1")
else:
    for i in "abcdefghijklmnopqrstuvwxyz":
        if s.find(i)==-1:
            print(s+i)
            exit()

Submission status: Wrong Answer

Solution code:
s = input()
if len(s)>25:
    print("-1")
else:
    for i in "abcdefghijklmnopqrsuvwxyz":
        if s.find(i)==-1:
            print(s+i)
            exit()

Submission status: Wrong Answer

Solution code:
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
if len(N) < 26:
    for d in D:
        if not d in setN:
            N.append(d)
            print(''.join(N))
            exit()
else:
    N.reverse()
    for i in range(25):
        if N[i] < N[i+1]:
            continue
        else:
            tmp = N[i+1]
            ans = N[i+2:]
            ans.reverse()
            ans.append(chr(ord(tmp)+1))
            print(''.join(ans))
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
if len(N) < 26:
    for d in D:
        if not d in setN:
            N.append(d)
            print(''.join(N))
            exit()
else:
    N.reverse()
    for i in range(25):
        if N[i] < N[i+1]:
            continue
        else:
            tmp = N[i+1]
            ans = N[i+2:]
            ans.sort()
            ans.append(chr(ord(tmp)+1))
            print(''.join(ans))
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
if len(N) < 26:
    for d in D:
        if not d in setN:
            N.append(d)
            print(''.join(N))
            exit()
else:
    N.reverse()
    for i in range(25):
        print(N[i], N[i+1])
        if N[i] < N[i+1]:
            continue
        else:
            if i == 0:
                print(-1)
                exit()
            tmp = N[i+1]
            ans = N[i+2:]
            ans.sort()
            ans.append(chr(ord(tmp)+1))
            print(''.join(ans))
            exit()