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 = str(input())
list_s = list(s)
alp_list = list("abcdefghijklmnopqrstuvwxyz")
dict_alp = {}
ans = 0
for i in range(26):
    dict_alp[alp_list[i]] = i+1
x = list_s[-1]
if len(list_s) == 26:
    i = 25
    while True:
        try:
            if dict_alp[list_s[i]] > dict_alp[list_s[i-1]]:
                list_s = list_s[:i]
                list_s.pop()
                list_s.append(x)
                break
            else:
                i -= 1
        except IndexError:
            ans = -1
            break

else:
    for alp in alp_list:
        if not alp in list_s:
            list_s.append(alp)
            break
if ans == -1:
    print(ans)
else:
    print("".join(list_s))

Submission status: Wrong Answer

Solution code:
s = input()
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
l = []
for i in range(26):
    l.append(0)
a_num = ord('a')
temp = -1
i_temp = -1
if len(s) == 26:
    for i in range(len(s)):
        num = ord(s[i]) - a_num
        if temp < num:
            l[num] = 1
            temp = num
            i_temp += 1
        else:
            break
    add_alp = -1
    for i in range(26):
        if l[i] == 0:
            add_alp = i
            break
    if add_alp == -1 | i_temp == 25:
        print(-1)
        exit()
    else:
        print(s[:i_temp] + chr(add_alp + a_num))
        exit()

add_alp = -1
for i in range(len(s)):
    num = ord(s[i]) - a_num
    l[num] += 1
 
for i in range(26):
    if l[i] == 0:
        add_alp = i
        break

if add_alp == -1:
    print(-1)
else:
    print(s + chr(add_alp + a_num))

Submission status: Wrong Answer

Solution code:
s = input()
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
l = []
for i in range(26):
    l.append(0)
a_num = ord('a')
temp = -1
i_temp = -1
if len(s) == 26:
    for i in range(len(s)):
        num = ord(s[i]) - a_num
        if temp < num:
            l[num] = 1
            temp = num
            i_temp += 1
        else:
            break
    add_alp = -1
    for i in range(26):
        if l[i] == 0:
            add_alp = i
            break
    if add_alp == -1 | i_temp == 25:
        print(-1)
        exit()
    else:
        print(s[:i_temp] + chr(add_alp + a_num))
        exit()

add_alp = -1

for i in range(26):
    if l[i] == 0:
        add_alp = i
        break

if add_alp == -1:
    print(-1)
else:
    print(s + chr(add_alp + a_num))

Submission status: Wrong Answer

Solution code:
s = input()

l = []
for i in range(26):
    l.append(0)
a_num = ord('a')
for i in range(len(s)):
    num = ord(s[i]) - a_num
    l[num] = 1

add_alp = -1

for i in range(26):
    if l[i] == 0:
        add_alp = i
        break

if add_alp == -1:
    print(-1)
else:
    print(s + chr(add_alp + a_num))

Submission status: Wrong Answer

Solution code:
alph={chr(i) for i in range(97,123)}
s=input()
n=len(s)

if n<26:
  print(s+sorted(alph-set(s))[0])
else:
  b=""
  for i in range(n-1)[::-1]:
    if s[i]<s[i+1]:
      break
  if not i:
    print(-1)
  else:
    for j in sorted(s[i+1:]):
      if j>s[i]:
        print(s[:i]+j)
        break

Submission status: Wrong Answer

Solution code:
alph={chr(i) for i in range(97,123)}
s=input()
n=len(s)

if n<26:
  print(s+sorted(alph-set(s))[0])
else:
  b=""
  for i in range(n-1)[::-1]:
    if s[i]<s[i+1]:
      break
  if not i:
    print(-1)
  else:
    print(s[:i]+sorted(s[i+1:])[0])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
atoz = [chr(i) for i in range(97,97+26)]

S = input()

if len(S) < 26:
    for a in atoz:
        if not a in S:
            print(S+a)
            break
else:
    right = S[-1]
    for i in reversed(range(len(S))):
        s = S[i]
        if s < right:
            print(S[:i]+right)
            sys.exit()
        else:
            right = max(s,right)
    print(-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
atoz = [chr(i) for i in range(97,97+26)]

S = input()

if len(S) < 26:
    for a in atoz:
        if not a in S:
            print(S+a)
            break
else:
    right = S[-1]
    for i in reversed(range(len(S))):
        s = S[i]
        if s < right:
            print(S[:i]+right)
            sys.exit()
        else:
            right = min(s,right)
    print(-1)

Submission status: Wrong Answer

Solution code:
# cook your dish here
s=list(input())
k = 0
if s.count('a') == 0:
    s += 'a'
elif s.count('b') == 0:
    s += 'b'
elif s.count('c') == 0:
    s += 'c'
elif s.count('d') == 0:
    s += 'd'
elif s.count('e') == 0:
    s += 'e'
elif s.count('f') == 0:
    s += 'f'
elif s.count('g') == 0:
    s += 'g'
elif s.count('h') == 0:
    s += 'h'
elif s.count('i') == 0:
    s += 'i'
elif s.count('j') == 0:
    s += 'j'
elif s.count('k') == 0:
    s += 'k'
elif s.count('l') == 0:
    s += 'l'
elif s.count('m') == 0:
    s += 'm'
elif s.count('n') == 0:
    s += 'n'
elif s.count('o') == 0:
    s += 'o'
elif s.count('p') == 0:
    s += 'p'
elif s.count('q') == 0:
    s += 'q'
elif s.count('r') == 0:
    s += 'r'
elif s.count('s') == 0:
    s += 's'
elif s.count('t') == 0:
    s += 't'
elif s.count('u') == 0:
    s += 'u'
elif s.count('v') == 0:
    s += 'v'
elif s.count('w') == 0:
    s += 'w'
elif s.count('x') == 0:
    s += 'x'
elif s.count('y') == 0:
    s += 'y'
elif s.count('z') == 0:
    s += 'z'
else:
    
    for i in range(25):
        if s[25-i] > s[25-i-1]:
            s = s[:25-i-1:]+list(s[25])
            break
        else:
            k += 1
if k == 25:
    print(-1)
else:
    ass = ''
    for i in range(len(s)):
        ass += s[i]
    print(ass)

Submission status: Wrong Answer

Solution code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[-i + 1]:
            break
        if i == 26:
            print(-1)
    s_ = sorted(s[-i + 1:])
    for j in s_:
        if j > s[-i]:
            break
    print(s[:-i] + j)

Submission status: Wrong Answer

Solution code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[-i + 1]:
            break
    if i == 26:
        print(-1)
    else:
        s_ = sorted(s[-i + 1:])
        for j in s_:
            if j > s[-i]:
                break
        print(s[:-i] + j)

Submission status: Wrong Answer

Solution code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[-i + 1]:
            break
    if i == 26:
        print(-1)
    else:
        s_ = sorted(s[-i + 1:])
        for j in s_:
            if j > s[-i]:
                break
        print(s[:-i] + j)

Submission status: Wrong Answer

Solution code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[1 - i]:
            break
    if i == 26:
        print(-1)
    else:
        s_ = s[-i:]
        s_ = sorted(s_)
        for j in s_:
            if j > s[-i]:
                break
        print(s[:-i] + j)

Submission status: Wrong Answer

Solution code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(1, 27):
        if s[-i] <= s[-i + 1]:
            break
    s_ = sorted(s[-i:])
    for j in s_:
        if j > s[-i]:
            break
    print(s[:-i] + j)

Submission status: Wrong Answer

Solution code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] < s[1 - i]:
            break
    if i == 26:
        print(-1)
    else:
        s_ = s[-i + 1:]
        s_ = sorted(s_)
        for j in s_:
            if j > s[-i]:
                break
        print(s[:-i] + j)

Submission status: Wrong Answer

Solution code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(1, 27):
        if s[-i] > s[-i - 1]:
            break
    print(i)
    s_ = sorted(s[-i:])
    for j in s_:
        if j > s[-i - 1]:
            break
    print(s[:-i - 1] + j)

Submission status: Wrong Answer

Solution code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if s == "zyxwvutsrqponmlkjihgfedcba":
     print(-1)
elif len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[1 - i]:
            break
    for k in range(1, 27):
        if s[-k] > s[-k - 1]:
            break
    #print(i, k)
    else:
        s_ = sorted(s[-i + 1:])
        for j in s_:
            if j > s[-i]:
                break
        #print(s[:-i] + j)

        T = sorted(s[-k:])
        for t in T:
            if t > s[-k - 1]:
                break
        print("".join(list(s)[:-k - 1]) + t)
        #print(s_, T)

Submission status: Wrong Answer

Solution code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[1 - i]:
            break
    if i == 26:
        print(-1)
    else:
        s_ = s[-i + 1:]
        s_ = sorted(s_)
        for j in s_:
            if j > s[-i]:
                break
        print(s[:-i] + j)

Submission status: Wrong Answer

Solution code:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[1 - i]:
            break
    if i == 26:
        print(-1)
    else:
        print(s[:-i] + s[-1])

Submission status: Wrong Answer

Solution code:
def solv(S):
    for i in range(25, 0, -1):
        for j in range(i-1, -1, -1):
            if ord(S[i]) > ord(S[j]):
                print(S[:j]+S[i])
                return


alph = "abcdefghijklmnopqrstuvwxyz"
S = input()
for c in S:
    alph = alph.replace(c, "")
if alph != "":
    print(S+alph[0])
else:
    if S == alph[::-1]:
        print(-1)
    else:
        solv(S)

Submission status: Wrong Answer

Solution code:
alph = "abcdefghijklmnopqrstuvwxyz"
S = input()
for c in S:
    alph = alph.replace(c, "")
if alph != "":
    print(S+alph[0])
else:
    alph = "abcdefghijklmnopqrstuvwxyz"
    if S == alph[::-1]:
        print(-1)
    else:
        for i in range(len(S)):
            if S[i] != alph[i]:
                print(S[:i-1]+alph[i])
                break

Submission status: Wrong Answer

Solution code:
s = input()

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

def youngest(str):
    cnt = [0]*26
    for c in str:
        cnt[ord(c)-ord('a')] += 1
    return chr(ord('a')+cnt.index(0))

if len(s)<26:
    print(s+youngest(s))
    exit()

# len(s)==26
suffix = ''
for i,c in enumerate(s[::-1]):
    if len(suffix)==0:
        suffix += c
    else:
        if suffix[i-1]>c:
            break
        else:
            suffix += c

print(s[:25-len(suffix)]+sorted(suffix)[-1])

Submission status: Wrong Answer

Solution code:
s = input()

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

def youngest(str):
    cnt = [0]*26
    for c in str:
        cnt[ord(c)-ord('a')] += 1
    return chr(ord('a')+cnt.index(0))

if len(s)<26:
    print(s+youngest(s))
    exit()

ab = 'abcdefghijklmnopqrstuvwxyz'

# len(s)==26
suffix = ''
for i,c in enumerate(s[::-1]):
    if len(suffix)==0:
        suffix += c
    else:
        if suffix[i-1]>c:
            break
        else:
            suffix += c

#if suffix==ab[-len(suffix):]:
print(s[:25-len(suffix)]+suffix[0])
#else:
#    print(s[:25-len(suffix)]+suffix[0])

Submission status: Wrong Answer

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

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

r = []
for c in t:
    r.append(ord(c))

if len(t) < 26:
    r = sorted(r)

    temp = ord('a')

    for x in r:
        if x == temp:
            temp += 1
        else:
            break

    t.append(chr(temp))

    print(''.join(t))

else:
    temp = r[25]
    for i in range(24, -1, -1):
        if r[i] < temp:
            t[i] = chr(temp)
            break
        else:
            temp = max(temp, r[i])
            t[i] = ''

    t[25] = ''
    print(''.join(t))

Submission status: Wrong Answer

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

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

r = []
for c in t:
    r.append(ord(c))

if len(t) < 26:
    r = sorted(r)

    temp = ord('a')

    for x in r:
        if x == temp:
            temp += 1
        else:
            break

    t.append(chr(temp))

    print(''.join(t))

else:
    for i in range(24, -1, -1):
        if r[i] < r[25]:
            t[i] = t[25]
            break
        else:
            t[i] = ''


    t[25] = ''
    print(''.join(t))

Submission status: Wrong Answer

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

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)

r = []
for c in t:
    r.append(ord(c))

if len(t) < 26:
    r = sorted(r)

    temp = ord('a')

    for x in r:
        if x == temp:
            temp += 1
        else:
            break

    t.append(chr(temp))

    print(''.join(t))

else:
    for i in range(24, -1, -1):
        if r[i] < r[25]:
            t[i] = t[25]
            break
        else:
            t[i] = ''


    t[25] = ''
    print(''.join(t))

Submission status: Wrong Answer

Solution code:
s = input()
a = [chr(i) for i in range(ord('a'), ord('z')+1)]
if len(s)< 26:
    for i in a:
        if sorted(s).count(i)==0:
            break
    print(s+i)
else:
    l = [ord(i) for i in s]
    for i in range(1,len(s)):
        if l[-i]-l[-i-1]>0:
            print(s[:-i-1]+chr(ord(s[-i-1])+1))
            break
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
def a_diverse_word(S):
    from string import ascii_lowercase
    if len(S) < 26:
        # 26字未満なら、Sにまだ現れていない文字で辞書順最小のものを末尾に加えたものが解
        for c in ascii_lowercase:
            if c not in S:
                ans = S + c
                break
    else:  # Sの長さは定義上26字以下なので、Sが26字のときこの処理を行う
        idx = 0  # S[idx]以降末尾まで降順になっている
        for k in range(len(S) - 1, 0, -1):
            if S[k] > S[k - 1]:
                idx = k
                break
        if idx == 0:
            ans = '-1'  # Sは辞書の最後の単語だった。「次」はない
        else:
            for c in ascii_lowercase:
                if S[idx - 1] < c:
                    ans = S[:idx - 1] + c
                    break
    return ans

S = input().strip()
print(a_diverse_word(S))

Submission status: Wrong Answer

Solution code:
s = input()

s_set = set(s)
a_set = set('abcdefghijklmnopqrstuvwxyz')
left_list = sorted(list(a_set - s_set))

ans = -1
if len(left_list) == 0:#未使用文字なし
    while ans == -1:
        left_list.append(s[-1])
        s = s[:-1]
        if len(s) == 0:
            break
        left_list = sorted(left_list)
        print(s, left_list)
        for c in left_list:
            print(c, s[-1])
            if c > s[-1]:
                ans = s[:-1] + c
                break
else:#未使用文字あり
    ans = s + left_list[0]
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

s_set = set(s)
a_set = set('abcdefghijklmnopqrstuvwxyz')
left_list = sorted(list(a_set - s_set))

ans = -1
if len(left_list) == 0:#未使用文字なし
    while True:
        left_list.append(s[-1])
        s = s[:-1]
        if len(s) == 0:
            break
        left_list = sorted(left_list)
        for c in left_list:
            if c > s[-1]:
                ans = s[:-1] + c
                break
else:#未使用文字あり
    ans = s + left_list[0]
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

s_set = set(s)
a_set = set('abcdefghijklmnopqrstuvwxyz')
left_list = sorted(list(a_set - s_set))

ans = -1
if len(left_list) == 0:#未使用文字なし
    while True:
        left_list.append(s[-1])
        s = s[:-1]
        if len(s) == 0:
            break
        left_list = sorted(left_list)
        if left_list[0] > s[-1]:
            ans = s[:-1] + left_list[0]
            break
else:#未使用文字あり
    ans = s + left_list[0]
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
a_list = 'abcdefghijklmnopqrstuvwxyz'
d = dict()
for c in s:
    d[c] = 1

ans = ''
t = ''
for c in a_list:
    if d.get(c, 0) == 0:
        t = c
        break

if t == '':#未使用文字なし
    if s == a_list[::-1]:
        ans = -1
    else:
        for i in range(len(s) - 2, -1, -1):
            if s[i] < s[-1]:
                ans = s[:i] + s[-1]
                break
else:#未使用文字あり
    ans = s + t
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) < 26:
    for i in range(26):
        c = chr(ord('a') + i)
        if c in S: continue
        print(S + c)
        exit()

cset = set()
for i,(a,b) in enumerate(reversed(list(zip(S,S[1:])))):
    cset.add(b)
    if a < b:
        print(S[:-i-2] + min(cset))
        exit()

Submission status: Wrong Answer

Solution code:
S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) < 26:
    for i in range(26):
        c = chr(ord('a') + i)
        if c in S: continue
        print(S + c)
        exit()

cset = set([S[-1]])
for i,(a,b) in enumerate(reversed(list(zip(S,S[1:])))):
    if a > b:
        cset.add(a)
    else:
        print(S[:-i-2] + min(cset))
        exit()

assert False

Submission status: Wrong Answer

Solution code:
S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) < 26:
    for i in range(26):
        c = chr(ord('a') + i)
        if c in S: continue
        print(S + c)
        exit()

assert len(S) == 26

cset = set([S[-1]])
for i,(a,b) in enumerate(reversed(list(zip(S,S[1:])))):
    if a > b:
        cset.add(a)
    else:
        print(S[:-i-2] + min(cset))
        exit()

Submission status: Wrong Answer

Solution code:
s = input()

alphaset = set()
for i in range(97, 97+27):
    alphaset.add(chr(i))
    

if len(s) < 26:
    for c in list(s):
        alphaset.remove(c)
        
    alphalist = list(alphaset)
    alphalist.sort()
    
    print(s + alphalist[0])
    
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        
    else:
        c = list(s)
        point = 100
        for i in range(25,0,-1):
            if c[i-1] > c[i]:
                continue
            else:
                for ci in c[:i]:
                    alphaset.remove(ci)
                    
                alphalist = list(alphaset)
                alphalist.sort()
                
                c[i-1] = alphalist[0]
                point = i
                break
        
        print("".join(c[:point]))

Submission status: Wrong Answer

Solution code:
s = input()

alphaset = set()
for i in range(97, 97+27):
    alphaset.add(chr(i))
    

if len(s) < 26:
    for c in list(s):
        alphaset.remove(c)
        
    alphalist = list(alphaset)
    alphalist.sort()
    
    print(s + alphalist[0])
    
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        
    else:
        c = list(s)
        point = 100
        for i in range(25,0,-1):
            if c[i-1] > c[i]:
                continue
            else:
                c[i-1] = chr(ord(c[i-1]) + 1)
                point = i
                break
        
        print("".join(c[:point]))

Submission status: Wrong Answer

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

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

for i in range(26):
    bucket.append(0)
for x in S:
    bucket[character.index(x)] += 1

if len(S) < 26:
    i=0
    while True:
        if not bucket[i]:
            print(S+character[i])
            quit()
        else:
            i+=1
else:
    j=26-1
    index=26-1
    while True:
        if  S[j-1] > S[j]:
            j -= 1
        else:
            index = j-1
            break
    print(S[:index]+S[25])

Submission status: Wrong Answer

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

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

for i in range(26):
    bucket.append(0)
for x in S:
    bucket[character.index(x)] += 1

if len(S) < 26:
    i=0
    while True:
        if not bucket[i]:
            print(S+character[i])
            quit()
        else:
            i+=1
else:
    i=26-1
    while True:
        if  S[i-1] > S[i]:
            i -= 1
        else:
            index = i-1
            break
    print(S[:index]+S[25])

Submission status: Wrong Answer

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

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

for i in range(26):
    bucket.append(0)
for x in S:
    bucket[character.index(x)] += 1

if len(S) < 26:
    i=0
    while True:
        if not bucket[i]:
            print(S+character[i])
            quit()
        else:
            i+=1
else:
    i=26-1
    while i > 0:
        if  S[i-1] > S[i]:
            i -= 1
        else:
            index = i-1
            break
    print(S[:index]+character[character.index(S[index])+1])
    quit()

Submission status: Wrong Answer

Solution code:
words = []

for i in range(26):
	words.append(chr(ord("a")+i))

s = list(raw_input())

for i in words:
	if i not in s :
		s.append(i)
		print ''.join(s)
		quit()

print -1

Submission status: Wrong Answer

Solution code:
s = input()

ans = s
ansa = s
a = 'abcdefghijklmnopqrstuvwxyz'
a = [a[i] for i in range(26)]
if len(s)<26:
    for i in a:
        if ans.count(i) == 0:
            ans += i
            break
else:
    b = 26
    for i in range(1,26):
        if a.index(s[i]) > a.index(s[i-1]):
            b = i
    if b == 26:
        print(-1)
    else:
        s = s[:b]
        for j in a:
            if a.index(j) > a.index(s[b-1]) and j not in s:
                s = s[:b-1]+j
                break
        print(s)

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import bisect
 
def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

S = input()
N = len(S)
last = 'zyxwvutsrqponmlkjihgfedcba'

if S == last:
  print(-1); exit()
if len(S) < 26:
  c = sorted(set(last) - set(S))[0]
  print(S + c); exit()
else:
  for i in range(1, N):
    if S[-i-1] < S[-i]:
      print(S[-i-1], S[-i], S[-1])
      if S[-i-1] < S[-1]:
        print(S[:-i-1] + S[-1])
      else:
        print(S[:-i] + S[-1])
      exit()

Submission status: Wrong Answer

Solution code:
s = input()
unused = {chr(x+97)for x in range(26)} - set(s)
if unused:
    print(s+sorted(unused)[0])
else:
    for k,c in enumerate(map(ord,s)):
        if k:
            if past>c:
                break
            else:
                past=c
        else:
            past=c
        idx=k-1
    if idx<0:
        print(idx)
    else:
        print(s[:idx]+sorted(c for c in s[idx+1:]if s[idx]<c)[0])

Submission status: Wrong Answer

Solution code:
S=list(map(str,input()))
F=False
try:
    while 1:
        for I in range(ord("a"),ord("z")+1):
            if len(S+[chr(I)])==len(set(S+[chr(I)])):
                F=True;S+=[chr(I)];break
        if F:break
        S.pop()
        S[len(S)-1]=chr(ord(S[len(S)-1])+1)
        while ord(S[len(S)-1])>ord("y"):
            S.pop()
            S[len(S)-1]=chr(ord(S[len(S)-1])+1)
        if len(set(S))==len(S):break
    print("".join(S))
except:print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
non = []

if len(S) < 26:
    for a in abc:
        if not a in S:
            print(S + a)
            break
elif S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    Zind = S.index('z')
    tmpind = abc.index(S[Zind-1])
    print(S[:Zind-1] + abc[tmpind + 1])

Submission status: Wrong Answer

Solution code:
S = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
non = []
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
elif len(S) == 26:
    Zind = S.index('z')
    tmpind = abc.index(S[Zind-1])
    print(S[:Zind-1] + abc[tmpind + 1])
else:
    for a in abc:
        if not a in S:
            print(S + a)
            exit()

Submission status: Wrong Answer

Solution code:
S = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
non = []
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
elif len(S) == 26:
    Zind = S.index('z')
    tmpind = abc.index(S[Zind-1])
    print(S[:Zind] + abc[tmpind + 1])
else:
    for a in abc:
        if not a in S:
            print(S + a)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
s = input()
if(len(s) > 26):
    print("-1")
    sys.exit()
elif(len(s) == 26):
     ed = ord(s[25])
     for i in range(25):
         if(ord(s[25-i]) > ord(s[24-i])):
             s = s[:24-i]
             print(s+chr(ed))
             sys.exit()
         if(i == 24):
             print("-1")
             sys.exit()

nums = []
for i in s:
    nums.append(ord(i))
nums.sort()

for i in range(len(nums)):
    if(nums[i] != i+97):
        s += chr(i+97)
        print(s)
        sys.exit()

s += chr(len(nums) + 97)
print(s)

Submission status: Wrong Answer

Solution code:
import sys
s = input()
if(len(s) > 26):
    print("-1")
    sys.exit()
elif(len(s) == 26):
     ed = ord(s[25])
     for i in range(25):
         if(ed > ord(s[24-i])):
             s = s[:24-i]
             print(s+chr(ed))
             sys.exit()
         if(i == 24):
             print("-1")
             sys.exit()
             
nums = []
for i in s:
    nums.append(ord(i))
nums.sort()

for i in range(len(nums)):
    if(nums[i] != i+97):
        s += chr(i+97)
        print(s)
        sys.exit()

s += chr(len(nums) + 97)
print(s)

Submission status: Wrong Answer

Solution code:
S = input()
alphabet = list("abcdefghijklmnopqrstuvwxyz")

if S == "zyxwvutsrqponmlkjihgfedcba":
     print(-1)
        
elif len(S) < 26:
    print(S + min(set(alphabet) - set(S)))
    
else:
    for i in range(26):
        if list(S)[-i] > list(S)[-(i + 1)]:
            break
    T = sorted(list(S)[-i:])
    for t in T:
        if t > list(S)[-(i + 1)]:
            break
    print("".join(list(S)[:-(i + 1)]) + t)

Submission status: Wrong Answer

Solution code:
s = raw_input()

w = ["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"]

for t in w:
	if not s.count(t) :
		print s+t
		break

Submission status: Wrong Answer

Solution code:
ABC = sorted(list("zyxwvutsrqponmlkjihgfedcba"))

S = input()

if len(S)<26:
    for a in ABC:
        if a not in S:
            print(S+a)
            break
else:
    Z_index = S.index("z")
    back = Z_index-1
    if back<0:
        print(-1)
    else:
        back_a = S[back]
        S = S[:back]
        for a in ABC:
            if a not in S+back_a:
                print(S+a)
                break

Submission status: Wrong Answer

Solution code:
N=list(input())
mark=0
for i in range (len(N)):
    if N[i]!='9':
        mark=i
        print (mark)
        break
if mark==0:
    answer=list((''.join(['9']*(len(N)-1))))
else:
    answer=list((''.join(N[:mark-1]+[str(int(N[mark-1])-1)]+['9']*len(N[mark:]))))
    
answer_sum=0
for j in range (len(answer)):
    answer_sum+=int(answer[j])
print(answer_sum)

Submission status: Wrong Answer

Solution code:
S=input()
alphabet=['a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for i in range (len(S)):
    for j in range (len(alphabet)):
        if S[i]==alphabet[j]:
            alphabet[j]=0
import sys
for k in range (len(alphabet)):
    if alphabet[k]!=0:
        print(S+alphabet[k])
        sys.exit()
print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
A="abcdefghijklmnopqrstuvwxyz"

C = set(S)
new_alpha_index = 0

COMP = False
for a in A:
    if a not in C:
        S += a
        COMP = True
        break
    elif a=="z":
        new_alpha_index = S.index(a)-1

if not COMP:
    if new_alpha_index<0:
        print(new_alpha_index)
    else:
        S = S[0:new_alpha_index]+A[A.index(S[new_alpha_index])+1]
        print(S)
else:
    print(S)

Submission status: Wrong Answer

Solution code:
s=input()
ans=""
if len(s)==26:
    print(-1)
    exit()
else:
    for i in range(97,97+26):
        if not chr(i) in s:
            ans+=chr(i)
            break
print(s+ans)