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:
# -*- coding: utf-8 -*-


a_code = 97
z_code = 122

def main(text):
    ret = text
    if text == 'zyxwvutsrqponmlkjihgfedcba':
        return -1
    l = len(text)
    ls = range(l)
    i = a_code
    while i <= z_code:
        flag = False
        for j in ls:
            if ord(text[j]) == i:
                break
        if j == l - 1 and ord(text[j]) != i: 
            break
        i = i + 1
    if i == 123:
        if text[0] == "a":
            abc = "abcdefghijklmnopqrstuvwxyz"
            for i in range(len(text)):
                if abc[i] == text[i]:
                    continue
                return abc[:i-1]+abc[i]
        else:
            abc = 'zyxwvutsrqponmlkjihgfedcba'
            for i in range(len(text)):
                if abc[i] == text[i]:
                    continue
                return abc[:i-1]+"a"
        return -1
    else:
        return ret + chr(i)

if __name__ == "__main__":
    s = raw_input()

    print(main(s))

Submission status: Wrong Answer

Solution code:
def rev26(s):
    for i in range(len(s) - 1, 0, -1):
        if (s[i] > s[i - 1]):
            chars = sorted(s[i:])
            return s[0:i - 1] + chars[0]

    sss = sorted(s)
    sss.reverse()
    if s == ''.join(sss):
        return "-1"
    return s[0:len(s)-2] + s[len(s)-1]
    

s = input()

if len(s) == 26:
    print(rev26(s))

else:
    alphabets = "abcdefghijklmnopqrstuvwxyz"
    for i in range(len(s)):
        alphabets = alphabets.replace(s[i], "")

    print(s + alphabets[0])

Submission status: Wrong Answer

Solution code:
alp = ["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"]
alp.sort()
Alp = ["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"]
Alp.sort()
put = 0
s = list(input())
for i in range(len(s)):
    if s[i] in alp:
        alp.remove(s[i])
    if s[i] == "z":
        put = i
if s == ["z","y","x","w","v","u","t","s","r","q","p","o","n","m","l","k","j","i","h","g","f","e","d","c","b","a"]:
    print("-1")
    
elif "z" in s:
    for i in range(len(Alp)):
        if s[put-1] < Alp[i]:
            s[put-1] = Alp[i]
            break
    s = ''.join(s)
    print(s[:put])
    
else:
    print(''.join(s) + alp[0])

Submission status: Wrong Answer

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


a_code = 97
z_code = 122

def main(text):
    ret = text
    if text == 'zyxwvutsrqponmlkjihgfedcba':
        return -1
    l = len(text)
    ls = range(l)
    i = a_code
    while i <= z_code:
        flag = False
        for j in ls:
            if ord(text[j]) == i:
                break
        if j == l - 1 and ord(text[j]) != i: 
            break
        i = i + 1
    if i == 123:
        if text[0] == "a":
            abc = "abcdefghijklmnopqrstuvwxyz"
        else:
            abc = 'zyxwvutsrqponmlkjihgfedcba'
        for i in range(len(text)):
            if abc[i] == text[i]:
                continue
            return abc[:i-1]+abc[i]
        return -1
    else:
        return ret + chr(i)

if __name__ == "__main__":
    s = raw_input()

    print(main(s))

Submission status: Wrong Answer

Solution code:
def agc022A():
    from collections import OrderedDict
    S = input()
    alfa_list = [chr(i) for i in range(97, 97 + 26)]
    alfa_dict = OrderedDict()

    # {"a":0, ...}
    for i in range(26):
        alfa_dict[alfa_list[i]] = i

    S_max = "zyxwvutsrqponmlkjihgfedcba"
    S_min = "abcdefghijklmnopqrstuvwxyz"

    if S == S_max:
        print(-1)

    elif len(S) < 26:
        for i in range(len(S)):
            del alfa_dict[S[i]]

        remainings = [v for k, v in alfa_dict.items()]

        for key, value in alfa_dict.items():
            if value == remainings[0]:
                alfa = key

        print("{}{}".format(S, alfa))
        return 0

    else:
        alfa_dict2 = alfa_dict.copy()
        for i in range(26):
            tmp = alfa_dict[S[i]]
            del alfa_dict[S[i]]

            if S[i] != S_min[i]:
                remainings = [v for k, v in alfa_dict.items() if v > alfa_dict2[S[i-1]]]
                for key, value in alfa_dict.items():
                    if value == remainings[0]:
                        alfa = key
                print("{}{}".format(S[:i-1], alfa))
                return 0


agc022A()

Submission status: Wrong Answer

Solution code:
s=input()
a='abcdefghijklmnopqrstuvwxyz'
b=[i for i in a if i not in s]
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif b:
    print(s + b[0])
else:
    for i in range(1, len(s)+1):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            b=[str(j) for j in a if j not in s[:-i] + s[-i:][0]][0]
            if (i == 26):
                print( chr(ord(s[0]) + 1))
            else:
                print(s[:-i] + b)
            break

Submission status: Wrong Answer

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

s = input()
s_list = list(s.split())


# 文字チェック
alphabet_dict = {}
for i, c in enumerate(range(ord('a'), ord('z') + 1)):
    alphabet_dict[chr(c)] = i

check_list = [0 for i in range(26)]

for i in range(len(s)):
    k = alphabet_dict[s[i]]
    check_list[k] = i + 1

key = 1
for i in range(26):
    if check_list[i] == 0:
        key = 0
        break

# 
if key == 1:
    key2 = 1
    for i in range(25):
        if check_list[i] < check_list[i + 1]:
            key2 = 0
            t = i + 1
    
    if key2 == 1: 
        print(-1)
    
    else:
        s = s[:t - 1]
        s = s + chr(97 + t)

        print(s)


else:
    i = 0
    while key == 0:
        if check_list[i] == 0:
            s = s + chr(97 + i)
            key = 1
        i = i + 1

    print(s)

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:
            print(-1)
        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
s=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"]
numbers=["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"]
check=[0]*26
a_n=dict(zip(alpha,numbers))
n_a=dict(zip(numbers,alpha))
n=len(s)

if n==1:
    if s=="z":
        print("za")
        sys.exit()
    else:
        print(s,end="")
        print(n_a[str(int(a_n[s])+1)])
        sys.exit()
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()
if s in "zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba":
    x=int(a_n[s[0]])
    x+=1
    print(n_a[str(x)])
    sys.exit()
        
if n==26:
    count=0
    num=int(a_n[s[0]])

    
    check[num]+=1
    for i in range(1,26):
        if int(a_n[s[i]])>num:
            num=int(a_n[s[i]])
            check[int(a_n[s[i]])]+=1
            count+=1
            
        else:
            for j in range(count-1):
                print(s[j],end="")
            for i in range(26):
                if check[i]==0:
                    print(n_a[str(i)])
                    sys.exit()
            
    
else:
    for i in range(n):
        check[int(a_n[s[i]])]+=1
    #print(check)
    print(s,end="")
    for i in range(26):
        if check[i]==0:
            print(n_a[str(i)])
            sys.exit()

Submission status: Wrong Answer

Solution code:
A = input()
if A == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:

    isNoCheck = [True for _ in range(30)]

    for cha in A:
        isNoCheck[ord(cha) - ord('a')] = False

    isEnd = False
    num = 0
    while num <= ord('z') - ord('a'):
        if isNoCheck[num]:
            A_list = list(A)
            A_list.append(chr(num + ord('a')))
            A = "".join(A_list)
            print(A)
            isEnd = True
            break
        num = num + 1

    if isEnd:
        pass
    else:
        num2 = len(A) - 1
        while num2 >= 0:
            num = num2 -1

            while num >= 0:
                if A[num2] > A[num]:
                    A_list = list(A[:num])
                    A_list.append(A[num2])
                    A = "".join(A_list)
                    print(A)
                    num2 = -1
                    break
                num = num - 1

            num2 = num2 - 1

Submission status: Wrong Answer

Solution code:
def agc022A():
    from collections import OrderedDict
    S = input()
    alfa_list = [chr(i) for i in range(97, 97 + 26)]
    alfa_dict = OrderedDict()

    # {"a":0, ...}
    for i in range(26):
        alfa_dict[alfa_list[i]] = i

    S_max = "zyxwvutsrqponmlkjihgfedcba"
    S_min = "abcdefghijklmnopqrstuvwxyz"

    if S == S_max:
        print(-1)

    elif len(S) < 26:
        for i in range(len(S)):
            del alfa_dict[S[i]]

        remainings = [v for k, v in alfa_dict.items()]

        for key, value in alfa_dict.items():
            if value == remainings[0]:
                alfa = key

        print("{}{}".format(S, alfa))
        return 0

    else:
        for i in range(26):
            tmp = alfa_dict[S[i]]
            del alfa_dict[S[i]]

            if S[i] != S_min[i]:
                remainings = [v for k, v in alfa_dict.items()]
                for key, value in alfa_dict.items():
                    if value == remainings[0]:
                        alfa = key
                print("{}{}".format(S[:i-1], alfa))
                return 0


agc022A()

Submission status: Wrong Answer

Solution code:
s = list(input())
t = "abcdefghijklmnopqrstuvwxyz"
if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) <= 25:
    for i in range(ord("a"), ord("a") + 26):
        if chr(i) not in s:
            s += chr(i)
            break
    print("".join(s))
else:
    i, j = 25, 25
    flag = True
    while s[i] != t[j] and flag:
        i -= 1
        if i == 25 - j:
            flag = False
            j -= 1
            i = 25
    i -= 1
    for j in range(ord("a"), ord("a") + 26):
        if chr(j) not in s[:i + 1]:
            s[i] = chr(j)
            break
    #s[i] = chr(ord(s[i]) + 1)
    print("".join(s[:i + 1]))

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 = 0
        while j < 27:
            if G[(i + j) % 26] not in ans:
                ans.append(G[(i + j) % 26])
                break
            j += 1

for i in range(len(ans)):
    if "".join(ans[:i+1]) > S:
        print("".join(ans[:i+1]))
        exit()
for i in range(100):
    aaa = sorted(ans)
    if "".join(ans) > S:
        print("".join(ans))
        exit()
    else:
        i = G.index(aaa[0])
        j = 0
        while j < 27:
            if G[(i + j) % 26] not in ans:
                ans.append(G[(i + j) % 26])
                break
            j += 1

ans = "".join(ans)
S = "".join(S)
if ans == S:
    ans = list(ans)
    aaa = sorted(list(ans))
    i = G.index(aaa[0])
    j = 0
    while j < 27:
        if G[(i + j) % 26] not in ans:
            ans.append(G[(i + j) % 26])
            break
        j += 1
    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)

Submission status: Wrong Answer

Solution code:
s = list(input())
if sorted(s, reverse=True) == s and len(s) == 26:
    print(-1)
    quit()
sn = []
for i in s:
    sn.append(ord(i)-97)
for i in range(1, 26+1):
    if i not in sn:
        if len(s) != 26:
            print(''.join(s) + chr(97+i))
            quit()
ans = []
for j in range(len(s)):
    ans.append(chr(97 + j))
    if sn[j] != j:
        print(''.join(ans))
        quit()

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 = 0
        while j < 27:
            if G[(i + j) % 26] not in ans:
                ans.append(G[(i + j) % 26])
                break
            j += 1

for i in range(len(ans)):
    if "".join(ans[:i+1]) > S:
        print("".join(ans[:i+1]))
        exit()
for i in range(100):
    aaa = sorted(ans)
    print(ans)
    if "".join(ans) > S:
        print("".join(ans))
        exit()
    else:
        i = G.index(aaa[0])
        j = 0
        while j < 27:
            if G[(i + j) % 26] not in ans:
                ans.append(G[(i + j) % 26])
                break
            j += 1

ans = "".join(ans)
S = "".join(S)
if ans == S:
    ans = list(ans)
    aaa = sorted(list(ans))
    i = G.index(aaa[0])
    j = 0
    while j < 27:
        if G[(i + j) % 26] not in ans:
            ans.append(G[(i + j) % 26])
            break
        j += 1
    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)

Submission status: Wrong Answer

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

s = input()
s_list = list(s.split())


# 文字チェック
alphabet_dict = {}
for i, c in enumerate(range(ord('a'), ord('z') + 1)):
    alphabet_dict[chr(c)] = i

check_list = [0 for i in range(26)]

for i in range(len(s)):
    k = alphabet_dict[s[i]]
    check_list[k] = i + 1

key = 1
for i in range(26):
    if check_list[i] == 0:
        key = 0
        break

# 
if key == 1:
    key2 = 1
    for i in range(25):
        if check_list[i] < check_list[i + 1]:
            key2 = 0
            t = i
    
    if key2 == 1: 
        print(-1)
    
    else:
        s = s[:t - 1]
        s = s + chr(97 + t + 1)

        print(s)


else:
    i = 0
    while key == 0:
        if check_list[i] == 0:
            s = s + chr(97 + i)
            key = 1
        i = i + 1

    print(s)

Submission status: Wrong Answer

Solution code:
import sys
s=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"]
numbers=["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"]
check=[0]*26
a_n=dict(zip(alpha,numbers))
n_a=dict(zip(numbers,alpha))
n=len(s)

if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()
if s in "zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba":
    x=int(a_n[s[0]])
    x+=1
    print(n_a[str(x)])
    sys.exit()
    

if n==26:
    count=0

    
    num=int(a_n[s[0]])

    
    check[num]+=1
    for i in range(1,26):
        if int(a_n[s[i]])>num:
            num=int(a_n[s[i]])
            check[int(a_n[s[i]])]+=1
            count+=1
            
        else:
            for j in range(count-1):
                print(s[j],end="")
            for i in range(26):
                if check[i]==0:
                    print(n_a[str(i)])
                    sys.exit()
            
    
else:
    for i in range(n):
        check[int(a_n[s[i]])]+=1
    #print(check)
    print(s,end="")
    for i in range(26):
        if check[i]==0:
            print(n_a[str(i)])
            sys.exit()

Submission status: Wrong Answer

Solution code:
D = [chr(i) for i in range(97, 97+26)]
rD = D[::-1]
S = input()
s = list(S)
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(S) <26:
    for i in s:
        D.remove(i)
    S += D[0]
    print(S)
else:
    zi = s.index("z")
    tS = s[:]
    del tS[0:zi]
    if ''.join(tS) in ''.join(rD):
        a = s[25]
        del s[zi-1:26]
        s.append(a)
        print(''.join(s))
    else:
        temp = s[25]
        s[25] = s[24]
        s[24] = temp
        print(''.join(s))

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))
            break
else: #len=26
    if S=='zyxwvutsrqponmlkjihgfedcba':print(-1)
    elif S=='abcdefghijklmnopqrstuvwxyz':
        print('abcdefghijklmnopqrstuvwxzy')
    else:
        for i in range(25):
            if S[i]>S[i+1]:
                if S[i+1]=="z":
                    if i==0:
                        end=0
                    else:end=i-1
                    newS=S[0:end]+chr(ord(S[i])+1)
                else:
                    newS=S[0:i]+chr(ord(S[i+1])+1)
        print(newS)

Submission status: Wrong Answer

Solution code:
s = list(input())
t = "abcdefghijklmnopqrstuvwxyz"
if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) <= 25:
    for i in range(ord("a"), ord("a") + 26):
        if chr(i) not in s:
            s += chr(i)
            break
    print("".join(s))
else:
    i, j = 25, 25
    flag = True
    while s[i] != t[j] and flag:
        i -= 1
        if i == 25 - j:
            flag = False
            j -= 1
            i = 25
    i -= 1
    s[i] = chr(ord(s[i]) + 1)
    print("".join(s[:i + 1]))

Submission status: Wrong Answer

Solution code:
A = input()
if A == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:

    isNoCheck = [True for _ in range(30)]

    for cha in A:
        isNoCheck[ord(cha) - ord('a')] = False

    isEnd = False
    num = 0
    while num <= ord('z') - ord('a'):
        if isNoCheck[num]:
            A_list = list(A)
            A_list.append(chr(num + ord('a')))
            A = "".join(A_list)
            print(A)
            isEnd = True
            break
        num = num + 1

    if isEnd:
        pass
    else:
        num2 = len(A) - 1
        while num2 >= 0:
            num = len(A) - 2

            while num >= 0:
                if A[num2] > A[num]:
                    A_list = list(A[:num])
                    A_list.append(A[num2])
                    A = "".join(A_list)
                    print(A)
                    num2 = -1
                    break
                num = num - 1

            num2 = num2 - 1

Submission status: Wrong Answer

Solution code:
s=input()
a='abcdefghijklmnopqrstuvwxyz'
b=[i for i in a if i not in s]
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif b:
    print(s + b[0])
else:
    for i in range(1, len(s)+1):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            b=[str(j) for j in a if j not in s[:-i] + s[-i:][0]]
            print(s[:-i] + b[0])
            break

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)):
    if l[i] != b[i] and l[i] =='z':
      d = c[0]
      for j in range(i,len(N)-1):
        if l[j+1] != c[0]:
          N = N[0: i+1] + c.pop(1)
          print(N)
          sys.exit()
      N = N[0: i-1] + d
      print(N)
      sys.exit()
    elif l[i] != b[i]:
      N = N[0:i] + chr(ord(l[i]) + 1)
      print(N)
      sys.exit()
    c.remove(l[i])

Submission status: Wrong Answer

Solution code:
D = [chr(i) for i in range(97, 97+26)]
rD = D[::-1]
S = input()
s = list(S)
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(S) <26:
    for i in s:
        D.remove(i)
    S += D[0]
    print(S)
else:
    zi = s.index("z")
    tS = s[:]
    del tS[0:zi]
    if ''.join(tS) in ''.join(rD):
        a = s[25]
        del s[zi:26]
        s.append(a)
        print(''.join(s))
    else:
        temp = s[25]
        s[25] = s[24]
        s[24] = temp
        print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
if sorted(s, reverse=True) == s and len(s) == 26:
    print(-1)
    quit()
sn = []
for i in s:
    sn.append(ord(i)-97)
for i in range(1, 26+1):
    if chr(97+i) not in s:
        if len(s) != 26:
            print(''.join(s) + chr(97+i))
            quit()
        else:
            ans = []
            for j in range(len(s)):
                ans.append(chr(97 + j))
                if sn[j] != j:
                    print(''.join(ans))
                    quit()

Submission status: Wrong Answer

Solution code:
dic = ['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']
s = input()
end = 0
for i in s:
    if i in dic:
        dic.remove(i)
    else:
        end = 1
        break
if end == 1 or len(dic) == 0:
    print(-1)
else :
    print(s+dic[0])

Submission status: Wrong Answer

Solution code:
s = list(input())
t = "abcdefghijklmnopqrstuvwxyz"
if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) <= 25:
    for i in range(ord("a"), ord("a") + 26):
        if chr(i) not in s:
            s += chr(i)
            break
    print("".join(s))
else:
    i, j = 25, 25
    flag = True
    while s[i] != t[j] and flag:
        i -= 1
        if i == 25 - j:
            flag = False
            j -= 1
            i = j - 1
    i -= 1
    s[i] = chr(ord(s[i]) + 1)
    print("".join(s[:i + 1]))

Submission status: Wrong Answer

Solution code:
import sys
S = []

S = input()

Len = len(S)

Cnt = [0 for i in range(26)]
Chk = 0

S2 = 'abcdefghijklmnopqrstuvwxyz'

if Len == 26:
    for i in range(Len):
        TmpS = S[i]
        for j in range(26):
            if S2[j] == TmpS:
                Cnt[j] += 1
                if Cnt[j] > 1:
                    print('-1')
                    sys.exit()
            break

        
    Cnt = [0 for i in range(26)]
    
    for i in range(26):
        TmpI2 = 25 - i
        TmpI1 = 25 - i - 1
        if TmpI2 < 0:
            print('-1')
            sys.exit()
            
        TmpS2 = S[TmpI2]
        TmpS1 = S[TmpI1]
        
        TmpS1N = 26
        TmpS2N = 26
        for j in range(26):
            if TmpS2 == S2[j]:
                TmpS2N = j

            if TmpS1 == S2[j]:
                TmpS1N = j
            
            if (TmpS1N < 26) and (TmpS1N < 26):
                break
        
        if TmpS1N < TmpS2N:
            for j in range(26):
                TmpI3 = 25 - j
                TmpS3 = S[TmpI3]
                if TmpS3 == S2[TmpS1N]:
                    break
                for j2 in range(26):
                    if TmpS3 == S2[j2]:
                        TmpS3N = j2
                        
                        if TmpS3N < TmpS1N:
                            Cnt[TmpS3N] = 1
                        break
                        
                    
            
            S = S[:TmpI1]
            Len = len(S)
            Cnt[TmpS1N] = 1
            
            break

                
for i in range(Len):
    TmpS = S[i]
    
    for j in range(26):
        if S2[j] == TmpS:
            Cnt[j] += 1
            if Cnt[j] > 1:
                Chk = 1
            break
    
    if (Chk==1):
        print('-1')
        sys.exit()
        
for i in range(26):
    
    if Cnt[i] == 0:
        S = S + S2[i]
        break

print(S)

Submission status: Wrong Answer

Solution code:
def rev26(s):
    for i in range(len(s) - 1, 0, -1):
        for j in range(i - 1, 0, -1):
            if s[i] < s[j]:
                char = s[i]
                tmp = s[0:i]
                for p in range(len(tmp) - 1, 0, -1):
                    if char > tmp[p]:
                        return tmp[0:p] + char

    if s == ''.join(sorted(s)):
        return s[0:len(s)-2] + "z"
    return "-1"

s = input()

if len(s) == 26:
    print(rev26(s))

else:
    alphabets = "abcdefghijklmnopqrstuvwxyz"
    for i in range(len(s)):
        alphabets = alphabets.replace(s[i], "")

    print(s + alphabets[0])

Submission status: Wrong Answer

Solution code:
dic = ['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']
s = input()
end = 0
for i in s:
    if i in dic:
        dic.remove(i)
    else:
        end = 1

if end == 1 or len(dic) == 0:
    print(-1)
else :
    print(s+dic[0])

Submission status: Wrong Answer

Solution code:
S = input()
Alph = ['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']

plot = []
S = list(S)
if len(S) < 26:
    for s in S:
        Alph.remove(s)
    S.append(Alph[0])
    print(''.join(S))

else:
    if ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        for i in range(len(S)):
            if S[i] == Alph[i]:
                continue
            else:
                del S[i+1:]
                S.append(Alph[i])
                print(''.join(S))
                break
            print(-1)

Submission status: Wrong Answer

Solution code:
import math
import itertools
from heapq import heapify, heappop, heappush
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))



##### main #####
def main():

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

	set_al = set([chr(i) for i in range(97,123)])
	set_s = set(S)

	if len(S) != len(set_s):
		print("-1")

	availables = sorted(list(set_al - set_s), reverse = True)

	if availables:
		print(S+str(availables[-1]))
	else:
		f = False
		for i in range(len(S))[::-1]:
			chr_n = ord(S[i])

			while chr_n <= 122:
				if chr(chr_n) not in S:
					S += chr(chr_n)
					f = True
					break
				chr_n += 1

			if f:
				break
			S = S[:-1]

		print(S)


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import string


def main():
    S = input()

    # 全文字使ってsort済み
    az = string.ascii_lowercase
    if S == az or S == az[::-1]:
        print(-1)
        return

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

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

    for i in range(1, len(S) + 1):
        # sort済みかつ連続であるか
        if S[:i] == az[:i]:
            continue

        # sortずみでないので、sort済みまでの最後を置き換え
        a = sorted(S[i:])[0]
        ans = S[:i-2] + a
        print(ans)
        return


if __name__ == '__main__':
    main()