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()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    quit()
if S == 'abcdefghijklmnopqrstuvwxyz':
    print('abcdefghijklmnopqrstuvwxz')
    quit()

ans = None
alphabet = [chr(c) for c in range(97, 97 + 26)]
if len(S) == 26:
    for i in range(0, 26):
        if S[i] != alphabet[i]:
            print(S[0:i] + alphabet[i])
            quit()


used_c = set()
for c in S:
    used_c.add(c)
for c in alphabet:
    if not c in used_c:
        ans = S + c
        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]
      break
  minw='z'
  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:
          minw=S[jtmp]
      print(S[0:i]+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:
s=input()

ss=[0 for i in range(26)]
for i in range(len(s)):
    for j in range(26):
        if s[i]==chr(97+j):
            ss[j]=1



if len(s)!=26:
        for i in range(26):
            if ss[i]==0:
                s=s+chr(97+i)
                break
        print(s)
else:
    if s=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        for i in range(26):
            if s[i]=="z":
                s=s[:i]
                break

        sss=[0 for i in range(26)]
        for i in range(len(s)):
            for j in range(26):
                if s[i]==chr(97+j):
                    sss[j]=1

        for i in range(26):
            if sss[i]==0:
                s=s[:len(s)-1]+chr(97+i)
                break

        print(s)





#print(ss)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from string import ascii_lowercase

s = input()
if s == 'zyxwvutsrqponmlkjihgfedcba' :
    print(-1)
elif len(s) < 26 :
    s = list(s)
    d = defaultdict(int)
    for c in s :
        d[c] += 1
    for c in ascii_lowercase :
        if d[c] == 0 :
            s.append(c)
            print(''.join(s))
            break
elif len(s) == 26 :
    s = list(s)
    d = defaultdict(int)
    for i in range(25, 0, -1) :
        if s[i-1] < s[i] :
            d[s[i]] = 1
            for c in ascii_lowercase :
                if d[c] == 1 :
                    ans = s[0:i-1]
                    ans = ans + [c]
                    print(''.join(ans))
                    exit()
        elif s[i-1] > s[i] :
            d[s[i]] = 1

Submission status: Wrong Answer

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

ABC = "abcdefghijklmnopqrstuvwxyz"

def add_next(s):    
    for c in ABC:
        if c not in s:
            return s + c
    raise Exception

def change_next(s):
    for i in reversed(range(n)):
        flag = False
        for j in range(i + 1, n):
            if ord(s[i]) < ord(s[j]):
                flag = True
                break
        if flag:
            return s[:i] + chr(ord(s[i]) + 1)
    raise Exception

s = input()
n = len(s)

if n < 26:
    res = add_next(s)
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        res = "-1"
    else:
        res = change_next(s)

print(res)

Submission status: Wrong Answer

Solution code:
import string

S = input()
N = len(S)

if S == string.ascii_lowercase[::-1]:
    print(-1)
elif N <= 25:
    for l in string.ascii_lowercase:
        if l not in S:
            print(S + l)
            break
else:
    ret = string.ascii_lowercase[::-1]
    for i in range(N):
        for c in string.ascii_lowercase:
            if c in S[:i]:
                continue
            s = S[:i] + c
            if S[i] == 'z' or c in S[:i] or S > s:
                continue
            ret = min(ret, s)
    print(ret)

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):
    index = alp.find(x)
    if i>1 and s[i-2]<s[i-1] and s[i-1]>s[i]:
        y = min(s[i-1:])
        print("".join(s[0:i-2])+y)
        exit()
    else:
        idx = index

print("-1")

Submission status: Wrong Answer

Solution code:
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']
word = list(input())

achars = alph[:]
for char in word:
    achars.remove(char)

if len(word) < 26:
    print(''.join(word)+achars[0])
else:
    ind = 26
    for i in range(1,26):
        if alph.index(word[i]) > alph.index(word[i-1]):
            ind = i
    if ind == 26:
        print(-1)
    else:
        word = word[:ind]
        word[ind-1] = alph[alph.index(word[ind-1])+1]
        print(''.join(word))

Submission status: Wrong Answer

Solution code:
S = input()
frag = False
for i in range(97, 123):
    if chr(i) not in S:
        print("".join([S, chr(i)]))
        frag = True
        break
if frag == False:
    for i in range(2, len(S)):
        for j in range(97, 123):
            if chr(j) not in S[:1-i]:
                frag = True
                break
        if frag:
            break
    if frag:
        print("".join([S[:-i], chr(j)]))
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
S= input()
alpha = [chr(i) for i in range(ord('a'), ord('z')+1)]
used = [0] * 26
for i in range(len(S)):
    for j in range(26):
        if S[i] == alpha[j]:
            used[j] = 1
            break
if 0 not in used:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        remv = []
        minind = 100
        for x in range(25,0,-1):
            remv.append(S[x])
            minind = min(minind,alpha.index(S[x]))
            if minind > alpha.index(S[x-1]):
                print(S[:x-1]+alpha[minind])
                break
else:
    for x in range(26):
        if used[x] == 0:
            print(S+alpha[x])
            break

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:
        if flag['z'] == 1:
            print('-1')
            sys.exit()
        else:
            for i in range(25, -1, -1):
                if flag[chr(97+i)] != 0:
                    tmp = ''
                    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()

Submission status: Wrong Answer

Solution code:
s = input()
s2 = list(s)
ch = [chr(i) for i in range(97, 97+26)]
flg = 0
for k in ch:
	if not k in s2:
		s += k
		flg = 1
		break

if flg == 1:
	print(s)
	exit(0)
else:
	l = len(s)
	ans = ''
	for i in range(l-1,0,-1):
		for k in ch[::-1]:
			if k == s[i]:
				break
			elif not k in s2[:i]:
				ans = s[:i] + k
				print(ans)
				exit(0)

	if s[0] == 'z':
		print(-1)
	else:
		print(chr(ord(s[0])+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):
    index = alp.find(x)
    if idx > index and i>1 and s[i-2]<s[i-1] and s[i-1]>s[i]:
        y = min(s[i-1:])
        print("".join(s[0:i-2])+y)
        exit()
    else:
        idx = index

print("-1")

Submission status: Wrong Answer

Solution code:
S = input().rstrip()

#A = [chr(a+97) for a in range(26)]

# elongation
if len(S)<26:
    A = [chr(a+97) for a in range(26) if not chr(a+97) in S]
    print(S+A[0])
    exit()

#
A = list('abcdefghijklmnopqrstuvwxyz')
for i in range(25, -1, -1):
    A = [chr(a+97) for a in range(26) if not chr(a+97) in S[:(i+1)]]
    if len(A)>0 and S[i]<A[0]:
        print(S[:i] + A[0])
        exit()

#
print(-1)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8


def main(s):
	alphabet = "abcdefghijklmnopqrstuvwxyz"
	d = {alphabet[i]:i for i in range(26)}
	if s == "zyxwvutsrqponmlkjihgfedcba":
		print("-1")
	elif len(s) < 26:
		for i in range(26):
			if alphabet[i] not in s:
				print(s + alphabet[i])
				break
	else:
		tail = [d[s[25]]]
		for i in range(0, 25):
			if d[s[24 - i]] >= max(tail):
				tail.append(d[s[24 - i]])
				continue
			else:
				tmp = min([x for x in tail if x >= d[s[24-i]]])
				print(s[0:(24-i)] + alphabet[tmp])
				break


if __name__ == '__main__':
	#s = input()
	main("abc")
	main("adc")
	main("zyawvutsrqponmlkjihgfedcbx")
	main("abcdefghijklmnopqrstuvwzyx")

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)):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            print(s[:-i] + chr(ord(s[-i:][0]) + 1))
            break
    else:
        print(chr(ord(s[0])+1))

Submission status: Wrong Answer

Solution code:
import string

S = input()
N = len(S)

if S == string.ascii_lowercase[::-1]:
    print(-1)
elif N <= 25:
    for l in string.ascii_lowercase:
        if l not in S:
            print(S + l)
            break
else:
    ret = string.ascii_lowercase[::-1]
    for i in range(N):
        c = chr(ord(S[i]) + 1)
        s = S[:i] + c
        if S[i] == 'z' or c in S[:i] or S > s:
            continue
        ret = min(ret, s)
    print(ret)

Submission status: Wrong Answer

Solution code:
s=input()
a='abcdefghijklmnopqrstuvwzyx'
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)):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            print(s[:-i] + chr(ord(s[-i:][0]) + 1))
            break
    else:
        print(chr(ord(s[0])+1))

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase


def nxt(s, i):
    pi = ascii_lowercase.index(s[i])
    s = s[:i]
    while True:
        for c in ascii_lowercase[pi + 1:]:
            if c not in s:
                return s + c
        pi = ascii_lowercase.index(s[-1])
        s = s[:-1]


def solve(s):
    if len(s) < 26:
        for c in ascii_lowercase:
            if c not in s:
                return s + c

    for i, c in enumerate(ascii_lowercase[::-1]):
        try:
            j = s.index(c)
        except:
            continue
        if i == j:
            continue
        if c == 'z':
            return nxt(s, j - 1)
        else:
            return nxt(s, j)
    return -1


s = input()
print(solve(s))

Submission status: Wrong Answer

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


a_code = 97
z_code = 122

def main(text):
    ret = text
    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:
        return -1
    else:
        return ret + chr(i)

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

    print(main(s))

Submission status: Wrong Answer

Solution code:


def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    
    if "z" in temp and len(temp)==26:
        t1,t2=temp.split("z")
        temp=t1
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=t1[:-1]
        temp=temp+alps[0]
        print(temp)
        exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

S = input()

if len(S) == 26:
    for i in range(25):
        for j in range(ord(S[-i - 1]) + 1, 97 + 26):
            if chr(j) not in S[:-i - 1]:
                print(S[:-i - 1] + chr(j))
                sys.exit()
        if i == 24:
            print(-1)
else:
    for i in range(97, 97 + 26):
        if chr(i) not in S:
            print(S + chr(i))
            break

Submission status: Wrong Answer

Solution code:
S = input()
if len(S) != 26:
    for i in range(97, 123):
        if chr(i) not in S:
            print("".join([S, chr(i)]))
            break
else:
    frag = False
    for i in range(2, len(S)):
        for j in range(ord(S[1 - i]) + 1, 123):
            if chr(j) not in S[:1-i]:
                frag = True
                break
        if frag:
            break
    if frag:
        print("".join([S[:-i], chr(j)]))
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
s2 = list(s)
ch = [chr(i) for i in range(97, 97+26)]
flg = 0
for k in ch:
	if not k in s2:
		s += k
		flg = 1
		break

if flg == 1:
	print(s)
	exit(0)
else:
	l = len(s)
	ans = ''
	for i in range(l-1,0,-1):
		if chr((ord(s[i])+1)) != s[i-1]:
			for k in ch[::-1]:
				if k == s[i]:
					break
				if not k in s2[:i]:
					ans = s[:i-1] + k
					print(ans)
					exit(0)
	if s[0] == 'z':
		print(-1)
	else:
		print(chr(ord(s[0])+1))

Submission status: Wrong Answer

Solution code:
s=input()
a='abcdefghijklmnopqrstuvwzyx'
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)):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            print(s[:-i] + chr(ord(s[-i:][0]) + 1))
            break
    else:
        print(chr(ord(s[0])))

Submission status: Wrong Answer

Solution code:
def main():
    d = [0]*26
    s = input()
    for i in s:
        d[ord(i)-ord('a')]+=1

    if len(s) < 26:
        for i in range(26):
            if d[i]!=1:
                print(s+chr(ord('a')+i))
                break
    else:
        d[ord(s[-1])-ord('a')] = 0
        for i in range(1,26):
            if s[-i] > s[-i-1]:
                for j in range(26):
                    if d[j] != 1:
                        print(s[:-i-1]+chr(ord('a')+j))
                        return 0
            d[ord(s[-i-1])-ord('a')] = 0
        else:
            print(-1)

main()

Submission status: Wrong Answer

Solution code:
S=input()
if len(S)!=26:
    f=[0 for i in range(26)]
    for i in S:
        f[ord(i)-97]+=1
    t=""
    for i in range(26):
        if f[i]==0:
            t=chr(i+97)
            break
    print(S+t)
else:
    if S=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        k=25
        for i in range(25):
            if ord(S[25-i])>ord(S[24-i]):
                k=24-i
                break
        T=S[:k]
        g=[0 for i in range(26)]
        g[ord(S[k])-97]+=1
        for i in T:
            g[ord(i)-97]+=1
        t=""
        for i in range(26):
            if g[i]==0:
                t=chr(i+97)
                break
        print(T+t)

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:
    TmpS = S[0]
    
    if TmpS == 'z':
        print('-1')
        sys.exit()
    else:
        for j in range(26):
            if S2[j] == TmpS:
                print(S2[j + 1])
                sys.exit()
                
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()
a='abcdefghijklmnopqrstuvwzyx'
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)):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            print(s[:-i] + chr(ord(s[-i:][0]) + 1))
            break

Submission status: Wrong Answer

Solution code:
def main():
    S = input()

    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        return

    if len(S) < 26:
        for i in range(97, 123):
            if chr(i) not in S:
                print(S + chr(i))
                break
    else:
        for i in range(24, -1, -1):
            code = ord(S[i]) + 1
            if chr(code) not in S[:i] and code < 123:
                print(S[:i] + chr(code))
                break

main()

Submission status: Wrong Answer

Solution code:


def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    
    if "z" in temp:
        t1,t2=temp.split("z")
        temp=t1
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=t1[:-1]
        temp=temp+alps[0]
        print(temp)
        exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
s2 = list(s)
ch = [chr(i) for i in range(97, 97+26)]
flg = 0
for k in ch:
	if not k in s2:
		s += k
		flg = 1
		break

if flg == 1:
	print(s)
	exit(0)
else:
	l = len(s)
	ans = ''
	for i in range(l-1,0,-1):
		if chr((ord(s[i])+1)) != s[i-1]:
			for k in ch:
				if not k in s2[:i]:
					ans = s[:i-1] + k
					print(ans)
					exit(0)

	print(-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:
    TmpS = S[0]
    
    if TmpS == 'z':
        print('-1')
        sys.exit()
    else:
        for j in range(26):
            if S2[j] == TmpS:
                print(S2[j + 1])
                sys.exit()
                
for i in range(Len):
    TmpS = S[i]
    
    for j in range(26):
        if S2[j] == TmpS:
            Cnt[j] += 1
            if Cnt[j] > 2:
                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:
j = input()
lis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
abs = ""
for h in j:
    lis.remove(h)
if not lis:
    ans = "-1"
else:
    ans = "{}{}".format(j, lis[0])
tmp = "zz"
for i in range(len(j)-1, -1, -1):
    if j[i] != "z":

        if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):

            tmp = j[:i]+chr(ord(j[i])+1)
if tmp == "zz" and ans == "-1":
    print("-1")
elif tmp == "zz":
    print(ans)
elif ans == "-1":
    print(tmp)
else:
    print(min(ans, tmp))

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:
            ans.append(ALPHA.pop(0))
            break
    else:
        if ALPHA:
            ans.append(ALPHA.pop(0))
        else:
            alpha = sorted([a for a in "zyxwvutsrqponmlkjihgfedcba"])
            for i in range(0, len(ans) - 1):
                if ans[i] > ans[i + 1]:
                    return ''.join(ans[:i] + [alpha.pop(0)])
                else:
                    alpha.remove(ans[i])

    return "".join(ans)


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

Submission status: Wrong Answer

Solution code:
# encoding:utf-8


def main():
	s = input()
	alphabet = "abcdefghijklmnopqrstuvwxyz"
	if s == "zyxwvutsrqponmlkjihgfedcba":
		print("-1")
	elif len(s) < 26:
		for i in range(26):
			if alphabet[i] not in s:
				print(s + alphabet[i])
				break
	elif s == alphabet:
		print("ac")
	else:
		for i in range(26):
			if s[i] != alphabet[i]:
				for i2 in range(26):
					if alphabet[i2] not in s[0:(i-1)]:
						print(s[0:(i-1)] + alphabet[i2])
						break
				break


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
j = input()
lis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
abs = ""
for h in j:
    lis.remove(h)
if not lis:
    ans = "-1"
else:
    ans = "{}{}".format(j, lis[0])
tmp = "zz"
for i in range(len(j)-1, -1, -1):
    if j[i] != "z":

        if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):

            tmp = j[:i]+chr(ord(j[i])+1)
if tmp == "zz" and ans == "-1":
    print("-1")
elif tmp == "zz":
    print(ans)
else:
    print(tmp)

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"]
if len(set(Z)) == 26:
    print(-1)
else:
    i = G.index(Z[0])
    j = 1
    while True:
        if G[(i+j)%26] not in S:
            S.append(G[((i+j)%26)])
            break
        else:
            j += 1
    print("".join(S))

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase


def nxt(s):
    if len(s) < 26:
        for c in ascii_lowercase:
            if c not in s:
                return s + c

    for i, c in enumerate(ascii_lowercase[::-1]):
        try:
            j = s.index(c)
        except:
            continue
        if i == j:
            continue
        if c == 'z':
            pre = chr(ord(s[j - 1]) + 1)
            return s[:j - 1] + pre
        else:
            cur = chr(ord(s[j]) + 1)
            return s[:j] + cur
    return -1


def solve(s):
    while True:
        s = nxt(s)
        if s == -1:
            return s
        if s.index(s[-1]) == len(s) - 1:
            return s


s = input()
print(solve(s))

Submission status: Wrong Answer

Solution code:
S = input()
al = 'abcdefghijklmnopqrstuvwxyz'
if len(S) < 26:
    for c in al:
        if not c in S:
            print(S+c)
            exit()
elif S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    T = S
    min_c = T[-1]
    T = T[:-2] + min_c

    while S > T:
        if T[-1] < min_c:
            min_c = T[-1]
        T = T[:-2] + min_c

    print(T)

Submission status: Wrong Answer

Solution code:
j = input()
lis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
abs = ""
for h in j:
    lis.remove(h)
if not lis:
    ans = "-1"
else:
    ans = "{}{}".format(j, lis[0])
tmp = "zz"
for i in range(len(j)-1, -1, -1):
    if j[i] != "z":

        if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):

            tmp = j[:i]+chr(ord(j[i])+1)
print(min(ans, tmp))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8


def main():
	s = input()
	alphabet = "abcdefghijklmnopqrstuvwxyz"
	if s == "zyxwvutsrqponmlkjihgfedcba":
		print("-1")
	elif len(s) < 26:
		for i in range(26):
			if alphabet[i] not in s:
				print(s + alphabet[i])
				break
	elif s == alphabet:
		print("ac")
	else:
		for i in range(26):
			if s[i] != alphabet[i]:
				print(s[0:(i-1)] + alphabet[i])
				break


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
j = input()
lis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
abs = ""
for h in j:
    lis.remove(h)
if not lis:
    ans = "-1"
else:
    ans = "{}{}".format(j, lis[0])
tmp = "zz"
for i in range(len(j)-1, -1, -1):
    if j[i] != "z":

        if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):
            print(j[:i] + chr(ord(j[i]) + 1))
            tmp = j[:i]+chr(ord(j[i])+1)
print(min(ans, tmp))

Submission status: Wrong Answer

Solution code:
j = input()
lis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
abs = ""
for h in j:
    lis.remove(h)
if not lis:
    ans = "-1"
else:
    ans = "{}{}".format(j, lis[0])
tmp = "zz"
for i in range(len(j)-1, -1, -1):
    if j[i] != "z":

        if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):
            print(j[:i] + chr(ord(j[i]) + 1))
            tmp = j[:i]+chr(ord(j[i])+1)
print(max(ans, tmp))

Submission status: Wrong Answer

Solution code:
s = input()
s2 = list(s)
ch = [chr(i) for i in range(97, 97+26)]
flg = 0
for k in ch:
	if not k in s2:
		s += k
		flg = 1
		break

if flg == 1:
	print(s)
	exit(0)
else:
	l = len(s)
	ans = ''
	for i in range(l-1,0,-1):
		if chr((ord(s[i])+1)) != s[i-1]:
			ans = s[:i-1] + chr(ord(s[i-1])+1)
			break

	if ans != '':
		print(ans)
	else:
		print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
ct = Counter(S)
if len(ct) != 26:
  for i in range(26):
    c = chr(ord('a')+i)
    if c not in ct:
      print(S+c)
      exit()

prev = chr(ord('a')-1)
arr = []
for i in range(26)[::-1]:
  if prev > S[i]:
    print(S[:i] + min(arr))
    break
  arr.append(S[i])
  prev = S[i]
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
from string import lowercase
s = raw_input().strip()
if len(s) < 26:
    for c in lowercase:
        if c not in s:
            print s + c
            break
else:
    for i in xrange(25, -1, -1):
        for j in xrange(i - 1, -1, -1):
            if s[j] < s[i]:
                s = s[:j+1]
                for c in lowercase:
                    if c not in s:
                        print s[:-1] + c
                        quit()
    print -1

Submission status: Wrong Answer

Solution code:
def inc(s):
	ans = s[:-1]
	# print(ans)
	# print(chr(ord(s[-1]) + 1))
	ans += chr(ord(s[-1]) + 1)
	return ans


s = input()
w = []
for i in range(26):
	w += chr(i + ord('a'))
# print(w)
for l in w:
	if l not in s:
		print(s + l)
		exit(0)

ans=''
for l in s:
	if l == 'z':
		if len(ans) == 0:
			print(-1)
		else:
			print(inc(ans))
	ans += l

Submission status: Wrong Answer

Solution code:
import sys

alph="abcdefghijklmnopqrstuvwxyz"
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()
if(S=="abcdefghijklmnopqrstuvwxyz"):
    print("b")
    sys.exit()
for i in alph:
    if(i not in S):
        print(S+i)
        sys.exit()
        
outp=""
for i in range(len(S)):
    if(S[i]==alph[i]):
        outp+=S[i]
    else:
        outp=outp[:-1]
        print(outp+alph[i])
        sys.exit()
print(-1)

Submission status: Wrong Answer

Solution code:
d = [0]*26
s = input()
for i in s:
    d[ord(i)-ord('a')]+=1
if len(s) < 26:
    for i in range(26):
        if d[i]!=1:
            print(s+chr(ord('a')+i))
            break
else:
    for i in range(1,26):
        if s[-i] > s[-i-1]:
            print(s[:-i-1]+s[-1])
            break
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
from string import lowercase
s = raw_input().strip()
if len(s) < 26:
    for c in lowercase:
        if not c in s:
            print s + c
            break
else:
    for i in xrange(25, -1, -1):
        for j in xrange(i - 1, -1, -1):
            if s[j] < s[i]:
                print s[:j] + chr(ord(s[j]) + 1)
                quit()
    print -1

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase


def solve(s):
    if len(s) < 26:
        for c in ascii_lowercase:
            if c not in s:
                return s + c

    for i, c in enumerate(ascii_lowercase[::-1]):
        j = s.index(c)
        if i == j:
            continue
        if c == 'z':
            pre = chr(ord(s[j - 1]) + 1)
            return s[:j - 1] + pre
        else:
            cur = chr(ord(s[j]) + 1)
            return s[:j] + cur
    return -1


s = input()
print(solve(s))

Submission status: Wrong Answer

Solution code:
s=input()
t=list(s)
a=[]
for i in range(26):
    a.append(chr(i+97))
flag=True
for i in range(len(a)):
    if a[i] not in t:
        b=a[i]
        flag=False
        break
if flag:
    print(-1)
else:
    print(s+a[i])

Submission status: Wrong Answer

Solution code:
import string
s = input()
s2=s.lower()
alp = string.ascii_lowercase
ans=''
for i in range(26):
    if alp[i] not in s2:
        ans=alp[i]
        break
if ans=='':
    print(-1)
else:
    print(s+ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = [ord(c)-ord('a') for c in S]

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

def next(x):
    if len(x) < 26:
        for c in range(26):
            if not c in x:
                x.append(c)
                return x
    k = 0
    flag = True
    x[-1] += 1
    c = 0
    for i in range(len(x)):
        x[-1-i] += k
        if x[-1-i] >= 26:
            if flag: c += 1
            else: x[-1-i] -= 26
            k = 1
        else:
            flag = False
            k = 0
    if k == 1: return None
    if c: return x[:-c]
    return x

def check(x):
    c = [False]*26
    for i in x:
        if x == -1: continue
        if c[i]: return False
        c[i] = True
    return True

while True:
    n = next(n)
    if n == None:
        print(-1)
        exit()
    if check(n): break

ans = ""
for i in n:
    if i != -1: ans += chr(ord('a') + i)
print(ans)