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:
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
if len(N) < 26:
    for d in D:
        if not d in setN:
            N.append(d)
            print(''.join(N))
            exit()
else:
    for i in range(25):
        if N[i] < N[i+1]:
            continue
        else:
            if i == 0:
                print(-1)
                exit()
            ans = N[:i-1]
            tmp = N[i-1]
            tmpL = N[i-1:]
            tmpL.sort()
            for t in tmpL:
                if t != tmp:
                    ans.append(t)
                    print(''.join(ans))
                    exit()

Submission status: Wrong Answer

Solution code:
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
if len(N) < 26:
    for d in D:
        if not d in setN:
            N.append(d)
            print(''.join(N))
            exit()
else:
    for i in range(25):
        if N[i] < N[i+1]:
            continue
        else:
            if i == 0:
                print(-1)
                exit()
            ans = N[:i-1]
            ans.append(chr(ord(N[i-1]) + 1))
            print(''.join(ans))
            exit()

Submission status: Wrong Answer

Solution code:
import copy
N = list(input())
setN = set(N)
A = list('abcdefghijklmnopqrstuvwxyz')

if len(N) < len(A):
  for a in A:
      if not a in setN:
          N.append(a)
          print(''.join(N))
          exit()
else:
    ans = '-1'
    for i in range(len(N)-1):
        if N[i] < N[i+1]:
            continue
        else:
            ans = copy.copy(N[:i-1])
            ind = A.index(N[i-1])
            n = A[ind+1]
            if n not in ans:
                ans.append(n)
                print(''.join(ans))
            else:
                print('-1')
            break

Submission status: Wrong Answer

Solution code:
N = list(input())
setN = set(N)
A = list('abcdefghijklmnopqrstuvwxyz')

if len(N) < len(A):
  for a in A:
      if not a in setN:
          N.append(a)
          print(''.join(N))
          exit()
else:
    ans = '-1'
    for i in range(len(N)-1):
        if N[i] < N[i+1]:
            continue
        else:
            if i == 0:
                print(ans)
                exit()
            ans = ''.join(N[:i-1])
            ind = A.index(N[i-1])
            ans += A[ind+1]
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
for d in D:
    if not d in setN:
        N.append(d)
        print(''.join(N))
        exit()
ans = []
key = ''
for i in range(0, 25):
    if N[i] < N[i+1]:
        ans.append(N[i])
    else:
        key = N[i]
        break
if len(ans) == 0:
    print(-1)
else:
    ind = D.index(ans[-1])
    for i in range(ind, 26):
        if not D[i] in ans:
            ans[-1] = D[ind+1]
            print(''.join(ans))
            exit()

Submission status: Wrong Answer

Solution code:
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
for d in D:
    if not d in setN:
        N.append(d)
        print(''.join(N))
        exit()
ans = []
key = ''
for i in range(0, 25):
    if N[i] < N[i+1]:
        ans.append(N[i])
    else:
        key = N[i]
        break
if len(ans) == 0:
    print(-1)
else:
    ind = D.index(ans[-1])
    ans[-1] = D[ind+1]
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
N = list(input())
setN = set(N)
D = list('abcdefghijklmnopqrstuvwxyz')
rD = list('zyxwvutsrqponmlkjihgfedcba')
for d in D:
    if not d in setN:
        N.append(d)
        print(''.join(N))
        exit()
ans = []
for i in range(0, 25):
    if N[i] < N[i+1]:
        ans.append(N[i])
if len(ans) == 0:
    print(-1)
else:
    del(ans[-1])
    for d in D:
        if not d in ans:
            ans.append(d)
            print(''.join(ans))
            exit()

Submission status: Wrong Answer

Solution code:
import string
chars = string.ascii_lowercase
def solve(S):
    for c in chars:
        if c in S:
            continue
        else:
            return S + c
    S = S[::-1]
    for i, c in enumerate(S):
        if c == chars[-1]:
            if i == len(S) - 1:
                continue
            c = S[i + 1]
            ans = S[i + 2:]
            n = chars[chars.find(c) + 1]
            while n in ans:
                n = chars[chars.find(n)+1]
            ans = ans[::-1]
            ans += n
            return ans
        else:
            n = chars[chars.find(c)+1]
            if n not in S[i:]:
                ans = S[i+1:]
                ans = ans[::-1]
                ans += n
                return ans
    return -1

if __name__ == "__main__":
    print(solve(input()))

Submission status: Wrong Answer

Solution code:
import string
def solve(S):
    for c in string.ascii_lowercase:
        if c in S:
            continue
        else:
            return S + c
    S = S[::-1]
    for i, c in enumerate(S):
        if c == "z":
            continue
        n = string.ascii_lowercase[string.ascii_lowercase.find(c)+1]
        if n not in S[i:]:
            ans = S[i+1:]
            ans = ans[::-1]
            ans += n
            return ans
    return -1


if __name__ == "__main__":
    print(solve(input()))

Submission status: Wrong Answer

Solution code:
s = input()
length_s =len(s)
alphabet_small = [chr(i) for i in range(97, 97+26)]
if length_s < 26:
    for alphabet in alphabet_small:
        if alphabet not in s:
            print(s+alphabet)
            exit()
for i in range(length_s-1):
    if s[i] < s[i+1]:
        ans = s[:i] + min(s[i+1:])
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
length_s =len(s)
alphabet_small = [chr(i) for i in range(97, 97+26)]
if length_s < 26:
    for alphabet in alphabet_small:
        if alphabet not in s:
            print(s+alphabet)
            exit()
for i in range(length_s-2,-1,-1):
    if s[i] < s[i+1]:
        ans = s[:i] + min(s[i+1:])
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
length_s =len(s)
alphabet_small = [chr(i) for i in range(97, 97+26)]
if length_s < 26:
    for alphabet in alphabet_small:
        if alphabet not in s:
            print(s+alphabet)
            exit()
for i in range(length_s-2,-1,-1):
    if s[i] < s[i+1]:
        ans = s[:i] + max(s[i+1:])
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
length_s =len(s)
alphabet_small = [chr(i) for i in range(97, 97+26)]
if length_s < 26:
    for alphabet in alphabet_small:
        if alphabet not in s:
            print(s+alphabet)
            exit()
for i in range(length_s-2,-1,-1):
    if s[i] < s[i+1]:
        ans = s[:i] + max(s[i:])
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
length_s =len(s)
alphabet_small = [chr(i) for i in range(97, 97+26)]
if length_s < 26:
    for alphabet in alphabet_small:
        if alphabet not in s:
            print(s+alphabet)
            exit()
for i in range(length_s-2,-1,-1):
    if s[i] < s[i+1]:
        ans = s[:i] + min(s[i:])
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
length_s =len(s)
alphabet_small = [chr(i) for i in range(97, 97+26)]
if length_s < 26:
    for alphabet in alphabet_small:
        if alphabet not in s:
            print(s+alphabet)
            exit()
Q = s[length_s-1]
for i in range(length_s-2,-1,-1):
    if s[i] < Q:
        ans = s[:i] + Q
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = list(input())
az = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != len(set(s)):
    print(-1)
elif len(s) != 26:
    for r in az:
        if r not in s:
            print("".join(s) + r)
            exit()
else:
    ar = az[::-1]
    if "".join(s) == "".join(ar):
        print(-1)
    else:
        i = 0
        while True:
            if s[i] == ar[i]:
                i += 1
            else:
                j = s.index(ar[i])
                break
        sr = s[0:j-1]
        k = az.index(s[j-1])+1
        for l in range(k,27):
            if az[l] not in sr:
                print("".join(sr) + az[l])
                exit()

Submission status: Wrong Answer

Solution code:
s = list(input())
az = list("abcdefghijklmnopqrstubwxyz")
if len(s) != len(set(s)):
    print(-1)
elif len(s) != 26:
    for r in az:
        if r not in s:
            print("".join(s) + r)
            exit()
else:
    ar = az[::-1]
    if s == ar:
        print(-1)
    else:
        i = 0
        while True:
            if s[i] == ar[i]:
                i += 1
            else:
                j = s.index(ar[i])
                break
        sr = s[0:j-1]
        k = az.index(s[j-1])+1
        print("".join(sr) + az[k])
        exit()

Submission status: Wrong Answer

Solution code:
s = input()

alp = [0]*26
a_int = ord('a')

ans = -1
cand = []
if len(s) == 26:
    for i in reversed(range(1, 26)):
        if s[i] < s[i-1]:
            cand.append(s[i])
            continue
        else:
            cand.append(s[i])
            cand = sorted(cand)
            ans = s[0:i-1]+cand[0]
            break

else:
    for c in s:
        alp[ord(c)-a_int] = 1

    for i in range(26):
        if alp[i] == 0:
            ans = s+chr(i+a_int)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

alp = [0]*26
a_int = ord('a')

if len(s) == 26:
    ans = -1
else:
    for c in s:
        alp[ord(c)-a_int] = 1

    for i in range(26):
        if alp[i] == 0:
            ans = s+chr(i+a_int)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

alp = [0]*26
a_int = ord('a')

if len(s) == 26:
    ans = -1
else:
    for c in s:
        alp[ord(c)-a_int] = 1

    for i in range(26):
        if alp[i] == 0:
            s += chr(a_int+i)
            break
print(s)

Submission status: Wrong Answer

Solution code:
s = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
tmpset = set()
n = len(s)
if n != 26:
    for i in range(n):
        tmpset.add(s[i])
    for i in range(26):
        if alpha[i] not in tmpset:
            s = s + alpha[i]
            print(s)
            exit()
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        for i in range(n - 1, 0, -1):
            if s[i] > s[i - 1]:
                tmpset.add(s[i])
                for j in range(26):
                    if alpha[j] in tmpset:
                        if s[i - 1] < alpha[j]:
                            s = s[:i - 1] + alpha[i]
                            print(s)
                            exit()
            else:
                tmpset.add(s[i])

Submission status: Wrong Answer

Solution code:
s = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
tmpset = set()
n = len(s)
if n != 26:
    for i in range(n):
        tmpset.add(s[i])
    for i in range(26):
        if alpha[i] not in tmpset:
            s = s + alpha[i]
            print(s)
            exit()
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        for i in range(n - 1, 0, -1):
            if s[i] > s[i - 1]:
                for j in range(26):
                    if alpha[j] in tmpset:
                        if s[i - 1] < alpha[j]:
                            s = s[:i - 1] + alpha[i]
                            print(s)
                            exit()
            else:
                tmpset.add(s[i])

Submission status: Wrong Answer

Solution code:
s = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
tmpset = set()
n = len(s)
if n != 26:
    for i in range(n):
        tmpset.add(s[i])
    for i in range(26):
        if alpha[i] not in tmpset:
            s = s + alpha[i]
            print(s)
            exit()
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        for i in range(n - 1, 0, -1):
            if s[i] > s[i - 1]:
                for j in range(26):
                    if alpha[j] in tmpset:
                        s = s[:i - 1] + alpha[i]
                        print(s)
                        exit()
            else:
                tmpset.add(s[i])

Submission status: Wrong Answer

Solution code:
s = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
tmpset = set()
n = len(s)
if n != 26:
    for i in range(n):
        tmpset.add(s[i])
    for i in range(26):
        if alpha[i] not in tmpset:
            s = s + alpha[i]
            print(s)
            exit()
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        for i in range(n - 1, 0, -1):
            if s[i] > s[i - 1]:
                for j in range(26):
                    if alpha[i] in tmpset:
                        s = s[:i - 1] + alpha[i]
                        print(s)
                        exit()
            else:
                tmpset.add(s[i])

Submission status: Wrong Answer

Solution code:
import string

flag = [False for i in range(26)]
s = input()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

for c in s:
    flag[ord(c)-97] = True
ans = ""
if len(s) != 26:
    for i, f in enumerate(flag):
        if not f:
            ans = s + chr(i+97)
            break
else:
    before = s[-1]
    minimumC = s[-1]
    for i in range(2, 25):
        if ord(before) > ord(s[-i]):
            break
        else:
            before = c
    if i != 24:
        ans = s[:26-i] + minimumC
    else:
        ans = chr(ord(s[0])+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import string

flag = [False for i in range(26)]
s = input()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

for c in s:
    flag[ord(c)-97] = True
ans = ""
if len(s) != 26:
    for i, f in enumerate(flag):
        if not f:
            ans = s + chr(i+97)
            break
else:
    before = s[-1]
    minimumC = s[-1]
    for i in range(2, 26):
        if ord(before) > ord(s[-i]):
            break
        else:
            minimuC = c
        if i == 25:
            i = 26
    ans = s[:26-i] + chr(ord(s[0])+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
s = input() + chr(96)

for j in range(len(s) - 1, 0, -1):
    sets = set(list(s[:j]))
    for i in range(ord(s[j]) + 1, 123):
        if chr(i) not in sets:
            print(s[:j] + chr(i))
            sys.exit(0)
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
s = list(input()) + [chr(96)]

for j in range(len(s) - 1, 0, -1):
    sets = set(s[:j])
    for i in range(ord(s[j]) + 1, 122):
        if chr(i) not in sets:
            print(''.join(s[:j]) + chr(i))
            sys.exit(0)
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
s = list(input()) + [chr(96)]

for j in range(len(s) - 1, 0, -1):
    sets = set(s[:j])
    if len(s[:j]) != len(sets):
        continue
    for i in range(ord(s[j]) + 1, 122):
        if chr(i) not in sets:
            print(''.join(s[:j]) + chr(i))
            sys.exit(0)
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
s = list(input())

for i in range(97, 122):
    sets = set(s)
    if len(s) != len(sets):
        break
    if chr(i) not in sets:
        print(''.join(s) + chr(i))
        sys.exit(0)

for j in range(len(s) - 1, 0, -1):
    sets = set(s[:j])
    if len(s[:j]) != len(sets):
        continue
    for i in range(ord(s[j]) + 1, 122):
        if chr(i) not in sets:
            print(''.join(s[:j]) + chr(i))
            sys.exit(0)
print(-1)

Submission status: Wrong Answer

Solution code:
s=list(input())
al=[chr(ord('a') + i) for i in range(26)]
al=[i for i in al if i not in s]
if al:
    print(''.join(s)+al[0])
    exit()
for i in range(25,0,-1):
    if s[i-1]<s[i]:
        s=s[:i-1]+[s[-1]]
        print(''.join(s))
        exit()
else:print(-1)

Submission status: Wrong Answer

Solution code:
import string
y = input()
x = list(y)
k = 0
az=string.ascii_lowercase
#for i in x:
for j in az:
    if j not in x:
        k = j
        break
if k ==0:
    print(-1)
else:print(y+k)

Submission status: Wrong Answer

Solution code:
s = input()
arr = [1 for _ in range(26)]
ok = True
for i in s:
    if arr[ord(i)-97] > 0:
        arr[ord(i)-97] = 0
    else:
        ok = False
        break
mina = 25
for i in range(26):
    if arr[i] > 0 :
        mina = i
        break
        
if ok and s != 'zyxwvutsrqponmlkjihgfedcba':
    if len(s) < 26:
        print(s+chr(mina+97))
    else:
        for i in range(1,26)[::-1]:
            if s[i-1] < s[i]:
                tmp = s[i-1]
                maxs = 'z'
                break
        for i in range(1,26)[::-1]:
            if tmp  < s[i] and maxs > s[i]:
                maxs = s[i]
        print(s[0:s.index(tmp)]+maxs)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# coding:utf-8


INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


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

abc = 'abcdefghijklmnopqrstuvwxyz'
used = set()

ans = ''
if len(s) != 26:
    for c in abc:
        if c not in s:
            print(s + c)
            exit()

else:
    for i in range(26)[::-1]:
        prev_c = ord(s[i])
        for j in range(0, i)[::-1]:
            curr_c = ord(s[j])
            if prev_c > curr_c:
                print(s[:j] + s[-1])
                exit()
            prev_c = curr_c

Submission status: Wrong Answer

Solution code:
# coding:utf-8


INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


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

abc = 'abcdefghijklmnopqrstuvwxyz'
used = set()

ans = ''
if len(s) != 26:
    for c in abc:
        if c not in s:
            print(s + c)
            exit()

else:
    for i in range(26)[::-1]:
        c_int = ord(s[i])
        for j in range(0, i)[::-1]:
            if c_int > ord(s[j]):
                print(s[:j] + chr(c_int))
                exit()

Submission status: Wrong Answer

Solution code:
# coding:utf-8


INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


s = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
used = set()

ans = ''
if len(s) != 26:
    for c in abc:
        if c not in s:
            print(s + c)
            exit()

else:
    for i in range(26)[::-1]:
        c_int = ord(s[i])
        for j in range(0, i)[::-1]:
            if c_int > ord(s[j]):
                print(s[:j] + chr(c_int))
                exit()

print(-1)

Submission status: Wrong Answer

Solution code:
# coding:utf-8


INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


s = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
used = set()

ans = ''
if len(s) == 26:
    prev = ord(s[-1])
    for i in range(26)[::-1]:
        tmp = ord(s[i])
        if tmp >= prev:
            prev = tmp
            continue

        if tmp < ord(s[-1]):
            print(s[:i] + s[-1])
        else:
            print(s[:i - 1] + s[-1])
        exit()

else:
    for i in range(len(s)):
        used.add(s[i])

        for st in abc:
            if st not in used:
                print(s + st)
                exit()

print(-1)

Submission status: Wrong Answer

Solution code:
# coding:utf-8


INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


s = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
used = set()

ans = ''
if len(s) == 26:
    prev = ord(s[-1])
    for i in range(26)[::-1]:
        tmp = ord(s[i])
        if tmp >= prev:
            prev = tmp
            continue
        else:
            print(s[:i] + s[-1])
            exit()

else:
    for i in range(len(s)):
        used.add(s[i])

        for st in abc:
            if st not in used:
                print(s + st)
                exit()

print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
L = []
for i in range(ord("a"),ord("z")+1) :
    L.append(chr(i))
for i in range(len(S)) :
    if S[i] in L :
        L.remove(S[i])
        
if len(S) < 26 :
    ans = S + L[0]
else :
    if S.find("z") == 0 :
        ans = -1
    else :
        ans = ""
        ans += S[:S.find("z")-1]
        for i in range(ord("a"),ord("z")+1) :
            if (chr(i) not in ans) and (S < (ans+chr(i))) :
                ans += chr(i)
                break
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
L = []
for i in range(ord("a"),ord("z")+1) :
    L.append(chr(i))
for i in range(len(S)) :
    if S[i] in L :
        L.remove(S[i])
        
if len(S) < 26 :
    ans = S + L[0]
else :
    if S.find("z") == 0 :
        ans = -1
    else :
        ans = ""
        ans += S[:S.find("z")-1] #+ chr(ord(S[S.find("z")-1])+1)
        for i in range(ord("a"),ord("z")+1) :
            if chr(i) not in S[:S.find("z")-1] :
                ans += chr(i)
                break
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
L = []
for i in range(ord("a"),ord("z")+1) :
    L.append(chr(i))
for i in range(len(S)) :
    if S[i] in L :
        L.remove(S[i])
        
if len(S) < 26 :
    ans = S + L[0]
else :
    if S.find("z") == 0 :
        ans = -1
    else :
        ans = S[:S.find("z")-1] + chr(ord(S[S.find("z")-1])+1)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

ans = ''

if len(S) != 26:
    a_z = [chr(i) for i in range(97, 123)]
    for s in S:
        a_z.remove(s)
    ans = S + a_z[0]
    print(ans)
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        ans = -1
        print(ans)
    else:
        a_z = [int(i) for i in range(97, 123)]
        inputs = list(map(ord, list(S)))
        buf = [inputs[-1]]
        for i in range(1, len(S)):
            if inputs[25-i] > inputs[25-(i-1)]:
                buf.append(inputs[25-i])
            else:
                buf.sort()
                for item in buf:
                    if inputs[25-i] < item:
                        last = item
                print(''.join(list(map(chr, inputs[:25-i]+[last]))))
                break

Submission status: Wrong Answer

Solution code:
S = input()

ans = ''

if len(S) != 26:
    a_z = [chr(i) for i in range(97, 123)]
    for s in S:
        a_z.remove(s)
    ans = S + a_z[0]
    print(ans)
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        ans = -1
        print(ans)
    else:
        a_z = [int(i) for i in range(97, 123)]
        inputs = list(map(ord, list(S)))
        buf = [inputs[-1]]
        for i in range(1, len(S)):
            if inputs[25-i] > inputs[25-(i-1)]:
                buf.append(inputs[25-i])
            else:
                print(''.join(list(map(chr, inputs[:25-i]+[min(buf)]))))
                break

Submission status: Wrong Answer

Solution code:
S = input()

ans = ''

if len(S) != 26:
    a_z = [chr(i) for i in range(97, 123)]
    for s in S:
        a_z.remove(s)
    ans = S + a_z[0]
else:
    a_z = [int(i) for i in range(97, 123)]
    inputs = list(map(ord, list(S)))

print(ans)

Submission status: Wrong Answer

Solution code:
S=list(input())

chara=list("abcdefghijklmnopqrstuvwxyz")
chara_dic={}
for i in range(len(chara)):
	chara_dic[chara[i]]=i
chara_dic_2={}
for i in range(len(chara)):
	chara_dic_2[i]=chara[i]

count={}
for s in S:
	count[s]=count.get(s,0)+1

flag=0
if len(count)==len(chara):
	cur_chara=len(S)-1
	for pt in range(len(S)-2,0,-1):
		if chara_dic[S[cur_chara]]<chara_dic[S[pt]]:
			cur_chara-=1
		else:
			flag=1
			ans=''
			for i in range(0,pt):
				ans+=str(S[i])
			ls=[]
			for i in range(pt+1,len(S)):
				if chara_dic[S[pt]]<chara_dic[S[i]]:
						ls.append(chara_dic[S[i]])
			ans+=chara_dic_2[min(ls)]
			break
else:
	flag=1
	ans=''
	for i in range(len(S)):
		ans+=S[i]
	for i in range(len(chara)):
		if chara[i] not in S:
			end=chara[i]
			break
	ans+=end

print(ans if flag else "-1")

Submission status: Wrong Answer

Solution code:
S=list(input())

chara=list("abcdefghijklmnopqrstuvwxyz")
chara_dic={}
for i in range(len(chara)):
	chara_dic[chara[i]]=i
chara_dic_2={}
for i in range(len(chara)):
	chara_dic_2[i]=chara[i]

count={}
for s in S:
	count[s]=count.get(s,0)+1

flag=0
if len(count)==len(chara):
	cur_chara=len(S)-1
	for pt in range(len(S)-2,0,-1):
		if chara_dic[S[cur_chara]]<chara_dic[S[pt]]:
			cur_chara-=1
		else:
			flag=1
			ans=''
			for i in range(0,pt):
				ans+=str(S[i])
			ls=[]
			for i in range(pt+1,len(S)):
				ls.append(chara_dic[S[i]])
			ans+=chara_dic_2[min(ls)]
			break
else:
	flag=1
	ans=''
	for i in range(len(S)):
		ans+=S[i]
	for i in range(len(chara)):
		if chara[i] not in S:
			end=chara[i]
			break
	ans+=end

print(ans if flag else "-1")

Submission status: Wrong Answer

Solution code:
S=list(input())

chara=list("abcdefghijklmnopqrstuvwxyz")
chara_dic={}
for i in range(len(chara)):
	chara_dic[chara[i]]=i
chara_dic_2={}
for i in range(len(chara)):
	chara_dic_2[i]=chara[i]

count={}
for s in S:
	count[s]=count.get(s,0)+1

flag=0
if len(count)==len(chara):
	cur_chara=len(S)-1
	for pt in range(len(S)-2,0,-1):
		if chara_dic[S[cur_chara]]<chara_dic[S[pt]]:
			cur_chara-=1
		else:
			flag=1
			ans=''
			for i in range(0,pt):
				ans+=str(S[i])
			ans+=chara_dic_2[chara_dic[S[pt]]+1]
			break
else:
	flag=1
	ans=''
	for i in range(len(S)):
		ans+=S[i]
	for i in range(len(chara)):
		if chara[i] not in S:
			end=chara[i]
			break
	ans+=end

print(ans if flag else "-1")

Submission status: Wrong Answer

Solution code:
S = input()
chars = [0 for i in range(26)]
for i, s in enumerate(S):
    chars[ord(s)-97] = i+1
if 0 in chars:
    ans = S + chr(chars.index(0)+97)
else:
    prev = 0
    i = 0
    for c in reversed(chars):
        if prev < c:
            i += 1
            prev = c
        else:
            break
    if i==26:
        ans = -1
    else:
        max_s = chars[-i-1]
        min_c = 27
        for c in chars[-i:]:
            if c>max_s and c<min_c:
                min_c = c
        ans = S[:-i-1] + chr(min_c-1+97)

print(ans)

Submission status: Wrong Answer

Solution code:
S=list(input())
N=len(S)
alphabet="abcdefghijklmnopqrstuvwxyz"
Appeared,A_to_N={},{}
for i in range(26):
  Appeared[alphabet[i]]=False
  A_to_N[alphabet[i]]=i
if N<26:
  for i in range(N):
    Appeared[S[i]]=True
  for i in range(26):
    if not Appeared[alphabet[i]]:
      S.append(alphabet[i])
      print("".join(S))
      exit()

last=A_to_N[S[-1]]
a=[S[-1]]
for i in range(N-1)[::-1]:
  if A_to_N[S[i]]>last:
    a.append(S[i])
  else:
    for k in a:
      if A_to_N[S[i]]<A_to_N[k]:
        S[i]=k
        print("".join(S[:i+1]))
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
chr_list = [1] * 26

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for s in S:
        chr_list[ord(s) - ord("a")] = 0

    if all(map(lambda c: c == 0, chr_list)):
        c_set = [S[-1]]
        for i in range(24, -1, -1):
            if not ord(S[i]) > ord(S[i+1]):
                print(S[:i] + min(c_set))
                break
            c_set.append(S[i])
            tail = s
    else:
        for i, v in enumerate(chr_list):
            if v == 1:
                print(S + chr(ord("a") + i))
                break

Submission status: Wrong Answer

Solution code:
S = input()
chr_list = [1] * 26

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for s in S:
        chr_list[ord(s) - ord("a")] = 0

    if all(map(lambda c: c == 0, chr_list)):
        c_set = [S[-1]]
        for i in range(24, -1, -1):
            print(S[i])
            if not ord(S[i]) > ord(S[i+1]):
                print(S[:i] + min(c_set))
                break
            c_set.append(S[i])
            tail = s
    else:
        for i, v in enumerate(chr_list):
            if v == 1:
                print(S + chr(ord("a") + i))
                break

Submission status: Wrong Answer

Solution code:
S = input()
chr_list = [1] * 26

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for s in S:
        chr_list[ord(s) - ord("a")] = 0

    if all(map(lambda c: c == 0, chr_list)):
        c_set = []
        for i in range(25, -1, -1):
            c_set.append(S[i])
            if not ord(S[i-1]) > ord(S[i]):
                print(S[:i-1] + min(c_set))
                break
            tail = s
    else:
        for i, v in enumerate(chr_list):
            if v == 1:
                print(S + chr(ord("a") + i))
                break

Submission status: Wrong Answer

Solution code:
S = input()
chr_list = [1] * 26

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for s in S:
        chr_list[ord(s) - ord("a")] = 0

    if all(map(lambda c: c == 0, chr_list)):
        c_set = []
        for i in range(25, -1, -1):
            c_set.append(S[i])
            if ord(S[i-1]) != 1 + ord(S[i]):
                print(S[:i-1] + min(c_set))
                break
            tail = s
    else:
        for i, v in enumerate(chr_list):
            if v == 1:
                print(S + chr(ord("a") + i))
                break

Submission status: Wrong Answer

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

s = []
for i in range(24,-1,-1):
    if S[i] > S[i+1]:
        s.append(S[i+1])
        continue
    else:
        s.append(S[i+1])
        print(S[:i] + min(s))
        exit()