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

if len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    K = []
    for i in range(25, -1, -1):
        K.append(S[i])
        K.sort()
        for j in range(25, -1, -1):
            if K[0] > S[j]:
                print(S[:j] + K[0])
                exit()
print(-1)

Submission status: Wrong Answer

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

if len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    K = []
    for i in range(25, -1, -1):
        K.append(S[i])
        K.sort()
        for j in range(25, -1, -1):
            if K[0] > S[j]:
                print(S[:j])
                exit()

Submission status: Wrong Answer

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

d = dict()
d['a'] = 1
d['b'] = 2
d['c'] = 3
d['d'] = 4
d['e'] = 5
d['f'] = 6
d['g'] = 7
d['h'] = 8
d['i'] = 9
d['j'] = 10
d['k'] = 11
d['l'] = 12
d['m'] = 13
d['n'] = 14
d['o'] = 15
d['p'] = 16
d['q'] = 17
d['r'] = 18
d['s'] = 19
d['t'] = 20
d['u'] = 21
d['v'] = 22
d['w'] = 23
d['x'] = 24
d['y'] = 25
d['z'] = 26

e = dict()
e[1] = 'a'
e[2] = 'b'
e[3] = 'c'
e[4] = 'd'
e[5] = 'e'
e[6] = 'f'
e[7] = 'g'
e[8] = 'h'
e[9] = 'i'
e[10] = 'j'
e[11] = 'k'
e[12] = 'l'
e[13] = 'm'
e[14] = 'n'
e[15] = 'o'
e[16] = 'p'
e[17] = 'q'
e[18] = 'r'
e[19] = 's'
e[20] = 't'
e[21] = 'u'
e[22] = 'v'
e[23] = 'w'
e[24] = 'x'
e[25] = 'y'
e[26] = 'z'

appear = [0 for i in range(27)]
string = [0]
for i in range(n):
	string.append(d[s[i]])
	appear[d[s[i]]] += 1

exist = 0
for i in range(1,27):
	if appear[i] == 0:
		exist = i
		break

if exist != 0: #ない文字があった時
	string.append(exist)
	for k in range(1,n+2):
		if k != n+1:
			print(e[string[k]],end='')
		else:
			print(e[string[k]])
else:
	bunki = 26
	i = 26
	while i > 1:
		if string[i-1] > string[i]:
			bunki = i-1
			i += -1
		else:
			break
	memo = []
	for k in range(bunki,27):
		memo.append(string[k])
	memo.sort()
	t = [string[bunki-1]]
	for k in range(len(memo)):
		if t[0] < memo[k]:
			okikae = memo[k]
			break
	string[bunki-1] = okikae
	for h in range(1,bunki):
		if h!= bunki-1:
			print(e[string[h]],end='')
		else:
			print(e[string[h]])

Submission status: Wrong Answer

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

d = dict()
d['a'] = 1
d['b'] = 2
d['c'] = 3
d['d'] = 4
d['e'] = 5
d['f'] = 6
d['g'] = 7
d['h'] = 8
d['i'] = 9
d['j'] = 10
d['k'] = 11
d['l'] = 12
d['m'] = 13
d['n'] = 14
d['o'] = 15
d['p'] = 16
d['q'] = 17
d['r'] = 18
d['s'] = 19
d['t'] = 20
d['u'] = 21
d['v'] = 22
d['w'] = 23
d['x'] = 24
d['y'] = 25
d['z'] = 26

e = dict()
e[1] = 'a'
e[2] = 'b'
e[3] = 'c'
e[4] = 'd'
e[5] = 'e'
e[6] = 'f'
e[7] = 'g'
e[8] = 'h'
e[9] = 'i'
e[10] = 'j'
e[11] = 'k'
e[12] = 'l'
e[13] = 'm'
e[14] = 'n'
e[15] = 'o'
e[16] = 'p'
e[17] = 'q'
e[18] = 'r'
e[19] = 's'
e[20] = 't'
e[21] = 'u'
e[22] = 'v'
e[23] = 'w'
e[24] = 'x'
e[25] = 'y'
e[26] = 'z'

appear = [0 for i in range(27)]
string = [0]
for i in range(n):
	string.append(d[s[i]])
	appear[d[s[i]]] += 1

exist = 0
for i in range(1,27):
	if appear[i] == 0:
		exist = i
		break

if exist != 0: #ない文字があった時
	string.append(exist)
	for k in range(1,n+2):
		if k != n+1:
			print(e[string[k]],end='')
		else:
			print(e[string[k]])
else:
	bunki = 26
	i = 26
	while i > 1:
		if string[i-1] > string[i]:
			bunki = i-1
		i += -1
	memo = []
	for k in range(bunki,27):
		memo.append(string[k])
	memo.sort()
	t = [string[bunki-1]]
	for k in range(len(memo)):
		if t[0] < memo[k]:
			okikae = memo[k]
			break
	string[bunki-1] = okikae
	for h in range(1,bunki):
		if h!= bunki-1:
			print(e[string[h]],end='')
		else:
			print(e[string[h]])

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    for i in range(25):
        if ord(inp[-1 - i]) > ord(inp[-2 - i]):
            an = inp[:-2-i]
            ls = inp[-2-i]
            for char in map(ord,list(inp[-1-i:])):
                dic[char] = "exist"
            break
    for j in range(26):
        if  97 + j in dic and 97+ j  >  ord(ls):
            an =  an + chr(97+j)
            break
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    for i in range(25):
        if ord(inp[-1 - i]) > ord(inp[-2 - i]):
            an = inp[:-2-i]
            ls = inp[-2-i]
            for char in map(ord,list(inp[-1-i:])):
                dic[char] = "exist"
            break
    if an == "":
        an = "-1"
    else:
        #print(dic)
        for j in range(26):
            if  97 + j in dic and 97+ j  >  ord(ls):
                an =  an + chr(97+j)
                break
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Submission status: Wrong Answer

Solution code:
import sys
 
 
alph="abcdefghijklmnopqrstuvwxyz"
allis=list(alph)
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()
 
for i in alph:
    if(i not in S):
        print(S)
        sys.exit()
        
l=-1
for i in range(len(S)-1)[::-1]:
    if(ord(S[i])<ord(S[i+1])):
        l=i
        break
        
x=sorted(S[i+1:])
for i in x:
    if(i>S[l]):
        print(S[:l]+i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    for i in range(25):
        if ord(inp[-1 - i]) > ord(inp[-2 - i]):
            an = inp[:-2-i]
            ls = inp[-2-i]
            for char in map(ord,list(inp[:-2-i])):
                dic[char] = "exist"
            break
    if an == "":
        an = "-1"
    else:
        for j in range(26):
            if (not 97 + j in dic) and 97+ j  >  ord(ls):
                an =  an + chr(97+j)
                break
else:
    alps=[chr(ord('a') + i) for i in range(26)]
    for w in list(inp):
        alps.remove(w)
    an = inp+alps[0]
    #for char in chars:
    #    dic[char] = "exist"
    #for i in range(26):
    #    if not (97 + i) in dic:
    #        an =  inp + chr(97+i)
    #        break
print(an)

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    for i in range(25):
        if ord(inp[-1 - i]) > ord(inp[-2 - i]):
            an = inp[:-2-i]
            ls = inp[-2-i]
            for char in map(ord,list(inp[:-2-i])):
                dic[char] = "exist"
            break
    if an == "":
        an = "-1"
    else:
        #print(dic)
        for j in range(26):
            if  (not (97 + j) in dic) and 97+ j  >  ord(ls):
                an =  an + chr(97+j)
                break
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from string import ascii_lowercase
from bisect import bisect_left


def main():
    word = stdin.readline().rstrip()
    if word == ascii_lowercase[::-1]:
        print(-1)
        return

    spam = sorted(list(set(ascii_lowercase) - set(word)))
    if 1 <= len(spam):
        print(word + spam[0])
        return

    rword = word[::-1]
    tmp = []
    for x in rword:
        # if len(tmp) != 0 and x < sorted(tmp)[-1]:
        if len(tmp) != 0 and x < tmp[-1]:
            # idx = bisect_left(tmp, x)
            # print(word[:-len(tmp) - 1] + sorted(tmp)[idx])
            print(word[:-len(tmp) - 1] + tmp[0])
            return
        tmp.append(x)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

alp = 'abcdefghijklmnopqrstuvwxyz'
S = input()
if S == alp[::-1]:
    print(-1)
else:
    if len(S) == len(alp):
        l = list(S)
        for i in range(1, len(S))[::-1]:
            if l[i-1] > l[i]:
                l = l[:i-1] + [l[i]]
            else:
                break
        l = l[:-2] + [l[-1]]
        print(''.join(l))
    else:
        for i in S : alp = alp.replace(i, '')
        print(S+alp[0])

Submission status: Wrong Answer

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

alp = 'abcdefghijklmnopqrstuvwxyz'
S = input()
if S == alp[::-1]:
    print(-1)
else:
    if len(S) == len(alp):
        l = list(S)
        for i in range(1, len(S))[::-1]:
            if l[i-1] > l[i]:
                l = l[:i-1] + [l[i]]
        l = l[:-2] + [l[-1]]
        print(''.join(l))
    else:
        for i in S : alp = alp.replace(i, '')
        print(S+alp[0])

Submission status: Wrong Answer

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

alp = 'abcdefghijklmnopqrstuvwxyz'
S = input()
if S == alp[::-1]:
    print(-1)
else:
    if len(S) == len(alp):
        l = list(S)
        for i in range(1, len(S))[::-1]:
            if l[i-1] > l[i]:
                l = l[:i-1] + [l[i]]
        print(''.join(l))
    else:
        for i in S : alp = alp.replace(i, '')
        print(S+alp[0])

Submission status: Wrong Answer

Solution code:


def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    elif len(temp)==26:
        temp=list(temp)
        p=0
        for i in range(25):
            if temp[25-i]>temp[25-i-1]:
                p=25-i        
        print("".join(temp[:p-1])+min(temp[p:]))
        exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:


def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    elif len(temp)==26:
        temp=list(temp)
        p=0
        for i in range(25):
            if temp[25-i]>temp[25-i-1]:
                p=25-i        
                print("".join(temp[:p-1])+min(temp[p:]))
                exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# input
S = input()
# S = "abcdefghijklmnopqrstuvwzyx"
# S = "atcoder"

s = list(S)
a = []
for i in range(len(s)):
    a.append(ord(s[i]))

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


# function
def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(s) < 26):
    for i in range(len(s)):
        b.remove(a[i])
    a.append(min(b))
    print(func(a))

if (len(s) == 26):
    for i in reversed(range(len(s))):
        if (a[i] < a[i-1]):
            if (i == 1):
                print(-1)
                break
            else:
                continue
        else:
            c = a[0:i]
            d = a[i:len(a)]
            # a[i-1]よりも大きくて最も小さいものを探す
            c.pop()
            c.append(min(d))
            print(func(c))
            break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# input
S = input()
# S = "abcdefghijklmnopqrstuvwzyx"
# S = "atcoder"

s = list(S)
a = []
for i in range(len(s)):
    a.append(ord(s[i]))

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


# function
def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(s) < 26):
    for i in range(len(s)):
        b.remove(a[i])
    a.append(min(b))
    print(func(a))

if (len(s) == 26):
    for i in reversed(range(len(s))):
        if (a[i] < a[i-1]):
            if (i == 1):
                print(-1)
                break
            else:
                continue
        else:
            a = a[0:i]
            # ここから26文字未満の場合とほとんど同じ
            for i in range(len(a)):
                b.remove(a[i])
            a.pop()
            a.append(min(b))
            print(func(a))
            break

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    s = inp[::-1]
    for i in range(25):
        if ord(s[i]) > ord(s[i+1]):
            an = s[i+2:][::-1]
            for char in map(ord,list(s[:i+1])):
                dic[char] = "exist"
            break
    if an == "":
        an = "-1"
    else:
        for i in range(26):
            if (97 + i) in dic:
                an =  an + chr(97+i)
                break        
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Submission status: Wrong Answer

Solution code:
#problem A
import itertools

S = input()
letters = "abcdefghijklmnopqrstuvwxyz"


def find_next_letter(S):
    letters_dict = {}
    for letter in letters:
        letters_dict[letter] = 0

    for letter in S:
        letters_dict[letter] += 1

    for key, value in letters_dict.items():
        if value == 0:
            return key
            break
        else:
            pass

                
def main():
    if len(S) != len(letters):
        print(S + find_next_letter(S))
    elif S == letters[::-1]:
        print(-1)
    else:
        for i in range(len(S) - 1, 0, -1):
            if S[i - 1] > S[i]:
                pass
            else:
                break

        for a in sorted(set(letters) - set(S[:i])):
            if a > S[i-1]:
                print(S[:i-1] + a)
        
main()

Submission status: Wrong Answer

Solution code:
#problem A
import itertools

S = input()
letters = "abcdefghijklmnopqrstuvwxyz"


def find_next_letter(S):
    letters_dict = {}
    for letter in letters:
        letters_dict[letter] = 0

    for letter in S:
        letters_dict[letter] += 1

    for key, value in letters_dict.items():
        if value == 0:
            return key
            break
        else:
            pass

                
def main():
    if S == letters[::-1]:
        print(-1)
    elif len(S) != len(letters):
        print(S + find_next_letter(S))
    else:
        for i in range(len(S) - 1, 0, -1):
            if S[i - 1] > S[i]:
                pass
            else:
                break

        for a in sorted(set(letters) - set(S[:i])):
            if a > S[i-1]:
                print(S[:i-1] + a)
        
main()

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    s = inp[::-1]
    for i in range(25):
        if ord(s[i]) > ord(s[i+1]):
            an = s[i+2:][::-1]
            for char in map(ord,list(s[:i+2])):
                dic[char] = "exist"
            break
    if an == "":
        an = "-1"
    else:
        for i in range(26):
            if (97 + i) in dic:
                an =  an + chr(97+i)
                break        
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Submission status: Wrong Answer

Solution code:
s = list(str(input()))


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']

nosame = 26
lastal = 0
nexts = ''
changeal = 'z'

if len(s) is 26:
    for k,i in enumerate(reversed(s)):
        if k is 25:
            zesxrdtcfyvguh = 2
        elif i is alpha[k]:
            nosame = 25-k
            continue
        else:
            break

    for k,i in enumerate(reversed(s)):
        if k < 26-nosame:
            continue
        if i < s[nosame-1]:
            lastal = 25-k
            changeal = i
            break
    for i in range(lastal):
        nexts += s[i]
    nexts += s[nosame-1]
    print(nexts)

else:
    for i in s:
        alpha[alpha.index(i)] = 'z'

    for i in alpha:
        changeal = min(changeal,i)

    for i in s:
        nexts += i
    nexts += changeal
    print(nexts)

Submission status: Wrong Answer

Solution code:
import sys

N = input()
a = []
b = ['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']
c = ['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']
l = list(N)
if N =='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
elif len(N) != 26:
  for i in range(len(N)):
    c.remove(l[i])
  N = N[0: i+1] + c.pop(0)
  print(N)
else:
  for i in range(len(N)-1,0,-1):
    a.append(l[i])
    if ord(l[i]) > ord(l[i-1]):
      for j in range(len(a)):
        if l[i-1] < a[j]:
          print(N[0:i]+a[j])
          sys.exit()

Submission status: Wrong Answer

Solution code:
#problem A

S = input()
letters = "abcdefghijklmnopqrstuvwxyz"


def find_next_letter(S):
    letters_dict = {}
    for letter in letters:
        letters_dict[letter] = 0

    for letter in S:
        letters_dict[letter] += 1

    for key, value in letters_dict.items():
        if value == 0:
            return key
            break
        else:
            pass

def new_lex_string(S):
    rev_S = S[::-1]
    sub_str_lex = rev_S[0]
    for idx in range(1, len(rev_S)):
        if rev_S[idx-1] < rev_S[idx]:
            sub_str_lex = (sub_str_lex + rev_S[idx])
        else:
            last_letter = sorted(sub_str_lex)[0]
            break
    return (S[:-(idx+1)] + last_letter)
        
        
def main():
    if S == letters[::-1]:
        print(-1)
    elif len(S) == 26:
        print(new_lex_string(S))
    else:
        print(S + find_next_letter(S))

        
main()

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    s = inp[::-1]
    for i in range(25):
        if ord(s[i]) > ord(s[i+1]):
            an = s[i+2:][::-1]
            for char in map(ord,list(s[i+1:])):
                dic[char] = "exist"
            break
    if an == "":
        an = "-1"
    else:
        for i in range(26):
            if not (97 + i) in dic:
                an =  an + chr(97+i)
                break        
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Submission status: Wrong Answer

Solution code:
#problem A

S = input()
letters = "abcdefghijklmnopqrstuvwxyz"


def find_next_letter(S):
    letters_dict = {}
    for letter in letters:
        letters_dict[letter] = 0

    for letter in S:
        letters_dict[letter] += 1

    for key, value in letters_dict.items():
        if value == 0:
            return key
            break
        else:
            pass

def new_lex_string(S):
    rev_S = S[::-1]
    sub_str_lex = rev_S[0]
    for idx in range(1, len(rev_S)):
        if rev_S[idx-1] < rev_S[idx]:
            sub_str_lex = (sub_str_lex + rev_S[idx])
        else:
            last_letter = sorted(sub_str_lex)[0]
            break
    return (S[:-(idx+1)] + last_letter)
        
        
def main():
    if len(S) < 26:
        print(S + find_next_letter(S))
    elif S == letters[::-1]:
        print(-1)
    else:
        print(new_lex_string(S))
        
main()

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    s = inp[::-1]
    for i in range(25):
        if ord(s[i]) > ord(s[i+1]):
            an = s[i+2:][::-1]
            for char in map(ord,list(an)):
                dic[char] = "exist"
            break
    if an == "":
        an = "-1"
    else:
        for i in range(26):
            if not (97 + i) in dic:
                an =  an + chr(97+i)
                break        
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    for i in range(25):
        if ord(inp[-1 -i]) > ord(inp[-2-i]):
            an = inp[:-2-i] 
            for char in map(ord,list(inp[:-1-i])):
                dic[char] = "exist"
            break
    if an == "":
        an = "-1"
    else:
        for i in range(26):
            if not (97 + i) in dic:
                an =  an + chr(97+i)
                break        
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Submission status: Wrong Answer

Solution code:
import sys

N = input()
a = []
b = ['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']
c = ['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']
l = list(N)
if N =='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
elif len(N) != 26:
  for i in range(len(N)):
    c.remove(l[i])
  N = N[0: i+1] + c.pop(0)
  print(N)
else:
  for i in range(len(N)-1,-1,-1):
    for j in range(i-1,-1,-1):
      if ord(l[i]) > ord(l[j]):
        N = N[1: j] +l[i]
        print(N)
        sys.exit()

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp_len == 26:
    for i in range(25):
        if ord(inp[-1 -i]) > ord(inp[-2-i]):
            an = inp[:-2-i] 
            for char in map(ord,list(inp[:-1-i])):
                dic[char] = "exist"
            break
    for i in range(26):
        if not (97 + i) in dic:
            an =  an + chr(97+i)
            break
    if an == "":
        an = "-1"
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Submission status: Wrong Answer

Solution code:
import sys


alph="abcdefghijklmnopqrstuvwxyz"
allis=list(alph)
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()

"""
if(S=="abcdefghijklmnopqrstuvwxyz"):
    print("b")
    sys.exit()
"""
for i in alph:
    if(i not in S):
        print(S+i)
        sys.exit()
        
"""
outp=""
for i in range(len(S)):
    if(S[i]==alph[i]):
        outp+=S[i]
    else:
        outp=outp[:-1]
        outp=outp+alph[i]
        break
"""
l=-1
for i in range(len(S)-1)[::-1]:
    if(ord(S[i])<ord(S[i+1])):
        l=i
        break
        
x=sorted(S[i+1:])
for i in x:
    if(i>S[l]):
        print(S[:l-1]+i)
        sys.exit()
print("b")

Submission status: Wrong Answer

Solution code:
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
for char in chars:
    dic[char] = "exist"
an = ""
if inp_len == 26:
    for i in range(25):
        if ord(inp[-1 -i]) > ord(inp[-2-i]):
            if i == 0:
                an = inp[:-2-i] + inp[-1] 
                break
            else:
                an = inp[:-2-i] + inp[-1]
                break
    if an == "":
        an = "-1"
else:
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# 単語
keyword = input()
# 全アルファベットのリスト
word_list = ["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"]

ans_word = ""
ans_ltr = ""
# アルファベットを順番に検索
for ltr1 in word_list:
	# 一致する文字が見つからなかった所で候補の文字にしてループを抜ける
	if keyword.find(ltr1) == -1:
		ans_ltr = ltr1
		break
ans_word = keyword + ans_ltr

# 文字数が最大の26だった時の処理
if len(ans_word) == 26:
	# アルファベットを順番に検索
	for ltr1 in word_list:
		# 今度はzの手前までの部分から候補文字を決める
		if ans_word[0:ans_word.find("z")].find(ltr1) == -1:
			ans_ltr = ltr1
			break
	# zの手前の文字を候補文字に置換
	ans_word = ans_word[0:ans_word.find("z") - 1] + ans_ltr

# 最後の単語
if ans_word == keyword:
	ans_word = "-1"

print(ans_word)

Submission status: Wrong Answer

Solution code:
import sys

N = input()
a = []
b = ['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']
c = ['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']
l = list(N)
if N =='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
elif len(N) != 26:
  for i in range(len(N)):
    c.remove(l[i])
  N = N[0: i+1] + c.pop(0)
  print(N)
else:
  for i in range(len(N)-1,-1,-1):
    for j in range(i-1,-1,-1):
      if ord(l[i]) > ord(l[j]):
        N = l[i] + N[1: i] + l[j]
        print(N)
        sys.exit()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# 単語
keyword = input()
# 全アルファベットのリスト
word_list = ["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"]

ans_word = ""
ans_ltr = ""
# アルファベットを順番に検索
for ltr1 in word_list:
	# 一致する文字が見つからなかった所で候補の文字にしてループを抜ける
	if keyword.find(ltr1) == -1:
		ans_ltr = ltr1
		break
ans_word = keyword + ans_ltr

# 文字数が最大の26だった時の処理
if len(ans_word) == 26:
	# アルファベットを順番に検索
	for ltr1 in word_list:
		# 今度はzの手前までの部分から候補文字を決める
		if ans_word[0:ans_word.find("z")].find(ltr1) == -1:
			ans_ltr = ltr1
			break
	# zの手前の文字を候補文字に置換
	ans_word = ans_word[0:ans_word.find("z") - 1] + ans_ltr

print(ans_word)

Submission status: Wrong Answer

Solution code:
S = input()
Z = sorted(list(S))
G = ["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"]
ans = []

for s in S:
    if s not in ans:
        ans.append(s)
    else:
        i = G.index(s)
        j = 1
        while j < 27:
            if G[(i + j) % 26] not in ans:
                ans.append(G[(i + j) % 26])
                print("".join(ans))
                exit()
            j += 1

for i in range(100):
    aaa = sorted(ans)
    if "".join(ans) > S:
        print("".join(ans))
        exit()
    else:
        for g in G:
            if g not in ans:
                ans.append(g)
                break

ans = "".join(ans)
S = "".join(S)
if ans == S:
    ans = list(ans)
    aaa = sorted(list(ans))

    for g in G:
        if g not in ans:
            ans.append(g)
            break

    else:
        for i in range(len(S)-1, -1, -1):
            for j in range(i, -1, -1):
                if S[i] > S[j]:
                    print(S[:j] + S[i])
                    exit()
ans = "".join(ans)
if ans > S:
    print(ans)
else:
    print(-1)