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()

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

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

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

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

Submission status: Runtime Error

Solution code:
s = input()

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

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

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

Submission status: Runtime Error

Solution code:
s = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
tmpset = set()
n = len(s)
if n != 26:
    for i in range(n):
        tmpset.add(s[i])
    for i in range(26):
        if alpha[i] not in tmpset:
            s = s + alpha[i]
            print(s)
            exit()
else:
  jpjk

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n=input()
a=["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"]
if n=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    if len(n)==26:
        q=a.index(n[-1])
        c=0
        d=[n[-1]]
        for i in range(24,0,-1):
            c+=1
            d.append(n[i])
            d.sort()
            if d.index(n[i])<len(d)-1:
                print(n[:26-c-1]+d[d.index(n[i])+1])
                break
        else:
            print(a[a.index(n[i])+1])
    else:
        for i in range(len(n)):
            a.pop(a.index(n[i]))
        print(n+a[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S=list(input())

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

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

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

print(ans if flag else "-1")

Submission status: Runtime Error

Solution code:
S = input()
chars = list(map(lambda c: ord(c)-97, S))
if len(chars)!=26:
    chars = sorted(chars)
    i = 0
    while i==chars[i]:
        i += 1
    ans = S + chr(i+97)
else:
    prev = -1
    i = 0
    for c in reversed(chars):
        if prev < c:
            i += 1
            prev = c
        else:
            break
    if i==26:
        ans = -1
    else:
        max_s = chars[-i-1]
        min_c = 27
        for c in chars[-i:]:
            if c>max_s and c<min_c:
                min_c = c
        ans = S[:-i-1] + chr(min_c+97)

print(ans)

Submission status: Runtime Error

Solution code:
a={chr(i) for i in range(ord(a),ord(a)+25)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(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:
S = input()
l = len(S)
if l != 26:
    colors = [0]*26
    for i in range(26):
        colors[ ord(S[i]) - ord('a')]
    for i in range(26):
        if colors[i] == 0:
            ans = S + chr( i + ord('a'))
            break
    print(ans)
elif S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for i in range(25,0,-1):
        if S[i] > S[i-1]:
            now = i
            break
    print(S[:i-1] + S[-1])

Submission status: Runtime Error

Solution code:
S=input()
flag = False
if S=="zyxwvutsrqponmlkjihgfedcba":
    T="-1"
elif len(S)<=25:
    for i in range(97,123):
        if chr(i) not in S:
            T=S+chr(i)
            break
else:
    for i in range(2,26):
        for j in range(ord(S[-i])+1,123):
            if chr(j) not in S[:-i]:
                T=S[:-i]+chr(j)
                flag=True
                break
        if flag:
            break
print(T)

Submission status: Runtime Error

Solution code:
import java.util.*

fun main(`$`: Array<String>) {
    val v = readLine()!!
    var c = 'a'
    while (c <= 'z') {
        if (v.indexOf(c) < 0) {
            println(v + c)
            return
        }
        ++c
    }

    val set = TreeSet<Char>()
    set.add(v[v.length - 1])
    for (i in v.length - 2 downTo 0) {
        val c = v[i]
        val h = set.higher(c)
        if (h != null) {
            println(v.substring(0, i) + h)
            return
        }
        set.add(c)
    }
    println(-1)
}

Submission status: Runtime Error

Solution code:
s=input()
x=[0 for _ in range(26)]
if len(s)<26:
    for i in range(len(s)):
        x[ord(s[i])-ord('a')]=1
    for j in range(len(s)):
        if x[j]==0:
            k=j
            break
    print("".join([s,chr(ord('a')+k)]))
elif s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    mi=-1
    for i in range(1,26):
        if s[i]<s[i-1]:
            x[i]=1
            if mi==-1:
                mi=i
    tx=s[mi-1::]
    mx=min(list(tx))
    print(s[:mi-2]+mx)

Submission status: Runtime Error

Solution code:
s=input()
x=[0 for _ in range(26)]
if len(s)<26:
    for i in range(len(s)):
        x[ord(s[i])-ord('a')]=1
    for j in range(len(s)):
        if x[j]==0:
            k=j
            break
    print("".join([s,chr(ord('a')+k)]))
elif s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    mi=-1
    for i in range(1,26):
        if s[i]<s[i-1]:
            x[i]=1
            if mi==-1:
                mi=i
    print(s[:mi-2]+mx)

Submission status: Runtime Error

Solution code:
s = str(input())
list_s = list(s)
alp_list = list("abcdefghijklmnopqrstuvwxyz")
dict_alp = {}
ans = 0
for i in range(26):
    dict_alp[alp_list[i]] = i+1
if len(list_s) == 26:
    i = 25
    while True:
        try:
            if dict_alp[list_s[i]] > dict_alp[list_s[i-1]]:
                list_s = list_s[:i]
                x = list_s.pop()
                break
            else:
                i -= 1
        except IndexError:
            ans = -1
            break
    alp_set = []
    for alp in alp_list:
        if not alp in list_s:
            if dict_alp[alp] > dict_alp[x]:
                alp_set.append(alp)
    alp_set.sort()
    list_s.append(alp_set[0])
else:
    for alp in alp_list:
        if not alp in list_s:
            list_s.append(alp)
            break
if ans == -1:
    print(ans)
else:
    print("".join(list_s))

Submission status: Runtime Error

Solution code:
alphaL1 = [chr(i) for i in range(97, 97+26)]
alphaL2 = [chr(i) for i in range(97, 97+26)]

listS = list(input())
if len(listS) != 26:
    index =0
    while index < len(listS):
        if listS[index] in alphaL1:
            alphaL1.remove(listS[index])
        index+=1
    listS.append(alphaL1[0])
    print("".join(listS))
else:
    if "".join(listS) == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        listS.reverse()
        listA = []
        index =0
        while index < len(listS)-1:
            if alphaL2.index(listS[index]) < alphaL2.index(listS[index+1]):
                listA.append(listS[index])
                index+=1
            else:
                listA.sort()
                listS[index+1] = listA[0]
                count=0
                while 1:
                    if count==index+1:
                        break
                    else:
                        del listS[0]
                        count+=1
                listS.reverse()
                break
        print("".join(listS))

Submission status: Runtime Error

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

add_alp = -1

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

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

Submission status: Runtime Error

Solution code:
s = input()

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

add_alp = -1

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

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

Submission status: Runtime Error

Solution code:
a={chr(i) for i in range(97,123)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(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:
alph={chr(i) for i in range(97,123)}
s=input()
n=len(s)

if n<26:
  print(s+sorted(alph-set(s))[0])
else:
  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:
alph={chr(i) for i in range(97,123)}
s=input()
n=len(s)

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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


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

Submission status: Runtime Error

Solution code:
s = input()
a = "abcdefghijklmnopqrstuvwxyz"
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) == 26:
    cnt = 0
    for i, j in zip(a, s):
        if i == j:
            cnt += 1
        else:
            break
    print(s[:cnt-1]+a[cnt])
else:
    print(s+sorted(list(set(a)-set(s)))[0])

Submission status: Runtime Error

Solution code:
s = input()
a = "abcdefghijklmnopqrstuvwxyz"
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) == 26:
    cnt = 0
    for i, j in zip(a, s):
        if i == j:
            cnt += 1
        else:
            break
    print(s[:cnt]+a[cnt])
else:
    print(s+sorted(list(set(a)-set(s)))[0])

Submission status: Runtime Error

Solution code:
s = input()
hoge = "zyxwvutsrqponmlkjihgfedcba"
if s == hoge:
    print(-1)
    exit()
print(s+sorted(list(set(hoge)-set(s)))[0])

Submission status: Runtime Error

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

assert len(S) == 26

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

Submission status: Runtime Error

Solution code:
def f(s, i, d):
  if len(s) == i:
    d.sort()
    return d[0]
  if len(d) == 0:
    return "_"
  d.remove(s[i])
  r = f(s, i+1, d)
  if r == "_":
    d.sort()
    for i in d:
      if s[i] < i:
        return i
    d.append(s[i])
    return "_"
  return "".join([s[i], r])

def main():
  d = list("abcdefghijklmnopqrstuvwxyz")
  t = input()
  r = f(t, 0, d)
  print(r)
  
main()

Submission status: Runtime Error

Solution code:
def f(s, i, d):
  if len(s) == i:
    d.sort()
    return d[0]
  if len(d) == 0:
    return "_"
  d.remove(s[i])
  r = f(s, i+1, d)
  if r == "_":
    d.sort()
    for i in d:
      if s[i] < i:
        return i
    d.append(s[i])
    return "_"
  return "".join(s[i], r)

def main():
  d = list("abcdefghijklmnopqrstuvwxyz")
  t = input()
  r = f(t, 0, d)
  print(r)
  
main()

Submission status: Runtime Error

Solution code:
s = input()
alphabet = ["abcdefghijklmnopqrstuvwxyz"]
if s == str(alphabet[::-1]):
  print(-1)
else:
  if len(set(s))<26:
    for ele in alphabet:
      if ele not in s:
        print(s+ele)
        break
  else:
    suf=[s[-1]]
    for i in range(len(s)-1, 0, -1):
      if s[i]<s[i-1]:
        suf.append(s[i-1])
      else:
        last = i-1
        break
    suf.sort()
    for i in range(len(suf)):
      if s[last]<suf[i]:
        print(s[:last]+suf[i])
        break

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

Solution code:
s = input()
if(len(s) == 0):
    print('a')
if(len(s) != 26):
    for c in range(ord('a'), ord('z')+1):
        c = chr(c)
        if(not c in s):
            print(s+c)
            exit()
s = list(s)
t = []
while(True):
    for c in t:
        if(c > s[-1]):
            print(''.join(s[:-1]) + c)
            exit()
    t.append(s.pop())

Submission status: Runtime Error

Solution code:
s = input()
if(len(s) != 26):
    for c in range(ord('a'), ord('z')+1):
        c = chr(c)
        if(not c in s):
            print(s+c)
            exit()
s = list(s)
t = []
while(True):
    for c in t:
        if(c > s[-1]):
            print(''.join(s[:-1]) + c)
            exit()
    t.append(s.pop())

Submission status: Runtime Error

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

if len(set(S)) != 26:
    for a in A:
        if a not in S:
            print(S + a)
            break
else:
    used = []
    for i in range(1, 26):
        if S[-i] < S[-i-1]:
            used.append(S[-i])
        else:
            used.sort()
            print(S[:-i-1]+used[0])
            break
    else:
        print(-1)

Submission status: Runtime Error

Solution code:
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    u = {s[-1]}
    for i in range(len(s) - 1)[::-1]:
        x = [c for c in u if s[i] < c]
        if x:
            print(s[:i] + min(x))
            break
        u.add(s[i])
    else:
        print(-1)
else:
    out = s + min(set(sample)-set(s))

print(out)

Submission status: Runtime Error

Solution code:
s = input()
old = ''
flag = 0
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    if s == sample[::-1]:
        out = -1
    else:
        for i, s1 in enumerate(s[::-1]):
            if i != 0 and s1 < old[-1]:
                out = s[:len(s)-i-1] + min(old)
                break
            old += s1
else:
    for i1, i2 in zip(sorted(s), sample):
        if i1 != i2:
            out = s + i2
            flag = 1
            break
    if flag != 1:
        out = s + sample[len(s)]

print(out)

Submission status: Runtime Error

Solution code:

o = input()
s = list(o)
old = ''
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    if s == sample[::-1]:
        out = -1
    else:
        for i, s1 in enumerate(s[::-1]):
            if i != 0 and s1 < old[-1]:
                out = ''.join(s[:len(s)-i-1]) + min(old)
                break
            old += s1
else:
    for i1,i2 in zip(sorted(s), sample):
        if i1 != i2:
            out = o + i2
            break
print(out)

Submission status: Runtime Error

Solution code:
o = input()
s = list(o)
sample = [chr(i) for i in range(97, 97+26)]
if len(s) == 26:
    if s == sample[::-1]:
        out = -1
    else:
        for i, s1 in enumerate(sample):
            if s[i] != s1:
                out = ''.join(s[:i-1]) + s1
                break
else:
    for i1,i2 in zip(sorted(s), sample):
        if i1 != i2:
            out = o + i2
            break
print(out)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
S = input()
chars = "abcdefghijklmnopqrstuvwxyz"
if len(S) < 26:
    for c in chars:
        if c not in S:
            Ans = S+c
            break
else:
    if S == chars[::-1]:
        Ans = -1
    else:
        for i in range(26):
            if S[i] != chars[i]:
                Ans = S[0:i-1] + chars[i]
                break
print(Ans)

Submission status: Runtime Error

Solution code:
S = input()
chars = "abcdefghijklmnopqrstuvwxyz"
if len(S) < 26:
    for c in chars:
        if c not in S:
            Ans = S+c
            break
else:
    if S == chars[::-1]:
        Ans = -1
    else:
        for i in range(26):
            if S[i] != chars[i]:
                Ans = S[0:i] + chars[i]
                break
print(Ans)

Submission status: Runtime Error

Solution code:
s= input()
V = list(s)
X = [chr(ord('a') + i) for i in range(26)]

if len(s)<26:
  for i in range(26):
    count1 = s.count(X[i])
    if count1 >= 1:
      continue
    else:
      Nasi = X[i]
      break
  ans = s + Nasi
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    ans= -1
  else:
    for i in range(25, 0, -1):
        if V[i] > V[i-1]:
          ans = V[0:i-1]
          ans.append(min(V[i+1:26]))
          ans = ''.join(ans)
          break
        else:
          continue
print(ans)

Submission status: Runtime Error

Solution code:
s= input()
V = list(s)
X = [chr(ord('a') + i) for i in range(26)]

if len(s)<26:
  for i in range(26):
    count1 = s.count(X[i])
    if count1 >= 1:
      continue
    else:
      Nasi = X[i]
      break
  ans = s + Nasi
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    ans= -1
  else:
    for i in range(25, 0, -1):
        if V[i] > V[i-1]:
          ans = V[0:i-2]
          ans.append(min(V[i+1:26]))
          ans = ''.join(ans)
          break
        else:
          continue
print(ans)

Submission status: Runtime Error

Solution code:
s = s0 = input()
d = {chr(c) for c in range(97, 123)}
for c in s:
    d.remove(c)
if d:
    s += min(d)
else:
    for c in reversed(s):
        s = s[:-1]
        if d and c < min(d):
            s += min(d)
            break
        d.add(c)
print(s if s else -1)
assert s0 < s

Submission status: Runtime Error

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

if len(set(S)) < 26:
    for a in A:
        if a not in S:
            print(S+a)
            break
else:
    X = []
    for i in range(25, 0, -1):
        if S[i] > S[i-1]:
            X.sort()
            print(S[:i-1]+X[0])
            break
        else:
            X.append(S[i])
    else:
        print(-1)

Submission status: Runtime Error

Solution code:
S = input()
if len(S) < 26:
    for i in range(26):
        c = chr(i + ord('a'))
        if c not in S:
            print(S + c)
            break
else:
    tmp = 26
    for i in range(len(S) - 1, 0, -1):
        if ord(S[i - 1]) < ord(S[i]):
            break
        tmp = i
    tmp -= 1
    if tmp == 0:
        print(-1)
    c = ord(S[:tmp][-1])
    suf = S[tmp:]
    print(S[:tmp - 1] + chr(min([ord(si) for si in suf if ord(si) > c])))

Submission status: Runtime Error

Solution code:
import string

S = input()
alphabets = list(string.ascii_lowercase)
lastWord = ''.join(alphabets[::-1])
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i in S:
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
else:
    print('test')

Submission status: Runtime Error

Solution code:
import string

S = input()
alphabets = list(string.ascii_lowercase)
lastWord = ''.join(alphabets[::-1])
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i in S:
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
else:
    for j in range(26):
        if cnt[j] == 0:
            S += chr(ord('a')+j)
            print(S)
            break

Submission status: Runtime Error

Solution code:
import string

S = input()
alphabetsStr = string.ascii_lowercase
alphabets = list(map(lambda x: x, string.ascii_lowercase))
lastWord = ''.join(alphabets[::-1])
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i in S:
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
else:
    for j in range(26):
        if cnt[j] == 0:
            S += chr(ord('a')+j)
            print(S)
            break

Submission status: Runtime Error

Solution code:
A, B, X = list(map(int, input().split()))
if X - A <= B and X - A >= 0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
import string

S = input()
alphabetsStr = string.ascii_lowercase
alphabets = list(map(lambda x: x, string.ascii_lowercase))
lastWord = ''.join(alphabets[::-1])

if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i  in S:
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
# else:
#     for s in alphabets:
#         if s not in S:
#             print(S + s)
#             break

print(-1)

Submission status: Runtime Error

Solution code:
import string

S = input()
alphabetsStr = string.ascii_lowercase
alphabets = list(map(lambda x: x, string.ascii_lowercase))
lastWord = ''.join(alphabets[::-1])

if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i  in S:
            if alphabets[i] != S[i]:
                print(S[:i] + alphabets[i])
                break
else:
    for s in alphabets:
        if s not in S:
            print(S + s)
            break

Submission status: Runtime Error

Solution code:
import string


S = input()
retS = ''
alphabetsStr = string.ascii_lowercase
alphabets = list(map(lambda x: x, string.ascii_lowercase))
lastWord = ''.join(alphabets[::-1])

if len(S) == 26:
    if S == lastWord: print(-1)
    else:
        for i  in S:
            if alphabets[i] != S[i]:
                retS = S[:i] + alphabets[i]
                break
else:
    for s in alphabets:
        if s not in S:
            retS = S + s
            break
print(retS)

Submission status: Runtime Error

Solution code:
import string

S = input()

if len(S) == 26: print(-1)
retS = ''
alphabetsStr = string.ascii_lowercase
alphabets = list(map(lambda x: x, string.ascii_lowercase))
found = False
lenS = len(S)
if S[0] == 'a':
    for i in range(len(S)):
        if S[i] != alphabets[i]:
            retS = string.ascii_lowercase[:i+1]
            found = True
            break
else:
    idx = alphabets.index(S[0])
    for i in range(1, idx+1):
        if S[i] != alphabets[i-1]:
            retS = S[:i] + alphabets[i-1]
            found = True
            break
    if not found:
        for i in range(idx+1, len(S)):
            if S[i] != alphabets[i]:
                retS = string.ascii_lowercase[:i+1]
                found = True
                break
    
if not found: retS = S + alphabets[len(S)]
print(retS)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
num = int(raw_input())#数字を取得
num_of_digit = len(str(num)) #数字の桁数を取得
total = 0 #1が現れる回数
for i in range(num_of_digit):
    count = 0
    count  += (num // (10**(i+1)) +1) * 10**i
    if num % (10**(i+1)) < (10**i)*2:
        count -= min ((10**i)*2-(num % (10**(i+1))+1),10**i)
    total += count
print total

Submission status: Runtime Error

Solution code:
  # coding: utf-8
# Your code here!
eng_li = []
removed_list = []
all_letter = 26
for i in range (97,97+all_letter):
    eng_li.append(chr(i))

string = list(raw_input().strip())
length = len(string)
if length < all_letter:
    for i in string:
        eng_li.remove(i)
    string.append(eng_li[0])
    answer = "".join(string)
else:
    for i in range(all_letter-1):
        if ord(string[-1]) < ord(string[-2]) :
            removed_list.append(string[-1])
            string.pop()
        else:
            removed_list.append(string[-1])
            string.pop()
            removed_list=list(filter(lambda x:x>string[-1],sorted(removed_list)))
            string.pop()
            string.append(removed_list[0])
            answer ="".join(string)
            break
    else:
        answer = -1
print answer