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()
# print(s[:-1])
if len(s) != 26:
    for c in range(ord('a'), ord('z')+1):
        c = chr(c)
        if not c in s:
            print(s+c)
            exit()
s = list(s)
t = []
while s:
    for c in t:
        if c > s[-1]:
            print(''.join(s[-1]+c))
            exit()
    t.append(s.pop())

print('-1')

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:
  if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    t = ord(s[0])
    for i in range(1,n):
      if ord(s[i])==t+1:
        t += 1
      else:
        s[i-1] =  chr(t+1)
        print("".join(s[:i]))
        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(n):
    if l[i] not in s:
      s += [l[i]]
      print("".join(s))
      exit()

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

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)
if n!=26:
  t = ord(s[0])
  for i in range(1,n):
    if ord(s[i])==t+1:
      t += 1
    else:
      s[i-1] =  chr(t+1)
      print("".join(s[:i]))
      exit()
  else:
    s = s+[chr(t+1)]
    print("".join(s))
else:
  if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    t = ord(s[0])
    for i in range(1,n):
      if ord(s[i])==t+1:
        t += 1
      else:
        s[i-1] =  chr(t+1)
        print("".join(s[:i]))
        exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
s = input()
dic = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(s),0,-1):
    for j in dic:
        if not j in s[:i]:
            if i == len(s):
                print(s[:i]+j)
                sys.exit()
            else:
                if dic.index(s[i]) < dic.index(j):
                    print(s[:i]+j)
                    sys.exit()
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    if len(S)<26:
        for a in alphabet:
            if a not in S:
                print(S + a)
                exit()
    else:#コイツを下回らない程度に辞書順を最低にする
        ordmax = 0
        for n,s in enumerate(reversed(S)):
            if ordmax > ord(s):
                print(S[:-n-1] + "".join(alphabet[alphabet.index(s)+1]))
                exit()
            else:
                ordmax = max(ordmax,ord(s))

Submission status: Wrong Answer

Solution code:
S = list(input())

abc = ['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 "".join(S) == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

ans = []

"""
多彩じゃない入力に対処できるコードを書いてしまった
"""

# 全ての文字をまだ使っていない時
for i in abc:
    if i not in S:
        S.append(i)
        print("".join(S))
        exit()

# 後ろから見て自分より辞書順で後ろのやつが，前にいなければそいつに書き換える
for i, s in enumerate(reversed(S)):
    ind = abc.index(s)
    t = abc[ind+1:]
    for j in t:
        if j not in S[0:26-i+1]:
            S[26-i-1] = j
            print("".join(S[0:26-i]))
            exit()

Submission status: Wrong Answer

Solution code:
s = input() #sys.stdin.readlineは最後が改行
if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

s=list(s)
oa = ord('a')
alp = [True]*26
for i in range(len(s)):
    alp[ord(s[i])-oa]=False

if len(s)<26:
    nokori_min =alp.index(True)
    add = chr(nokori_min + ord('a'))
    s+=add

    print(*s,sep='')
    exit()

nokori = []

for i in reversed(range(len(s))):
    if ord(s[i-1]) > ord(s[i]):
        nokori.append(s.pop())
    else:
        if nokori == []:
            tmp = s.pop()
            s[-1] = tmp
            break
        else:
            nokori.append(s.pop())
            nokori.sort()
            s[-1] = nokori[0]
            break


print(*s,sep='')

Submission status: Wrong Answer

Solution code:

s = list(input()) #sys.stdin.readlineは最後が改行
oa = ord('a')
aa = [True]*26
for i in range(len(s)):
    aa[ord(s[i])-oa]=False

def my_index(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

aaa =my_index(aa,True)

if aaa==-1:
    print(-1)

aaaa = chr(aaa + ord('a'))


s+=aaaa

print(*s,sep='')

Submission status: Wrong Answer

Solution code:
S = input()
li = [chr(ord('a') + i) for i in range(26)]
used = [0] * 26
dic = dict(zip(li, used))
for i in range(len(S)): dic[S[i]] = 1
if(len(S) < 26):
    for i in range(26):
        k = chr(ord('a') + i)
        v = dic[k]
        if(v == 0):
            print(S + k)
            exit(0)

if(len(S) == 26):
    for i in range(25, 0, -1):
        for j in range(26): dic[chr(ord('a') + j)] = 0
        for j in range(i): dic[S[j]] = 1
        add_c = ""
        for j in range(i + 1, 26):
            if(S[j] > S[i]):
                if(add_c == ""): add_c = S[j]
                else: add_c = min(add_c, S[j])
        if(add_c):
            print(S[:i] + add_c)
            exit(0)
print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
li = [chr(ord('a') + i) for i in range(26)]
used = [0] * 26
dic = dict(zip(li, used))
for i in range(len(S)): dic[S[i]] = 1
if(len(S) < 26):
    for i in range(26):
        k = chr(ord('a') + i)
        v = dic[k]
        if(v == 0):
            print(S + k)
            exit(0)

if(len(S) == 26):
    for i in range(25, 0, -1):
        for j in range(26): dic[chr(ord('a') + j)] = 0
        for j in range(i): dic[S[j]] = 1
        add_c = ""
        for j in range(i, 26):
            if(S[j] > S[i]):
                if(add_c == ""): add_c = S[j]
                else: add_c = min(add_c, S[j])
        if(add_c):
            print(S[:i] + add_c)
            exit(0)
print(-1)

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
li = [chr(ord('a') + i) for i in range(26)]
used = [0] * 26
dic = dict(zip(li, used))
for i in range(len(S)): dic[S[i]] = 1
if(len(S) < 26):
    for i in range(26):
        k = chr(ord('a') + i)
        v = dic[k]
        if(v == 0):
            print(S + k)
            exit(0)

if(len(S) == 26):
    if(S == 'zyxwvutsrqponmlkjihgfedcba'):
        print(-1)
        exit(0)
    else:
        for i in range(25, 0, -1):
            for j in range(26): dic[chr(ord('a') + j)] = 0
            for j in range(i): dic[S[j]] = 1
            add_c = ""
            for j in range(i, 26):
                if(S[j] > S[i]):
                    if(add_c == ""): add_c = S[j]
                    else: add_c = min(add_c, S[j])
            if(add_c):
                print(S[:i] + add_c)
                exit(0)

Submission status: Wrong Answer

Solution code:
S = input()
li = [chr(ord('a') + i) for i in range(26)]
used = [0] * 26
dic = dict(zip(li, used))
for i in range(len(S)): dic[S[i]] = 1
if(len(S) < 26):
    for i in range(26):
        k = chr(ord('a') + i)
        v = dic[k]
        if(v == 0):
            print(S + k)
            exit(0)

if(len(S) == 26):
    if(S == 'zyxwvutsrqponmlkjihgfedcba'):
        print(-1)
        exit(0)
    else:
        for i in range(25, 0, -1):
            for i in range(26): dic[chr(ord('a') + i)] = 0
            for j in range(i): dic[S[j]] = 1
            for j in range(i, 26):
                if(S[j] > S[i] and dic[S[j]] == 0):
                    print(S[:i] + S[j - 1])
                    exit(0)

Submission status: Wrong Answer

Solution code:
S = input()
li = [chr(ord('a') + i) for i in range(26)]
used = [0] * 26
dic = dict(zip(li, used))
for i in range(len(S)): dic[S[i]] = 1
if(len(S) < 26):
    for k, v in dic.items():
        if(v == 0):
            print(S + k)
            exit(0)

if(len(S) == 26):
    if(S == 'zyxwvutsrqponmlkjihgfedcba'):
        print(-1)
        exit(0)
    else:
        for i in range(25, 0, -1):
            for k in dic.keys(): dic[k] = 0
            for j in range(i): dic[S[j]] = 1
            for j in range(i, 26):
                if(S[j] > S[i] and dic[S[j]] == 0):
                    print(S[:i] + S[j - 1])
                    exit(0)

Submission status: Wrong Answer

Solution code:
s = input()

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
chrs = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    ans = 0
    for i in range(26):
        if chrs[i] != s[i]:
            ans = s[:i-1] + chrs[i]
            break
else:
    for c in chrs:
        if c not in s:
            ans = s + c
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
ans = 0
chrs = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    for i in range(26):
        if chrs[i] != s[i]:
            ans = s[:i-1] + chrs[i]
            break
else:
    for c in chrs:
        if c not in s:
            ans = s + c
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
ans = 0
chrs = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    for i in range(26):
        if chrs[i] != s[i]:
            ans = s[:i] + chrs[i]
            break
else:
    for c in chrs:
        if c not in s:
            ans = s + c
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop

S = input()
slist = "abcdefghijklmnopqrstuvwxyz"

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

heap=[]
T = S
if len(S)<26:
    Sset = set(S)
    for s in slist:
        if s not in Sset:
            print(S+s)
            exit()
else:
    while len(S)>1:
        heappush(heap,S[-1])
        print(heap)
        S = S[:-1]
        for s in heap:
            if S + s > T:
                print(S + s)
                exit()
    else:
        print(chr(ord(S)+1))
        exit()

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop

S = input()
slist = "abcdefghijklmnopqrstuvwxyz"

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

heap=[]
T = S
if len(S)<26:
    Sset = set(S)
    for s in slist:
        if s not in Sset:
            print(S+s)
            exit()
else:
    while len(S)>0:
        heappush(heap,S[-1])
        S = S[:-1]
        for s in heap:
            if S + s > T:
                print(S + s)
                exit()

Submission status: Wrong Answer

Solution code:
import collections
s = list(input())
sset = set(s)
if len(sset) != 26:
    for i in range(97,123):
        if chr(i) in sset:
            continue
        else:
            tmp = chr(i)
            s.append(tmp)
            break

    print(''.join(s))
    exit()
else:
    tmp = []
    flg = False
    for i in range(1,26):
        if s[i-1] < s[i]:
            tmp.append(i-1)
            continue

    if len(tmp) == 0:
        print(-1)
        exit()
    change_i = max(tmp)
    if change_i == 0:
        print(chr(ord(s[0])+1))
        exit()
    ans = s[:change_i]
    for i in range(97,123):
        if chr(i) in ans:
            continue
        else:
            if s[change_i] != chr(i):
                ans.append(chr(i))
                break
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
import collections
s = list(input())
sset = set(s)
if len(sset) != 26:
    for i in range(97,123):
        if chr(i) in sset:
            continue
        else:
            tmp = chr(i)
            s.append(tmp)
            break

    print(''.join(s))
    exit()
else:
    tmp = []
    flg = False
    s = s[::-1]
    top = -1
    for i in range(1,26):
        if ord(s[i-1]) < ord(s[i]) and not flg:
            flg = True
            tmp.append(ord(s[i-1]))
            tmp.append((ord(s[i])))
            continue
        if flg and ord(s[i-1]) > ord(s[i]):
            top = i
            break
        if ord(s[i-1]) < ord(s[i]) and flg:
            tmp.append(ord(s[i]))

    if len(tmp) == 26:
        print(-1)
        exit()
    if top == -1:
        ans = s[::-1]
        tt = ans[-1]
        ans[-1] = ans[-2]
        ans[-2] = tt

    else:
        ans = s[top:]
        ans = ans[::-1]
        ans.append(chr(min(tmp)))
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
S = input()
slist = "abcdefghijklmnopqrstuvwxyz"

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

if len(S)<26:
    Sset = set(S)
    for s in slist:
        if s not in Sset:
            print(S+s)
            exit()
else:
    while len(S)>0:
        target = S[-1]
        nextchar = chr(ord(target) + 1)
        # print(S,target,nextchar)
        if target=="z":
            S = S[:-1]
            continue
        else:
            Sset = set(S[:-1])
            if nextchar not in Sset:
                print(S[:-1]+nextchar)
                exit()
            else:
                S = S[:-1]
                continue

Submission status: Wrong Answer

Solution code:
S = input()
slist = "abcdefghijklmnopqrstuvwxyz"

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

if len(S)<26:
    Sset = set(S)
    for s in slist:
        if s not in Sset:
            print(S+s)
            exit()
else:
    while len(S)>0:
        target = S[-1]
        nextchar = chr(ord(target) + 1)
        print(S,target,nextchar)
        if target=="z":
            S = S[:-1]
            continue
        else:
            Sset = set(S[:-1])
            if nextchar not in Sset:
                print(S[:-1]+nextchar)
                exit()
            else:
                S = S[:-1]
                continue

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
temp1 = []

for i in range(25):
    temp1 = []
    temp.append(S[-1-i])
    # print(temp,S[-1-i],S[-1-i-1])
    for i, v in enumerate(temp):
        if S[-1-i-1] < v:
            temp1.append(v)
    # print(temp1)
    if len(temp1) > 0:
        temp1.sort()
        print(S[:-1-i-1]+temp1[0])
        sys.exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
temp1 = []
# x = 10/0
for i in range(26):
    temp1 = []
    temp.append(S[-1-i])
    # print(S[-1-i])
    for i, v in enumerate(temp):
        if S[-1-i-1] < v:
            temp1.append(v)
    if len(temp1) > 0:
        temp1.sort()
        print(S[:-1-i-1]+temp[0])
        sys.exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
temp1 = []
for i in range(26):
    temp1 = []
    temp.append(S[-1-i])
    # print(S[-1-i])
    for i, v in enumerate(temp):
        if S[-1-i-1] < v:
            temp1.append(v)
    if len(temp1) > 0:
        print(S[:-1-i-1]+min(temp1))
        sys.exit()

Submission status: Wrong Answer

Solution code:
S=input()
if len(S)<26:
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            print(S[:26-len(tmp)]+sorted(tmp)[1])
            exit()
    print(-1)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    al = list("abcdefghijklmnopqrstuvwxyz")
    d = set(s)
    n = len(s)
    if s == al[::-1]:
        print(-1)
        return 0
    if n == 26:
        for i in (range(n-1))[::-1]:
            if s[i] < s[i+1]:
                for j in range(i+1,n)[::-1]:
                    if s[i] < s[j]:
                        print(s[:i]+s[j])
                        return 0
    else:
        for i in al:
            if i not in d:
                print(''.join(s)+i)
                return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)<26:
    al=[chr(ord('a') + i) for i in range(26)]
    for i in al:
        if not(i in s):
            print(s+i)
            exit()
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
a=[]
for i in range(25,-1,-1):
    for j in range(24-(25-i),-1,-1):
        if s[j]<s[i]:
            a.append(s[:j]+s[i])
min(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)<26:
    al=[chr(ord('a') + i) for i in range(26)]*1000
    for i in al:
        if not(i in s):
            print(s+i)
            exit()
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
a=[s[-1]]
for i in range(24,-1,-1):
    if s[i]<s[-1]:
        print(s[:i]+s[-1])
        exit()

Submission status: Wrong Answer

Solution code:
s=input()
al=[chr(ord('a') + i) for i in range(26)]
if len(s)<26:
    for i in al:
        if not(i in s):
            print(s+i)
            exit()
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
for i in range(24,-1,-1):
    if s[i]<s[-1]:
        print(s[:i]+s[-1])
        exit()

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)==26:
  if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
  f=s[-1]

  for i in range(2,27):
    if s[-i]>f:
      f=s[-i]
    else:print(s[:-i]+chr(ord(s[-i])+1));exit()
else:
  f=sorted(list(set(list("aqzxswedcvfrtgbnhyujmkilop"))-set(list(s))))
  print(s+f[0])

Submission status: Wrong Answer

Solution code:
s=input()
from bisect import bisect_left as bl,bisect_right as br
if len(s)==26:
  if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
  f=s[-1]
  p=[s[-1]]
  for i in range(2,26):
    if s[-i]>f:
      f=s[-i];p.append(f)
    else:print("!",s[:-i]+p[bl(p,s[-i])]);exit()
  print(chr(ord(s[0])+1))
else:
  f=sorted(list(set(list("aqzxswedcvfrtgbnhyujmkilop"))-set(list(s))))
  print(s+f[0])

Submission status: Wrong Answer

Solution code:
s=input()
from bisect import bisect_left as bl,bisect_right as br
if len(s)==26:
  if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
  f=s[-1]
  p=[s[-1]]
  for i in range(2,26):
    if s[-i]>f:
      f=s[-i];p.append(f)
    else:print("!",s[:-i]+p[bl(p,s[-i])]);exit()
  print(p[bl(p,s[-i])])
else:
  f=sorted(list(set(list("aqzxswedcvfrtgbnhyujmkilop"))-set(list(s))))
  print(s+f[0])

Submission status: Wrong Answer

Solution code:
s=input()
from bisect import bisect_left as bl,bisect_right as br
if len(s)==26:
  if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
  f=s[-1]
  p=[s[-1]]
  for i in range(2,26):
    if s[-i]>f:
      f=s[-i];p.append(f);continue
    else:
      print(s[:-i]+p[br(p,s[-i])]);exit()
else:
  f=sorted(list(set(list("aqzxswedcvfrtgbnhyujmkilop"))-set(list(s))))
  print(s+f[0])

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)==26:
  if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
  f=s[-1]
  p=f
  for i in range(2,26):
    if s[-i]>f:
      f=s[-i];continue
    else:
      print(s[:-i]+p);exit()
else:
  f=sorted(list(set(list("aqzxswedcvfrtgbnhyujmkilop"))-set(list(s))))
  print(s+f[0])

Submission status: Wrong Answer

Solution code:
s = input()
if len(s)<26:
    seen = set()
    for c in s:
        seen.add(c)
    for i in range(26):
        tmp = chr(i+ord('a'))
        if tmp not in seen:
            print(s+tmp)
            break
else:
    pre = 'a'
    for i, c in enumerate(reversed(s)):
        if c < pre:
            print(s[:25-i]+s[-1])
            break
        pre = c
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
import string
ABC=list(string.ascii_lowercase)
s=input()
S=list(s[::-1])

if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    if len(s)==26:
        for i in range(len(s)):
            n=ABC.index(S[i])
            if not set(ABC[n+1:])<=set(S[i+1:]):
                j=i
                break
        L=list(set(ABC[n+1])-set(S[j+1:]))
        L.sort()
        sgyku=L[0:1]+S[j+1:]
        print("".join(sgyku[::-1]))
    else:
        L=list(set(ABC)-set(s))
        L.sort()
        print(s+L[0])

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()

for i in range(26):
    if S[-1-i] != 'z' and chr(ord(S[-1-i])+1) not in S[0:-1-i]:
        temp=list(S[-1-i+1:])
        # print(min(temp),temp)
        print(S[0:-1-i]+min(temp))
        sys.exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()

for i in range(26):
    if S[-1-i] != 'z' and chr(ord(S[-1-i])+1) not in S[0:-1-i]:
        print(S[0:-1-i]+chr(ord(S[-1-i])+1))
        sys.exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
for i, v in enumerate(S):
    if v == 'z':
        temp = S[0:i]
        for k in range(i, len(S)):
            d[S[k]] = d.get(S[k], 0)-1
        # print(temp, d)
        for i in range(1, 26):
            if d[chr(ord(temp[-1])+i)] != 1:
                print(temp[0:-1]+chr(ord(temp[-1])+i))
                sys.exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
for i, v in enumerate(S):
    if v == 'z':
        temp = S[0:i]
        for k, l in enumerate(temp):
            if k != len(temp):
                d1[l] = d1.get(l, 0)+1
        # print(temp)
        for k, l in enumerate(d1):
            # print(d1.get(l, 0))
            if d1.get(l, 0) != 2:
                # print("aaa")
                temp1 = temp[0:-1]
                print(temp1+l)
                sys.exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
for i, v in enumerate(S):
    if v == 'z':
        temp = S[0:i]
        for k, l in enumerate(temp):
            d1[l] = d1.get(l, 0)+1
        # print(temp)
        for k, l in enumerate(d1):
            # print(d1.get(l, 0))
            if d1.get(l, 0) != 2:
                # print("aaa")
                print(temp+l)
                sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')







def solve():
    S = list(input())

    abc = [chr(i) for i in range(97, 123)]
    # print(abc)

    for s in S:
        if s in abc:
            abc[ord(s) - 97] = 0



    if len(S) == 26:
        # abc = [chr(i) for i in range(97, 123)]
        # print(S)
        SR = S[::-1]
        # print(SR)
        for i in range(26):
            for j in range(i+1, 26):
                if SR[i] > SR[j]:
                    # print(i, j)
                    # print(S[:-j])
                    ans = S[:-j-1]
                    ans.append(SR[i])
                    printlist(ans, '')
                    return
        print(-1)

    else:
        for t in abc:
            if t != 0:
                S.append(t)
                printlist(S, k='')
                return

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    S = list(input())

    abc = [chr(i) for i in range(97, 123)]
    # print(abc)

    for s in S:
        if s in abc:
            abc[ord(s) - 97] = 0



    if len(S) == 26:
        abc = [chr(i) for i in range(97, 123)]
        # print(abc)
        r = S[-1]
        for idx, s in enumerate(reversed(S[:-1])):
            # print(s, r)
            if s > r:
                continue
            else:
                break
        # print(idx)
        idx += 2
        if idx == 26:
            print(-1)
        else:
            ans = S[:-idx]
            ans.append(r)
            # print(ans)
            printlist(ans, k='')
    else:
        for t in abc:
            if t != 0:
                S.append(t)
                printlist(S, k='')
                return

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = list(input())
n = len(s)
d = list('abcdefghijklmnopqrstuvwxyz')
se = set(s)
if n < 26:
    for i,x in enumerate(d):
        if not x in se:
            s.append(x)
            break
    print(''.join(s))
else:
    for i in range(25)[::-1]:
        if s[i] < s[i+1]:
            s[i] = s[-1]
            # print(i)
            print(''.join(s[:i+1]))
            break
    else:
        print(-1)

Submission status: Wrong Answer

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

if l <=25:
    for i in range(26):
        ch=chr(ord('a')+i)
        if ch not in S:
            S+=ch
            break
elif S=='zyxwvutsrqponmlkjihgfedcba':
    S=-1
else:
    index=24
    tmp=[ord(S[25])]
    mi=ord(S[25])
    while mi < ord(S[index]):

        tmp.append(ord(S[index]))
        mi=min(tmp)
        index -= 1
    S=S[:index]+chr(mi)

print(S)

Submission status: Wrong Answer

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

if l <=25:
    for i in range(26):
        ch=chr(ord('a')+i)
        if ch not in S:
            S+=ch
            break
elif S=='zyxwvutsrqponmlkjihgfedcba':
    S=-1
else:
    index=25
    tmp=[ord(S[25])]
    mi=ord(S[25])
    while mi > ord(S[index-1]):
        tmp.append(ord(S[index-1]))
        mi=min(tmp)
        index -= 1
    S=S[:index-3]+chr(mi)

print(S)