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 len(S) < 26:
    for i in range(26):
        if chr(i+97) not in S:
            ans = S + chr(i+97)
            break
elif S == "zyxwvutsrqponmlkjihgfedcba":
    ans = -1
else:
    ans = ""
    for i in range(24, -1, -1):
        if S[i+1] > S[i]:
            for j in range(i):
                ans += S[j]
            ans += S[-1]
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
aaaa = "abcdefghijklmnopqrstuvwxyz"

if len(s) == 26:
    if s[0] == "z":
        print(-1)
        exit()
    s_max = max(s)
    b = s.find(s_max)
    s = s[:b]
    for i in aaaa:
        if i not in s:
            tmp = i
            break
    print(s[:-1] + tmp)
else:
    for i in aaaa:
        if i not in s:
            tmp = i
            break
    print(s + tmp)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    if S == "zyxwvutsrqponmlkjihgfedcba":
        ans = -1
    elif len(S) != 26:
        for i in range(26):
            a = chr(ord('a') + i)
            if a not in S:
                print(S + a)
                return
    else:
        while len(S) > 1:
            S = S[:-1]
            last = S[-1]
            while ord(last) < ord('z'):
                last = chr(ord(last) + 1)
                if last not in S:
                    print(S[:-1] + last)
                    return
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
alf = 'abcdefghijklmnopqrstuvwxyz'
if s == alf[::-1]:
    print(-1)
else:
    if len(s) < len(alf):
        print(s+sorted(set(alf)-set(s))[0])
    else:
        for i in range(len(s)):
            if s[i] != alf[i]:
                print(s[:i-1]+sorted(set(alf)-set(s[:i]))[0])
                break

Submission status: Wrong Answer

Solution code:
s = input()
alf = 'abcdefghijklmnopqrstuvwxyz'
if s == alf[::-1]:
    print(-1)
else:
    if len(s) < len(alf):
        print(s+sorted(set(alf)-set(s))[0])
    else:
        for i in range(len(s)):
            if s[i] != alf[i]:
                print(s[:i-1]+alf[i])
                break

Submission status: Wrong Answer

Solution code:
s = input()
is_there = [False for i in range(26)]


for c in s:
    is_there[ord(c)-97] = True

if len(s) == 26:
    tail = ord(s[-1])
    flag = True
    sp = -1
    for i in range(2,26):
        n = s[-i]
        if ord(n) < tail:
            flag = False
            sp = -i
            break
    if flag:
        print(-1)
    else:
        tp = list(s)
        tp = tp[:sp]
        print("".join(tp)+s[-1])
else:
    for i in range(26):
        if not is_there[i]:
            print(s+chr(i+97))
            break

Submission status: Wrong Answer

Solution code:
S = input()

# 1 <= |S| <= 26
# lowercase

import sys
import copy

def next_permutation(a):
    for i in reversed(range(len(a) - 1)):
        if a[i] < a[i + 1]:
            break
    else:
        return False

    j = next(j for j in reversed(range(i + 1, len(a))) if a[i] < a[j])
    a[i], a[j] = a[j], a[i]
    a[i + 1:] = reversed(a[i + 1:])
    return True

if len(S) == 26:
    sl = list(S)
    if next_permutation(sl):
        np = "".join(sl)
        for b in range(0, 26):
            if np[b] != S[b]:
                print(np[:b+1])
                exit()

    else:
        print(-1)
        exit()

Submission status: Wrong Answer

Solution code:
s = input()

abc = ['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 a in abc:
    if a not in abc:
        print(s+a)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = input()

abc = ['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']

print(len(abc))

for a in abc:
    if a not in abc:
        print(s+a)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
S = input()

if len(S) < 26:
    ls = [False] * 26
    for s in S:
        ind = ord(s) - ord("a")
        ls[ind] = True
    x = min([i for i,l in enumerate(ls) if not l])
    s_ = chr(x + ord("a"))
    S += s_
    print(S)
elif len(S) == 26:
    prev = -1
    ans = []
    ls = [False] * 26
    for s in S:
        ind = ord(s) - ord("a")
        if ind-prev == 1:
            ans.append(s)
            ls[ind] = True
            prev = ind
        else:
            if len(ans) == 0:
                print(-1)
                exit()
            ans.pop()
            ans.append(chr(prev+1 + ord("a")))
            print("".join(ans))
            exit()

Submission status: Wrong Answer

Solution code:
S = input()

if len(S) < 26:
    ls = [False] * 26
    for s in S:
        ind = ord(s) - ord("a")
        ls[ind] = True
    x = min([i for i,l in enumerate(ls) if not l])
    s_ = chr(x + ord("a"))
    S += s_
    print(S)
elif len(S) == 26:
    prev = -1
    ans = []
    ls = [False] * 26
    for s in S:
        ind = ord(s) - ord("a")
        if ind-prev == 1:
            ans.append(s)
            ls[ind] = True
            prev = ind
        else:
            if len(ans) == 0:
                print(-1)
                exit()
            x = min([i for i,l in enumerate(ls) if not l])
            ans.pop()
            ans.append(chr(x + ord("a")))
            print("".join(ans))
            exit()

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    al = set(list('abcdefghijklmnopqrstuvwxyz'))
    S = input()
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    elif len(S)==26:
        for i in range(len(S)-1):
            if S[i]>S[i+1]:
                for x in sorted(list(S[i+1:])):
                    if x<S[i-1]:
                        continue
                    if x>S[i-1]:
                        break
                print(S[:i-1]+x)
                break
    else:
        for i in S:
            al-=set(i)
        al = sorted(list(al))
        print(S+al[0])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    al = set(list('abcdefghijklmnopqrstuvwxyz'))
    S = input()
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    elif len(S)==26:
        for i in range(len(S)-1):
            if S[i]>S[i+1]:
                print(S[:i-1]+sorted(list(S[i+1:]))[0])
                break
    else:
        for i in S:
            al-=set(i)
        al = sorted(list(al))
        print(S+al[0])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    Alphabet = "abcdefghijklmnopqrstuvwxyz"

    if len(S) == 26:
        j = 0
        for i in reversed(range(26)):
            while S[i] != Alphabet[j]:
                j = j + 1
                if j == 26:
                    k = 0
                    while S[i] != Alphabet[k]:
                        k = k+1
                    while Alphabet[k] in S[i+1]:
                        k = k+1
                    return S[:i] + S[k]                
        return -1

    else:
        for i in range(len(Alphabet)):
            j = 0
            while Alphabet[i] != S[j]:
                j += 1
                if j == len(S):
                    return S + Alphabet[i]

print(aaa(S))

Submission status: Wrong Answer

Solution code:

S = input()
def aaa(S):

    Alphabet = "abcdefghijklmnopqrstuvwxyz"

    if len(S) == 26:
        j = 0
        for i in reversed(range(26)):
            while S[i] != Alphabet[j]:
                j = j + 1
                if j == 26:
                   return S[:i] + S[i+1]                
        return -1

    else:
        for i in range(len(Alphabet)):
            j = 0
            while Alphabet[i] != S[j]:
                j += 1
                if j == len(S):
                    return S + Alphabet[i]

print(aaa(S))

Submission status: Wrong Answer

Solution code:

S = input()
def aaa(S):

    Alphabet = "abcdefghijklmnopqrstuvwxyz"

    if len(S) == 26:
        j = 0
        for i in reversed(range(26)):
            while S[i] != Alphabet[j]:
                j = j + 1
                if j == 26:
                   return S[:i] + S[-1]
                
        return -1

    else:
        for i in range(len(Alphabet)):
            j = 0
            while Alphabet[i] != S[j]:
                j += 1
                if j == len(S):
                    return S + Alphabet[i]

print(aaa(S))

Submission status: Wrong Answer

Solution code:
import sys

S = input()

Alphabet = "abcdefghijklmnopqrstuvwxyz"

if len(S) == 26:
    j = 0
    for i in reversed(range(26)):
        while S[i] != Alphabet[j]:
            j = j + 1
            if j == 26:
                print(S[:i] + S[-1])
                sys.exit()
    print(-1)

else:
    for i in range(len(Alphabet)):
        j = 0
        while Alphabet[i] != S[j]:
            j += 1
            if j == len(S):
                print(S + Alphabet[i])
                sys.exit()

Submission status: Wrong Answer

Solution code:
import sys

S = input()

Alphabet = "abcdefghijklmnopqrstuvwxyz"

if len(S) == 26:
    Start = 0
    for i in reversed(range(26)):
        for j in range(Start, 26):
            if S[i] == Alphabet[j]:
                Start = j+1
                if j == 26:
                    if i == 25:
                        print(-1)
                    else:
                        print(S[:i-1] + S[-1])
                    sys.exit()
                break
            if j == 25:
                print(S[:i] + S[-1])
                sys.exit()

else:
    for i in range(len(Alphabet)):
        j = 0
        while Alphabet[i] != S[j]:
            j += 1
            if j == len(S):
                print(S + Alphabet[i])
                sys.exit()

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

S = input()

A = set(S)

for x in ascii_lowercase:
	if not x in A:
		print(S+x)
		break
else:
	if S == ascii_lowercase[::-1]:
		print(-1)
	else:
		S = S[::-1]
		for i in range(len(S)-1):
			if S[i+1] < S[i]:
				for char in sorted(S[:i+1]):
					if char > S[i+1]:
						print(S[::-1][:-i-2]+char)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

S = input()

A = set(S)

for x in ascii_lowercase:
	if not x in A:
		print(S+x)
		break
else:
	if S == ascii_lowercase[::-1]:
		print(-1)
	else:
		for i in range(len(S)-1):
			if S[i+1] < S[i]:
				for char in sorted(S[:i+1]):
					if char > S[i+1]:
						print(S[::-1][:-i-2]+char)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

S = input()

A = set(S)

for x in ascii_lowercase:
	if not x in A:
		print(S+x)
		break
else:
	B = [S[-1]]
	for i in range(len(S)-2, -1, -1):
		if S[i] < B[0]:
			print(S[:i]+B[0])
			break
		else:
			insort(B, S[i])
	else:
		print(-1)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

S = input()

A = set(S)

for x in ascii_lowercase:
	if not x in A:
		print(S+x)
		break
else:
	B = [S[-1]]
	for i in range(len(S)-2, -1, -1):
		if S[i] < B[0]:
			print(S[:i]+B[0])
			break
	else:
		print(-1)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

S = input()

a = set(S)
for x in ascii_lowercase:
	if not x in a:
		print(S+x)
		break
else:
	for i in range(len(S)):
		if S[i] != ascii_lowercase[i]:
			print(S[:max(0, i-1)] + ascii_lowercase[i])
			break

Submission status: Wrong Answer

Solution code:
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline

def main():
    s = str(input())
    abc = 'abcdefghijklmmopqrstuvwxyz'
    usable = []
    for a in list(abc):
        if a not in s:
            usable.append(a)
    if len(usable) > 0:
        print(s.strip() + usable[0])
        exit()
    if s == list(abc)[::-1]:
        print(-1)
        exit()
    for i in (range(len(s)-1))[::-1]:
        if s[i] < s[i+1]:
            for j in range(i+1, len(s))[::-1]:
                if s[i] < s[j]:
                    print(s[:i]+s[j])
                    exit()


def divide_list(l, args):
    result = []
    pre = 0
    for i, a in enumerate(args):
        if i != 0:
            pre = args[i-1]
        result.append(l[pre:a])
        if i == len(args) - 1:
            result.append(l[a:])
    return result

def divide_two(n):
    c = 0
    while True:
        if c >= 2:
            break
        if n % 2 != 0:
            break
        n //= 2
        c += 1
    return c

def get_camulative(l):
    import itertools
    # 累積和
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline

def main():
    s = str(input())
    abc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    usable = []
    for a in abc:
        if a not in s:
            usable.append(a)
    if len(usable) > 0:
        ss = s+usable[0]
        print(ss)
    else:
        print(-1)


def divide_list(l, args):
    result = []
    pre = 0
    for i, a in enumerate(args):
        if i != 0:
            pre = args[i-1]
        result.append(l[pre:a])
        if i == len(args) - 1:
            result.append(l[a:])
    return result

def divide_two(n):
    c = 0
    while True:
        if c >= 2:
            break
        if n % 2 != 0:
            break
        n //= 2
        c += 1
    return c

def get_camulative(l):
    import itertools
    # 累積和
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
s = input()
alphabet = "abcdefghijknmlopqrstuvwxyz"
dif = sorted(list(set(alphabet) - set(s)))
if len(dif):
    print(s + dif[0])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
S = input()
alf = 'abcdefghijklmnopqrstuvwxyz'

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

if len(S) < 26:
    for i in range(26):
        if not(alf[i] in S):
            print(S+alf[i])
            exit(0)

for i in range(26):
    if S[i] != alf[i]:
        print(S[:i-1]+alf[i])
        exit(0)
print('ac')

Submission status: Wrong Answer

Solution code:
S = input()
alf = 'abcdefghijklnmopqrstuvwxyz'

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

if len(S) < 26:
    for i in range(26):
        if not(alf[i] in S):
            print(S+alf[i])
            exit(0)

for i in range(26):
    if S[i] != alf[i]:
        print(S[:i-1]+alf[i])
        exit(0)
print('ac')

Submission status: Wrong Answer

Solution code:
import string
charset = string.ascii_lowercase
s = list(input())

unused = set(charset) - set(s)

if unused:
    s.append(min(unused))
    print(''.join(s))
    exit()
else:
    length = len(s)
    
    minchar=s[-1]
    for i in range(length-1):
        if s[length-i-2] < s[length-i-1]:
            s[length-i-2] = minchar
            print(''.join(s[:length-i-1]))
            exit()
        minchar = min(minchar, s[length-i-2])
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
s=input()
if len(s)==26:
    if s=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        sys.exit()
    so="abcdefghijklmnopqrstuvwx"
    for i in range(25):
        if ord(s[i])+1==ord(s[i+1]):
            continue
        else:
            so=s[:i]
            break
    se=set(so[:i+1])
    p=sorted(list(se))
    moji=[]
    alphabet=[chr(i) for i in range(97, 97+26)]
    for i in range(26):
        if alphabet[25-i] not in se:
            
            moji.append(alphabet[25-i])
    print(so+moji[len(moji)-2])
else:
    se=set(s)
    p=sorted(list(set(s)))
    alphabet=[chr(i) for i in range(97, 97+26)]
    for i in range(26):
        if alphabet[25-i] not in se:
            moji=alphabet[25-i]
    print(s+moji)

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
L = "abcdefghijklmnopqrstuvwxyz"
invL = L[::-1]
S = S()
if len(S) != 26:
  for l in L:
    if l not in S:
      print(S+l)
      exit()
else:
  prev = chr(96)
  for s in S[::-1]:
    now = s
    if ord(now)<ord(prev):
      k = S.index(now)
      for l in L:
        if l not in S[:k]:
          print(S[:k]+l)
          exit()
    prev = now
  print(-1)

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
L = "abcdefghijklmnopqrstuvwxyz"
invL = L[::-1]
S = S()
if len(S) != 26:
  for l in L:
    if l not in S:
      print(S+l)
      exit()
else:
  prev = chr(96)
  for s in S[::-1]:
    now = s
    if ord(now)<ord(prev):
      k = S.index(now)
      print(S[:k]+chr(ord(now)+1))
      exit()
    prev = now
  print(-1)

Submission status: Wrong Answer

Solution code:
S = input()

s_sort = sorted(list(S))

new_character = "?"

if len(S) < 26:
  for  s in range(97,123,1):
    if S.count(chr(s))==0:
      new_character = chr(s)
      print(S + new_character)
      break
else:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    letter = S[25]
    for x in range(25,0,-1):
      if ord(S[x-1]) > ord(S[x]):
        letter = chr(min(ord(S[x-1]),ord(S[x]),ord(letter)))
      else:
        letter = chr(min(ord(S[x]),ord(letter)))
        ans = S[:x-1] + letter
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
s = input()
abc = [chr(i) for i in range(ord('a'), ord('z')+1)]

if len(s) == 26:
  for i in range(24, -1, -1):
    cand = list(s[i+1:])
    for c in cand:
      if ord(c) > ord(s[i]):
        print(s[:i] + c)
        exit()
  print(-1)
else:
  for l in abc:
    if l not in s:
      print(s + l)
      exit()