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:
alpha = {"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"}
s = list(str(input()))
for i in s:
    if i in alpha:
        alpha.remove(i)
if len(alpha) == 0:
    flag = True
    for i in range(len(s)):
        #print(s[i])
        if s[i] > s[i+1]:
            al = {"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 j in range(i):
                if s[j] in al:
                    al.remove(s[j])
            ans = "".join(s[:i-1] + [sorted(list(al))[0]])
            flag = False
            break
    if flag:
        ans = -1
else:
    ans = "".join(s + [sorted(list(alpha))[0]])
print(ans)

Submission status: Runtime Error

Solution code:
M=["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"]
O=input()
S=list(O)

if(len(O)!=26):
    for i in range(26):
        if(M[i] not in S):
            print(O,M[i],sep="")
            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()
a = 'abcdefghijklmnopqrstuvwxyz'
ans = ''

if len(s) < 26:
    for w in a:
        if not w in s:
            ans = s + w
            break

r = ''.join(sorted(a, reverse=True))
if len(s) == 26:
    for i in range(len(s), -1, -1):
        if i == len(s) and r[:i] == s[-i:]:
            print('-1')
            exit()
        if r[:i] == s[-i:]:
            ele = i
            break
    ans = s[:-(ele+1)] + sorted(r[:ele])[0]

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
ans = ''
if len(s) < 26:
    for w in a:
        if not w in s:
            ans = s + w
            break
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    ans = '-1'
else:
    l = list(a)
    l.sort(reverse=True)
    l = ''.join(l)
    ele = 0
    for i in range(len(s)):
        if l[:i] == s[-i:]:
            ele = i
    if ele < 25:
        t = s[:-(ele+1)]
        u = l[:ele]+s[-(ele+1):-(ele)]
        u2 = sorted(u)
        ans = t + u2[1]
'''
        for w in a:
            if not w in t and t + w != s[:-ele]:
                ans = t + w
                break
'''
print(ans)

Submission status: Runtime Error

Solution code:
alphabet=[chr(i+97) for i in range(0,26)]
S=input()

#S=    "zyawvutsrqponmlkjihgfedcbx"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:

    for i in S:
        alphabet.remove(i)
    if alphabet:
        print(S+alphabet[0])
    else:
        motoS=S
        S=list(S)
        poplist=[]
        stringlist=[]
        while len(S)>=2:
            poplist.append(S.pop())
            for s in poplist:
                _S=S
                _S[-1]=s
                string=""
                for ss in _S:
                    string+=ss
                stringlist.append(string)
        stringlist.append(motoS)
        stringlist.sort()
        print(stringlist[stringlist.index(motoS)+1])

Submission status: Runtime Error

Solution code:
alphabet=[chr(i+97) for i in range(0,26)]
S=input()

#S=    "zyawvutsrqponmlkjihgfedcbx"
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:

    for i in S:
        alphabet.remove(i)
    if alphabet:
        print(S+alphabet[0])
    else:
        motoS=S
        S=list(S)
        poplist=[]
        stringlist=[]
        while len(S)>=2:
            poplist.append(S.pop())
            for s in poplist:
                _S=S
                _S[-1]=s
                string=""
                for ss in _S:
                    string+=ss
                stringlist.append(string)
        stringlist.append(motoS)
stringlist.sort()
print(stringlist[stringlist.index(motoS)+1])

Submission status: Runtime Error

Solution code:
s = input()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    alphabet = [0 for i in range(26)]
    if len(s) != 26:
        for i in s:
            alphabet[ord(i)-97] = 1
        addindex = alphabet.index(0)
        print(s + chr(addindex+97))
    else:
        for i, v in enumerate(s):
            alphabet[ord(v)-97] = 1
            if v == "z":
                zindex = i
                break
        ans = s[:zindex-1]
        addindex = alphabet.index(0)
        print(ans + chr(addindex+97))

Submission status: Runtime Error

Solution code:
s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			if d[0]==s[-i-1]:
				k=d[1]
			else:
				k=d[0]
				print(2/0)
			print(s[:-i-1]+k)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)

Submission status: Runtime Error

Solution code:
s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			if d[0]==s[-i-1]:
				k=d[1]
				print(2/0)
			else:
				k=d[0]
			print(s[:-i-1]+k)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)

Submission status: Runtime Error

Solution code:
s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			k=d[1]
			print(s[:-i-1]+k)
			print(2/0)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)

Submission status: Runtime Error

Solution code:
S = input()

abc = list("abcdefghijklmnopqrstuvwxyz")
# ord('a') = 97
n = len(abc)
check = [0] * n
for s in S:
    check[ord(s) - 97] = 1

if sum(check) != n:
    for i in range(n):
        if check[i] == 0:
            S += abc[i]
            break
    print(S)
elif S == ''.join(abc[::-1]):
    print(-1)
else:
    check = [0] * n
    for i in range(n):
        if ord(S[i]) > ord(S[i + 1]):
            p = i
            break
        check[ord(S[i]) - 97] = 1
    ans = S[:p - 1]
    for i in range(n):
        if check[i] == 0:
            ans += abc[i]
            break
    print(ans)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)

D = [0 for i in range(26)]
for i in range(N):
    D[ord(S[i]) - 97] = 1

if N != 26:
    for i in range(N):
        if D[i] == 0:
            s = chr(97 + i)
            break
    print(S + s)

else:
    if S == "abcdefghijklmnopqrstuvwxyz"[::-1]:
        print(-1)
    else:
        c = 2
        for i in range(N):
            if ord(S[-2 - i]) - ord(S[-1 - i]) == 1:
                c += 1
            else:
                break
        print(S[:26 - c] + S[-1])

Submission status: Runtime Error

Solution code:
S = list(input())

a = 'abcdefghijklmnopqrstuvwxyz'
if len(S) != 26:
    for i in range(26):
        if not a[i] in S:
            print (*S, sep = '', end = '')
            print (a[i])
            exit()

for i in range(25, 0, -1):
    if ord(S[i]) < ord(S[i - 1]):
        continue
    else:
        break
# print (i)
if i == 1:
    print (-1)
    print (A)
    exit()

tmp_n = ord('z')
for j in S[i:]:
    if ord(j) > ord(S[i - 1]):
        tmp_n = min(tmp_n, ord(j))

print (*S[:i - 1], sep = '', end = '')
print (chr(tmp_n))

Submission status: Runtime Error

Solution code:
S = list(input())

#最後かどうかのチェック
final = 'zyxwvutsrqponmlkjihgfedcba'
flag = True
for i in range(len(S)):
    if S[i] == final[i]:
        pass
    else:
        flag = False
        break

if flag and len(S) == 26:
    print (-1)
    exit()

a = 'abcdefghijklmnopqrstuvwxyz'
if len(S) != 26:
    for i in range(26):
        if not a[i] in S:
            print (*S, a[i], sep = '')
            exit()

Submission status: Runtime Error

Solution code:
S = list(input())
S_unique = list(set(S))

alpha = list("abcdefghijklmnopqrstuvwxyz")


if len(S_unique) != 26:
    for i in range(len(alpha)):
        if alpha[i] not in S_unique:
            ans = alpha[i]
            break

a = ''.join(S) + ans
print(a)

Submission status: Runtime Error

Solution code:
# 2019/08/12

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

st=set(s)
"""
if len(s)<26:
    for i in range(97,97+26+1):
        if chr(i) in st:continue
        print(s+chr(i))
        exit()
"""
s=list(s)
res=[s.pop()]

def solve(s):
    for _ in range(len(s)):
        tmp=s.pop()
        if tmp>res[-1]:
            res.append(tmp)
            res.sort()
        else:            
            for e in res:
                if e<tmp:continue
                s.append(e)
                return s

print(''.join(solve(s)))

Submission status: Runtime Error

Solution code:
# 2019/08/12

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

st=set(s)
if len(s)<26:
    for i in range(97,97+26+1):
        if chr(i) in st:continue
        print(s+chr(i))
        exit()
s=list(s)
tmp=[]

def solve(s):
    for _ in range(26):
        for j in range(25,-1,-1):
            if s[j-1]>s[j]:
                tmp.append(s[j])
                s[j]=''
            else:
                if s[j]=='z':
                    s[j]=''
                    for e in tmp:
                        if e<s[j-1]:continue
                        s[j-1]=e
                        return s
                else:
                    s[j]=chr(ord(s[j-1])+1)
                    return s


print(''.join(solve(s)))

Submission status: Runtime Error

Solution code:
import string

S = input()

abc = [chr(i) for i in range(97, 97+26)]

if len(S) < 26:
    for s in S:
        abc.remove(s)
    add = abc[0]
    print('wahaha')
    print(S + add)
elif S == ''.join(sorted(abc, reverse=True)):
    print(-1)
else:
    N = len(S)
    for i in range(1, N):
        now = S[N-i]
        fow = S[N-i+1:]
        fows = sorted(list(fow))
        for f in fows:
            if now < f:
                now = f
                break
        if now != S[N-i]:
            ans = S[:N-i] + now
            break
    print(ans)

Submission status: Runtime Error

Solution code:
import string

S = input()

abc = [chr(i) for i in range(97, 97+26)]

if len(S) < 26:
    for s in S:
        abc.remove(s)
    add = abc[0]
    print(S + add)
elif S == ''.join(sorted(abc, reverse=True)):
    print(-1)
else:
    N = len(S)
    for i in range(1, N):
        now = S[N-i]
        fow = S[N-i+1:]
        fows = sorted(list(fow))
        for f in fows:
            if now < f:
                now = f
                break
        if now != S[N-i]:
            ans = S[:N-i] + now
            break
    print(ans)

Submission status: Runtime Error

Solution code:
s=input()
a='abcdefghijklmnopqrstuvwxyz'
r='zyxwvutsrqponmlkjihgfedcba'
if len(s)!=26:
  for i in a:
    if i not in s:
      s=s+i
      break
elif s==r:
  s=-1
else:
  for i in range(25,0,-1):
    if i==1:
      s=chr(ord(s[0])+1)
      break
    if s[i]>s[i-1]:
      l=sorted(s[i:])
      for i in l:
        if i>s[i-1]:
          m=i
          break
      s=s[:i-1]+m
      break
print(s)

Submission status: Runtime Error

Solution code:
s=input()
a="abcdefghijklmnopqrstuvwxyz"
if(s==a[::-1]):
    print(-1)
else:
    if(len(s)==26):
        c=s[-1]
        i=2
        while 1:
            if(s[-i]<c):
                print(s[:26-i]+c)
                break
            else:
                i+=1
    else:
        for i in a:
            if(not i in s):
                print(s+i)
                break

Submission status: Runtime Error

Solution code:
import collections
S = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
dic = collections.defaultdict(int)
ans = -1
if len(S) <= 25:
    for i in S:
        dic[i] += 1
    for i in alp:
        if dic[i] == 0:
            ans = S + i
            break
else:
    dic2 = {}
    dic3 = {}
    lst = []
    tmp = 0
    for i, j in zip(alp, range(1, 27)):
        dic2[i] = j
        dic3[j] = i
    for i in range(1, 27):
        a = S[-i]
        idx = dic2[a]
        if idx < tmp:
            lst.sort()
            for j in lst:
                if j > idx:
                    ans = S[:-i] + dic3[j]
                    flag = True
                    break
        
        else:
            tmp = idx
            lst.append(idx)
        if flag:
            break


print(ans)

Submission status: Runtime Error

Solution code:
alp = set(["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'])
s = input()
if len(s) == 26:
    if "".join(list(reversed(sorted(s)))) == s:
        ans = -1
    else:
        ans = s.split("z")[0][:-1] + "".join(sorted(list(s.split("z")[1]))[0])
else:
    ans = list(alp - set(s))
    ans.sort()
    s += ans[0]
    ans = "".join(s)
print(ans)

Submission status: Runtime Error

Solution code:
def solve():
    S = input()
    A = "abcdefghijklmnopqrstuvwxyz"
    if S == A[::-1]:
        return -1

    if len(S) < 26:
        return S + min(set(A) - set(S))

    i = [e == f for e, f in zip(A, S)].index(False)
    return S[: i - 1] + min(S[i:])

print(solve())

Submission status: Runtime Error

Solution code:
s=input()
abc="abcdefghijklmnopqrstuvwxyz"
if len(s)<26:
  print(s+sorted(list(set(abc)-set(s)))[0])
else:
  x=s[-1]
  Tail=[x]
  count,flag=0,0
  for i in range(2,27):
    if s[-i]<x:
      count=i
      flag=1
      break
    else:
      x=s[-i]
      Tail.append(x)
  t="z"
  for tt in Tail:
    if tt>s[26-count]:
       t=min(t,tt)  
  print(s[:-count]+t if flag==1 else -1)

Submission status: Runtime Error

Solution code:
a = set(["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"])
s = input()
for i in range(len(s)):
    a.remove(s[i])
b = list(a).sort()
if b:
    print(s[i]+b[0])
else:
    for i in range(2,27):
        if s[-i] < s[-i+1]:
            break
        if i == 26:
            print(-1)
            exit()
    for j in sorted(s[-i+1:]):
        if j > s[-i]:break
    print(s[:-i]+j)

Submission status: Runtime Error

Solution code:
a = set(["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"])
s = input()
for i in range(len(s)):
    a.remove(s[i])
b = list(a).sort()
if b:
    print(s[i]+s[0])
else:
    for i in range(2,27):
        if s[-i] < s[-i+1]:
            break
        if i == 26:
            print(-1)
            exit()
    for j in sorted(s[-i+1:]):
        if j > s[-i]:break
    print(s[:-i]+j)

Submission status: Runtime Error

Solution code:
import numpy as np
alp = [chr(v) for v in range(ord("a"), ord("z") + 1)]
inp = input()

if inp[::-1] == "".join(alp):
    print(-1)
    exit()

if len(inp) == len(alp):
    prev = inp[0]
    indices = [0]
    for index, char in enumerate(inp[1:]):
        if prev > char:
            indices.append(index)
        prev = char
    diff = [0] * (len(indices) - 1)
    for i, (v1, v2) in enumerate(zip(indices[1:], indices[:-1])):
        diff[i] = v1 - v2
    maxv = float("-inf")
    maxv_index = 0
    for i, d in enumerate(diff):
        if maxv <= d:
            maxv = d
            maxv_index = i

    index = indices[maxv_index + 1]
    targets = inp[index:]
    for v in sorted(targets):
        if inp[index - 1] < v:
            break
    print(inp[:index - 1] + v)

else:
    print(inp + min(set(alp) - set(list(inp))))

Submission status: Runtime Error

Solution code:
import numpy as np
alp = [chr(v) for v in range(ord("a"), ord("z") + 1)]
inp = input()

if inp[::-1] == "".join(alp):
    print(-1)
    exit()

if len(inp) == len(alp):
    prev = inp[0]
    indices = [0]
    for index, char in enumerate(inp[1:]):
        if prev > char:
            indices.append(index)
        prev = char
    diff = [0] * (len(indices) - 1)
    for i, (v1, v2) in enumerate(zip(indices[1:], indices[:-1])):
        diff[i] = v1 - v2
    maxv = float("-inf")
    maxv_index = 0
    for i, d in enumerate(diff):
        if maxv <= d:
            maxv = d
            maxv_index = i

    index = indices[maxv_index + 1]
    print(inp[:index - 1] + min(inp[index:]))

else:
    print(inp + min(set(alp) - set(list(inp))))

Submission status: Runtime Error

Solution code:
import numpy as np
alp = [chr(v) for v in range(ord("a"), ord("z") + 1)]
inp = input()

if inp[::-1] == "".join(alp):
    print(-1)
    exit()

if len(inp) == len(alp):
    prev = inp[0]
    indices = [0]
    for index, char in enumerate(inp[1:]):
        if prev > char:
            indices.append(index)
        prev = char
    indices = np.array(indices)
    diff = indices[1:] - indices[:-1]
    maxv = float("-inf")
    maxv_index = 0
    for i, d in enumerate(diff):
        if maxv <= d:
            maxv = d
            maxv_index = i

    index = indices[maxv_index + 1]
    print(inp[:index - 1] + min(inp[index:]))

else:
    print(inp + min(set(alp) - set(list(inp))))

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np
alp = [chr(v) for v in range(ord("a"), ord("z") + 1)]
inp = input()

if inp[::-1] == "".join(alp):
    print(-1)
    exit()

if len(inp) == len(alp):
    prev = inp[0]
    indices = [0]
    for index, char in enumerate(inp[1:]):
        if prev > char:
            indices.append(index)
        prev = char
    indices = np.array(indices)
    diff = indices[1:] - indices[:-1]
    index = indices[diff.argmax() + 1]
    print(inp[:index - 1] + min(inp[index:]))

else:
    print(inp + min(set(alp) - set(list(inp))))

Submission status: Runtime Error

Solution code:
str = input()
sortstr=sorted(str)
alpha = [chr(ord('a') + i) for i in range(26)]
for i in str:
    if i in alpha:
        alpha.remove(i)
if len(str)!=len(set(str)) or str=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif list(str)==sorted(str):#sorted(str) is list
    print(str+alpha[0])
elif len(str)==26:
    alpha2=[chr(ord('a') + i) for i in range(26)]
    for i in range(len(str)):
        if str[i]==sortstr[i]:
            alpha2.remove(str[i])
           # print(alpha2)
        else:
            print(str[:i]+alpha2[0])
            break
else:
    print(str+alpha[0])

Submission status: Runtime Error

Solution code:
str = input()
sortstr=sorted(str)
alpha = [chr(ord('a') + i) for i in range(26)]

for i in str:
    if i in alpha:
        alpha.remove(i)
if len(str)!=len(set(str)) or str=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif list(str)==sorted(str):#sorted(str) is list
    print(str+alpha[0])
elif len(str)==26:
    alpha2=[chr(ord('a') + i) for i in range(26)]
    for i in range(len(str)):
        if str[i]==sortstr[i]:
            continue
            alpha2.remove(str[i])
        else:
            print(str[i-1]+alpha[0])
            break
else:
    print(str+alpha[0])

Submission status: Runtime Error

Solution code:
str = input()
alpha = [chr(ord('a') + i) for i in range(26)]
for i in str:
    alpha.remove(i)
if len(str)!=len(set(str)) or str=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    lalpha = alpha[len(str)-1]
    lindex = alpha.index(lalpha)
  #  nindex = (lindex+1)//(26-len(alpha))
    print(str+alpha[0])

Submission status: Runtime Error

Solution code:
s = input()
L = []
alp = [chr(ord('a') + i) for i in range(26)]
TF = [False]*26
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
    TF[ord(s[i])-97] = True
if len(L) != 26:
  for i in range(26):
    if TF[i] == False:
      k = alp[i]
      break
  print(s+k)
else:
  if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
  elif s == 'abcdefghijklmnopqrstuvwxyz':
    print('b')
  else:
    P = []
    for i in range(25,-1,-1):
      if s[i] > s[i-1]:
        break
      else:
        P.append(s[i-1])
        P.append(s[i])
    P.sort()
    print(s[0:i-1]+P[0])

Submission status: Runtime Error

Solution code:
s = input()
L = []
alp = [chr(ord('a') + i) for i in range(26)]
TF = [False]*26
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
    TF[ord(s[i])-97] = True
if len(L) != 26:
  for i in range(26):
    if TF[i] == False:
      k = alp[i]
      break
  print(s+k)
else:
  if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
  elif s == 'abcdefghijklmnopqrstuvwxyz':
    print('b')
  else:
    for i in range(25):
      if ord(s[i+1])-ord(s[i]) != 1:
        break
    print(s[0:i]+alp[ord(s[i])-97+1])

Submission status: Runtime Error

Solution code:
s = input()
l = list('abcdefghijklmnopqrstuvwxyz')
for s_ in s:
    l.remove(s_)
print(s+l[0])

Submission status: Runtime Error

Solution code:
s=input()
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      print(s[:i]+mn)
      exit()
print(-1)

Submission status: Runtime Error

Solution code:
s=input() 
b="".join(list(reversed("zyxwvutsrqponmlkjihgfedcba")))
if s=="zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      print(s[:i]+mn+s[i:first]+s[first+1])
      exit()

Submission status: Runtime Error

Solution code:
import string
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            t = 0
            for x in range(len(s)-1, 0, -1):
                for y in range(x-1, -1, -1):
                    if x == y:
                        continue
                    if s[x] > s[y]:
                        print(s.translate(string.maketrans(s[x],x[y])))
                        return 
        if s.count(i) == 0:
            print (s + i)
            break

main()

Submission status: Runtime Error

Solution code:
import string
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            t = 0
            for x in range(len(s), 0, -1):
                for y in range(x-1, -1, -1):
                    if x == y:
                        continue
                    if s[x] > s[y]:
                        print(s.translate(string.maketrans(s[x],x[y])))
                        return 
        if s.count(i) == 0:
            print (s + i)
            break

main()

Submission status: Runtime Error

Solution code:
import string
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            t = 0
            for x in range(len(s), -1, 0):
                for y in range(x-1, -1, -1):
                    if x == y:
                        continue
                    if s[x] > s[y]:
                        print(s.translate(string.maketrans(s[x],x[y])))
                        return 
        if s.count(i) == 0:
            print (s + i)
            break

main()

Submission status: Runtime Error

Solution code:
import string
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            t = 0
            for x in range(len(s), -1, 0):
                for y in rnage(x-1, -1, -1):
                    if x == y:
                        continue
                    if s[x] > s[y]:
                        print(s.translate(string.maketrans(s[x],x[y])))
                        return 
        if s.count(i) == 0:
            print (s + i)
            break

main()

Submission status: Runtime Error

Solution code:
S = input()

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

tmp = {a: 0 for a in 'abcdefghijklmnopqrstuvwxyz'}

for x in S:
    tmp[x] += 1

tmp2 = []
if all(x == 1 for x in tmp.values()):
    for i in range(len(S)-1, 0, -1):
        if S[i-1] < S[i]:
            print(S[:i-1] + min(tmp2))
            exit()
        tmp2.append(S[i])
else:
    for k, v in tmp.items():
        if v == 0:
            tmp2.append(k)
    print(S+min(tmp2))

Submission status: Runtime Error

Solution code:
S = input()

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

tmp = {a: 0 for a in 'abcdefghijklmnopqrstuvwxyz'}

for x in S:
    tmp[x] += 1

tmp2 = []
if all(x == 1 for x in tmp.values()):
    for i in range(len(S)-1, 0, -1):
        if S[i-1] < S[i]:
            print(S[:i-1] + min(tmp2))
            exit()
        tmp2.append(S[i])
else:
    for k, v in tmp.items():
        if v == 0:
            print(S+k)
            break

Submission status: Runtime Error

Solution code:
s=input()
t=0
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    r=[ord(x) for x in s]
#    print(r)
    if len(s)==26:
        while 1:
            if r[t+1]==r[t]+1:
                t+=1
                continue
            else:
              #  print(r[t+1])
                print(s[:t]+chr(min(r[t+1:])))
                break
    else:
        print(s+ chr(min(list(set(range(97,123))-set(r)))) )

Submission status: Runtime Error

Solution code:
using System;
using System.Linq;

namespace AGC022_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var alpha = "abcdefghijklmnopqrstuvwxyz";
            string S = Console.ReadLine();

            foreach (var s in S)
            {
                if (!alpha.Contains(s))
                {
                    Console.WriteLine(-1);
                    return;
                }
                alpha = alpha.Replace(s.ToString(), "");
            }

            Console.WriteLine(S + alpha[0]);
        }
    }
}

Submission status: Runtime Error

Solution code:
S = list(input())


if len(S) != 26:
    AL = [chr(i) for i in range(97, 123)]
    for i in range(len(S)):
        AL.remove(S[i])
    ans = ''.join(S) + AL[0]
elif S == 'zyxwvutsrqponmlkjihgfedcba':
    ans = -1
else:
    for i in range(24, -1, -1):
        if S[i] < S[i+1]:
            S[i] = min(S[i+1:])
            ans = ''.join(S[:i+1])
            break
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
MAX = 'zyxwvutsrqponmlkjihgfedcba'
lst_s = list(s)

if len(s) != 26:
    AL = [chr(i) for i in range(97, 123)]
    for i in range(len(s)):
        AL.remove(lst_s[i])
    ans = s + AL[0]
elif s == MAX:
    ans = -1
else:
    for i in range(24, -1, -1):
        if s[i] < min(lst_s[i+1:]):
            lst_s[i] = min(lst_s[i+1:])
            ans = ''.join(lst_s[:i+1])
            break
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
MAX = 'zyxwvutsrqponmlkjihgfedcba'
lst_s = list(s)

if len(s) != 26:
    AL = [chr(i) for i in range(97, 123)]
    for i in range(len(s)):
        AL.remove(lst_s[i])
    ans = s + AL[0]
elif s == MAX:
    ans = -1
else:
    count = 0
    for i in range(24, 0, -1):
        if s[i] < min(lst_s[i+1:]):
            lst_s[i] = min(lst_s[i+1:])
            ans = ''.join(lst_s[:i+1])
            break
print(ans)

Submission status: Runtime Error

Solution code:
a=input()
abc="abcdefghijklmnopqrstuvwxvyz"
k=[]
for i in a:
  k.append(i)
k.sort()
for j, l in zip(a,abc):
  if j!=l:
    I+=a+l
    break
if I ==a:print(-1)
else:print(I)

Submission status: Runtime Error

Solution code:
a=input()
abc=‘abcdefghijklmnopqrstuvwxvyz’
k=[]
for i in a:
  k.append(i)
k.sort()
for j, l in zip(a,abc):
  if j!=l:
    I+=a+l
    break
if I ==a:print(-1)
else:print(I)

Submission status: Runtime Error

Solution code:
from collections import deque
from itertools import dropwhile

alphabet = set('abcdefghijklmnopqrstuvwxyz')

if __name__ == '__main__':
    s = input()
    l = [c for c in alphabet - set(s)]
    if l != []:
        print(s + min(l))
        quit(0)

    deq = deque()
    deq.append(s[-1])
    for i in range(24, -1, -1):
        if s[i] < s[i + 1]:
            small = next(dropwhile(lambda c <= s[i], deq))
            print(s[:i] + small)
            quit(0)
        else:
            deq.append(s[i])

    print(-1)

Submission status: Runtime Error

Solution code:
from collections import deque
from itertools import dropwhile

alphabet = set('abcdefghijklmnopqrstuvwxyz')

if __name__ == '__main__':
    s = input()
    l = [c for c in alphabet - set(s)]
    if l != []:
        print(s + min(l))
        quit(0)

    deq = deque()
    deq.append(s[-1])
    for i in range(24, -1, -1):
        if s[i] < s[i + 1]:
            small = dropwhile(lambda c <= s[i], deq)
            print(s[:i] + small)
            quit(0)
        else:
            deq.append(s[i])

    print(-1)

Submission status: Runtime Error

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

if len(S) != 26:
    print(S + sorted(list(set(M) - set(S)))[0])
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        for i in range(26):
            if S[i] != M[i]:
                if S[i] == 'z':
                    ans = S[: i - 1] + M[i]
                    break
                else:
                    ans = S[: i] +str(list(M)[list(M).index(S[i]) + 1])
                    break
        print(ans)

Submission status: Runtime Error

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

if len(S) != 26:
    print(S + sorted(list(set(M) - set(S)))[0])
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        for i in range(26):
            if S[i] != M[i]:
                ans = S[: i - 1] + M[i]
                break
        print(ans)