Problem:


Score : 300 points

Problem Statement

Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible diverse words in lexicographical order.

A word is called diverse if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, atcoder, zscoder and agc are diverse words while gotou and connect aren't diverse words.

Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist.

Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Constraints

1 \leq |S| \leq 26

S is a diverse word.

Input

Input is given from Standard Input in the following format:

S

Output

Print the next word that appears after S in the dictionary, or -1 if it doesn't exist.

Sample Input 1

atcoder

Sample Output 1

atcoderb

atcoderb is the lexicographically smallest diverse word that is lexicographically larger than atcoder. Note that atcoderb is lexicographically smaller than b.

Sample Input 2

abc

Sample Output 2

abcd

Sample Input 3

zyxwvutsrqponmlkjihgfedcba

Sample Output 3

-1

This is the lexicographically largest diverse word, so the answer is -1.

Sample Input 4

abcdefghijklmnopqrstuvwzyx

Sample Output 4

abcdefghijklmnopqrstuvx



Sample input:
atcoder


Sample output:
atcoderb

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
    
alp_d = {chr(ord('a') + i): False for i in range(26)}
if n < 26:
    for si in s:
        alp_d[si] = True
    for k,v in alp_d.items():
        if not v:
            print(s+k)
            exit()

else:
    if s[0] == 'a':
        alps = 'abcdefghijklmnopqrstuvwxyz'
        ans = []
        for si,a in zip(s,alps):
            if si == a:
                ans.append(si)
            else:
                ans[-1] = a
                print(''.join(ans))
                exit()
    else:
        print('a')

    # alps = 'bacdefghijklnmopqrstuvwxyz'

Submission status: Wrong Answer

Solution code:
S = input().strip()
if len(S)<26:
    for i in range(97,123):
        if chr(i) not in S:
            print(S+chr(i))
            break
else:
    for j in range(24,-1,-1):
        if j==0 and S[j]=="z":
            print(-1)
            break
        a = S[j]
        if a=="z":continue
        b = chr(ord(a)+1)
        if j==0:
            print(b)
            break
        if b in S[:j]:continue
        print(S[:j]+b)
        break

Submission status: Wrong Answer

Solution code:
s = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
if len(s) < 26:
    for a in alp:
        if a not in s:
            print(s + a)
            exit()
else:
    c = s[-1]
    for i in range(25, -1, -1):
        if s[i] < c:
            print(s[:i] + c)
            exit()
        c = max(c, s[i])

    print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
if len(s) < 26:
    for a in alp:
        if a not in s:
            print(s + a)
            exit()
else:
    unko = []
    for i in range(25, 0, -1):
        unko.append(s[i])
        if s[i - 1] < s[i]:
            for c in sorted(unko):
                print(s[:i-1] + c)
                exit()
    print(-1)

Submission status: Wrong Answer

Solution code:
S = input().strip()
if len(S)<26:
    for i in range(97,123):
        if chr(i) not in S:
            print(S+chr(i))
            break
else:
    for j in range(24,-1,-1):
        if j==0 and S[j]=="z":
            print(-1)
            break
        a = S[j]
        if a=="z":continue
        b = chr(ord(a)+1)
        if b in S[:j]:continue
        print(S[:j]+b)
        break

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
c = Counter(s)
if len(s) < 26:
    for a in alp:
        if c[a] == 0:
            print(s + a)
            exit()
else:
    for i in range(len(s) - 2, -1, -1):
        if s[i] < s[-1]:
            print(s[:i] + s[-1])
            exit()
    print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
c = Counter(s)
if len(s) < 26:
    for a in alp:
        if c[a] == 0:
            print(s + a)
            exit()
else:
    # c1 c2 ... cx cy
    # cx > cyなら
    ita = -1
    for i in range(len(s) - 2, -1, -1):
        if s[i] < s[-1]:
            ita = i
            break
    if ita == -1:
        print(-1)
    else:
        print(s[:ita] + s[-1])

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase

S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()


not_used = [x for x in ascii_lowercase if x not in S]

if len(S) != 26:
    ans = S + not_used[0]
    print(ans)
else:
    memo = []
    for i in reversed(range(25)):
        memo.append(S[i+1])
        if S[i] < S[i+1]:
            memo.append(S[i])
            memo.sort()
            ans = S[:i] + memo[1]
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
c = Counter(s)
if len(s) < 26:
    for a in alp:
        if c[a] == 0:
            print(s + a)
            exit()
else:
    # c1 c2 ... cx cy
    # cx > cyなら
    s = list(s)
    ita = -1
    for i in range(len(s) - 2, -1, -1):
        if s[i] < s[-1]:
            ita = i
            break
    if ita == -1:
        print(-1)
    else:
        s[ita], s[-1] = s[-1], s[ita]
        print(''.join(s[:ita + 1]))

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) < 26:
    for a in ascii_lowercase:
        if a not in S:
            print(S + a)
            exit()
can = []
for i in range(25, 0, -1):
    can.append(S[i])
    if S[i - 1] < S[i]:
        print(S[:i - 1] + sorted(can)[0])
        exit()

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase

S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()


not_used = [x for x in ascii_lowercase if x not in S]

if len(S) != 26:
    ans = S + not_used[0]
    print(ans)
else:
    memo = []
    for i in reversed(range(25)):
        memo.append(S[i+1])
        if S[i] < S[i+1]:
            ans = S[:i] + memo[0]
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase
S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) < 26:
    for a in ascii_lowercase:
        if a not in S:
            print(S + a)
            exit()
for i in range(25, 0, -1):
    if S[i - 1] < S[i]:
        print(S[:i - 1] + chr(ord(S[i - 1]) + 1))
        exit()

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
    
alp_d = {chr(ord('a') + i): False for i in range(26)}
if n < 26:
    for si in s:
        alp_d[si] = True
    for k,v in alp_d.items():
        if not v:
            print(s+k)
            exit()

else:
    alps = 'abcdefghijklmnopqrstuvwxyz'
    ans = ''
    for si,a in zip(s,alps):
        if si == a:
            ans += si
        else:
            ans += a
            print(ans)
            exit()

Submission status: Wrong Answer

Solution code:
l='abcdefghijklmnopqrstuvwxyz'
d=[0]*26
s=input()
for i in s:
    x=l.index(i)
    d[x]+=1
f=0
x=''
for i in range(26):
    if(d[i]==0):
        f=1
        x=l[i]
        break
if(f==0):
    print(-1)
else:
    print(s+x)

Submission status: Wrong Answer

Solution code:
def char2int(c):
    return ord(c) - ord('a')


def int2char(i):
    return chr(i + ord('a'))


def main():
    S = input()
    # 全種類使ってない場合
    # 使っていない文字の中の最小の文字を付け加える
    #     afd -> afdb
    if len(S) < 26:
        used = [0] * 26
        for c in S:
            used[char2int(c)] = 1
        unused_min_c = int2char(min([i for i in range(26) if used[i] == 0]))
        print(S + unused_min_c)
    # 全種類使っている場合
    # 右から順に見ていって、S[i - 1] < max(S[i:]) なるiがあったら
    # S[i:]の中でS[i - 1]より大きい最小の文字でS[(i - 1):]を置き換える
    #     ....xvzwy -> ...xvzy
    else:
        if S == 'zyxwvutsrqponmlkjihgfedcba':
            print(-1)
        else:
            used = [0] * 26
            for i in range(len(S) - 1, 1, -1):
                used[char2int(S[i])] = 1
                target_char = None
                for j in range(26):
                    if used[j] == 0:
                        continue
                    c = int2char(j)
                    if c > S[i - 1]:
                        if target_char is None:
                            target_char = c
                        else:
                            target_char = min(target_char, c)
                if target_char is None:
                    continue
                print(S[:(i - 1)] + target_char)
                return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = list(input())
l = [chr(i) for i in range(ord("a"), ord("z") + 1)]
if len(s) == 26:
    if s == reversed(l):
        print(-1)
        exit()
    else:
        fi = False
        for i in range(26)[-2::-1]:
            if fi:
                break
            for j in range(25, i, -1):
                if s[i] < s[j]:
                    a = s[i]
                    s[i] = s[j]
                    s[j] = a
                    fi = True
                    break
        print("".join(s))
else:
    for i in range(26)[-1::-1]:
        if l[i] in s:
            del l[i]
    s.append(l[0])
    print("".join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
if len(s) == 26:
    print(-1)
    exit()
l = [chr(i) for i in range(ord("a"), ord("z") + 1)]
for i in range(26)[-1::-1]:
    if l[i] in s:
        del l[i]
s.append(l[0])
print("".join(s))

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

import string
s = v()

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

lis =list(string.ascii_lowercase)
nlis = [0]*26

for i in s:
    t = lis.index(i)
    nlis[t] += 1

if sum(nlis) != 26:
    for i in range(26):
        if nlis[i] == 0:
            print(s+lis[i])
            break
else:
    for i in range(25, -1, -1):
        for j in lis:
            if s[i] < j and j not in s[:i]:
                print(s[:i] + j)
                exit()
print(lis)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

s = v()

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()
if len(s) == 26:
    for i in range(26):
        if s[i] == "z":
            cnt = i
            break
    print(s[:cnt-1]+al[cnt])
else:
    ans = inf
    for i in range(len(s)):
        if s[i] != al[i]:
            ans = i
            break
    if ans == inf:
        ans = len(s)
    print(s+al[ans])

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

s = v()

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()
if len(s) == 26:
    for i in range(26):
        if s[i] == "z":
            cnt = i
            break
    print(s[:cnt-1]+al[cnt])
else:
    for i in range(len(s)):
        if s[i] != al[i]:
            ans = i
            break
    print(s+al[ans])

Submission status: Wrong Answer

Solution code:
import string
s = input()

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

lis =list(string.ascii_lowercase)
nlis = [0]*26

for i in s:
    t = lis.index(i)
    nlis[t] += 1

if sum(nlis) != 26:
    for i in range(26):
        if nlis[i] == 0:
            print(s+lis[i])
            break
else:
    for i in range(26):
        if s[i] != lis[i]:
            print(s[:i-1]+lis[i])
            break

Submission status: Wrong Answer

Solution code:
S = input()
a = 97
for i in range(26):
    if not chr(a + i) in S:
        S += chr(a + i)
        ans = S
        break
else:
    memo = [-1] * 200 #使える文字を記録
    while True:
        if memo[ord(S[-1]) + 1] == -1:
            memo[ord(S[-1])] = 1
            S = S[:-1]
        elif memo[ord(S[-1]) + 1] == 1:
            s = chr(ord(S[-1])+1)
            #S[-1] = chr(ord(S[-1]) + 1)
            S = S[:-1]
            S += s
            ans = S
            break
        if len(S) <= 0:
            ans = -1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
al='abcdefghijklmnopqrstuvwxyz'
if len(s)<=25:
  al=list(al)
  for i in range(len(s)):
    al.remove(s[i])
  print(s+al[0])
elif s=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
else:
  flg=-1
  for i in range(len(s)):
    if flg==-1 and s[i]!=al[i]:
      flg=i
    elif s[i]!=al[i]:
      break
  al2=list(al[i+1:])
  for j in range(i+1,len(s)):
    if s[j]==al[j]:
      al2.remove(s[j])
  if len(al2)==0:
    print(s[:i]+al[i])
  else:
    print(s[:i]+al2[0])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import string


def main():
    S = input()
    S_temp = S
    for i in range(len(S), 0, -1):
        for c in string.ascii_lowercase:
            if c not in S[:i]:
                S_temp = S[:i] + c
            if S < S_temp:
                break
        if S < S_temp:
            break
    print(S_temp if S < S_temp else -1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)

li = [False] * 26

for i in range(n):
    s1 = s[i]
    li[ord(s1) - ord('a')] = True

if n != 26:
    for i in range(26):
        if not li[i]:
            s += chr(ord('a') + i)
            print(s)
            exit()

else:
    if s == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        for i in range(2,27):
            s2 = s[-i:]
            if not all((s2[j] > s2[j+1] for j in range(i-1))):
                print(s[:-i] + chr(ord(s2[0])+1))
                exit()

Submission status: Wrong Answer

Solution code:
S=input()
l=""
for i in range(26):
    l+=chr(97+i)
#print(l)
if len(S)==26:
    if S=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        s=[]
        for i in range(26):
            s.append(ord(S[i])-96)
        #print(s)
        if s[0]!=26:
            anslist=[]
            for i in range(26):
                if s[i]==26:
                    t=s[:i]
                    t[-1]+=1
                    #print(t)
                    ans=""
                    for j in range(len(t)):
                        ans+=chr(t[j]+96)
                    print(ans)
                    exit()
                    
        else:
            anslist=[]
            for i in range(25):
                if s[i]-s[i+1]>=2:
                    t=s[:i+2]
                    t[-1]+=1
                    #print(t)
                    ans=""
                    for j in range(len(t)):
                        ans+=chr(t[j]+96)
                    #print(ans)
                    anslist.append(ans)
            anslist.sort()
            print(anslist[0])
                    
else:
    for i in l:
        if i not in S:
            ans= S + i
            print(ans)
            exit()

Submission status: Wrong Answer

Solution code:
S=input()
l=""
for i in range(26):
    l+=chr(97+i)
#print(l)
if len(S)==26:
    if S=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        s=[]
        for i in range(26):
            s.append(ord(S[i])-96)
        #print(s)
        if s[0]!=26:
            for i in range(26):
                if s[i]==26:
                    t=s[:i]
                    t[-1]+=1
                    #print(t)
                    ans=""
                    for j in range(len(t)):
                        ans+=chr(t[j]+96)
                    print(ans)
                    exit()
        else:
            for i in range(26):
                if s[i]-s[i+1]>=2:
                    t=s[:i+2]
                    t[-1]+=1
                    #print(t)
                    ans=""
                    for j in range(len(t)):
                        ans+=chr(t[j]+96)
                    print(ans)
                    exit()
                    exit()
else:
    for i in l:
        if i not in S:
            ans= S + i
            print(ans)
            exit()

Submission status: Wrong Answer

Solution code:
S = str(input())

if len(S)<=25:
    #未使用アルファベットで一番辞書順が早いものを1字加える
    all_alphabet_set = {chr(i) for i in range(97, 97+26)}
    not_used = all_alphabet_set - set(S)
    not_used = list(not_used)
    not_used.sort(reverse=True)
    ans = S + not_used.pop(-1)
    print(ans)
else:
    #最後の1文字を繰り上げ可能になるまでpopする
    S = list(S)
    while 1:
        last_letter = S.pop(-1)
        last_letter_next = chr(ord(last_letter)+1)
        #print(last_letter,last_letter_next)
        if last_letter_next not in S and last_letter_next != "{": #zの繰り上げを防ぐためにandする
            S.append(last_letter_next)
            print(''.join(map(str,S)))
            break
        elif len(S) == 0:
            print(-1)
            break

Submission status: Wrong Answer

Solution code:
s = input()

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

if len(s) < 26:
    for i in "abcdefghijklmnopqrstuvwxyz":
        if i not in s:
            print(s+i)
            exit()

else:
    l = s[-1]
    for i in range(1,len(s)):
        if s[-1-i] < l:
            print(s[:-1-i]+l)
            exit()
    print(chr(ord(s[0])+1))

Submission status: Wrong Answer

Solution code:
s = input()

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

if len(s) < 26:
    for i in "abcdefghijklmnopqrstuvwxyz":
        if i not in s:
            print(s+i)
            exit()

Submission status: Wrong Answer

Solution code:
s = input()

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

if len(s) < 26:
    for i in "abcdefghijklmnopqrstuvwxyz":
        if i not in s:
            print(s+i)
            exit()

else:
    l = s[-1]
    for i in range(1,len(s)):
        if s[-1-i] < l:
            print(s[:-1-i]+l)
            exit()

Submission status: Wrong Answer

Solution code:
S = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
if len(S) < 26:
    for char in alp:
        if not char in S:
            print(S+char)
            exit()
else:
    for i in range(1,26)[::-1]:
        if S[i-1] < S[i]:
            print(S[:i-1]+S[25])
            exit()
    print(-1)

Submission status: Wrong Answer

Solution code:
def next(x):
    return chr(ord(x)+1)

import sys

A=set([chr(ord("a")+k) for k in range(26)])
S=input()

if len(S)!=26:
    u=min(A-set(S))
    print(S+u)
    exit()

p=-1
for i in range(25):
    if S[i]<S[i+1]:
        p=i

if p==-1:
    print(-1)
else:
    T=S[:p-1]
    a=next(S[p])

    while a in T:
        a=next(a)
    print(T+a)

Submission status: Wrong Answer

Solution code:
import sys

S = sys.stdin.readline().strip()
ls = len(S)

if ls == 26 and list(S) == sorted(S, reverse=True):
    print(-1)
    sys.exit()

alpha = "abcdefghijklmnopqrstuvwxyz"
exists = set(S)
if ls < 26:
    for a in alpha:
        if a not in exists:
            print(S + a)
            sys.exit()
else:
    for i in range(ls):
        tmp = S[ls-1-i:] 
        if list(tmp) != sorted(tmp, reverse=True):
            break
    min_a = sorted(S[ls-i:])[0]
    print(S[:ls-i-1] + min_a)

Submission status: Wrong Answer

Solution code:
s = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"
ans = -1
for i in range(len(s)):
    t = s[:~i]
    dif = set(map(chr,range(ord(s[~i])+1,123))) - set(t)
    if dif:
        ans = t + min(dif)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"
dif = sorted(list(set(alphabet) - set(s)))
if len(dif):
    print(s + dif[0])
else:
    tmp = [s]
    for i in range(25):
        dif = sorted(list(set(alphabet) - set(s[:i])))
        tmp.append(s[:i-1] + dif[0])
    tmp.sort()
    i = tmp.index(s)
    if tmp[i] == tmp[i+1]:
        print(-1)
    else:
        print(tmp[i+1])

Submission status: Wrong Answer

Solution code:
import collections
s = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"
dif = sorted(list(set(alphabet) - set(s)))
if len(dif):
    print(s + dif[0])
else:
    tmp = [s]
    for i in range(25):
        dif = sorted(list(set(alphabet) - set(s[:i])))
        tmp.append(s[:i-1] + dif[0])
    tmp.sort()
    i = tmp.index(s)
    if tmp[i] == tmp[i+1]:
        print(-1)
    else:
        print(tmp[i])

Submission status: Wrong Answer

Solution code:
import collections
s = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"
dif = sorted(list(set(alphabet) - set(s)))
if len(dif):
    print(s + dif[0])
else:
    if alphabet[::-1] == s:
        print(-1)
    else:
        tmp = [s]
        for i in range(25):
            dif = sorted(list(set(alphabet) - set(s[:i])))
            tmp.append(s[:i-1] + dif[0])
        tmp.sort()
        print(tmp[tmp.index(s)+1])

Submission status: Wrong Answer

Solution code:
import collections
s = input()
alphabet = "abcdefghijknmlopqrstuvwxyz"
dif = sorted(list(set(alphabet) - set(s)))
if len(s) > 26:
    print(-1)
elif 0 < len(dif):
    if len(s) == len(set(s)):
        print(s + dif[0])
    else:
        print(-1)
else:
    if reversed(alphabet) == s:
        print(-1)
    else:
        tmp = [s]
        for i in range(25):
            if s[i] == alphabet[i]:
                continue
            else:
                tmp.append(s[:i-1] + alphabet[i])
        tmp.sort()
        print(tmp[tmp.index(s)+1])

Submission status: Wrong Answer

Solution code:
import collections
s = input()
alphabet = "abcdefghijknmlopqrstuvwxyz"
dif = sorted(list(set(alphabet) - set(s)))
if len(s) > 26:
    print(-1)
elif 0 < len(dif):
    if len(s) == len(set(s)):
        print(s + dif[0])
    else:
        print(-1)
else:
    if reversed(alphabet) == s:
        print(-1)
    else:
        tmp = [s]
        for i in range(25):
            if s[i] == alphabet[i]:
                continue
            else:
                tmp.append(s[:i] + alphabet[i])
        tmp.sort()
        print(tmp[tmp.index(s)-1])

Submission status: Wrong Answer

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

    if len(S) < 26:
        for a in [chr(ord("a")+i) for i in range(26)]:
            if a in S:
                continue
            print(S+a)
            return


    for i in range(len(S)):
        for a in [chr(j) for j in range(ord(S[-1-i]), ord("z"))]:
            if a in S[:len(S)-i]:
                continue
            print(S[:len(S)-i-1]+a)
            return

    else:
        print(-1)

solve()

Submission status: Wrong Answer

Solution code:
import math

s = input()

if len(s) == 26:
    print(-1)
    exit()

atz = list("abcdefghijklmnopqrstuvwxyz")

for i in range(26):
    if atz[i] in s:
        atz[i] = "-"

nxt = ""
for alp in atz:
    if alp != "-":
        nxt = alp
        break

print(s + nxt)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
s = input()
n = len(s)
ans = -1

if len(s) < 26:
    alphabet_ls = [chr(i) for i in range(97, 97+26)]
    alphabet_dict = defaultdict(int)
    for i in range(n):
        alphabet_dict[s[i]] = 1
    for alphabet in alphabet_ls:
        if alphabet_dict[alphabet] == 0:
            ans = s + alphabet
            break

else:
    stock_ls = []
    for i in range(25,0,-1):
        now = s[i]
        greater = []
        for stock in stock_ls:
            if now < stock:
                greater.append(stock)
        if greater:
            replacer = min(greater)
            ans = s[:i] + replacer
            break
        else:
            stock_ls.append(s[i])
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
a=set(list(s))
for i in range(26):
  if chr(ord("a")+i) not in a:
    print(s+chr(ord("a")+i))
    exit()
i=1
while i<len(s):
  if ord(s[-1])<ord(s[-1-i]):
      i+=1
  else:
    print(s[:-1-i]+s[-1])
    break
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
s=input()
ans=list(s)
a=set(ans)
h=-1
for i in range(26):
  if chr(ord("a")+i) not in a:
    print(s+chr(ord("a")+i))
    exit()

for i in range(len(s)):
  ss=s[-1-i]
  j=1
  while ord(ss)+j<ord("z"):
    if chr(ord(ss)+j) not in a:
      ans=ans[:-2-i]+[chr(ord(ss)+j)]
      print("".join(ans))
      h=i
      break
    j+=1
  
  a.remove(ss)
  if h!=-1:break
if h==-1:
  print(-1)
  exit()

Submission status: Wrong Answer

Solution code:
s = list(input())
kouho = ["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 i in s:
    kouho.remove(i)
if kouho == []:
    kouho.append(s.pop(-1))
    for i in range(24):
        dum = s.pop(-1)
        if dum < kouho[0]:
            s.append(kouho[0])
            break
        else:
            kouho.append(dum)
            kouho.sort()
    if s[0] == "z":
        print(-1)
    else:
        print("".join(s))
else:
    s.append(kouho[0])
    print("".join(s))

Submission status: Wrong Answer

Solution code:
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

A = list("abcdefghijklmnopqrstuvwxyz")
if len(S) < 26:
    for i in A:
        if i not in S:
            print(S+i)
            exit()

for i in range(24,0,-1):
    if S[i] != max(S[i:]):
        print(S[:i]+min(S[i+1:]))
        exit()
print(A[A.index(S[0]) + 1])

Submission status: Wrong Answer

Solution code:
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

A = list("abcdefghijklmnopqrstuvwxyz")
if len(S) < 26:
    for i in A:
        if i not in S:
            print(S+i)
            exit()

for i in range(24,1,-1):
    if S[i] != max(S[i:]):
        print(S[:i]+min(S[i+1:]))
        exit()
print(A[A.index(S[0]) + 1])

Submission status: Wrong Answer

Solution code:
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

A = list("abcdefghijklmnopqrstuvwxyz")
if len(S) < 26:
    for i in A:
        if i not in S:
            print(S+i)
            exit()

for i in range(24,1,-1):
    if S[i] != max(S[i:]):
        print(S[:i]+min(S[i+1:]))
        exit()
print(S[1])

Submission status: Wrong Answer

Solution code:
s = input()

set1 = set([chr(i+97) for i in range(26)])
set2 = set(s)
li = sorted(list(set1.difference(set2)))
#print(li)

if len(s) > 26 or s[0] == "z":
    print(-1)
    exit()

idx = 0
ans = ""
if "z" in s:
    idx = s.index("z")
    ans = s[:idx-1] + chr(ord(s[idx-1])+1)
    print(ans)
    exit()
else:
    ans = s + li[0]
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

A = list("abcdefghijklmnopqrstuvwxyz")
if len(S) < 26:
    for i in A:
        if i not in S:
            print(S+i)
            exit()

for i in range(24,-1,-1):
    if S[i] != max(S[i:]):
        print(S[:i]+min(S[i+1:]))
        exit()

Submission status: Wrong Answer

Solution code:
s = list(input())
arufa = ["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 i in s:
    arufa.remove(i)
if arufa == []:
    dum = sorted(s,reverse=1)
    if dum == s:
        print(-1)
    else:
        arufa.append(s.pop(-1))
        for i in range(27):
            arufa.sort()
            if s == []:
                s.append(arufa[0])
                break
            if s[-1] < arufa[0]:
                s.pop(-1)
                s.append(arufa[0])
                break
            #for j in range(len(arufa)):
            #    if s[-1] < arufa[i]:
            #        s.append(arufa[0])
            #        print("".join(s))
            #        exit()
            if 1 == len(s):
                s.clear()
                s.append(arufa[-1])
                break
            arufa.append(s.pop(-1))
        print("".join(s))

else:
    s.append(arufa[0])
    print("".join(s))

Submission status: Wrong Answer

Solution code:
import sys
s = input()

if len(s) < 26:
    for i in range(ord('a'), ord('z')+1):
        if not chr(i) in s:
            print(s+chr(i))
            break
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    for i in range(1, 26):
        if ord(s[-i]) > ord(s[-i-1]):
            val = ord('z')+1
            for j in s[-i:]:
                val = min(ord(j), val)
            print(s[:-i-1]+chr(val))
            break

Submission status: Wrong Answer

Solution code:
import sys
s = input()

if len(s) < 26:
    for i in range(ord('a'), ord('z')+1):
        if not chr(i) in s:
            print(s+chr(i))
            break
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    num = s.index('z')
    a = sorted(s[num-1:])
    print(s[:num-1]+a[1])

Submission status: Wrong Answer

Solution code:
import sys
s = input()

if len(s) < 26:
    for i in range(ord('a'), ord('z')+1):
        if not chr(i) in s:
            print(s+chr(i))
            sys.exit()

elif ord(s[0]) < ord(s[1]):
    for i in range(25):
        if ord(s[i])+1 > ord('z'):
            continue
        elif chr(ord(s[i])+1) == s[i+1]:
            continue
        else:
            print(s[:i]+chr(ord(s[i])+1))
            sys.exit()

else:
    for i in range(25):
        if ord(s[i])-1 < ord('z'):
            continue
        elif chr(ord(s[i])-1) == s[i+1]:
            continue
        else:
            print(s[:i]+chr(ord(s[i])-1))
            sys.exit()
            
print(-1)