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 = str(input())
N = len(S)
L = list(S)
L = set(L)
if N != 26: #含まないものがある
  for i in range(26):
    temp = chr(i+97)
    if temp not in L:
      ans = S+temp
      print(ans)
      exit()
M = []
All = [chr(97+i) for i in range(26)]
print(All)
for i in range(25):
  now = 25-i
  M.append(S[now])
  if S[now] > S[now-1]:
    M.sort()
    for x in M:
      if x > S[now-1]:
        temp = x
        ans = S[:now-1]+temp
        print(ans)
        exit()
  
print(-1)

Submission status: Wrong Answer

Solution code:
S = str(input())
N = len(S)
L = list(S)
L = set(L)
if N != 26: #含まないものがある
  for i in range(26):
    temp = chr(i+97)
    if temp not in L:
      ans = S+temp
      print(ans)
      exit()
M = []
for i in range(25):
  now = 25-i
  M.append(S[now])
  if S[now] > S[now-1]:
    ans = S[:now-1]+min(M)
    print(ans)
    exit()
  
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
all_set = set([chr(97+i) for i in range(26)])
raw_set = set(S)

if len(S)<26:
    lis = list(all_set - raw_set)
    lis.sort()
    S.append(lis[0])
    print(''.join(S))
else:
    can_use = set()
    p = S[-1]
    can_use.add(p)
    for i in range(24, -1, -1):
        nx = S[i]
        if ord(nx)<ord(p):
            lis = sorted(list(can_use))
            ans = S[:i]+[lis[0]]
            print(''.join(ans))
            break
        else:
            can_use.add(nx)
            p = nx
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
all_set = set([chr(97+i) for i in range(26)])
raw_set = set(S)

if len(S)<26:
    lis = list(all_set - raw_set)
    lis.sort()
    S.append(lis[0])
    print(''.join(S))
else:
    can_use = set()
    p = S[-1]
    can_use.add(p)
    for i in range(24, -1, -1):
        nx = S[i]
        if ord(nx)<ord(p):
            lis = sorted(list(can_use))
            ans = S[:i]+[lis[0]]
            print(''.join(ans))
            break
        else:
            can_use.add(nx)
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
s = input()
stock = [m for i in range(26) if (m := chr(ord("a") + i)) not in s]
if stock:
    print(s + stock[0])
else:
    for i in range(1, 26):
        if s[-i] > s[-1 - i]:
            print(s[:-1 - i] + s[-1])
            break
        if i == 25:
            print(-1)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')
kijun = ord("a")
if len(s) == 26:
    if s == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        exit()
    else:
        for i in range(kijun,kijun+26):
            if s[i-kijun] != chr(i):
                print(s[:i-kijun-1]+chr(ord(s[i-kijun-1])+1))
                exit()


for i in range(kijun,kijun+26):
    if chr(i) not in s:
        print(s+chr(i))
        exit()

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')
if len(s) == 26:
    print(-1)
    exit()

kijun = ord("a")
for i in range(kijun,kijun+26):
    if chr(i) not in s:
        print(s+chr(i))
        exit()

Submission status: Wrong Answer

Solution code:
s=str(input())
s=list(s)
t=["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"]
if len(s)!=26:
  for i in range(26):
    if t[i] not in s:
      s.append(t[i])
      break
  print("".join(s))
else:
  if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    ans=[]
    for i in range(26):
      if s[0]==t[i]:
        k=i
        break
    cnt=0
    for i in range(26):
      if k+i<=25:
        if s[i]==t[k+i]:
          ans.append(s[i])
          cnt=cnt+1
        else:
          del ans[len(ans)-1]
          ans.append(t[k+i])
          break
      else:
        if s[i]==t[k+i-26]:
          ans.append(s[i])
          cnt=cnt+1
        else:
          del ans[len(ans)-1]
          ans.append(t[k+i-26])         
          break
    if cnt==26:
      print(t[k+1])
    else:
      print("".join(ans))

Submission status: Wrong Answer

Solution code:
s=str(input())
s=list(s)
t=["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"]
if len(s)!=26:
  for i in range(26):
    if t[i] not in s:
      s.append(t[i])
      break
  print("".join(s))
else:
  if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    ans=[]
    for i in range(26):
      if s[0]==t[i]:
        k=i
        break
    cnt=0
    for i in range(26):
      if k+i<=25:
        if s[i]==t[k+i]:
          ans.append(s[i])
          cnt=cnt+1
        else:
          del ans[len(ans)-1]
          ans.append(t[k+i])
          break
      else:
        if s[i]==t[k+i-25]:
          ans.append(s[i])
          cnt=cnt+1
        else:
          del ans[len(ans)-1]
          ans.append(t[k+i-25])         
          break
    if cnt==26:
      print(t[k+1])
    else:
      print("".join(ans))

Submission status: Wrong Answer

Solution code:
s=str(input())
s=list(s)
t=["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"]
if len(s)!=26:
  for i in range(26):
    if t[i] not in s:
      s.append(t[i])
      break
  print("".join(s))
else:
  if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    ans=[]
    for i in range(26):
      if s[0]==t[i]:
        k=i
        break
    for i in range(26):
      if k+i<=25:
        if s[i]==t[k+i]:
          ans.append(s[i])
        else:
          del ans[len(ans)-1]
          ans.append(t[k+i])
          break
      else:
        if s[i]==t[k+i-25]:
          ans.append(s[i])
        else:
          del ans[len(ans)-1]
          ans.append(t[k+i-25])         
          break
    print("".join(ans))

Submission status: Wrong Answer

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

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

S = input()

import string
lower = [0 for i in range(len(string.ascii_lowercase))]
for i in S:
    lower[string.ascii_lowercase.index(i)] = 1

if all(lower):
    print(-1)
else:
    print(S + string.ascii_lowercase[lower.index(0)])

Submission status: Wrong Answer

Solution code:
s=str(input())
s=list(s)
t=["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"]
if len(s)!=26:
  for i in range(26):
    if t[i] not in s:
      s.append(t[i])
      break
  print("".join(s))
else:
  if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    ans=[]
    for i in range(24):
      ans.append(s[i])
    ans.append(s[25])
    ans.append(s[24])
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
s=str(input())
s=list(s)
t=["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"]
if len(s)!=26:
  for i in range(26):
    if t[i] not in s:
      s.append(t[i])
      break
  print("".join(s))
else:
  if "".join(s)=="abcdefghijklmnopqrstuvwxyz":
    print("abcdefghijklmnopqrstuvwxzy")
  elif "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    ans=[]
    for i in range(26):
      if s[i]==t[i]:
        ans.append(s[i])
      else:
        if len(ans)==0:
          ans.append(t[i])
        else:
          del ans[len(ans)-1]
          ans.append(t[i])
          break
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
s=str(input())
s=list(s)
t=["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"]
if len(s)!=26:
  for i in range(26):
    if t[i] not in s:
      s.append(t[i])
      break
  print("".join(s))
else:
  if "".join(s)=="abcdefghijklmnopqrstuvwxyz":
    print("abcdefghijklmnopqrstuvwxzy")
  elif "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    ans=[]
    for i in range(26):
      if s[i]==t[i]:
        ans.append(s[i])
      else:
        ans.append(t[i])
        break
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
dic = [False for i in range(26)]
txt = input()
for i in txt:
  dic[ord(i) - 97] = True
for i in range(26):
  if not dic[i]:
    break
else:
  for j in range(25):
    if txt[24 - j] < txt[25 - j]:
      
      last = txt[24-j] #以降の文字列を修正
      txt = txt[:24 - j]
      
      dic = [False for i in range(26)]
      for k in txt:
        dic[ord(k) - 97] = True
      txt += chr(dic[ord(last) - 96:].index(False) + ord(last) + 1)

      print(txt)
      break

  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
dic = [False for i in range(26)]
txt = input()
for i in txt:
  dic[ord(i) - 97] = True
for i in range(26):
  if not dic[i]:
    print(txt + chr(i + 97))
    break
else:
  for j in range(25):
    if txt[24 - j] < txt[25 - j]:
      
      last = txt[24-j] #以降の文字列を修正
      txt = txt[:24 - j]
      
      dic = [False for i in range(26)]
      for k in txt:
        dic[ord(k) - 97] = True
      print(chr(dic[ord(last) - 96:].index(False) + ord(last)))
      txt += chr(dic[ord(last) - 96:].index(False) + ord(last) + 1)

      print(txt)
      break

  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
dic = [False for i in range(26)]
txt = input()
for i in txt:
  dic[ord(i) - 97] = True
for i in range(26):
  if not dic[i]:
    print(txt + chr(i + 97))
    break
else:
  for j in range(25):
    #print(txt[24-j], txt[25-j])
    if txt[24 - j] < txt[25 - j]:
      txt = txt[:25 - j]
      temp = ord(txt[-1]) + 1
      txt = txt[:-1]
      txt += chr(temp)
      dic = [False for i in range(26)]
      print(txt)
      break

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
check = [0]*26
if len(S)==26:
    end = S[-1]
    for i in range(24, -1, -1):
        if ord(S[i])<ord(end):
            S[i] = end
            print(''.join(S[:i+1]))
            break
    else:
        if S[0]=='z':
            print(-1)
        else:
            print(chr(ord(S[0])+1))
else:
    for s in S:
        check[ord(s)-97] = 1
    for i in range(26):
        if not check[i]:
            S.append(chr(i+97))
            break
    print(''.join(S))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
check = [0]*26
if len(S)==26:
    if S[0]=='z':
        print(-1)
    else:
        end = S[-1]
        for i in range(24, -1, -1):
            if ord(S[i])<ord(end):
                S[i] = end
                print(''.join(S[:i+1]))
                break
        else:
            print(chr(ord(S[0])+1))
else:
    for s in S:
        check[ord(s)-97] = 1
    for i in range(26):
        if not check[i]:
            S.append(chr(i+97))
            break
    print(''.join(S))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
check = [0]*26
if len(S)==26:
    if S[0]=='z':
        print(-1)
    else:
        for i in range(26):
            if S[i]!=chr(i+97):
                S[i] = chr(i+97)
                print(''.join(S[:i+1]))
                break
        else:
            print(chr(ord(S[0])+1))
else:
    for s in S:
        check[ord(s)-97] = 1
    for i in range(26):
        if not check[i]:
            S.append(chr(i+97))
            break
    print(''.join(S))

Submission status: Wrong Answer

Solution code:
import string
from itertools import permutations
S = input()

#%%
alphabet = set(string.ascii_lowercase)

if len(S) < 26:
    s_diff = alphabet.difference(set(S))
    ans = S + min(s_diff)
elif S == "zyxwvutsrqponmlkjihgfedcba":
    ans = -1
else:
    it = permutations(S)
    next(it)
    T = next(it)
    ans = ''
    for i in range(len(S)):
        ans += T[i]
        if S[i] > T[i]:
            break

print(ans)

Submission status: Wrong Answer

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

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

if n < 26:
    for a in alp:
        if a not in s:
            print(s + a)
            exit()
else:
    i = 25
    while True:
        if i == 0:
            print('-1')
            exit()
        if s[i - 1] < s[i]:
            break
        i -= 1
    mi = sorted(s[i:])[0]
    print(s[:i-1] + mi)

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase

S = input()

used = set(list(S))
alph = set(ascii_lowercase)

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

if len(used) < 26:
    ans = S + min(used ^ alph)
    print(ans)
    exit()
else:
    S = list(S)
    while len(S) > 0:
        remain = set(S)
        last = S.pop()
        cond = remain ^ alph
        if cond and last < min(cond):
            S.append(min(cond))
            print(*S, sep="")
            exit()

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase

S = input()

used = set(list(S))
alph = set(ascii_lowercase)

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

if len(used) < 26:
    ans = S + min(used ^ alph)
    print(ans)
    exit()
else:
    S = list(S)
    while len(S) > 0:
        remain = set(S)
        last = S.pop()
        cond = remain ^ alph
        if cond and last < min(cond):
            S.pop()
            S.append(min(cond))
            print(*S, sep="")
            exit()

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase

S = input()

used = set(list(S))
alph = set(ascii_lowercase)

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

if len(used) < 26:
    ans = S + min(used ^ alph)
    print(ans)
    exit()
else:
    S = list(S)
    while len(S) > 0:
        last = S.pop()
        remain = set(S)
        cond = remain ^ alph
        if cond and last > min(cond):
            S.pop()
            S.append(min(cond))
            print(*S, sep="")
            exit()
print("b")

Submission status: Wrong Answer

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

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

else:
    if len(S)<=25:
        for word in words:
            if not word in S:
                S+=word
                break
        print(S)
    else:
        if S[1:]=='zyxwvutsrqponmlkjihgfedcb':
            place=words.index(S[0])
            print(words[place+1])
        else:
            for n in range(1, 25):
                saisho = S_list[-n]
                N_f = words.index(saisho)
                saigo = S_list[-n - 1]
                N_l = words.index(saigo)
                if N_f < N_l:
                    continue
                else:
                    S_f = S_list[:-n - 1]
                    S_l = S_list[-n:]
                    S_l_new = sorted(S_l)
                    new = []
                    for number in S_l_new:
                        if words.index(number) > N_l:
                            new.append(number)
                            break
                    S_f += new
                    print(''.join(S_f))
                    break

Submission status: Wrong Answer

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

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

else:
    if len(S)<=25:
        for word in words:
            if not word in S:
                S+=word
                break
        print(S)
    else:
        for n in range(1,25):
            saisho=S_list[-n]
            N_f=words.index(saisho)
            saigo=S_list[-n-1]
            N_l=words.index(saigo)
            if N_f<N_l:
                continue
            else:
                S_f=S_list[:-n-1]
                S_l=S_list[-n:]
                S_l_new=sorted(S_l)
                new=[]
                for number in S_l_new:
                    if words.index(number)>N_l:
                        new.append(number)
                        break
                S_f+=new
                print(''.join(S_f))
                break

Submission status: Wrong Answer

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

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

else:
    if len(S)<=25:
        for word in words:
            if not word in S:
                S+=word
                break
        print(S)
    else:
        for n in range(1,25):
            saisho=S_list[-n]
            N_f=words.index(saisho)
            saigo=S_list[-n-1]
            N_l=words.index(saigo)
            if saisho<saigo:
                continue
            else:
                S_f=S_list[:-n-1]
                S_l=S_list[-n:]
                S_l_new=sorted(S_l)
                new=[S_l_new[0]]
                S_f+=new
                print(''.join(S_f))
                break

Submission status: Wrong Answer

Solution code:
s = input()
s2 = 'a'
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

if len(s)==26:
    cmp_s = s[s.index('z')+1:]
    cmp_s2 = list(cmp_s)
    cmp_s2.sort(reverse=True)
    if cmp_s == ''.join(cmp_s2):
        cmp_s = s[:s.index('z')]
        while s2 in cmp_s:
            s2 = chr(ord(s2)+1)
        print(s[:s.index('z')-1]+s2)
    else:
        cmp_s = list(s[s.index('z')+1:])
        for i in range(len(cmp_s)-1):
            if cmp_s[i] < cmp_s[i+1]:
                cmp_s[i],cmp_s[i+1] = cmp_s[i+1],cmp_s[i]
                s2 = i+1
                cmp_s = ''.join(cmp_s)
                break
        print(s[:s.index('z')+1]+cmp_s[:s2])
else:
    while s2 in s:
        s2 = chr(ord(s2)+1)
    print(s+s2)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

S = s()

alpha=["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"]
p = alpha.copy()
p.reverse()
aa = "".join(p)

if S==aa:
    print(-1)
    sys.exit()

if len(S) == 26:
    for i in range(len(S)):
        if S[i] != alpha[i]:
            print(S[:i-1]+min(S[i+1:]))
            sys.exit()
else:
    for i in alpha:
        if i not in S:
            print(S+i)
            sys.exit()

Submission status: Wrong Answer

Solution code:
s = input()
s2 = 'a'
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

if len(s)==26:
    cmp_s = s[:s.index('z')]
    while s2 in cmp_s:
        s2 = chr(ord(s2)+1)
    print(s[:s.index('z')-1]+s2)
else:
    while s2 in s:
        s2 = chr(ord(s2)+1)
    print(s+s2)

Submission status: Wrong Answer

Solution code:
s = input()
s2 = 'a'
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

if len(s)==26:
    print(s[:s.index('z')-1]+chr(ord(s[s.index('z')-1])+1))
else:
    while s2 in s:
        s2 = chr(ord(s2)+1)
    print(s+s2)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import string
    S = input()

    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        if len(S) < 26:
            temp_str = [item for item in string.ascii_lowercase]
            for item in S:
                temp_str.remove(item)
            print(S+temp_str[0])
            
        else:
            res_s = S[0]
            temp_str = [item for item in string.ascii_lowercase]
            temp_str.remove(S[0])
            for i in range(1,26):
                if ord(S[i-1]) + 1 < ord(S[i]):
                    break
                
                temp_str.remove(S[i])
                res_s += S[i]
            else:
                res_s = res_s[:-1]
                temp_str = 'z'


            print(res_s[:-1] + temp_str[0])


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import string
    S = input()

    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        if len(S) < 26:
            temp_str = [item for item in string.ascii_lowercase]
            for item in S:
                temp_str.remove(item)
            print(S+temp_str[0])
            
        else:
            res_s = S[0]
            temp_str = [item for item in string.ascii_lowercase]
            temp_str.remove(S[0])
            for i in range(1,26):
                temp_str.remove(S[i])
                if ord(S[i-1]) + 1 < ord(S[i]):
                    break
                res_s += S[i]
            else:
                res_s = res_s[:-1]
                temp_str = 'z'


            print(res_s[:-1] + temp_str[0])


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
S=list(input())
A='abcdefghijklmnopqrstuvwxyz'

ans='-1'
if len(S)<26:
    for a in A:
        if a not in S:
            ans=''.join(S)+a
            break
else:
    i=0
    ss=S[::-1]
    while i+1<26:
        if ss[i]>ss[i+1]:
            ss[i],ss[i+1]='',chr(ord(ss[i+1])+1)
            ans=''.join(ss[::-1])
            break
        else:
            ss[i]=''
        i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
S=list(input())
A='abcdefghijklmnopqrstuvwxyz'

ans='-1'
if len(S)<26:
    for a in A:
        if a not in S:
            ans=''.join(S)+a
            break
else:
    i=0
    ss=S[::-1]
    while i+1<26:
        if ss[i]>ss[i+1]:
            ss[i],ss[i+1]='',S[-1]
            ans=''.join(ss[::-1])
            break
        else:
            ss[i]=''
        i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
enum = enumerate
INF = 1001001001

import collections
import random

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def dist(x1,y1,x2,y2):
	return abs(x1-x2)+abs(y1-y2)

def main():
	S = input().rstrip()
	#vS = [input().rstrip() for _ in [0,]*N]
	N = len(S)
	oA = ord("a")
	vD = [chr(i+oA) for i in range(26)]
	#vD += [".","#"]

	for d in vD:
		if d not in S:
			print(S+d)
			return
	
	if S=="".join(vD[::-1]):
		print(-1)
		return

	vQ = []
	vR = [ord(s) for s in S]
	vQ.append(vR.pop())
	
	while vR:
		r = vR.pop()
		nowq = INF
		for q in vQ:
			if q>r:
				nowq = min(nowq,q)
		if nowq<INF:
			vR.append(nowq)
			break
	
	res = "".join(chr(r) for r in vR)
	print(res)
	#sT = "No Yes".split()
	#print(sT[res])
	

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import bisect
s=input()
n=len(s)
if n!=26:
  alp=[1]*26
  for i in s:
    alp[ord(i)-ord('a')]=0
  for i in range(26):
    if alp[i]:break
  ans=s+chr(ord('a')+i)
else:
  alp=[]
  for i in range(n-1,-1,-1):
    if bisect.bisect_left(alp,ord(s[i]))==len(alp):
      bisect.insort_left(alp,ord(s[i]))
    else:
      ans=s[:i+1]+chr(alp[bisect.bisect_left(alp,ord(s[i]))])
      break
  else:ans=-1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from string import ascii_lowercase

    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    elif len(s) < 26:
        x = set(ascii_lowercase) - set(s)
        x = list(x)
        x.sort()
        print(s + x[0])
    else:
        for i in range(25, -1, -1):
            if s[i] == "z":
                continue
            if chr(ord(s[i]) + 1) not in set(s[:i]):
                return print(s[:i] + chr(ord(s[i]) + 1))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase

def solve():
    s = input()
    a = [x for x in s]
    if s == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        return
    x = set(a)
    xd = []

    if len(s) == 26:
        while a[-2] > a[-1]:
            xd.append(a.pop())
        xd.append(a.pop())
        a.pop()
        print(''.join(a) + min(xd))
    else:
        for e in string.ascii_lowercase:
            if e not in x:
                print(s + e)
                return
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase

def solve():
    s = input()
    a = [x for x in s]
    if s == 'zyxwvutsrqponmlkjihgfedcba' or len(a) != len(set(a)):
        print(-1)
        return
    x = set(a)

    if len(s) == 26:
        while a[-2] > a[-1]:
            x.remove(a.pop())
        x.remove(a.pop())
        a.pop()

    for e in string.ascii_lowercase:
        if e not in x:
            print(''.join(a) + e)
            return
    
    

    
    


    


    
    
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

R s
S p
P r

"""

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase

def solve():
    s = input()
    a = [x for x in s]
    if s == 'zyxwvutsrqponmlkjihgfedcba' or len(a) != len(set(a)):
        print(-1)
        return
    x = set(a)

    if len(s) == 26:
        while a[-1] < a[-2]:
            a.pop()
        a.pop()
        a.pop()

    for e in string.ascii_lowercase:
        if e not in set(a):
            print(''.join(a) + e)
            return
    
    

    
    


    


    
    
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

R s
S p
P r

"""

Submission status: Wrong Answer

Solution code:
import collections
s = input()


cnt = collections.Counter(s)
used = set(cnt.keys())
c = -1
if len(used) < 26:
    for i in range(26):
        if not chr(i+ord("a")) in used:
            c = chr(i+ord("a"))
            break
if c != -1:
    print(s+c)
else:
    i = 25
    while i > 1 and s[i-1] > s[i]:
        i -= 1
    if i == 1:
        print("-1")
        exit()
    lused = sorted(s[i-1:])
    print(s[:i-1]+lused[lused.index(s[i-1])+1])

Submission status: Wrong Answer

Solution code:
import collections
s = input()


cnt = collections.Counter(s)
used = set(cnt.keys())
c = -1
if len(used) < 26:
    for i in range(26):
        if not chr(i+ord("a")) in used:
            c = chr(i+ord("a"))
            break
if c != -1:
    print(s+c)
else:
    i = 25
    while i > 1 and s[i-1] > s[i]:
        i -= 1
    print(i)
    if i == 1:
        print("-1")
        exit()
    lused = sorted(s[i-1:])
    print(s[:i-1]+lused[lused.index(s[i-1])+1])

Submission status: Wrong Answer

Solution code:
import collections
s = input()


cnt = collections.Counter(s)
used = set(cnt.keys())
c = -1
if len(used) < 26:
    for i in range(26):
        if not chr(i+ord("a")) in used:
            c = chr(i+ord("a"))
            break
if c != -1:
    print(s+c)
else:
    lused = []
    for i in range(1, len(s)):
        lused.append(s[-i])
        if s[-i-1] < min(lused):
            print(s[:-i-1]+min(lused))
            break
    else:
        print("-1")

Submission status: Wrong Answer

Solution code:
import collections
s = input()


cnt = collections.Counter(s)
used = set(cnt.keys())
c = -1
if len(used) < 26:
    for i in range(26):
        if not chr(i+ord("a")) in used:
            c = chr(i+ord("a"))
            break
if c != -1:
    print(s+c)
else:
    lused = []
    for i in range(1, len(s)):
        lused.append(s[-i])
        if s[-i-1] < min(lused):
            print(s[:-i-2]+min(lused))
            break
    else:
        print("-1")