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: Runtime Error

Solution code:
s = input()
L = ["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"]
res = ""
if len(s) < 26:
    for i in range(26):
        if L[i] in s:
            continue
        else:
            res += s + L[i]
            break
else:
    for i in range(1, 26):
        if s[i - 1] > s[i]:
            if L[L.index(s[i]) + 1] != s[i - 1]:
                continue
            else:
                res = s[: i - 1]
                res += L[res.index(res[-1]) + 1]
                break
    else:
        res ="-1"

print(res)

Submission status: Runtime Error

Solution code:
S = input()

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]
rev = chars[::-1]

c = dict()

for ci in chars:
    c[ci] = 0

ans = None
if S == 'zyxwvutsrqponmlkjihgfedcba':
    ans = -1
elif len(S) < 26:
    for si in S:
        c[si] += 1

    ne = None
    for k in sorted(c.keys()):
        if c[k] == 0:
            ne = k
            break
    ans = S + ne
else:
    S = S[::-1]
    ind = None
    for i in range(len(S)-1):
        if ord(S[i]) > ord(S[i+1]):
            ind = i
            break
    # ans_rev = S[0] + S[i+2:]
    # ans = ans_rev[::-1]

    S = S[::-1]
    ind = len(S) - ind - 1
    # print(S, ind)
    ans = S[:ind-1] + min(list(S)[ind+1:])

print(ans)

Submission status: Runtime Error

Solution code:
S = input()

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]
rev = chars[::-1]

c = dict()

for ci in chars:
    c[ci] = 0

ans = None
if S == 'zyxwvutsrqponmlkjihgfedcba':
    ans = -1
elif len(S) < 6:
    for si in S:
        c[si] += 1

    ne = None
    for k in sorted(c.keys()):
        if c[k] == 0:
            ne = k
            break
    ans = S + ne
else:
    S = S[::-1]
    ind = None
    for i in range(len(S)-1):
        if ord(S[i]) > ord(S[i+1]):
            ind = i
            break
    # ans_rev = S[0] + S[i+2:]
    # ans = ans_rev[::-1]

    S = S[::-1]
    ind = len(S) - ind - 1
    # print(S, ind)
    ans = S[:ind-1] + min(list(S)[ind+1:])

print(ans)

Submission status: Runtime Error

Solution code:
S = input()

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]
rev = chars[::-1]

c = dict()

for ci in chars:
    c[ci] = 0

ans = None
if S == 'zyxwvutsrqponmlkjihgfedcba':
    ans = -1
elif len(S) < 26:
    for si in S:
        c[si] += 1

    ne = None
    for k in sorted(c.keys()):
        if c[k] == 0:
            ne = k
            break
    ans = S + ne
else:
    if S[-2] < S[-1]:
        ans = S[:-2] + S[-1]
    else:
        S = S[::-1]
        ch = S[0]
        ch_ind = None
        for i, si in enumerate(S):
            # print(i, si, ord(ch), ord(si), ord(si) - ord(ch))
            if i == 0:
                continue
            if ord(si) < ord(ch):
                ch = si
                ch_ind = i
                break
            ch = min(si, ch)
        # print(ch, ch_ind)

        S = S[::-1]
        mn = min(list(S)[-1*ch_ind:])
        # print('mn', mn)
        ans = S[:-1*ch_ind-1] + mn

print(ans)

Submission status: Runtime Error

Solution code:
S = input()

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]
rev = chars[::-1]

c = dict()

for ci in chars:
    c[ci] = 0

ans = None
if S == 'zyxwvutsrqponmlkjihgfedcba':
    ans = -1
elif len(S) < 26:
    for si in S:
        c[si] += 1

    ne = None
    for k in sorted(c.keys()):
        if c[k] == 0:
            ne = k
            break
    ans = S + ne
else:
    S = S[::-1]
    sm = S[0]
    sm_ind = None
    for i, si in enumerate(S):
        if si < sm:
            sm = si
            sm_ind = i
            break
    # print(sm, sm_ind)
    S = S[::-1]
    ans = S[:-1*sm_ind-1] + S[-1]

print(ans)

Submission status: Runtime Error

Solution code:
from string import ascii_lowercase


def main():
    word = input()
    if len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count_l = list(count.items())
        add = ""
        for i in range(26):
            if count_l[i][1] == 0:
                add = count_l[i][0]
                break
        print(word + add)
    else:
        stop = ascii_lowercase[::-1]
        final_permutation_index = 26
        for i in range(-2, -27, -1):
            if word[i:] not in stop:
                final_permutation_index = 26 + i
                break
        if final_permutation_index == 26:
            print(-1)
        else:
            add = sorted(list(word[final_permutation_index:]))
            final = ""
            for i in range(len(add)):
                if add[i] == word[final_permutation_index]:
                    final = add[i + 1]
                    break
            print(word[:final_permutation_index] + final)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from string import ascii_lowercase


def main():
    word = input()
    if word == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    elif len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count = count.items()
        add = ""
        for i in range(26):
            if count[i][1] == 0:
                add = count[i][0]
                break
        print(word + add)
    else:
        stop = ascii_lowercase[::-1]
        final_permutation_index = 25
        for i in range(-2, -27, -1):
            if word[i:] not in stop:
                final_permutation_index = 26 + i
                break
        if final_permutation_index != 25:
            print(word[:final_permutation_index] + word[-1])
        else:
            word = list(word)
            if word[-2] == "z":
                word[-1], word[-3] = word[-3], word[-1]
            else:
                word[-1], word[-2] = word[-2], word[-1]
            print("".join(word))



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
invalpha = "zyxwvutsrqponmlkjihgfedcba"
D = {alpha[i]: i for i in range(26)}
E = [0 for i in range(26)]
def sugar(s):
  n = len(s)
  q = 0
  for i in range(n):
    if s[i] == 'z':
      q = i
  return i

for i in range(len(S)):
  E[D[S[i]]] = 1
if min(E) == 0:
  for m in range(26):
    if E[m] == 0:
      S = S[:] + alpha[m]
      break
  print(S)
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
else:
  p = 26
  for i in range(25, 0, -1):
    if D[S[i]] < D[S[i-1]]:
      p = i
    else:
      break
  if p == 26:
    S = S[:24] + S[25]
  else:
    m = D[S[p-2]]
    L = []
    for x in range(p, 26):
      if D[S[x]] >= m + 1:
        L.append(S[x])
    L.sort()
    S = S[:p-2] + L[0]
  print(S)

Submission status: Runtime Error

Solution code:
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
invalpha = "zyxwvutsrqponmlkjihgfedcba"
D = {alpha[i]: i for i in range(26)}
E = [0 for i in range(26)]
def sugar(s):
  n = len(s)
  q = 0
  for i in range(n):
    if s[i] == 'z':
      q = i
  return i

for i in range(len(S)):
  E[D[S[i]]] = 1
if min(E) == 0:
  for m in range(26):
    if E[m] == 0:
      S = S[:] + alpha[m]
      break
  print(S)
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
else:
  p = 26
  for i in range(25, 0, -1):
    if D[S[i]] < D[S[i-1]]:
      p = i
    else:
      break
  S = S[:p-2] + alpha[min(D[S[x]] for x in range(p, 26))]
  print(S)

Submission status: Runtime Error

Solution code:
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1);exit()
if len(s)!=26:
    print(s+sorted(list(set(list("zyxwvutsrqponmlkjihgfedcba"))-set(list(s))))[0])
else:
    des=set()
    l=list(s)
    while chr(ord(s[-1])+1) not in des:
        des.add(l.pop())
    print("".join(l[:-1])+sorted(list(des))[0])

Submission status: Runtime Error

Solution code:
from string import ascii_lowercase

s = input()
d = dict(zip(ascii_lowercase, [0 for _ in range(len(ascii_lowercase))]))

for c in s:
    d[c] += 1

if len(s) < 26:
    for k, v in d.items():
        if v == 0:
            print(s + k)
            exit()
elif s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

idx = -1
for i in range(1, len(s)):
    if s[i] > s[i + 1]:
        idx = i
        break
check = dict(zip(ascii_lowercase, [False for _ in range(len(ascii_lowercase))]))
for i in range(idx):
    check[s[i]] = True
i = 0
for c, v in check.items():
    if v == False:
        print(s[: i - 1] + c)
        exit()
    i += 1

Submission status: Runtime Error

Solution code:
from string import ascii_lowercase

s = input()
d = dict(zip(ascii_lowercase, [0 for _ in range(len(ascii_lowercase))]))
nex = ""
for c in s:
    d[c] += 1

if len(s) < 26:
    for k, v in d.items():
        if v == 0:
            print(s + k)
            exit()
elif s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

idx = -1
for i in range(1, len(s)):
    if s[i] > s[i + 1]:
        idx = i
        break
check = dict(zip(ascii_lowercase, [False for _ in range(len(ascii_lowercase))]))
for i in range(idx):
    check[s[i]] = True
i = 0
for c, v in check.items():
    if v == False:
        print(s[: i - 1] + c)
        exit()
    i += 1

Submission status: Runtime Error

Solution code:
import sys
calcLower2Index = lambda x: ord(x) - ord("a")
calcUpper2Index = lambda x: ord(x) - ord("A")
calcIndex2Lower = lambda x: chr(ord("a") + x)
calcIndex2Upper = lambda x: chr(ord("A") + x)
s = input()
f = [False] * 26
l = len(s)
if  l == 26: #full
    res = []
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        m = -1 # これまでのmax
        ind = -1
        endf = False
        for i in range(l):
            ch = calcLower2Index(s[i])
            f[ch] = True
            ind += 1
            if m > ch:
                for k in range(26):
                    if f[k] is False:
                        t = k
                        break
                res[-2] = calcIndex2Lower(t)
                print("".join(res[:-1]))
                endf = True
                break
            else:
                m = ch
                res.append(calcIndex2Lower(ch))
            if endf:
                break

else: # under 26
    for i in range(l):
        c = calcLower2Index(s[i])
        f[c] = True
    can = ""
    for i in range(26):
        if f[i] is False:
            can = calcIndex2Lower(i)
            break
    print(s + can)

Submission status: Runtime Error

Solution code:
import sys
calcLower2Index = lambda x: ord(x) - ord("a")
calcUpper2Index = lambda x: ord(x) - ord("A")
calcIndex2Lower = lambda x: chr(ord("a") + x)
calcIndex2Upper = lambda x: chr(ord("A") + x)
s = input()
f = [False] * 26
l = len(s)
if  l == 26: #full
    res = []
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        sys.exit(0)
    m = -1 # これまでのmax
    ind = -1
    for i in range(l):
        ch = calcLower2Index(s[i])
        f[ch] = True
        ind += 1
        if m > ch:
            for k in range(26):
                if f[k] is False:
                    t = k
                    break
            res[-2] = calcIndex2Lower(t)
            print("".join(res[:-1]))
            sys.exit(0)
        else:
            m = ch
            res.append(calcIndex2Lower(ch))

else: # under 26
    for i in range(l):
        c = calcLower2Index(s[i])
        f[c] = True
    can = ""
    for i in range(26):
        if f[i] is False:
            can = calcIndex2Lower(i)
            break
    print(s + can)

Submission status: Runtime Error

Solution code:
calcLower2Index = lambda x: ord(x) - ord("a")
calcUpper2Index = lambda x: ord(x) - ord("A")
calcIndex2Lower = lambda x: chr(ord("a") + x)
calcIndex2Upper = lambda x: chr(ord("A") + x)
s = input()
f = [False] * 26
l = len(s)
if  l == 26: #full
    res = []
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    m = -1 # これまでのmax
    ind = -1
    for i in range(l):
        ch = calcLower2Index(s[i])
        f[ch] = True
        ind += 1
        if m > ch:
            for k in range(26):
                if f[k] is False:
                    t = k
                    break
            res[-2] = calcIndex2Lower(t)
            print("".join(res[:-1]))
            return
        else:
            m = ch
            res.append(calcIndex2Lower(ch))

else: # under 26
    for i in range(l):
        c = calcLower2Index(s[i])
        f[c] = True
    can = ""
    for i in range(26):
        if f[i] is False:
            can = calcIndex2Lower(i)
            break
    print(s + can)

Submission status: Runtime Error

Solution code:
S=input()
alphabet=[chr(i) for i in range(ord('a'),ord('z')+1)]
if len(S)!=26:
    for x in alphabet: 
        if not(x in set(S)):
            flag=1
            break
    ans=S+x
    print(ans)
else:
    s=ord(S[25])
    for i in range(24,-1,-1):
        if s<ord(S[i]):
            j=i
            s=ord(S[i])

    if j==0:
        print(-1)
    else:
        l=S[j:]
        y=300
        for x in list(map(ord,l)):
            if ord(S[j-1])<x:
                y=min(y,x)
        ans=S[:j-1]+chr(y)
        print(ans)

Submission status: Runtime Error

Solution code:

from string import ascii_lowercase
s = input()

if s == ascii_lowercase[::-1]:
    print(-1)
elif len(s)!=len(ascii_lowercase):
    s1 = set(list(s))
    s2 = set(list(ascii_lowercase))
    w = min(s2-s1)
    print(s+w)
else:
    back = ''
    tmp = ''
    pos = 0
    for i in range(len(s))[::-1]:
        if i==25:
            back += s[i]
            tmp = s[i]
        elif s[i]>tmp:
            back += s[i]
            tmp = s[i]
        else:
            pos = i
            break

    res = s[:pos]
    l = []
    for b in back:
        if b > w:
            l.append(b)
    print(res + min(l))

Submission status: Runtime Error

Solution code:
from string import ascii_lowercase
s = input()

if s == ascii_lowercase[::-1]:
    print(-1)
elif len(s)!=len(ascii_lowercase):
    s1 = set(list(s))
    s2 = set(list(ascii_lowercase))
    w = min(s2-s1)
    print(s+w)
else:
    a = ''
    res = ''
    tmp = ''
    back = ''
    for i in range(len(s))[::-1]:
        if i==0:
            tmp = s[i]
            a += s[i]
        else:
            if s[i]>tmp:
                a += s[i]
                tmp = s[i]
            else:
                res = s[:i]
                back = s[i:]
                break
    p = back[0]
    back = list(back)
    back.sort()
    if back[0]==p:
        print(res+back[1])
    else:
        print(res+back[0])

Submission status: Runtime Error

Solution code:
from string import ascii_lowercase
s = input()

if s == ascii_lowercase[::-1]:
        print(-1)
elif len(s)!=len(ascii_lowercase):
    s1 = set(list(s))
    s2 = set(list(ascii_lowercase))
    w = min(s2-s1)
    print(s+w)
else:
    a = ''
    res = ''
    tmp = ''
    for i in range(len(s))[::-1]:
        if i==0:
            tmp = s[i]
            a += s[i]
        else:
            if s[i]>tmp:
                a += s[i]
                tmp = s[i]
            else:
                res = s[:i]
                break
    
    m = max(list(res))
    
    tmp = []
    for i in range(len(a)):
        if a[i]>m:
            tmp.append(a[i])
    print(res + min(tmp))

Submission status: Runtime Error

Solution code:
s = input()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    full_lst = [i for i in range(ord('a'), ord('z')+1)]
    lst = []
    for i in range(len(s)):
        lst.append(ord(s[i]))
    
    if len(lst)!=len(full_lst):
        w = chr(min(set(full_lst)-set(lst)))
        print(s+w)
    else:
        res = ''
        for i in range(len(lst)):
            if lst[i]!=full_lst[i]:
                x = s[:i]
                y = lst[i:]
                break
        print(x[:-1] + chr(min(y)))

Submission status: Runtime Error

Solution code:
s = input()

if len(s) > 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans)
    exit()


for i in range(24,-1,-1):
    for j in range(25,i,-1):
        if s[i]<s[j]:
            print(s[:i]+s[j])
            exit()

print(-1)

Submission status: Runtime Error

Solution code:
s = input()

if len(s) > 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans) 


for i in range(24,-1,-1):
    for j in range(25,i,-1):
        if s[i]<s[j]:
            print(s[:i]+s[j])
            exit()

print(-1)

Submission status: Runtime Error

Solution code:
S=input()
abc=[chr(ord('a')+i) for i in range(26)]

if len(S)<26:
    for s in S:
        abc.remove(s)
    print(S+abc[0])
else:
    index_z=S.index('z')
    index_=abc.index(S[index_z-1])
    abc_=abc[index_:]
    for s in S[:index_z]:
        abc_.remove(s)
    print(S[:index_z-1]+abc_[0])

Submission status: Runtime Error

Solution code:
S=input()
tmp=("abcdefghijklmnopqrstuvwxyz")
C=len(S)
M=sorted(S)
count=0
if C!=26:
	for i in range (C):
		if M[i]!=tmp[i]:
			print(S,end="")
			print(tmp[i])
			break
		else:
			count+=1
	if count== C:
		print(S,end="")
		print(tmp[C])
else:
	if S == ("zyxwvutsrqponmlkjihgfedcba"):
		print("-1")
	else:
		for i in range (26):
			if S[i]>S[i+1]:
				print(S[0:i-1],end="")
				print(tmp[i])
				break;

Submission status: Runtime Error

Solution code:
s=input()
A='abcdefghijklmnopqrstuvwxyz'
#文字の追加ができないケース
if len(s)==26:
    for i in range(25):
        if chr(ord(s[i])+1)!=s[i+1]:
            print(s[:i]+A[A.index(s[i])+1])
            exit()
dic_w=''
for i in A:
    if i not in s:
        dic_w=i
        print(s+dic_w)
        exit()

print(-1)

Submission status: Runtime Error

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=list(ST())
    exist = defaultdict(int)
    N=len(S)
    for s in S:
        exist[s]+=1
    if len(S)==26:
        flag = False
        for i in range(N)[::-1]:
            s = chr(ord("a")+i)
            if S[i]==s:
                flag = True
                continue
            if flag:
                exist_s = set(S[:i+1])
                for j in range(26):
                    t = chr(ord("a")+j)
                    if t not in exist_s and t>S[i]:
                        S[i]=t
                        break
            else:
                done = False
                for i in range(N-1)[::-1]:
                    if S[i]<S[i+1]:
                        for j in range(N)[::-1]:
                            if S[i]<S[j]:
                                S[i],S[j] = S[j],S[i]
                                # S[i+1:] = S[i+1:][::-1]
                                S=S[:i+1]
                                done = True
                                break
                    if done:
                        break
            break
        if done:
            print(*S,sep="")
        else:
            print(-1)
    else:
        for i in range(26):
            s = chr(i+ord("a"))
            if exist[s]==0:
                S+=s
                break
        print(*S,sep="")
        
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
sl = list(input())
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
if len(sl) != 26:
    for s in ascii_lowercase:
        if s not in sl:
            sl.append(s)
            break
    print("".join(sl))
elif "".join(sl) == "zyxwvutsrqponmlkjihgfedcba":
    print("-1")
else:
    ansl = []
    for s, t in zip(sl, ascii_lowercase):
        if s != t:
            ansl[-1] = t
            print("".join(ansl))
            break
        ansl.append(t)

Submission status: Runtime Error

Solution code:
sl = list(input())
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
if len(sl) != 26:
    for s in ascii_lowercase:
        if s not in sl:
            sl.append(s)
            break
    print("".join(sl))
elif "".join(sl) == "zyxwvutsrqponmlkjihgfedcba":
    print("zyxwvutsrqponmlkjihgfedcba")
else:
    ansl = []
    for s, t in zip(sl, ascii_lowercase):
        if s != t:
            ansl[-1] = t
            print("".join(ansl))
            break
        ansl.append(t)

Submission status: Runtime Error

Solution code:
s = input()
ans = list(s)
alpha = [chr(i) for i in range(97, 97+26)]
if len(s) == 26 and s == "".join(alpha): print(-1)
else:
    for i in range(len(s)):
        if alpha[i] == ans[i]:
            if i == len(s) - 1:
                ans.append(alpha[i+1])
            else: continue
        else:
            ans = alpha[:i]
            ans[-1] = alpha[i]
            break
    print("".join(ans))

Submission status: Runtime Error

Solution code:
S = list(input())

W = list('abcdefghijklmnopqrstuvwxyz')

if len(S) < 26:
    for s in S:
        W.remove(s)
    S += W[0]
    print(*S, sep='')
else:
    s_last = S[-1]
    for i in range(24, -1, -1):
        s = S[i]
        if s > s_last:
            s_last = s
        else:
            idx = i
            break
    if idx == 0:
        print(-1)
    else:
        res = []
        for s in S[idx+1:]:
            if s > S[idx]:
                res.append(s)
        res.sort()
        print(*(S[:idx] + [res[0]]), sep='')

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
ls=[0]*26

for i in range(n):
  ls[ord(s[i])-97]=i+1
if n<26:
  for i in range(26):
    if ls[i]==0:
      x=i
      break
  print(s+chr(x+97))
else:
  for i in range(24,-1,-1):
    if ls[i+1]>ls[i]:

Submission status: Runtime Error

Solution code:
S = list(input())
n = len(S)
W = list('abcdefghijklmnopqrstuvwxyz')

ans = []
if S == list('zyxwvutsrqponmlkjihgfedcba'):
    print(-1)
elif n == 26:
    for i in range(n):
        if S[i] == W[i]:
            ans.append(W[i])
        else:
            ans.pop(-1)
            ans.append(W[i])
            break
    print(*ans, sep='')
else:
    for s in S:
        W.remove(s)
        ans.append(s)
    ans.append(W[0])
    print(*ans, sep='')

Submission status: Runtime Error

Solution code:
s = input()
if len(s)<26:
  for i in al:
    if i not in s:
      print(s+i)
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    k = []
    for i in range(25, 0, -1):
      k.append(s[i])
      if s[i-1] < s[i]:
        for j in sorted(k):
          if j > s[i-1]:
            print(s[:i-1] + j)
            exit()

Submission status: Runtime Error

Solution code:
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + X
else:
    T = []
    x = S[-1]
    T.append(x)
    for i in range(2,27):
        y = S[-i]
        if y > x:
            x = y
            T.append(y)
        else:
            break
    m = 26 - len(T)
    if m != 0:
        ans = S[0]
        for i in range(1,m-1):
            ans += S[i]
        for t in T:
            if t > S[m-1]:
                ans += t
                break
    else:
        ans = -1
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + chr(X)d
else:
    T = []
    x = S[-1]
    T.append(x)
    for i in range(2,27):
        y = S[-i]
        if y > x:
            x = y
            T.append(y)
        else:
            break
    m = 26 - len(T)
    if m != 0:
        ans = S[0]
        for i in range(1,m-1):
            ans += S[i]
        for t in T:
            if t > S[m-1]:
                ans += t
                break
    else:
        ans = -1
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + chr(X)
else:
    T = []
    p = 0
    q,r = -1,-1
    for i in range(n):
        j = S[i]
        if ord(j) > p:
            q = i
            T = []
        else:
            if len(T) == 0:
                r = i
                T.append(S[i-1])
            T.append(j)
        p = ord(j)
    if len(T) == 0:
        T.append(S[n-1])
        r = n
    if (r == 1) & (S[r-1] == 'z'):
        ans = -1
    else:
        ans = S[0]
    for i in range(1,r-2):
         ans += S[i]
    for i in range(1,len(T)+1):
            if S[r-2] < T[-i]:
                ans += T[-i]
                break
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + chr(X)
else:
    T = []
    p = 0
    q,r = -1,-1
    for i in range(n):
        j = S[i]
        if ord(j) > p:
            q = i
            T = []
        else:
            if len(T) == 0:
                r = i
            T.append(j)
        p = ord(j)
    if q < r:
        if S[r-1] == 'z':
            if r == 1:
                ans = -1
            else:
                ans = S[0]
                for i in range(1,r-2):
                    ans += S[i]
                ans += T[-1]
    else:
        ans = S[0]
        for i in range(1,n-2):
            ans += S[i]
        ans += S[n-1]
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + ord(X)
else:
    A = []
    B = []
    p = 0
    d,e = -1,-1
    for i in range(n):
        j = ord(s[i])
        if ord(j) > p:
            d = i
            A.append(j)
            B = []
        else:
            if len(B) == 0:
                e = i
            B.append(j)
            A = []
    if d < e:
        if S[e-1] == 'z':
            if e == 1:
                ans = -1
            else:
                ans = S[0]
                for i in range(1,e-2):
                    ans += S[i]
                ans += B[-1]
    else:
        ans = S[0]
        for i in range(1,n-2):
            ans += S[i]
        ans += S[n]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = []
n = N//2
if N == 3:
    ans = [2,3,63]
elif 4 <= N <= 15000:
    for i in range(1,n):
        ans.append(2*i)
        x = 30000 - 2*i
        ans.append(x)
    if N % 2 == 1:
        ans.append(30000)
    ans.append(3)
    ans.append(9)
else:
    for i in range(1,15000):
        ans.append(2*i)
    x = N - 14999
    for j in range(x-1):
        y = 6*j + 3
        ans.append(y)
    if x % 2 == 1:
        ans.append(30000)
    else:
        ans.append(6*x - 3)
print(*ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = []
n = N//2
if N == 3:
    ans = [2,3,63]
elif 4 <= N <= 15000:
    for i in range(1,n):
        ans.append(2*i)
        x = 30000 - 2*i
        ans.append(x)
    if N % 2 == 0:
        ans.append(30000)
    ans.append(3)
    ans.append(9)
else:
    for i in range(1,15000):
        ans.append(2*i)
    x = N - 14999
    for j in range(x):
        y = 6*x + 3
        if y <= 30000:
            ans.append(y)
    if N == 20000:
        ans.append(30000)
print(*ans)

Submission status: Runtime Error

Solution code:
w="qwertyuiopasdfghjklzxcvbnm"
l=sorted(list(w))
d={}
for i in l:
  d[i]=0
w1=list(input())
for i in w1:
  d[i]=1
for i in l:
  if d[i]==0:
    print(w1+i)
    exit()
index=-1
for i in range(len(w1)-1):
  b=True
  for j in range(i,len(w1)-1):
    if w1[i]>w1[i+1]:
      pass
    else:
      b=False
      break
  if b:
    index=i
    break
if index==0:
  print(-1)
else:
  ans=""
  d={}
  for i in l:
    d[i]=0
  for i in range(index-1):
    ans+=w1[i]
    d[w1[i]]=1
  for i in l:
    if d[i]==0 and i!=w1[index-1]:
      ans+=i
      break
  print(ans)

Submission status: Runtime Error

Solution code:
s = input()

if len(c) < 26:
    for i in "abcdefghijklmnopqrstuvwxyz":
        if not i in s:
            ans = s + i
            break

else:
    tmp = ""
    ss = list(s)
    for i in range(len(ss)):
        if i == 0:
            tmp += ss.pop()
            continue

        if ss[-1] > tmp[-1]:
            tmp += ss.pop()
        else:
            ss.pop()
            ans = "".join(ss) + min(tmp)
            break
    else:
        ans = -1

print(ans)