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:
import string
s = input()
s2=s.lower()
alp = string.ascii_lowercase
ans=''
def diff(a, b):
    if a=='a' or b=='a':
        if a=='z' or b=='z':
            return 1
    if a=='z' or b=='z':
        if a=='a' or b=='a':
            return 1
    return abs(alp.index(a)-alp.index(b))
if len(s)<26:
    for i in range(26):
        if alp[i] not in s2:
            ans=alp[i]
            break
    if ans=='':
        print(-1)
    else:
        print(s+ans)
        
else:
    found = False
    ans=-1
    for i in range(1,26):
        if diff(s2[i], s2[i-1])>1:
            found=True
            ans=i
            break

    if not found:
        if s2[0]<s2[1]:
            for j in range(25, -1, -1):
                if s2[j-1]<s2[j]:
                    J=j
                    break
            temp=s2[J]
            t2=s2[J-1]
            s2=s2[:j-1]+temp+t2+s2[J+1:]
            print(s2)
        else:
            can=False
            for i in range(1, 26):
                if s2[i]=='z' and s2[i-1]=='a':
                    if list(s2[:i])==sorted(list(s2[:i]))[::-1] and list(s2[i:])==sorted(list(s2[i:]))[::-1]:
                        print(s2[:i-1]+s2[i:]+'a')
                        can=True
                        break
                                            
            if not can and s2[0]=='z':
                print(-1)
            elif not can:
                s2=alp[alp.index(s2[0])+1]
                print(s2)
    else:
        for j in range(25, -1, -1):
            if diff(s2[j-1],s2[j])>1:
                J=j
                break
        temp=s2[J]
        t2=s2[J-1]
        s2=s2[:j-1]+temp+t2+s2[J+1:]
        print(s2)

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:
        ii = 0
        a = s[25]
        i = 25
        for i in range(24,-1,-1):
            if ord(a) >= ord(s[i]):
                ii = i
                break
        del s[25]
        s.insert(ii+1,a)
        print(''.join(s))

Submission status: Wrong Answer

Solution code:
alphabet='abcdefghijklmnopqrstuvwxyz'

def main(S):
    if len(S)<26:
        S1=alphabet[:]
        for s in S:
            S1=S1.replace(s,'')
        S1=list(S1)
        S1.sort()
        return S+S1[0]

    else:
        ind=S.find('z')
        S1=list(S[ind:])
        S1.sort()
        return S[:ind-1]+S1[0]

S=input()

if S==alphabet[::-1]:
    print(-1)
else:
    print(main(S))

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 = False
    while s[i] != t[j] or flag:
        flag = False
        i -= 1
        if s[i] == t[j] and i == 25 - j:
            flag = True
            j -= 1
            i = 25
    i -= 1
    q = sorted(s[i:])
    for k in q:
        if k > s[i]:
            s[i] = k
            break
    print("".join(s[:i + 1]))

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:
            #print(s[i])
            for j in range(count):
                print(s[j],end="")
            for i in range(26):
                if check[i]==0 and count<i:
                    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:
import copy

data = input()

if data == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

s = list(data)
abc_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',]
new_list = copy.copy(abc_list)

for i in range(len(s)):
    for j in range(26):
        if s[i] == new_list[j]:
            new_list[j] = None

for i in range(26):
    if new_list[i] != None:
        print((data + abc_list[i]))
        exit()

def data_cut(func_s,func_data):
    original_len = len(func_s)
    for k in range(original_len-1, -1, -1):
        if abc_list.index(func_s[k]) > abc_list.index(func_s[k-1]):
            for p in range(k):
                if func_s[p] == abc_list[abc_list.index(func_s[k-1])+1]:
                    func_s = func_s[:k]
                    func_data = func_data[:k]
                    break
            if original_len == len(func_s):
                print(func_data[:k-1] + abc_list[abc_list.index(func_s[k-1])+1])
                exit()
            else:
                data_cut(func_s,func_data)

data_cut(s,data)

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]:
            print(A+chr(num + ord('a')))
            isEnd = True
            break
        num = num + 1

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

            while num >= 0:
                if A[num2] > A[num]:

                    print(A[:num] + A[num2])
                    isEnd = True
                    break
                num = num - 1

            if isEnd:
                break
            num2 = num2 - 1

#zyxwvutsrqponmlkjihgfedcba

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
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[i] == "y":
        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:
    if s[0] == "z":
        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:
        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:
S = raw_input()

lis = 'abcdefghijklmnopqrstuvwxyz'

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

if len(S) != 26:
    for i in S:
        k = 0
        while i != lis[k]:
            k += 1
        exs[k] = 1
    j = 0
    
    while exs[j] == 1:
        j += 1
    print S + lis[j]

else:
    k = 0
    while S[len(S) - 1] != lis[k]:
        k += 1
    s = k
    while s >= k:
        s -= 1
    if s != -1:
        S = S[:s]
        print S + lis[k]
    else:
        print s

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:
        isEnd = False
        num2 = len(A) - 1
        while num2 >= 0:
            num = num2 - 1

            while num >= 0:
                if A[num2] > A[num]:

                    print(A[:num] + A[num2])
                    isEnd = True
                    break
                num = num - 1

            if isEnd:
                break
            num2 = num2 - 1

#zyxwvutsrqponmlkjihgfedcba

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:
        ii = 0
        a = s[25]
        i = 25
        for i in range(24,-1,-1):
            if ord(a) >= ord(s[i]):
                ii = i
                break
        del s[25]
        s.insert(ii,a)
        print(''.join(s))

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

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: #全部ある時
	if s == 'zyxwvutsrqponmlkjihgfedcba':
		print('-1')
	else:
		bunki = 0
		bunki2 = []
		memo = []
		for i in range(1,26):
			if string[i] > string[i+1]:
				bunki = i
				bunki2.append(i)

		if bunki != 25:		
			temp = [0]
			temp[0] = string[25]
			string[25] = string[26]
			string[26] = temp[0]
			for h in range(1,27):
				if h != 26:
					print(e[string[h]],end='')
				else:
					print(e[string[h]])
			
		else:
			w = len(bunki2)
			string[bunki2[w-1]-1] = d[s[25]]
			for h in range(1,bunki2[w-1]):
				if h != bunki2[w-1]-1:
					print(e[string[h]],end='')
				else:
					print(e[string[h]])

Submission status: Wrong Answer

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

ALPHA = sorted([a for a in "zyxwvutsrqponmlkjihgfedcba"])


def main():
    S = input().strip()

    if 'zyxwvutsrqponmlkjihgfedcba' == S:
        return '-1'

    S = [s for s in S]
    ans = []
    for s in S:
        if s in ALPHA:
            ALPHA.remove(s)
            ans.append(s)
        else:
            for a in ALPHA:
                if a > S[len(ans)]:
                    ans.append(a)
                    break
            break
    else:
        if ALPHA:

            ans.append(ALPHA.pop(0))
        else:
            alpha = sorted([a for a in "zyxwvutsrqponmlkjihgfedcba"])
            for i in range(len(ans) - 1, 0, -1):
                if ans[i - 1] < ans[i]:
                    break
            diff = sorted(list(set(alpha) - set(ans[:i])))
            ans = ans[:i - 1]
            ans.append(diff.pop(0))
    return "".join(ans)


if __name__ == '__main__':
    ans = main()
    print(ans)

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]:
                    
                    print(A[:num] + A[num2])
                    num2 = -100
                    break
                num = num - 1

            num2 = num2 - 1

#zyxwvutsrqponmlkjihgfedcba

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]=="z":
                    if i==0:
                        pass
                    else:
                        if i-1==0:end=0
                        else:end=i-1
                        newS=S[0:end]+chr(ord(S[i-1])+1)
                        break
                else:
                    newS=S[0:i]+chr(ord(S[i+1])+1)
                    break
        print(newS)

Submission status: Wrong Answer

Solution code:
#0. setting
CHR_A = ord("a") #97
NUM_CHR = 26
CHR_LIST = [chr(CHR_A+i) for i in range(NUM_CHR)]

def addChar(s, chr_list):
    for char in chr_list:
        if not(char in s):
            s = s+char
            break
    return s

def removeTail(s):
    for i in range(1,NUM_CHR):
        if ord(s[-1])<ord(s[-2]):
            s = s[:-1]
        else:
            s = s[:-1]
            last_s = s[-1]
            s = s[:-1:1]
            candidate = [chr(i) for i in range(ord(last_s)+1, CHR_A+NUM_CHR)]
            s = addChar(s, candidate)
            break
    return s

def main():
    #1. input
    s = input()

    #sp. output -1 if S='zyx...a'
    if s == ','.join(CHR_LIST[::-1]):
        print(-1)
    
    
    #2. add next char if |S| <= 25
    elif len(s) <= 25:
        s = addChar(s, CHR_LIST)
        print(s)
    
    
    #3. jump next step if |S| == 26
    else:
        s = removeTail(s)
        print(s)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ALPHA = sorted([a for a in "zyxwvutsrqponmlkjihgfedcba"])


def main():
    S = input().strip()

    if 'zyxwvutsrqponmlkjihgfedcba' == S:
        return '-1'

    S = [s for s in S]
    ans = []
    for s in S:
        if s in ALPHA:
            ALPHA.remove(s)
            ans.append(s)
        else:
            for a in ALPHA:
                if a > S[len(ans)]:
                    ans.append(ALPHA.pop(0))
                    break
            break
    else:
        if ALPHA:

            ans.append(ALPHA.pop(0))
        else:
            alpha = sorted([a for a in "zyxwvutsrqponmlkjihgfedcba"])
            for i in range(len(ans) - 1, 0, -1):
                if ans[i - 1] < ans[i]:
                    break
            diff = sorted(list(set(alpha) - set(ans[:i])))
            ans = ans[:i - 1]
            ans.append(diff.pop(0))
    return "".join(ans)


if __name__ == '__main__':
    ans = main()
    print(ans)

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 = False
    while s[i] != t[j] or flag:
        flag = False
        i -= 1
        if s[i] == t[j] and i == 25 - j:
            flag = True
            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 = 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 = -100
                    break
                num = num - 1

            num2 = num2 - 1

#zyxwvutsrqponmlkjihgfedcba

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])
                print("".join(ans))
                exit()
            j += 1

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_lis = ['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_lis2 = ['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 = 'abcdefghijklmnopqrstuvwzyx'

for i in range(len(S)):
    s_lis.remove(S[i])

if s_lis != []:
    print(S + s_lis[0])
else:
    S = S.split('z')[0][:-1]
    if S == '' or S[-1]=='y':
        print(-1)
    else:
        for i in range(len(S)):
            s_lis2.remove(S[i])

        try:
            if s_lis2 != []:
                print(S+ s_lis2[1])
        except:
            print( -1)

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]=="z":
                    if i==0:
                        pass
                    else:
                        if i-2==0:end=0
                        else:end=i-2
                        newS=S[0:end]+chr(ord(S[i-1])+1)
                        break
                else:
                    newS=S[0:i]+chr(ord(S[i+1])+1)
                    break
        print(newS)

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:
    print(-1)
elif len(dic) == 0:
    if s[0] == 'z':
        print(-1)
    else:
        print('z')
else :
    print(s+dic[0])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr  1 00:03:14 2018

@author: Kim
"""

S = input()
Slist = list(S)

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
Alpha = list(ascii_lowercase)

alpha_dict = {chr(c):i+1 for i,c in enumerate(range(ord('a'),ord('z')+1))}


ANS = []
ANSm = ""

#クソ
if S == "abcdefghijklmnopqrstuvwxyz":
    print("b")
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print("-1")
    
#全部使われない場合
else:
    for i in range(len(Slist)):
            if Slist[i] in alpha_dict:
                del alpha_dict[Slist[i]]
    if alpha_dict == {}:
        #全部使われる場合
        
        alpha_dict = {chr(c):i+1 for i,c in enumerate(range(ord('a'),ord('z')+1))}
        if Slist[0] == "z":
            DEL = alpha_dict[Slist[1]]
            ANS.append("z")
            ANS.append(Alpha[DEL])
            
        else:
                
            for i in range(len(Slist)):
                if Slist[i] == "z":
                    ANS.pop()
                    DEL = alpha_dict[Slist[i-1]]
                    
                    ANS.append(Alpha[DEL])
                    break
                else:
                   ANS.append(Slist[i])
                   
        print( ''.join(ANS))
        
    else:
        minS = min([(v,k) for k,v in alpha_dict.items()])[1]
        print(S+minS)

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):
                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:
# -*- 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]+"a"
        return -1
    else:
        return ret + chr(i)

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

    print(main(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]:
                print(S[i])
                if S[i]=="z":
                    if i==0:
                        pass
                    else:
                        if i-2==0:end=0
                        else:end=i-2
                        newS=S[0:end]+chr(ord(S[i-1])+1)
                        break
                else:
                    newS=S[0:i]+chr(ord(S[i+1])+1)
                    break
        print(newS)

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]:
                print(S[i])
                if S[i]=="z":
                    print("zzz")
                    if i==0:
                        pass
                    else:
                        if i-2==0:end=0
                        else:end=i-2
                        newS=S[0:end]+chr(ord(S[i-1])+1)
                        break
                else:
                    newS=S[0:i]+chr(ord(S[i+1])+1)
                    break
        print(newS)