Problem:


Score : 300 points

Problem Statement

Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible diverse words in lexicographical order.

A word is called diverse if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, atcoder, zscoder and agc are diverse words while gotou and connect aren't diverse words.

Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist.

Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Constraints

1 \leq |S| \leq 26

S is a diverse word.

Input

Input is given from Standard Input in the following format:

S

Output

Print the next word that appears after S in the dictionary, or -1 if it doesn't exist.

Sample Input 1

atcoder

Sample Output 1

atcoderb

atcoderb is the lexicographically smallest diverse word that is lexicographically larger than atcoder. Note that atcoderb is lexicographically smaller than b.

Sample Input 2

abc

Sample Output 2

abcd

Sample Input 3

zyxwvutsrqponmlkjihgfedcba

Sample Output 3

-1

This is the lexicographically largest diverse word, so the answer is -1.

Sample Input 4

abcdefghijklmnopqrstuvwzyx

Sample Output 4

abcdefghijklmnopqrstuvx



Sample input:
atcoder


Sample output:
atcoderb

Submission status: Wrong Answer

Solution code:
s = input()
if len(s) == 26:
  if ord(s[1]) != ord(s[0]) + 1:
    print(-1)
    exit()
  for i in range(1, 25):
    if ord(s[i+1]) != ord(s[i]) + 1:
      print(s[:i] + chr(ord(s[i]) + 1))
      exit()
else:
  for i in range(26):
    if chr(ord('a') + i) not in s:
      print(s + chr(ord('a') + i))
      exit()

Submission status: Wrong Answer

Solution code:
S = input()

s_sort = sorted(list(S))

new_character = "?"

if len(S) < 26:
  for  s in range(97,123,1):
    if S.count(chr(s))==0:
      new_character = chr(s)
      print(S + new_character)
      break
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    letter = S[25]
    for x in range(25,0,-1):
      if ord(S[x-1]) > ord(S[x]):
        letter = chr(min(ord(S[x-1]),ord(S[x]),ord(letter)))
      else:
        letter = chr(min(ord(S[x-1]),ord(S[x]),ord(letter)))
        ans = S[:x-1] + letter
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
S = input()

s_sort = sorted(list(S))

new_character = "?"

if len(S) < 26:
  for  s in range(97,123,1):
    if S.count(chr(s))==0:
      new_character = chr(s)
      print(S + new_character)
      break
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    letter = S[25]
    for x in range(25,0,-1):
      if ord(S[x-1]) > ord(S[x]):
        letter = chr(min(ord(S[x-1]),ord(S[x]),ord(letter)))
      else:
        ans = S[:x-1] + letter
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
S = input()

s_sort = sorted(list(S))

new_character = "?"

if len(S) < 26:
  for  s in range(97,123,1):
    if S.count(chr(s))==0:
      new_character = chr(s)
      print(S + new_character)
      break
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    letter = S[25]
    for x in range(25,0,-1):
      #print(S[x])
      if ord(S[x-1]) > ord(S[x]):
        letter = chr(min(ord(S[x-1]),ord(S[x]),ord(letter)))
      else:
        ans = S[:x] + letter
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
S = list(input())
c = set(S)
all_ar = list("abcdefghijklmnopqrstuvwxyz")
if len(c) == 26:
    print(-1)
    exit()
for i in range(26):
    if not all_ar[i] in c:
        print(''.join(S)+all_ar[i])
        exit()

Submission status: Wrong Answer

Solution code:
s = str(input())

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(s) == 26:
    tmp = ord(s[-1])
    for i in range(len(s))[::-1]:
        if ord(s[i]) > tmp:
            ans = sorted(s[i - 2:])
            for j in ans:
                if ord(j) > ord(s[i - 2]):
                    print(s[:i - 2] + j)
                    exit()
        tmp = ord(s[i])
    
else:
    alpha = [chr(i) for i in range(97, 97 + 26)]
    for i in alpha:
        if i not in s:
            print(s + i)
            break

Submission status: Wrong Answer

Solution code:
s = str(input())

strin = set(list(s))
alpha = [chr(i) for i in range(97, 97 + 26)]
for i in alpha:
    if i not in s:
        print(s+i)
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
remaining = set("abcdefghijklmnopqrstuvwxyz") - set(S)
if remaining:
    print(S + min(remaining))
else:
    prev = S[25]
    for i in range(24, -1, -1):
        c = S[i]
        if c < prev:
            print(S[:i] + min(S[i + 1 :]))
            break
        prev = c
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
remaining = set("abcdefghijklmnopqrstuvwxyz") - set(S)
if remaining:
    print(S + min(remaining))
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    prev = S[25]
    for i in range(24, -1, -1):
        c = S[i]
        if c > prev:
            print(S[: i - 2] + min(S[i - 1 :]))
            break
        prev = c

Submission status: Wrong Answer

Solution code:
alphs = set("abcdefghijklmnopqrstuvwxyz")
S = input()
remaining = alphs - set(S)
if remaining:
    print(S + min(remaining))
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    prev = S[25]
    for i in range(25, -1, -1):
        c = S[i]
        if prev < c:
            print(S[: i - 2] + min(S[i - 1 :]))
            break
        prev = c

Submission status: Wrong Answer

Solution code:
alphs = set("abcdefghijklmnopqrstuvwxyz")
S = input()
remaining = alphs - set(S)
if remaining:
    print(S + min(remaining))
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    prev = S[-1]
    for i in range(1, 26):
        c = S[25 - i]
        if c < prev:
            print(S[: 25 - i] + chr(ord(S[25 - i]) + 1))
            break
        prev = c

Submission status: Wrong Answer

Solution code:
from collections import deque


alphs = set("abcdefghijklmnopqrstuvwxyz")
S = input()
remaining = alphs - set(S)
if remaining:
    print(S + min(remaining))
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    q = deque(S[-1])
    prev = S[-1]
    for i in range(1, 25):
        c = S[25 - i]
        if c < prev:
            print(S[: 25 - i] + q.popleft())
            break
        q.append(c)
        prev = c

Submission status: Wrong Answer

Solution code:
s = input()
al = [chr(i) for i in range(97, 97+26)]
l = list(s)
if len(s) == 26:
    for i in range(24, -1, -1):
        for j in range(25, i, -1):
            if s[i] < s[j]:
                print(s[:i] + s[j])
                exit()
elif s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for i in al:
        if not i in s:
            print(s + i)
            exit()

Submission status: Wrong Answer

Solution code:
s = input()
al = [chr(i) for i in range(97, 97+26)]
l = list(s)
for i in al:
    if not i in s:
        print(s + i)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = list(input())

alfabet = list("abcdefghijklmnopqrstuvwxyz")
rev_alf = list("zyxwvutsrqponmlkjihgfedcba")

# len(s) < 26 のとき
if len(s) == 26:
  if s == rev_alf:
    print(-1)
  else:
    for idx, alf in enumerate(rev_alf):
      # print(idx, alf)
      break_point = s.index(alf)
      if break_point == idx:
        continue
      else:
        target_word = s[break_point - 1]
        join_word = alfabet[ alfabet.index(target_word) + 1 ]
        # print( target_word )
        # print( join_word )
        print("".join(s[:break_point - 1]) + join_word)
        break
else:
  add_word = ""
  for alf in alfabet:
    if alf in s:
      continue
    else:
      add_word = alf
      break

  if add_word == "":
    print(-1)
  else:
    print("".join(s) + add_word)

Submission status: Wrong Answer

Solution code:
s = list(input())

# len(s) < 26 のとき
alfabet = list("abcdefghijklmnopqrstuvwxyz")
add_word = ""
for alf in alfabet:
  if alf in s:
    continue
  else:
    add_word = alf
    break

if add_word == "":
  print(-1)
else:
  print("".join(s) + add_word)

Submission status: Wrong Answer

Solution code:
import sys
S = input()

asc = [0]*26
for s in S:
    asc[ord(s)-97] = 1



if len(S) == 26:
    temp = ord(S[-1])
    for i in range(26):
        if ord(S[25-i]) < temp:
            print(S[:(25-i)]+chr(temp))
            sys.exit()
    print(-1)
else:
    for i in range(26):
        if asc[i] == 0:
            S += chr(97+i)
            break
    print(S)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    S = input().strip()
    if len(S) < 26:
        for i in range(97, 123):
            if chr(i) not in S:
                print(S + chr(i))
                return
    
    c = ord(S[-1])
    for i in range(len(S)):
        if ord(S[-i-1]) < c:
            print(S[:-i-1] + chr(c))
            return
    print('-1')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    S = input().strip()
    if len(S) < 26:
        for i in range(97, 123):
            if chr(i) not in S:
                print(S + chr(i))
                return

    c = ord(S[-1])
    for i in range(len(S)):
        if ord(S[-i-1]) < c:
            print(S[:-i-1] + chr(c))
            return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
S = input()

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

if len(S) < 26:
    for a in ascii_lowercase:
        if a not in set(list(S)):
            print(S + a)
            exit()

T = S
S = "".join(sorted(S))
ans= ""
for i in range(26):
    ans += S[i]
    if S[i] != T[i]:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
if len(s) < 26:
    print(s + chr(ord(s[-1]) + 1))
else:
    i = len(s) - 1
    while i != 0 and s[i - 1] > s[i]:
        i -= 1
    if i == 0:
        print(-1)
    else:
        print(s[: i - 1] + chr(ord(s[i - 1]) + 1))

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    s = list(input())
    c = Counter(s)
    if len(set(s)) != 26:
        for i in range(97, 123):
            if c[chr(i)] == 0:
                s.append(chr(i))
                print(''.join(s))
                exit()
            else:
                pass
    else:
        for i in range(1, len(s) + 1):
            si = s[-i:]
            if si != sorted(si, reverse = True):
                ans = s[:-i]
                ans.append(min(si[1:]))
                print(''.join(ans))
                break
        else:
            print(-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import string
s = input()
ss = set(s)
for t in string.ascii_lowercase:
  if t not in ss:
    print(s + t)
    break
else:
  idx = -1
  flag = False
  for i in range(len(s) - 1):
    if s[-i - 1] < s[-i - 2]:
      flag = True
    if flag and s[-i - 1] > s[-i - 2]:
      print(s[:-i - 2] + chr(ord(s[-i - 2]) + 1))
      break
  else:
    if flag:
      print(-1)
    else:
      print(chr(ord(s[0]) + 1))

Submission status: Wrong Answer

Solution code:
import string
s = input()
ss = set(s)
for t in string.ascii_lowercase:
  if t not in ss:
    print(s + t)
    break
else:
  idx = -1
  flag = False
  for i in range(len(s) - 1):
    if s[-i - 1] < s[-i - 2]:
      flag = True
    if flag and s[-i - 1] > s[-i - 2]:
      print(s[:-i - 2] + chr(ord(s[-i - 2]) + 1))
      break
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import string
s = input()
ss = set(s)
for t in string.ascii_lowercase:
  if t not in ss:
    print(s + t)
    break
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
wl = [chr(i) for i in range(97,123)]
hoge = 'zyxwvutsrqponmlkjihgfedcba'
if s == hoge:
  print(-1)
  exit()
if len(s) < 26:
  for w in wl:
    if not w in s:
      s += w
      print(s)
      exit()
else:
  a = s[::-1]
  mae = ord(a[0])+1
  for i in range(26):
    if mae-1 == ord(a[i]):
      mae -= 1
      continue
    else:
      a = chr(ord(a[i+2])+1) + a[i+3:]
      print(a[::-1])
      exit()

Submission status: Wrong Answer

Solution code:
s = input()
wl = [chr(i) for i in range(97,123)]
if len(s) < 26:
  for w in wl:
    if not w in s:
      s += w
      print(s)
      exit()
else:
  a = s[::-1]
  mae = ord(a[0])+1
  for i in range(26):
    if mae-1 == ord(a[i]):
      mae -= 1
      continue
    else:
      a = chr(ord(a[i+2])+1) + a[i+3:]
      print(a[::-1])
      exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
wl = [chr(i) for i in range(97,123)]
if len(s) < 26:
  for w in wl:
    if not w in s:
      s += w
      print(s)
      exit()
else:
  for i in range(26):
    if s[i] != wl[25-i]:
      s = s[:i] + chr(ord(s[i])+1)
      print(s)
      exit()
print(-1)

Submission status: Wrong Answer

Solution code:
def check():
    S = input()
    s_set = set(S)
    alpha = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) == 26:
        if S == alpha[::-1]:
            return -1
        else:
            for i in range(1,len(S)):
                S1 = S[-i:]
                if S1 != ''.join(sorted(S1, reverse=True)):
                    S1 = S1[1:]
                    break
            for s in S1[::-1]:
                if s > S[-i]:
                    return S[:-i]+s
    else:
        for a in alpha:
            if a not in s_set:
                return S+a
print(check())

Submission status: Wrong Answer

Solution code:
def check():
    S = input()
    s_set = set(S)
    alpha = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) == 26:
        if S == alpha[::-1]:
            return -1
        else:
            for i in range(1,len(S)):
                S1 = S[-i:]
                if S1 != ''.join(sorted(S1, reverse=True)):
                    for s in S1[::-1][:-1]:
                        if s > S[-i]:
                            return S[:-i]+s
    else:
        for a in alpha:
            if a not in s_set:
                return S+a
print(check())

Submission status: Wrong Answer

Solution code:
def check():
    S = input()
    s_set = set(S)
    alpha = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) == 26:
        if S == alpha[::-1]:
            return -1
        else:
            for i in range(1,len(S)):
                S1 = S[-i:]
                if S1 != ''.join(sorted(S1, reverse=True)):
                    for s in S1[::-1]:
                        if s > S[-i]:
                            return S[:-i]+s
    else:
        for a in alpha:
            if a not in s_set:
                return S+a
print(check())

Submission status: Wrong Answer

Solution code:
def check():
    S = input()
    s_set = set(S)
    alpha = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) == 26:
        if S == alpha[::-1]:
            return -1
        else:
            for i in range(1,len(S)):
                S1 = S[-i:]
                if S1 != ''.join(sorted(S1, reverse=True)):
                    for s in S1[::-1]:
                        if s > S[-i-1]:
                            return S[:-i-1]+s
    else:
        for a in alpha:
            if a not in s_set:
                return S+a
              
print(check())

Submission status: Wrong Answer

Solution code:
S = input()
s_set = set(S)
ind = len(S)

if len(S) == 26:
    s_set.remove(S[-1])
    for i in range(24, -1, -1):
        if ord(S[i]) > ord(S[i+1]):
            s_set.remove(S[i])
            continue
        else:
            ind = i
            break
    if len(s_set) == 0:
        print(-1)
        exit()
    for i in range(26):
        if chr(i+97) in s_set:
            continue
        else:
            print(S[:ind] + chr(i+97))
            break

else:        
    for i in range(26):
        if chr(i+97) in s_set:
            continue
        else:
            print(S + chr(i+97))
            break

Submission status: Wrong Answer

Solution code:
S = input()
s_set = set(S)
ind = len(S)

if len(S) == 26:
    s_set.remove(S[-1])
    s_set.remove(S[-2])
    for i in range(23, -1, -1):
        if ord(S[i]) > ord(S[i+1]):
            s_set.remove(S[i])
            continue
        else:
            ind = i
            break
    if len(s_set) == 0:
        print(-1)
        exit()
    for i in range(26):
        if chr(i+97) in s_set:
            continue
        else:
            print(S[:ind] + chr(i+97))
            break

else:        
    for i in range(26):
        if chr(i+97) in s_set:
            continue
        else:
            print(S + chr(i+97))
            break

Submission status: Wrong Answer

Solution code:
S = input()
s_set = set(S)
ind = len(S)

if len(S) == 26:
    s_set.remove(S[-1])
    s_set.remove(S[-2])
    for i in range(23, -1, -1):
        if ord(S[i]) > ord(S[i+1]):
            s_set.remove(S[i])
            continue
        else:
            ind = i
            break
    if len(s_set) == 0:
        print(-1)
        exit()
    print(S[:ind])
    for i in range(26):
        if chr(i+97) in s_set:
            continue
        else:
            print(S[:ind] + chr(i+97))
            break

else:        
    for i in range(26):
        if chr(i+97) in s_set:
            continue
        else:
            print(S + chr(i+97))
            break

Submission status: Wrong Answer

Solution code:
S = input()
s_set = set(S)
ind = len(S)

if len(S) == 26:
    s_set.remove(S[-1])
    s_set.remove(S[-2])
    for i in range(23, -1, -1):
        if ord(S[i]) > ord(S[i+1]):
            s_set.remove(S[i])
            continue
        else:
            ind = i
            break
    if len(s_set) == 0:
        print(-1)
        exit()

        
for i in range(26):
    if chr(i+97) in s_set:
        continue
    else:
        print(S[:ind] + chr(i+97))
        break

Submission status: Wrong Answer

Solution code:
S = input()
s_set = set(S)

if len(S) == 26:
    s_set.remove(S[-1])
    s_set.remove(S[-2])
    for i in range(23, -1, -1):
        if ord(S[i]) > ord(S[i+1]):
            s_set.remove(S[i])
            continue
        else:
            break
    if len(s_set) == 0:
        print(-1)
        exit()

        
for i in range(26):
    if chr(i+97) in s_set:
        continue
    else:
        print(S[:len(s_set)] + chr(i+97))
        break

Submission status: Wrong Answer

Solution code:
s = input()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) != 26:
    used = [False] * 26
    for i in range(len(s)):
        used[ord(s[i]) - ord("a")] = True
    for i in range(26):
        if used[i] is False:
            s += chr(ord("a") + i)
            print(s)
            break
else:
    ss = []
    s = list(s)
    done = False
    used = [False] * 26

    for i in range(25, 0, -1):
        #print("load", s[i])
        if ord(s[i-1]) < ord(s[i]):
            start = ord(s[i]) - ord("a") + 1
            for i in range(start, 26):
                if used[i] is True:
                    ss = chr(ord("a") + i)
                    done = True
                    break
        else:
            ss += s[i]
            used[ord(s[i]) - ord("a")] = True

        if done:
            print("".join(s[:i-1]) + ss)
            break

Submission status: Wrong Answer

Solution code:
S = input()
if len(S)<26:
    for i in range(26):
        ans = S + chr(97+i)
        if len(ans) == len(list(set(ans))):
            print(ans)
            break
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        if S[25] < S[24]:
            for i in range(1,26):
                if S[25-i] < S[25]:
                    print(S[0:25-i]+S[25])
                    break
        else:
            print(S[0:24]+S[25])

Submission status: Wrong Answer

Solution code:
S = input()
if len(S)<26:
    for i in range(26):
        ans = S + chr(97+i)
        if len(ans) == len(list(set(ans))):
            print(ans)
            break
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        if S[25] < S[24]:
            for i in range(1,26):
                if S[25-i] < S[25]:
                    print(S[0:25-i]+S[25])
                    break
        else:
            print(S[0:24]+S[25]+S[24])

Submission status: Wrong Answer

Solution code:
S = input()
if len(S)<26:
    for i in range(26):
        ans = S + chr(97+i)
        if len(ans) == len(list(set(ans))):
            print(ans)
            break
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        for i in range(1,26):
            if S[25-i] < S[25]:
                print(S[0:25-i]+S[25])
                break

Submission status: Wrong Answer

Solution code:
S = list(input())

abc = [chr(ord('a') + i) for i in range(26)]

if len(S) < 26:
    rest_alp = list(set(abc) - set(S))
    rest_alp.sort()
    S.append(rest_alp[0])
    print("".join(S))
    exit()
else:
    for i in reversed(range(25)):
        for j in reversed(range(i+1, 26)):
            print(i, j)
            if S[i] < S[j]:
                ans = S[:i].append(S[j])
                print(ans)
                print("".join(S[:i]) + "".join(S[j]))
                exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = str(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
inv_alpha = 'zyxwvutsrqponmlkjihgfedcba'
if len(s) == 26:
    if s == alpha:
        print('b')
    elif s == inv_alpha:
        print(-1)
    else:
        for i in range(2, 26):
            sn = s
            pool = []
            for _ in range(i):
                pool.append(sn[-1])
                sn = sn[:-1]
            pool.sort(reverse=True)
            if s[:-(i-1)] < sn + pool[0]:
                print(sn + pool[pool.index(s[-i])-1])
                break
else:
    S = sorted(set(alpha) - set(s))
    print(s + S[0])

Submission status: Wrong Answer

Solution code:
s = str(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
inv_alpha = 'zyxwvutsrqponmlkjihgfedcba'
if len(s) == 26:
    if s == alpha:
        print('b')
    elif s == inv_alpha:
        print(-1)
    else:
        for i in range(2, 26):
            sn = s
            pool = []
            for _ in range(i):
                pool.append(sn[-1])
                sn = sn[:-1]
            pool.sort(reverse=True)
            if s[:-(i-1)] < sn + pool[-2]:
                print(sn + pool[-2])
                break
else:
    S = sorted(set(alpha) - set(s))
    print(s + S[0])

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
s = deque(map(str, input().rstrip()))

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

s = [ord(x) for x in s]

if len(s) < 26:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

else:
    add = []
    s = s[::-1]
    prev = s[0]
    add.append(prev)
    
    if prev == 122:
        s[1] = 122
        s = s[::-1]
        s = s[:-1]
    
    else:
        for i in range(1, len(s)):
            if prev > s[i]:
                s[i] = (min(add))
                s = s[::-1]
                s = s[:-i]
                break

s = [chr(x) for x in s]

print("".join(s))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
s = deque(map(str, input().rstrip()))

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

s = [ord(x) for x in s]

if len(s) < 26:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

else:
    add = []
    s = s[::-1]
    prev = s[0]
    add.append(prev)
    for i in range(1, len(s)):
        if prev > s[i]:
            s[i] = (min(add))
            s = s[::-1]
            s = s[:-i]
            break

s = [chr(x) for x in s]

print("".join(s))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
s = deque(map(str, input().rstrip()))

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

s = [ord(x) for x in s]

if len(s) < 26:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

else:
    add = []
    while s:
        q = s.pop()
        add.append(q)
        if q == 122:
            break
    add = [x for x in add if x > s[-1]]
    s[-1] = min(add)

s = [chr(x) for x in s]

print("".join(s))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
s = deque(map(str, input().rstrip()))

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

s = [ord(x) for x in s]

if len(s) < 26:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

else:
    add = []
    cnt = 0
    while s:
        cnt += 1
        q = s.pop()
        add.append(q)
        if q == 122:
            break
    add = [x for x in add if x > s[-1]]
    
    if cnt != 1:
        s[-1] = min(add)

s = [chr(x) for x in s]

print("".join(s))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from collections import Counter
s = deque(map(str, input().rstrip()))

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

s = [ord(x) for x in s]

if len(s) < 26:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

else:
    add = []
    while s:
        q = s.pop()
        add.append(q)
        if q == 122:
            break
    add = [x for x in add if x > s[-1]]
    s[-1] = min(add)

s = [chr(x) for x in s]

print("".join(s))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from collections import Counter
s = deque(map(str, input().rstrip()))

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

s = [ord(x) for x in s]

if len(s) < 26:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

else:
    add = []
    while s:
        q = s.pop()
        add.append(q)
        if q == 122:
            break
    s[-1] = min(add)

s = [chr(x) for x in s]

print("".join(s))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from collections import Counter
s = deque(map(str, input().rstrip()))

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

s = [ord(x) for x in s]

maxlen = False

if len(s) == 26:
    maxlen = True
    s = s[::-1]
    x = s[0]
    for i, w in enumerate(s):
        if x > w:
            break
    
    s[i] += 1
    s = s[::-1]
    s = s[:-i]

can_use = set(range(97, 123)) - set(s)

if not maxlen:
    s = s + [min(can_use)]

s = [chr(x) for x in s]

print("".join(s))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from collections import Counter
s = deque(map(str, input().rstrip()))

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

s = [ord(x) for x in s]

if len(s) == 26:
    s = s[::-1]
    x = s[0]
    for i, w in enumerate(s):
        if x > w:
            break

    s[i] = s[i] + 1
    s = sorted(s[:i], reverse=True) + s[i:]
    s = s[::-1][:-i]
else:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

s = [chr(x) for x in s]

print("".join(s))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from collections import Counter
s = deque(map(str, input().rstrip()))

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

s = [ord(x) for x in s]

if len(s) == 26:
    s = s[::-1]
    x = s[0]
    for i, w in enumerate(s):
        if x > w:
            break

    s[i] = x
    s[0] = w
    s = sorted(s[:i], reverse=True) + s[i:]
    s = s[::-1][:-i]
else:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

s = [chr(x) for x in s]

print("".join(s))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from string import*
from itertools import*
s = input()
l = len(s)
if l < 26:
    print(s + sorted(set(ascii_lowercase) - set(s))[0])
else:
    t = s[::-1]
    a = [(p, len(list(k))) for p, k in groupby([i < j for i, j in zip(t, t[1:])])][0]
    d = - a[0]*a[1] - 2
    print(-(d < -26) or s[:d] + chr(ord(s[d]) + 1))

Submission status: Wrong Answer

Solution code:
s = input()
word = [0] * 26
for i in s:
    word[ord(i) - 97] = 1

if sum(word) != 26:
    for i in range(26):
        if word[i] == 0:
            c = chr(i + 97)
            break
    print(s + c)
else:
    if s == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        for i in range(25, -1, -1):
            if s[i] == 'z':
                pass
            else:
                if chr(ord(s[i]) + 1) in s[0:i]:
                    pass
                else:
                    print(s[0:i] + chr(ord(s[i]) + 1))
                    break

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
s = input()
sl = [c for c in s]
lower = set(ascii_lowercase)
for c in s:
    if c in lower:
        lower.remove(c)
    else:
        print(-1)
        exit()
else:
    if len(lower) == 0:
        tc = sl.pop()
        while len(sl) > 0:
            c2 = sl.pop()
            if c2 < tc:
                print(''.join(sl)+tc)
                exit()
        print(-1)
    else:
        lower = list(lower)
        lower.sort()
        print(s+lower[0])

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)

alf=set('abcdefghijklmnopqrstuvwxyz')
for i in range(l):
    if s[i] in alf:
        alf.remove(s[i])

if alf:
    t = list(alf)
    t.sort()
    s+=t[0]
else:
    stock=[]
    for i in range(1,26):
        if s[l-i-1]>s[l-i]:
            stock.append(s[l-i])
        else:
            stock.append(s[l-i])
            stock.sort()
            s=s[:l-i-1]+stock[0]
            break
        if i==25:
            print('-1')
            exit()

print(s)

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)

if n!=26:
  l = [i for i in "abcdefghijklmnopqrstuvwxyz"]
  for i in range(26):
    if l[i] not in s:
      s += [l[i]]
      print("".join(s))
      exit()

else:
  q = "zyxwvutsrqponmlkjihgfedcba"
  if "".join(s) == q:
    print(-1)
  else:
    t = ord(s[0])
    for i in range(1,n):
      if ord(s[i])==t+1:
        t += 1
      else:
        if "".join(s[i:])==q[:n-i]:
          s[i-1] =  chr(t+1)
          print("".join(s[:i]))
          exit()
        else:
          s[i+1] = chr(ord(s[i])+1)
          print("".join(s[:i+2]))
          exit()

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)

if n!=26:
  l = [i for i in "abcdefghijklmnopqrstuvwxyz"]
  for i in range(26):
    if l[i] not in s:
      s += [l[i]]
      print("".join(s))
      exit()

else:
  q = "zyxwvutsrqponmlkjihgfedcba"
  if "".join(s) == q:
    print(-1)
  else:
    t = ord(s[0])
    for i in range(1,n):
      if ord(s[i])==t+1:
        t += 1
      else:
        if "".join(s[i:])==q[:n-i]:
          s[i-1] =  chr(t+1)
          print("".join(s[:i]))
          exit()
        else:
          s[i+1] = chr(ord(s[i+1])+1)
          print("".join(s[:i+2]))
          exit()