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()
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:
        continue

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:
alphabet = [chr(i) for i in range(ord('a'), ord('z') + 1)]
s = input()
ans = ''
if s == 'zyxwvutsrqponmlkjihgfedcba':
    ans = '-1'

elif len(s) == 26:
    pre = '`'
    end = 0
    for x in reversed(s):
        if ord(pre) > ord(x):
            ans = s[:end]
            break
        end -= 1
        pre = x
    for a in alphabet:
        if a not in ans:
            ans = ans[:len(ans)-1] + a
            break
else:
    for a in alphabet:
        if a not in s:
            ans = s + a
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
sorted_s = sorted(s)
import collections
import sys
dic = collections.defaultdict(lambda: 0)
min_word = '{'

if len(list(set(s))) == 26:
    if (ord(s[1]) - ord(s[0])) == -1:
        print(-1)
        sys.exit(0)

    before_str = s[0]
    for index, i in enumerate(s[1:]):
        if ord(i) - ord(before_str) != 1:
            if chr(ord(s[index]) + 1) == '{':
                print(-1)
                sys.exit(0)

            print(''.join(s[0:index]) + chr(ord(s[index]) + 1))
            sys.exit(0)
        before_str = i

else:
    min_word = sorted_s[0]
    for i in sorted_s[1:]:
        # min_word = min(min_word, i)
        if ord(i) - ord(min_word) == 1:
            min_word = i
    if chr(ord(min_word) + 1) == '{':
        print(-1)
    else:
        if chr(ord(sorted_s[0])) > 'a':
            print(''.join(s) + 'a')
        else:
            print(''.join(s) + chr(ord(min_word) + 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 = input()

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:
import sys
if __name__ == "__main__":
    S = str(input())
    tmp = 0
    flag = {}
    for i in range(97, 97 + 26):
        flag[chr(i)] = 0
    for i,ele in enumerate(S):
        if flag[ele] == 0:
            flag[ele] = i+1
    if len(S) < 26:
        for i in range(97, 97 + 26):
            if flag[chr(i)] == 0:
                print(S+chr(i))
                sys.exit()
    else:
        error = 1
        for i in range(25, -1, -1):
            if flag[chr(97+i)] != (26 - i):
                error = 0
        if error == 1:
            print('-1')
            sys.exit()
        if S[0] != 'z':
            tmp = ''
            for i in range(25, -1, -1):
                if flag[chr(97+i)] != 0:
                    for j,ele in enumerate(S):
                        if j != flag[chr(97+i)]-2:
                            tmp += ele
                        else:
                            tmp += chr(ord(ele)+1)
                            print(tmp)
                            sys.exit()
        else:
            tmp = ''
            for i in range(25, -1, -1):
                if flag[chr(97+i)] != (26 - i):
                    for j,ele in enumerate(S):
                        if j != (25 - i):
                            tmp += ele
                        else:
                            tmp += chr(ord(ele)+1)
                            print(tmp)
                            sys.exit()

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 = R()
	
	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:
s = str(input())
s_list = list(s)
s_length = len(s)
last_str = s[-1]

alphabet = ['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 s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)

elif s_length < 26:
    rest_list = list(set(alphabet) - set(s_list))
    rest_list.sort()
    print(s + rest_list[0])

else:
    trans_list = []
    for i in reversed(range(1,len(s))):
        trans_list.append(alphabet.index(s_list[i]))
        min_trans_list = min(trans_list)
        s_list = s_list[:i]

        if alphabet.index(s_list[i-1]) < min(trans_list):
            print(s[:i-1] + alphabet[min_trans_list])
            break

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 = input()

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 == ''and 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:
# -*- 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:
        abc = "abcdefghijklmnopqrstuvwxyz"
        for i in range(len(text)):
            if abc[i] == text[i]:
                continue
            return abc[:i-1]+abc[i]
        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:
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()

for k in range(25, -1, -1):
    if abc_list.index(s[k]) > abc_list.index(s[k-1]):
        print(data[:k-1] + abc_list[abc_list.index(s[k-1])+1])
        exit()

Submission status: Wrong Answer

Solution code:
S=input()
row='abcdefghijklmnopqrstuvwxyz'
row=list(row)
if len(S)!=26:
    for letter in S:
        row.remove(letter)
    print(S+row[0])
    
else:
    if S=='zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        S_=[]
        for i in range(25,1,-1):
            if S[i-1]<S[i]:
                for j in range(i-1):
                    S_.append(S[j])
                S_.append(S[25])
                S_=''.join(S_)
                print(str(S_))
                break
        else:
            print(row[row.index(S[0])+1])

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     
    return "-1"

s = input()

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

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

    print(s + alphabets[0])

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:
        num = len(A) - 2
        while num >= 0:
            if A[len(A) - 1] > A[num]:
                A_list = list(A[:num])
                A_list.append(A[len(A) - 1])
                A = "".join(A_list)
                print(A)
                break
            num = num - 1

Submission status: Wrong Answer

Solution code:
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

abc = "abcdefghijklmnopqrstuvwxyz"
s = S()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
if len(s) < 26:
    for a in abc:
        if not a in s:
            print(s+a)
            exit()
else:
    for i in range(len(s)-1):
        if s[-i-2] < s[-i-1]:
            print(s[:-i-2] + abc[abc.index(s[-i-2])+1])
            exit()

Submission status: Wrong Answer

Solution code:
S = list(input())

P = set(S)

flag = 0
if len(S) == 26:
    Q = set()
    for i in range(25):
        if ord(S[25 - i]) < ord(S[25 - i - 1]):
            Q.add(ord(S[25 - i]))
            S.pop()
        else:
            while len(Q)>0 and ord(S[25 - i - 1])>min(Q):
                Q.remove(min(Q))
            if len(Q)>0:
                S.pop()
                S.pop()
                S.append(chr(min(Q)))
                flag = 1
                break
            else:
                break
else:
    for j in range(26):
        M = chr(97 + j)
        if M in P:
            pass
        else:
            S.append(M)
            flag = 1
            break

if flag == 0:
    print(-1)
else:
    print(''.join(S))

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':
      N = N[0: i-1] + c.pop(0)
      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:
s = input()

c = 'abcdefghijklmnopqrstuvwxyz'

if len(s) < 26:
    for cc in c:
            if cc not in set(s):
                    print(s+cc)
                    exit(0)
elif s == 'zyxwvutsrqponmlkjihgfedcba':
     print(-1)
elif len(s) == 26:
        ti = 25
        while True:
            tc = s[ti]
            if c.index(tc) != 25 and c[c.index(tc)+1] not in s[:ti]:
                    print(s[:ti] + c[c.index(tc)+1])
                    exit(0)
            ti -= 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:		
			before = string[bunki-1]
			for k in range(26-bunki+2):
				if k != 26-bunki:
					memo.append(string[26-k])
			memo.sort()
			string[bunki-1] = string[bunki]
			for k in range(26-bunki+1):
				string[bunki+k] = memo[k]
			
			for h in range(1,27-abs(27-bunki)):
				if h!= bunki-1:
					print(e[string[h]],end='')
				else:
					print(e[string[h]])
		else:
			string[bunki2[0]-1] = d[s[25]]
			for h in range(1,bunki2[0]):
				if h != bunki2[0]-1:
					print(e[string[h]],end='')
				else:
					print(e[string[h]])

Submission status: Wrong Answer

Solution code:
S = raw_input()
letters = set(map(lambda x: chr(x+ord('a')),range(26))).difference(set(list(S)))
if len(letters) > 0:
    print S + min(letters)
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print "-1"
else:
    p = ""
    ans = 0
    for i in range(len(S))[::-1]:
        if p=="" or S[i] > p:
            p = S[i]
        else:
            ans = i
            break
    print S[:i] + str(chr(ord(S[ans])+1))

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     
    return "-1"

s = input()

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

else:
    alphabets = "abcdefghijklmnopqrstrvwxyz"
    for i in range(len(s)):
        alphabets = alphabets.strip(s[i])

    print(s + alphabets[0])

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 = input()

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

alp = "abcdefghijklmnopqrstuvwxyz"

s = list(input())
ss = set(s)

if len(s)<26:
    for x in list(alp):
        if x not in ss:
            print("".join(s)+x)
            exit()

idx = 0
for (i,x) in enumerate(s):
    if i>1 and s[i-2]<s[i-1] and s[i-1]>s[i]:
        l = list(filter(lambda x:x>s[i-2], s[i-1:]))
        if len(l)==0:
            l.appebd(s[i])
        y = min(l)
        print("".join(s[0:i-2])+y)
        exit()
    elif i>1 and s[i-2]>s[i-1] and s[i-1]<s[i]:
        l = list(filter(lambda x:x>s[i], s[i-1:]))
        if len(l)==0:
            l.append(s[i])
        y = min(l)
        print("".join(s[0:i])+y)
        exit()


print("-1")

Submission status: Wrong Answer

Solution code:
S = input()
T = "abcdefghijklmnopqrstuvwxyz"
if len(S) != 26:
    for i in T:
        if i not in S:
            print(S+i)
            exit()
else:
    if S == "zyxwvutsrqponmlkjihgfedcba" :
        print(-1)
    else:
        for i in range(25,-1,-1):
            if S[25-i] != T[i]:
                kouho = T[i]
                break
        dic = []
        for j in range(25,-1,-1):
                if S[j] != kouho:
                    dic.append(S[j])
                else:
                    if j == 0:
                        for k in range(26):
                            if T[j] == S[0]:
                                print(T[j+1])
                                exit()
                    else:
                        dic.append(kouho)
                        dic = sorted(dic)
                        print(S[0:j-1]+dic[0])
                        exit()

Submission status: Wrong Answer

Solution code:
s = input()

alphabets = "abcdefghijklmnopqrstuvwxyz"

if len(alphabets) == len(s):
    if s == alphabets:
        word = "ac"
    else:
        flag = 0
        for i in range(len(s)):
            if s[i] == "z":
                if i > 0:
                    tmp = s[:i-1]
                    remain = alphabets[:]
                flag = 1
                alphabets = alphabets.replace("z", "")
            elif flag == 1:
                if s[i] == alphabets[-1]:
                    alphabets = alphabets.replace(s[i], "")
                else:
                    flag = 2
                    alphabets = alphabets.replace(s[i], "")
                    word = s[:i] + alphabets[0]
                    break
            else:
                alphabets = alphabets.replace(s[i], "")
        if flag == 1:
            if s[0] == "z":
                word = "-1"
            else:
                word = tmp + remain[0]
else:
    for a in alphabets:
        if a not in s:
            word = s + a
            break

print(word)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s = input()
# print(len(s))
alpha = [0] * 26

# if len(s) == 27:
#     print(-1)
# else:
for c in s:
    i = ord(c)-97
    alpha[i] = 1
        # print(c)

flag = True
for i,e in enumerate(alpha):
    if e == 0:
        s += chr(i + 97)
        flag = False
        break

#全ての文字が使われている時
if flag:
    i = len(s) - 1
    while i >= 1:
        alpha[ord(s[i])-97] = 0
        if s[i] > s[i-1]:
            # print(s[i])
            s = s[:i-1]
            break
        i -= 1
    
    if i == 0:
        print(-1)
    else:
        for i,e in enumerate(alpha):
            if e == 0:
                s += chr(i + 97)
                print(s)
                break
else:
    print(s)

# print(ord("b")-97)

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:
            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:
s = input()

D = ord('z') - ord('a')

def to_integer(s):
    sum = 0
    for i in range(len(s)):
        sum *= D
        sum += ord(s[i]) - ord('a') + 1
    return sum

def inc(s):
    s = list(s)
    if s[-1] != 'z':
        s[-1] = chr(ord(s[-1]) + 1)
    else:
        if len(s) == 1:
            s = ['a', 'a']
        else:
            s = inc(s[:-1]) + 'a'
    return ''.join(s)

def is_xx(s):
    xx = set()
    for c in s:
        if c in xx:
            return False
        else:
            xx.add(c)
    return True

max_s = to_integer('zyxwvutsrqponmlkjihgfedcba')

x = to_integer(s)

if x >= max_s:
    print('-1')
else:
    s = inc(s)
    while not is_xx(s):
        s = inc(s)
    if to_integer(s) <= max_s:
        print(s)
    else:
        print('-1')

Submission status: Wrong Answer

Solution code:
s = input()

alphabets = "abcdefghijklmnopqrstuvwxyz"

if len(alphabets) == len(s):
    if s == alphabets:
        word = "ac"
    else:
        flag = 0
        for i in range(len(s)):
            if s[i] == "z":
                if i > 0:
                    tmp = s[:i]
                    remain = alphabets[:]
                flag = 1
                alphabets = alphabets.replace("z", "")
            elif flag == 1:
                if s[i] == alphabets[-1]:
                    alphabets = alphabets.replace(s[i], "")
                else:
                    flag = 2
                    alphabets = alphabets.replace(s[i], "")
                    word = s[:i] + alphabets[0]
                    break
            else:
                alphabets = alphabets.replace(s[i], "")
        if flag == 1:
            if s[0] == "z":
                word = "-1"
            else:
                word = tmp + remain[0]
else:
    for a in alphabets:
        if a not in s:
            word = s + a
            break

print(word)

Submission status: Wrong Answer

Solution code:
S=input()
row='abcdefghijklmnopqrstuvwxyz'
row=list(row)
if len(S)!=26:
    for letter in S:
        row.remove(letter)
    print(S+row[0])
    
else:
    if S=='zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        S_=[]
        for i in range(25,0,-1):
            if S[i-1]<S[i]:
                for j in range(i-1):
                    S_.append(S[j])
                S_.append(S[25])
                S_=''.join(S_)
                print(str(S_))
                break

Submission status: Wrong Answer

Solution code:
S = list(input())
Z = sorted(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:
        continue

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:
alphabet = [chr(i) for i in range(ord('a'), ord('z') + 1)]
s = input()
ans = ''
if s == 'zyxwvutsrqponmlkjihgfedcba':
    ans = '-1'

elif len(s) == 26:
    for x in s:
        if x == 'z':
            break
        else:
            ans += x
    for a in alphabet:
        if a not in ans:
            ans = ans[:len(ans)-1] + a
            break
else:
    for a in alphabet:
        if a not in s:
            ans = s + a
            break
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
if len(S)==26:
  max_code='zyxwvutsrqponmlkjihgfedcba'
  if S==max_code:
    print('-1')
    exit()
  for i in range(26):
    if max_code[i]!=S[i]:
      maxw=max_code[i]
      head=S[0:i]
      S=S[i:]
      break
  minw=maxw
  for i in range(len(S)):
    if S[i]==maxw:
      for j in range(len(S)-i-1):
        jtmp=j+i+1
        if S[jtmp]<minw and S[i-1]<S[jtmp]:
          minw=S[jtmp]
      if len(head)!=0:
        print(head+S[0:i-1]+minw)
      else:
        print(S[0:i-1]+minw)
      exit()
alp='abcdefghijklmnopqrstuvwxyz'
for i in S:
  for j in range(len(alp)):
    if i==alp[j]:
      alp=alp[0:j]+alp[j+1:]
      break
print(S+alp[0])

Submission status: Wrong Answer

Solution code:
def nextword(s):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print("-1")
    s_set = set(s)
    for c in alphabet:
        if c not in s:
            nexts = s + c
            return nexts
#    s_length = len(s)
#    for i in range(1, s_length+1):
#        nexts = s[:]
#        c = s[-i]
#        k = alphabet.find(c)
#        if k == 25:
#            continue
#        for j in range(k+1,26):
#            if alphabet[j] not in s:
#                nexts=s.replace(alphabet[k],alphabet[j])
#                return nexts
#        
s = input()
print(nextword(s))

Submission status: Wrong Answer

Solution code:
S = input()
ss= set(S)

def itoc(i): return chr(ord('a') + i)
def ctoi(c): return ord(c) - ord('a')

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(ss) == 26:
    cands = []
    tmp = ''
    for i,c in enumerate(S):
        if c == 'z': continue
        ti = ctoi(c) + 1
        while ti <= ctoi('z'):
            tc = itoc(ti)
            if tc not in tmp:
                cands.append(tmp + tc)
            ti += 1
        tmp += c
    for cand in sorted(cands):
        if cand > S:
            print(cand)
            exit()
else:
    for i in range(26):
        c = itoc(i)
        if c in S: continue
        print(S + c)
        break

Submission status: Wrong Answer

Solution code:
s = input()

D = ord('z') - ord('a')

def to_integer(s):
    sum = 0
    for i in range(len(s)):
        sum *= D
        sum += ord(s[i]) - ord('a') + 1
    return sum

def inc(s):
    s = list(s)
    if s[-1] != 'z':
        s[-1] = chr(ord(s[-1]) + 1)
    else:
        if len(s) == 1:
            s = ['a', 'a']
        else:
            s = inc(s[:-1]) + 'a'
    return ''.join(s)

def is_xx(s):
    xx = set()
    for c in s:
        if c in xx:
            return False
        else:
            xx.add(c)
    return True

max_s = to_integer('zyxwvutsrqponmlkjihgfedcba')

x = to_integer(s)

if x >= max_s:
    print('-1')
else:
    s = inc(s)
    while not is_xx(s):
        s = inc(s)
    print(s)

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:
        abc = "abcdefghijklmnopqrstuvwxyz"
        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))