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 = [chr(ord("a")+i) for i in range(26)]

if len(set(S)) != 26:
    for a in A:
        if a not in S:
            print(S + a)
            break
else:
    used = []
    for i in range(1, 26):
        if S[-i] < S[-i-1]:
            used.append(S[-i])
        else:
            used.append(S[-i])
            used.sort()
            print(S[:-i-1]+used[0])
            break
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
S=(input())
lastword=len(S)-1
S[lastword]
alphabet=['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']

import sys
if S=="abcdefghijklmnopqrstuvwzyx":
    print(-1)
    sys.exit()

for i in range (26):
    for j in range (lastword+1):
        if alphabet[i]==S[j]:
            alphabet[i]=0

for i in range (26):
    if alphabet[i]!=0:
        print(S[0:lastword+1]+alphabet[i])
        break

Submission status: Wrong Answer

Solution code:
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    for i, s1 in enumerate(s[::-1]):
        if i != 0 and s1 < old[-1]:
            for o in sorted(old):
                if o > s1:
                    out = s[:len(s)-i-1] + o
                    flag = 1
                    break
        old += s1
        if flag == 0:
            out = -1
else:
    out = s + min(set(sample)-set(s))

print(out)

Submission status: Wrong Answer

Solution code:
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    for i, s1 in enumerate(s[::-1]):
        if i != 0 and s1 < min(old):
            out = s[:len(s)-i-1] + min([o for o in old if o>s1])
            flag = 1
            break
        old += s1
        if flag == 0:
            out = -1
else:
    out = s + min(set(sample)-set(s))

print(out)

Submission status: Wrong Answer

Solution code:
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    for i, s1 in enumerate(s[::-1]):
        if i != 0 and s1 < min(old):
            out = s[:len(s)-i-1] + min(old)
            flag = 1
            break
        old += s1
        if flag == 0:
            out = -1
else:
    out = s + min(set(sample)-set(s))

print(out)

Submission status: Wrong Answer

Solution code:
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    for i, s1 in enumerate(s[::-1]):
        if i != 0 and s1 < min(old):
            out = s[:len(s)-i-1] + min(old)
            flag = 1
            break
        old += s1
        if flag == 0:
            out = -1
else:
    out = s + min(set(sample)-set(s))

print(out)

Submission status: Wrong Answer

Solution code:
s = input()
old = ''
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    for i, s1 in enumerate(s):
        if i != 0 and s1 > min(s[i:]):
            out = s[:i-1] + min(s[i:])
            break
        if s1 == s[-1]:
            out = -1
else:
    out = s + min(set(sample)-set(s))

print(out)

Submission status: Wrong Answer

Solution code:
s = input()
old = ''
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    if list(s) == sample[::-1]:
        out = -1
    else:
        for i, s1 in enumerate(s[::-1]):
            if i != 0 and s1 < old[-1]:
                out = s[:len(s)-i-1] + min(old)
                break
            old += s1
else:
    out = s + min(set(sample)-set(s))

print(out)

Submission status: Wrong Answer

Solution code:
s = input()
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    if list(s) == sample[::-1]:
        out = -1
    else:
        for i, s1 in enumerate(s):
            if i != 0 and s1 > old:
                out = s[:i-1] + min(s[i:])
                break
            old = s1
else:
    for i1, i2 in zip(sorted(s), sample):
        if i1 != i2:
            out = s + i2
            flag = 1
            break
    if flag != 1:
        out = s + sample[len(s)]

print(out)

Submission status: Wrong Answer

Solution code:
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    if list(s) == sample[::-1]:
        out = -1
    else:
        for i, s1 in enumerate(s[::-1]):
            if i != 0 and s1 < old[-1]:
                out = s[:len(s)-i-1] + min(old)
                break
            old += s1
else:
    for i1, i2 in zip(sorted(s), sample):
        if i1 != i2:
            out = s + i2
            flag = 1
            break
    if flag != 1:
        out = s + sample[len(s)]

print(out)

Submission status: Wrong Answer

Solution code:
S = input()
alphabet = list("abcdefghijklmnopqrstuvwxyz")

if S == "zyxwvutsrqponmlkjihgfedcba":
     print(-1)
        
elif len(S) < 26:
    print(S + min(set(alphabet) - set(S)))
    
else:
    for i in range(26):
        if list(S)[-i] > list(S)[-(i + 1)]:
            print("".join(S[:-(i + 1)]) + min(list(S)[-i:]))
            break

Submission status: Wrong Answer

Solution code:
S = input()
chars = "abcdefghijklmnopqrstuvwxyz"
if len(S) < 26:
    for c in chars:
        if c not in S:
            Ans = S+c
            break
else:
    if S == chars[::-1]:
        Ans = -1
    else:
        for i in range(25):
            if S[25-i] > S[25-i-1]:
                break
        Ans = S[0:25-i-1]+chr(ord(S[25-i-1])+1)
print(Ans)

Submission status: Wrong Answer

Solution code:
S = input()
chars = "abcdefghijklmnopqrstuvwxyz"
if len(S) < 26:
    for c in chars:
        if c not in S:
            Ans = S+c
            break
else:
    if S == chars[::-1]:
        Ans = -1
    else:
        for i in range(25):
            if S[25-i] > S[25-i-1]:
                break
        if i == 24:
            Ans = chr(ord(S[0])+1)
        else:
            Ans = S[0:25-i-1]+S[25]
print(Ans)

Submission status: Wrong Answer

Solution code:
S = input()
chars = "abcdefghijklmnopqrstuvwxyz"
if len(S) < 26:
    for c in chars:
        if c not in S:
            Ans = S+c
            break
else:
    if S == chars[::-1]:
        Ans = -1
    else:
        for i in range(25):
            if S[25-i] > S[25-i-1]:
                break
        Ans = S[0:25-i-1]+S[25]
print(Ans)

Submission status: Wrong Answer

Solution code:
S = input()
chars = "abcdefghijklmnopqrstuvwxyz"
if len(S) < 26:
    for c in chars:
        if c not in S:
            Ans = S+c
            break
else:
    if S == chars[::-1]:
        Ans = -1
    else:
        for i in range(26):
            if S[i] != chars[i]:
                Ans = S[0:i-1] + chars[i]
                break
        Ans = S[0:24]+S[25]
print(Ans)

Submission status: Wrong Answer

Solution code:
s= input()
V = list(s)
X = [chr(ord('a') + i) for i in range(26)]

if len(s)<26:
  for i in range(26):
    count1 = s.count(X[i])
    if count1 >= 1:
      continue
    else:
      Nasi = X[i]
      break
  ans = s + Nasi
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    ans= -1
  else:
    for i in range(25, 0, -1):
        if V[i] > V[i-1]:
          ans = V[0:i-1]
          if ans == []:
            ans = chr(ord(V[0]) + 1)
          else:
              B = min(V[i:26])
              while B <= V[i-1]:
                  B = chr(ord(B) + 1)
              ans.append(B)
              ans = ''.join(ans)
              break
        else:
            continue
print(ans)

Submission status: Wrong Answer

Solution code:
s= input()
V = list(s)
X = [chr(ord('a') + i) for i in range(26)]

if len(s)<26:
  for i in range(26):
    count1 = s.count(X[i])
    if count1 >= 1:
      continue
    else:
      Nasi = X[i]
      break
  ans = s + Nasi
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    ans= -1
  else:
    for i in range(25, 0, -1):
        if V[i] > V[i-1]:
          ans = V[0:i-1]
          if ans == []:
            ans = chr(ord(V[0]) + i)
          else:
              ans.append(min(V[i:26]))
              ans = ''.join(ans)
              break
        else:
            continue
print(ans)

Submission status: Wrong Answer

Solution code:
s= input()
V = list(s)
X = [chr(ord('a') + i) for i in range(26)]

if len(s)<26:
  for i in range(26):
    count1 = s.count(X[i])
    if count1 >= 1:
      continue
    else:
      Nasi = X[i]
      break
  ans = s + Nasi
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    ans= -1
  else:
    for i in range(25, 0, -1):
        if V[i] > V[i-1]:
          ans = V[0:i-1]
          ans.append(min(V[i:26]))
          ans = ''.join(ans)
          break
        else:
          continue
print(ans)

Submission status: Wrong Answer

Solution code:
s = s0 = input()
d = {chr(c) for c in range(97, 123)}
for c in s:
    d.remove(c)
if d:
    s += min(d)
else:
    for c in reversed(s):
        s = s[:-1]
        if d and c < min(d):
            s += min(d)
            break
        d.add(c)
print(s if s else -1)
if s:
    assert s0 < s

Submission status: Wrong Answer

Solution code:
s = input()
d = {chr(c) for c in range(97, 123)}
for c in s:
    d.remove(c)
if d:
    print(s + min(d))
else:
    for c in reversed(s):
        s = s[:-1]
        if d and c < min(d):
            s += min(d)
            break
        d.add(c)
    if not s:
        print(-1)
    else:
        print(s)

Submission status: Wrong Answer

Solution code:


if __name__ == '__main__':
    begin = ord('a')
    last = ord('z')

    alphabets = list(map(chr, range(begin, last+1)))
    has_used = {alphabet: False for alphabet in alphabets}

    S = input()
    if len(S) == 26:
        print(-1)

    else:
        for s in S:
            has_used[s] = True

        tail = [alphabet for alphabet in has_used if not has_used[alphabet]][0]
        print(S + tail)

Submission status: Wrong Answer

Solution code:
S = input()
if len(S) < 26:
    for i in range(26):
        c = chr(i + ord('a'))
        if c not in S:
            print(S + c)
            break
else:
    while len(S) > 0:
        if (S[-1] == 'z'):
            S = S[:-1]
        else:
            c = chr(ord(S[-1]) + 1)
            if c not in S[:-1]:
                print(S[:-1] + c)
                break
            else:
                S = S[:-1]

Submission status: Wrong Answer

Solution code:
ars = "abcdefghijklmnopqrstuvwxyz"
S = input()
def iftasai(s):
  for i in s:
    if s.count(i) > 1:
      return False
  return True
if len(S) != 26:
  for i in ars:
    if not (i in S):
      print(S + i)
      quit()
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  quit()
else:
  for i in range(1,len(S)):
    n = ars.index(S[-i])
    tmp = ars[n+1:]
    for j in tmp:
      ans = S[:-i] + j
      if iftasai(ans):
        print(ans)
        quit()
  n = ars.index(S[0])
  print(ars[n+1:])

Submission status: Wrong Answer

Solution code:
ars = "abcdefghijklmnopqrstuvwxyz"
S = input()
def iftasai(s):
  for i in s:
    if s.count(i) > 1:
      return False
  return True
if len(S) != 26:
  for i in ars:
    if not (i in S):
      print(S + i)
      quit()
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  quit()
else:
  for i in range(1,len(S)):
    n = ars.index(S[-i])
    tmp = ars[n+1:]
    for j in tmp:
      ans = S[:-i] + j
      if iftasai(ans):
        print(ans)
        quit()

Submission status: Wrong Answer

Solution code:
import string

S = input()
alphabets = list(string.ascii_lowercase)
lastWord = ''.join(alphabets[::-1])
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i in range(len(S)):
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
else:
    for j in range(26):
        if cnt[j] == 0:
            S += chr(ord('a')+j)
            print(S)
            break

Submission status: Wrong Answer

Solution code:
import string

S = input()
alphabets = list(string.ascii_lowercase)
lastWord = ''.join(alphabets[::-1])
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        print('test')    
        # for i in S:
        #     if alphabets[i] != S[i]:
        #         print(S[:i] + alphabets[i])
        #         break
else:
    for j in range(26):
        if cnt[j] == 0:
            S += chr(ord('a')+j)
            print(S)
            break

Submission status: Wrong Answer

Solution code:
S = str(input())

if len(S) == 26:
    print("-1")
else:
    SList = list(set(list(S)))

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

    for i in SList:
        al.remove(i)

    S += al[0]

print(S)

Submission status: Wrong Answer

Solution code:
S = str("audfycgdiyc")

if len(S) == 26:
    print("-1")
else:
    SList = list(set(list(S)))

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

    for i in SList:
        al.remove(i)

    S += al[0]

print(S)

Submission status: Wrong Answer

Solution code:
#agc022a

c='abcdefghijklmnopqrstuvwxyz'
s=raw_input()
if len(s)<26:
 for v in c:
  if v not in s:
   res=s+v
   print res
   break
elif s==c[::-1]:
 print -1
else:
 s=s[::-1]
 i=0
 t=''
 while s[i]<s[i+1]:
  t+=s[i]
  i+=1
 t+=s[i]
 l=s[i+1:]
 r=ord('z')
 for v in t:
  if ord(v)>ord(l[0]):
   temp=min(ord(v),r)
 res=chr(r)
 res=l[::-1][:-1]+res
 print res

Submission status: Wrong Answer

Solution code:
#agc022a

c='abcdefghijklmnopqrstuvwxyz'
s=raw_input()
if len(s)<26:
 for v in c:
  if v not in s:
   res=s+v
   break
elif s==c[::-1]:
 print -1
else:
 s=s[::-1]
 i=0
 t=''
 while s[i]<s[i+1]:
  t+=s[i]
  i+=1
 t+=s[i]
 l=s[i+1:]
 r=ord('z')
 for v in t:
  if ord(v)>ord(l[0]):
   temp=min(ord(v),r)
 res=chr(r)
 res=l[::-1][:-1]+res
 print res

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
eng_li = []
removed_list = []
all_letter = 26
for i in range (97,97+all_letter):
    eng_li.append(chr(i))
 
string = list(raw_input().strip())
length = len(string)
if length < all_letter:
    for i in string:
        eng_li.remove(i)
    string.append(eng_li[0])
    answer = "".join(string)
else:
    for i in range(all_letter-1):
        if ord(string[-1]) < ord(string[-2]) :
            removed_list.append(string[-1])
            string.pop()
        else:
            removed_list.append(string[-1])
            string.pop()
            print string[-1]
            removed_list=filter(lambda x:x>string[-1],sorted(removed_list))
            print removed_list
            string.pop()
            string.append(removed_list[0])
            answer ="".join(string)
            break
    else:
        answer = -1
print answer

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
eng_li = []
removed_list = []
all_letter = 26
for i in range (97,97+all_letter):
    eng_li.append(chr(i))

string = list(raw_input().strip())
length = len(string)
if length < all_letter:
    for i in string:
        eng_li.remove(i)
    string.append(eng_li[0])
    answer = "".join(string)
else:
    for i in range(all_letter-1):
        if ord(string[-1]) < ord(string[-2]) :
            removed_list.append(string[-1])
            string.pop()
        else:
            removed_list.append(string[-1])
            string.pop()
            print string[-1]
            removed_list=filter(lambda x:x>string[-1],sorted(removed_list))
            print removed_list
            string.pop()
            string.append(removed_list[0])
            answer ="".join(string)
            break
    else:
        answer = -1
print answer

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
eng_li = []
removed_list = []

for i in range (97,97+26):
    eng_li.append(chr(i))

string = list(raw_input().strip())
length = len(string)
if length < 26:
    for i in string:
        eng_li.remove(i)
    string.append(eng_li[0])
    answer = "".join(string)
else:
    for i in range(25):
        if ord(string[-1]) < ord(string[-2]) :
            removed_list.append(string[-1])
            string.pop()
        else:
            removed_list.append(string[-1])
            string.pop()
            removed_list=sorted(removed_list)
            string.pop()
            string.append(removed_list[0])
            answer ="".join(string)
            break
    else:
        answer = -1
print answer

Submission status: Wrong Answer

Solution code:
a=input().strip()
if len(a)<26:
  for i in range(97, 97+26):
    if chr(i) not in list(a):
      print(a+chr(i))
      break
else:
  for i in range(26):
    t0=a[25-i:]
    ts=list(t0)
    ts.sort(reverse=True)
    t1="".join(ts)
    if t0 != t1:
      print(a[:25-i]+t1[len(t1)-2])
      break
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if sum(cnt) == 26:
    pos = 0
    for j in range(25, 1, -1):
        if S[j] > S[j-1]:
            pos = j
            break
    if pos == 0:
        print(-1)
    else:
        a = S[pos:26]
        for x in a[::-1]:
            if S[pos-1] < x:
                T = S[:pos-1] + x
                print(T)
                break


else:
    for j in range(26):
        if cnt[j] == 0:
            S += chr(ord('a')+j)
            print(S)
            break

Submission status: Wrong Answer

Solution code:
S = input()
#list = [chr(i) for i in range(97, 97+26)]

# List に文字を数字に変換したものが入れる
List = []
answer= ""

if S == "zyxwvutsrqponmlkjihgfedcba":
    print('-1')
elif len(S) > 26 or len(S) < 1:
    print('-1')
else:
    for i in range(len(S)):
        if S[i] in S[i+1:]:
            print('-1')
            break
        else:
            # List に文字を数字に変換したものが入ってる
            List.append(ord(S[i]))
    list = List[:]
    if len(list) == 26:
        pass
    else:
        while len(List):
            if min(List)+1 in List:
                List.remove(min(List))
            else:
                list.append(min(List)+1)
                break
        for a in list:
            answer += chr(a)
        print(answer)

Submission status: Wrong Answer

Solution code:
import string

S = input()

if len(S) < 26:
    for c in string.ascii_lowercase:
        if c not in S:
            break
    print(S + c)
else:
    ret = None
    for i in range(1, 26):
        if max(S[-i:]) != S[-i]:
            ret = S[:-i] + min(S[-(i-1):])
            break
            
    if ret is None:
        print(-1)
    else:
        print(ret)

Submission status: Wrong Answer

Solution code:
import sys

alphabets = "abcdefghijklmnopqrstuvwxyz"
S = input()
mp = {}

for s in S:
    if s in mp.keys():
        mp[s] = mp[s] + 1
    else:
        mp[s] = 1

# 辞書順の値を返却
def val(c):
    if len(c) != 1:
        return None # invalid
    for i, e in enumerate(alphabets):
        if c == e:
            return len(alphabets) - i
    return None # invalid

def idx(c):
    if len(c) != 1:
        return None # invalid
    for i, e in enumerate(alphabets):
        if c == e:
            return i
    return None # invalid

# 使われてない文字がある場合
unused = []
for a in alphabets:
    if a not in mp.keys():
        unused.append(a)
        
if len(unused) > 0:
    print(S + unused[0])
    sys.exit(0)

# 先頭から探していく
pos = len(S) - 1
while True:
    if pos == 0:
        print(-1)
        sys.exit()
    x = S[pos-1]
    y = S[pos]
    if idx(x) < idx(y):
        # 書き換え
        target = 'z'
        unused.append(y)
        for c in unused:
            if idx(target) > idx(c):
                target = c
        print(S[:pos-1] + target)
        sys.exit()
    else:
        unused.append(y)

    # update
    pos = pos - 1

Submission status: Wrong Answer

Solution code:
import sys

alphabets = "abcdefghijklmnopqrstuvwxyz"
S = input()
mp = {}

for s in S:
    if s in mp.keys():
        mp[s] = mp[s] + 1
    else:
        mp[s] = 1

# 辞書順の値を返却
def val(c):
    if len(c) != 1:
        return None # invalid
    for i, e in enumerate(alphabets):
        if c == e:
            return len(alphabets) - i
    return None # invalid

def idx(c):
    if len(c) != 1:
        return None # invalid
    for i, e in enumerate(alphabets):
        if c == e:
            return i
    return None # invalid

# 使われてない文字がある場合
unused = []
for a in alphabets:
    if a not in mp.keys():
        unused.append(a)
        
if len(unused) > 0:
    print(S + unused[0])
    sys.exit(0)

# 先頭から探していく
pos = len(S) - 1
while True:
    if pos == 0:
        print(-1)
        sys.exit()
    x = S[pos-1]
    y = S[pos]
    if idx(x) < idx(y):
        n = alphabets[idx(x) + 1]
        print(S[:pos-1] + n)
        sys.exit()

    # update
    pos = pos - 1

Submission status: Wrong Answer

Solution code:
import sys

alphabets = "abcdefghijklmnopqrstuvwxyz"
S = input()
mp = {}

for s in S:
    if s in mp.keys():
        mp[s] = mp[s] + 1
    else:
        mp[s] = 1

# 辞書順の値を返却
def val(c):
    if len(c) != 1:
        return None # invalid
    for i, e in enumerate(alphabets):
        if c == e:
            return len(alphabets) - i
    return None # invalid

def idx(c):
    if len(c) != 1:
        return None # invalid
    for i, e in enumerate(alphabets):
        if c == e:
            return i
    return None # invalid

# 使われてない文字がある場合
unused = []
used = []
for a in alphabets:
    if a not in mp.keys():
        unused.append(a)
    else:
        used.append(a)
        
if len(unused) > 0:
    print(S + unused[0])
    sys.exit(0)

# 先頭から探していく
pos = len(S) - 1
while True:
    if pos-1 == 0:
        print(-1)
        sys.exit()
    x = S[pos-1]
    y = S[pos]
    if val(x) > val(y):
        n = alphabets[idx(x) + 1]
        print(S[:pos-1] + n)
        sys.exit()

    # update
    pos = pos - 1

Submission status: Wrong Answer

Solution code:
s = input()
t = set(map(chr, range(ord('a'), ord('z')+1))) - set(s)
if t:
    print(s + min(t))
else:
    m = s[-1]
    for i in range(len(s)-1)[::-1]:
        if s[i] > m:
            print(s[:i] + m)
            break
        m = s[i]
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
t = set(map(chr, range(ord('a'), ord('z')+1))) - set(s)
if t:
    print(s + min(t))
else:
    m = 'zz'
    for i in range(1, len(s))[::-1]:
        m = min(m, s[i])
        if s[i-1] < s[i]:
            print(s[:i-1] + m)
            break
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    s = input()
    alpha = list([1 for i in range(26)])
    if len(s) != 26:
        for i in range(len(s)):
            if(alpha[ord(s[i])-97] == 0):
                print("-1")
                exit()
            alpha[ord(s[i])-97] = 0
        for i in range(len(alpha)):
            if alpha[i]==1:
                print(str(s)+chr(i+97))
                exit()
        print("-1")
        exit()
    else:
        mini = ord(s[-1])
        for i in reversed(range(len(s))):
            if ord(s[i]) < mini:
                print(s[:i]+chr(mini))
                exit()
        print("-1")
        exit()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    s = input()
    alpha = list([1 for i in range(26)])
    if len(s) != 26:
        for i in range(len(s)):
            alpha[ord(s[i])-97] = 0
        for i in range(len(alpha)):
            if alpha[i]==1:
                print(str(s)+chr(i+97))
                exit()
        print("-1")
        exit()
    else:
        mini = ord(s[-1])
        for i in reversed(range(len(s))):
            if ord(s[i]) < mini:
                print(s[:i]+chr(mini))
                exit()
        print("-1")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    s = input()
    alpha = list([1 for i in range(26)])
    if len(s) != 26:
        for i in range(len(s)):
            alpha[ord(s[i])-97] = 0
        for i in range(len(alpha)):
            if alpha[i]==1:
                print(str(s)+chr(i+97))
                exit()
        print("-1")
        exit()
    else:
        max = 0
        for i in reversed(range(len(s))):
            if ord(s[i]) < max:
                print(s[:i]+chr(max))
                exit()
            if ord(s[i]) > max:
                max = ord(s[i])
        print("-1")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    s = input()
    alpha = list([1 for i in range(26)])
    if len(s) != 26:
        for i in range(len(s)):
            alpha[ord(s[i])-97] = 0
            for i in range(len(alpha)):
                if alpha[i]==1:
                    print(str(s)+chr(i+97))
                    exit()
            print("-1")
            exit()
    else:
        max = 0
        for i in reversed(range(len(s))):
            if ord(s[i]) < max:
                print(s[:i]+chr(max))
                exit()
            if ord(s[i]) > max:
                max = ord(s[i])
        print("-1")

Submission status: Wrong Answer

Solution code:
import string


def main():
    """
    abcdefghijklmnopqrstuvwxyz
    zyxwvutsrqponmlkjihgfedcba
    """
    S = input()

    az = string.ascii_lowercase
    za = az[::-1]
    if len(S) < len(az):
        # 全文字使ってない
        s_s = set(S)
        s_az = set(az)
        a = sorted(list(s_az - s_s))[0]

        # S=abのとき、abc < ac==True なので追加で良い
        ans = S + a
        print(ans)
        return

    editorial(S, az, za)

def editorial(S, az, za):
    for i in range(26)[::-1]:
        if S[i-1] > S[i]:
            continue

        # 逆sort済みの途中で辞書順になった
        # 逆sortの中で辞書順小さいもので置き換えて、辞書順最小にする
        s = S[i:]
        p_1 = S[i-1]
        idx = az.index(p_1)
        q = az[idx+1]
        ans = S[:i-1] + q
        print(ans)
        return

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import string


def main():
    """
    abcdefghijklmnopqrstuvwxyz
    zyxwvutsrqponmlkjihgfedcba
    """
    S = input()

    az = string.ascii_lowercase
    za = az[::-1]
    if len(S) < len(az):
        # 全文字使ってない
        s_s = set(S)
        s_az = set(az)
        a = sorted(list(s_az - s_s))[0]

        # S=abのとき、abc < ac==True なので追加で良い
        ans = S + a
        print(ans)
        return

    editorial(S, az, za)

def editorial(S, az, za):
    for i in range(26)[::-1]:
        if S[i-1] > S[i]:
            if i == 1:
                # S==za, ずっと前の文字と逆sort済み
                print(-1)
                return
        else:
            # 逆sort済みの途中で辞書順になった
            # 逆sortの中で辞書順小さいもので置き換えて、辞書順最小にする
            p_1 = S[i-1]
            idx = az.index(p_1)
            q = az[idx+1]
            ans = S[:i-1] + q
            print(ans)
            return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
S = input()

def solve():
    alpha = [c for c in 'abcdefghijklmnopqrstuvwxyz']
    if len(S) < 26:
        for S_i in S:
            alpha.remove(S_i)
        print(S + alpha[0])
        return
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        return
    last_alpha = ""
    post_fix = ""
    latest = -1
    post_fix_index = 25
    for S_i in S[::-1]:
        if last_alpha == "" or S_i > last_alpha:
            last_alpha = S_i
            post_fix = S_i + post_fix
            post_fix_index -= 1
            if latest == -1:
                latest = S_i
        else: 
            print(S[:post_fix_index] + latest)
            return


solve()

Submission status: Wrong Answer

Solution code:
S = input()

def solve():
    alpha = [c for c in 'abcdefghijklmnopqrstuvwxyz']
    if len(S) < 26:
        for S_i in S:
            alpha.remove(S_i)
        print(S + alpha[0])
        return
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        return
    last_alpha = ""
    post_fix = ""
    latest = -1
    post_fix_index = 25
    for S_i in S[::-1]:
        if last_alpha == "" or S_i > last_alpha:
            last_alpha = S_i
            post_fix = S_i + post_fix
            post_fix_index -= 1
            if latest == -1:
                latest = S_i
    print(S[:post_fix_index] + latest)


solve()

Submission status: Wrong Answer

Solution code:
def solve(S):
    chars = [chr(c) for c in range(ord("a"), ord("z") + 1)]
    cs = dict((c, S.count(c)) for c in chars)
    l = len(S) 
    if l < len(chars):
        return S + sorted(c for c, n in cs.items() if n == 0)[0]
    for i in range(2, l):
        sl = S[:l - i]
        sc = S[l - i]
        sr = S[l - i + 1:]
        msr = min(sr)
        if msr > sc:
            return sl + msr
    return -1

S = input()
print(solve(S))

Submission status: Wrong Answer

Solution code:
import sys
import math

s=list(input())
a=[0]*26
for i in s:
    a[ord(i)-97]+=1
b=0
for j in range(26):
    if a[j]==0:
        s.append(chr(j+97))
        b=1
        break
if b==1:
    print("".join(s))
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
import sys
import math

s=list(input())
a=[0]*27
for i in s:
    a[ord(i)-97]+=1
b=0
for j in range(27):
    if a[j]==0:
        s.append(chr(j+97))
        b=1
        break
if b==1:
    print("".join(s))
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
S = input()
C = [chr(97+i) for i in range(26)]

if len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    S = list(S)
    for i in range(25, -1, -1):
        if S[i:] != sorted(S[i:], reverse=True):
            print("".join(S[:i]) + C[C.index(S[i])+1])
            break
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
C = [chr(97+i) for i in range(26)]

if len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    S = list(S)
    for i in range(25, -1, -1):
        if S[i:] != sorted(S[i:], reverse=True):
            print("".join(S[:i]) + sorted(S[i:])[1])
            break
    else:
        print(-1)