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:
#print([chr(ord('a') + i) for i in range(26)])
#print([chr(i) for i in range(97, 97+26)])
import sys
import bisect
li = [chr(i) for i in range(97, 97+26)]
s = input()
if len(s)<26:
    for l in li:
        if l not in s:
            print(s+l)
            sys.exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    r = s[::-1]
    tmp = ''
    kabe = ''
    for i,rr in enumerate(r):
        if i == 0:
            continue
        if rr < r[i-1]:
            tmp = r[:i+1][::-1]
            kabe = rr
            break
    print(tmp) #wzyx

    tmp_li = list(tmp)
    tmp_li.sort()
    ind = bisect.bisect_left(tmp_li, kabe)
    s0 = tmp_li[ind+1]
    #s0 = tmp_li[1]
    print(s.replace(tmp, s0))

Submission status: Wrong Answer

Solution code:
#print([chr(ord('a') + i) for i in range(26)])
#print([chr(i) for i in range(97, 97+26)])
import sys
li = [chr(i) for i in range(97, 97+26)]
s = input()
if len(s)<26:
    for l in li:
        if l not in s:
            print(s+l)
            sys.exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    r = s[::-1]
    tmp = ''
    for i,rr in enumerate(r):
        if i == 0:
            continue
        if rr < r[i-1]:
            tmp = r[:i+1][::-1]
            break
    #print(tmp) wzyx

    #tmp_li = list(tmp)
    #tmp_li.sort()
    #s0 = tmp_li[1]
    #print(s.replace(tmp, s0))

    #print(tmp_li)
    #print(s - tmp + tmp[-1])
    xx = list(tmp[1:])
    xx.sort()
    print(s[:26-len(tmp)] + xx[0])

Submission status: Wrong Answer

Solution code:
#print([chr(ord('a') + i) for i in range(26)])
#print([chr(i) for i in range(97, 97+26)])
import sys
li = [chr(i) for i in range(97, 97+26)]
s = input()
if len(s)<26:
    for l in li:
        if l not in s:
            print(s+l)
            sys.exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    r = s[::-1]
    tmp = ''
    for i,rr in enumerate(r):
        if i == 0:
            continue
        if rr < r[i-1]:
            tmp = r[:i+1][::-1]
            break
    #print(tmp) wzyx

    #tmp_li = list(tmp)
    #tmp_li.sort()
    #s0 = tmp_li[1]
    #print(s.replace(tmp, s0))

    #print(tmp_li)
    #print(s - tmp + tmp[-1])
    print(s[:26-len(tmp)] + tmp[-1])

Submission status: Wrong Answer

Solution code:
#print([chr(ord('a') + i) for i in range(26)])
#print([chr(i) for i in range(97, 97+26)])
import sys
li = [chr(i) for i in range(97, 97+26)]
s = input()
if len(s)<26:
    for l in li:
        if l not in s:
            print(s+l)
            sys.exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    r = s[::-1]
    tmp = ''
    for i,rr in enumerate(r):
        if i == 0:
            continue
        if rr < r[i-1]:
            tmp = r[:i+1][::-1]
            break
    #print(tmp) wzyx
    tmp_li = list(tmp)
    tmp_li.sort()
    s0 = tmp_li[1]
    print(s.replace(tmp, s0))

Submission status: Wrong Answer

Solution code:
#print([chr(ord('a') + i) for i in range(26)])
#print([chr(i) for i in range(97, 97+26)])
import sys
li = [chr(i) for i in range(97, 97+26)]
s = input()
if len(s)<26:
    for l in li:
        if l not in s:
            print(s+l)
            sys.exit()
elif s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    r = s[::-1]
    tmp = ''
    for i,rr in enumerate(r):
        if i == 0:
            continue
        if rr < r[i-1]:
            tmp = r[:i+1][::-1]
            break
    #print(tmp) wzyx
    print(s.replace(tmp, tmp[-1]))
    #print(s - tmp + tmp[-1])

Submission status: Wrong Answer

Solution code:
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      q=S[25-i:]
      q2=[]
      for j in q:
        if ord(j)<ord(S[24-i]):
          pass
        else:
          q2+=[ord(j)]
      q2.sort()
      
      S=S[:24-i]+chr(q2[0])
      print(S)
      break
    if i==25:
      print(-1)
    
else:
  print(S+s[0])

Submission status: Wrong Answer

Solution code:
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      S=S[:24-i]+chr(ord(S[24-i])+1)
      print(S)
      break
    if i==25:
      print(-1)
    
else:
  print(S+s[0])

Submission status: Wrong Answer

Solution code:
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      S=S[:24-i]+chr((ord(S[24-i])+1-97)%26+97)
      break
  print(S)
else:
  print(S+s[0])

Submission status: Wrong Answer

Solution code:
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      s2=[]
      for j in range(26):
        s2=s2+[chr(97+j)]
      for j in range(24-i):
        s2.remove(S[j])
      S=S[:24-i]+s2[0]
      print(S)
      break
    if i==24:
      print(-1)
else:
  print(S+s[0])

Submission status: Wrong Answer

Solution code:
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      S=S[:24-i]+chr((ord(S[24-i])+1-97)%26+97)
      print(S)
      break
    if i==24:
      print(-1)
else:
  print(S+s[0])

Submission status: Wrong Answer

Solution code:
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      S=S[:24-i]+chr((ord(S[24-i])+1-97)%26+97)
      break
  print(S)
else:
  print(S+s[0])

Submission status: Wrong Answer

Solution code:
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  print(-1)
else:
  print(S+s[0])

Submission status: Wrong Answer

Solution code:
alp=[chr(ord('a') + i) for i in range(26)]
unused=set(alp)
     
S=input()
print("len",len(S))

if len(S)<26:
    for i in range(len(S)):
        if S[i] in unused:
            unused.remove(S[i])
    unused=sorted(unused)
    print(S+unused[0])
else:
    for j in range(len(S)-1,-1,-1):
        p=set(S[j:])
        #print(p)
        q=sorted(p)
        if S[j]==q[-1]:
            pass
        else:
            idx=q.index(S[j])
            print(S[:j]+q[idx+1])
            break
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    s = input()
    S = list(s)
    A = list(reversed(list("zyxwvutsrqponmlkjihgfedcba")))
    for i in range(26):
        if A[i] not in S:
            S.append(A[i])
            print(*S, sep="")
            return
    else:
        if s == "zyxwvutsrqponmlkjihgfedcba":
            print(-1)
        else:
            z = S.index("z")
            D = S[: z - 1]
            for i in range(26):
                if A[i] not in D and A[i] != S[z - 1]:
                    D.append(A[i])
                    print(*D, sep="")
                    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    s = input()
    S = list(s)
    A = list(reversed(list("zyxwvutsrqponmlkjihgfedcba")))
    N = len(S)
    for i in range(26):
        if A[i] not in S:
            S.append(A[i])
            print(*S, sep="")
            return
    else:
        if s == "zyxwvutsrqponmlkjihgfedcba":
            print(-1)
        else:
            z = S.index("z")
            S = S[:z]
            for i in range(26):
                if A[i] not in S:
                    S.append(A[i])
                    print(*S, sep="")
                    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return "".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = list(input())[:-1]

ans = ""

po = [0 for i in range(26)]

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

if len(s) == 26:
    for i in range(25,-1,-1):
        if i == 25:
            po[ord(s[-1])-97] = 1
            continue
        else:
            if s[i] > s[i+1]:
                #po[ord(s[i])-97] = 1
                po[ord(s[i+1])-97] = 1
            else:
                ans = jo(s[:i])
                for j in range(26):
                    if po[j] and ord(s[i])-97 < j:
                        ans += chr(97+j)
                        break
                

                break


else:
    for i in range(len(s)):
        on = ord(s[i])-97
        if po[on] == 0:
            ans += s[i]
            po[on] = 1
    for j in range(26):
        if po[j] == 0:
            ans += chr(97+j)
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return "".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = list(input())[:-1]

ans = ""

po = [0 for i in range(26)]

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

if len(s) == 26:
    for i in range(25,-1,-1):
        if i == 25:
            po[-1] = 1
            continue
        else:
            if s[i] > s[i+1]:
                #po[ord(s[i])-97] = 1
                po[ord(s[i+1])-97] = 1
            else:
                ans = jo(s[:i])
                for j in range(26):
                    if po[j] and ord(s[i])-97 < j:
                        ans += chr(97+j)
                        break
                

                break


else:
    for i in range(len(s)):
        on = ord(s[i])-97
        if po[on] == 0:
            ans += s[i]
            po[on] = 1
    for j in range(26):
        if po[j] == 0:
            ans += chr(97+j)
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return "".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = list(input())[:-1]

ans = ""

po = [0 for i in range(26)]

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

if len(s) == 26:
    for i in range(25,-1,-1):
        if i == 25:
            continue
        else:
            if s[i] > s[i+1]:
                #po[ord(s[i])-97] = 1
                po[ord(s[i+1])-97] = 1
            else:
                if i == 24:
                    i += 1
                ans = jo(s[:i])
                for j in range(26):
                    if po[j] and ord(s[i])-97 < j:
                        ans += chr(97+j)
                        break
                

                break


else:
    for i in range(len(s)):
        on = ord(s[i])-97
        if po[on] == 0:
            ans += s[i]
            po[on] = 1
    for j in range(26):
        if po[j] == 0:
            ans += chr(97+j)
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return "".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = list(input())[:-1]

ans = ""

po = [0 for i in range(26)]

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

if len(s) == 26:
    for i in range(25,-1,-1):
        if i == 25:
            continue
        else:
            if s[i] > s[i+1]:
                po[ord(s[i])-97] = 1
                po[ord(s[i+1])-97] = 1
            else:
                ans = jo(s[:i])
                for j in range(26):
                    if po[j]:
                        ans += chr(97+j)
                        break
                break


else:
    for i in range(len(s)):
        on = ord(s[i])-97
        if po[on] == 0:
            ans += s[i]
            po[on] = 1
    for j in range(26):
        if po[j] == 0:
            ans += chr(97+j)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
if len(S) == 26:
    print(-1)
else:
    l = [False for i in range(26)]
    for s in S:
        l[ord(s)-ord('a')] = True
    for i in range(26):
        if l[i] == False:
            print(S+chr(ord('a') + i))
            break

Submission status: Wrong Answer

Solution code:
import collections
S = input()

if(S == "zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    exit()
    
alp = "abcdefghijklmnopqrstuvwxyz"
r = S[::-1]

c = collections.Counter(S)
c_s = sorted(c.items(), key=lambda x:x[0])
tmp = ""

for i in range(len(c_s)):
    tmp += c_s[i][0]

if(len(S) < 26):
    for i in range(len(alp)):
        if(alp[i] not in tmp):
            print(S+alp[i])
            break
else:
    for i in range(len(S)-1):
        if(r[i] > r[i+1]):
            cha = sorted(r[:(i+1)])[0]
            print(S[:(len(S)-i-2)]+cha)
            break

Submission status: Wrong Answer

Solution code:
import collections
S = input()

if(S == "zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    exit()
    
alp = "abcdefghijklmnopqrstuvwxyz"
r = S[::-1]

c = collections.Counter(S)
c_s = sorted(c.items(), key=lambda x:x[0])
tmp = ""

for i in range(len(c_s)):
    tmp += c_s[i][0]

if(len(S) < 26):
    for i in range(len(alp)):
        if(alp[i] not in tmp):
            print(S+alp[i])
            break
else:
    for i in range(len(S)-1):
        if(r[i] > r[i+1]):
            cha = sorted(r[:(i+1)])[0]
            print(r[:(i+1)])
            print(sorted(r[:(i+1)]))
            print(S[:(len(S)-i-2)]+cha)
            break

Submission status: Wrong Answer

Solution code:
import collections
S = input()

if(S == "zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    exit()
    
alp = "abcdefghijklmnopqrstuvwxyz"
r = S[::-1]

c = collections.Counter(S)
c_s = sorted(c.items(), key=lambda x:x[0])
tmp = ""

cha = "z"
for i in range(len(c_s)):
    tmp += c_s[i][0]

if(len(S) < 26):
    for i in range(len(alp)):
        if(alp[i] not in tmp):
            print(S+alp[i])
            break
else:
    for i in range(len(S)-1):
        if(r[i] > r[i+1]):
            cha = sorted(r[:(i+1)])[0]
            #print(r[:(i+1)])
            print(S[:(len(S)-i-2)]+cha)
            break

Submission status: Wrong Answer

Solution code:
import collections
S = input()

if(S == "zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    exit()
    
alp = "abcdefghijklmnopqrstuvwxyz"
r = S[::-1]

c = collections.Counter(S)
c_s = sorted(c.items(), key=lambda x:x[0])
tmp = ""

cha = "z"
for i in range(len(c_s)):
    tmp += c_s[i][0]

if(len(S) < 26):
    for i in range(len(alp)):
        if(alp[i] not in tmp):
            print(S+alp[i])
            break
else:
    for i in range(len(S)-1):
        if(r[i] > r[i+1]):
            for j in range(i):
                if(cha > r[j]):
                    cha = r[j]
            print(S[:(len(S)-i-2)]+cha)
            break

Submission status: Wrong Answer

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

S = input()

if S == "zyxwvutsrqponmlkjihgfedcba":
	print(-1)
elif len(S) < len(ascii_lowercase):
	for char in ascii_lowercase:
		if char not in S:
			print(S+char)
			break
else:
	S = S[::-1]
	for i in range(len(S)-1):
		if S[i+1] < S[i]:
			print(S[::-1][:-i-2]+min(S[:i+1]))
			break

Submission status: Wrong Answer

Solution code:
s = input()
c = list(s)
c2 = set(c)
al = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
#26文字未満なら追加
#26文字なら末尾を使えるところに入れる?
if len(c)<26:
    for i in range(26):
        if al[i] not in c2:
            print(s+al[i])
            exit()

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

rev = "zyxwvutsrqponmlkjihgfedcba"
for i in range(25,-1,-1):
    if ord(s[i])<ord(s[-1]):
        print(s[:i]+s[-1])
        exit()

Submission status: Wrong Answer

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

if len(S_set) == len(C_set):
    S = list(S)
    p = None
    for i in range(len(S) - 2, -1, -1):
        if S[i] < S[i + 1]:
            p = i
            break
    else:
        p = 0

    if p == 0:
        print(-1)
    else:
        ans = S[:p].copy()
        rest = C_set - set(S[: p + 1])
        rest = sorted(rest)
        for r in rest:
            if S[p] < r:
                ans.append(r)
                break
        print(*ans, sep="")
else:
    diff = C_set - S_set
    diff = sorted(diff)
    print(S + diff[0])

Submission status: Wrong Answer

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

if len(S_set) == len(C_set):
    S = list(S)
    p = None
    for i in range(len(S) - 2, -1, -1):
        if S[i] < S[i + 1]:
            p = i
            break
    else:
        p = 0

    if p == 0:
        print(-1)
    else:
        ans = S[:p].copy()
        rest = C_set - set(S[: p + 1])
        rest = sorted(rest)
        ans.append(rest[0])
        print(*ans, sep="")
else:
    diff = C_set - S_set
    diff = sorted(diff)
    print(S + diff[0])

Submission status: Wrong Answer

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

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(S_set) == len(C_set):
    S = list(S)
    for i in range(len(S) - 1):
        if S[i] < S[i + 1]:
            continue
        else:
            c = sorted(S[i:])[0]
            ans = S[:i].copy() + [c]
            print(*ans, sep="")
            break
else:
    diff = C_set - S_set
    diff = sorted(diff)
    print(S + diff[0])

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc022/tasks/agc022_a

from string import ascii_lowercase

s = input()
rems = [c for c in ascii_lowercase if c not in s]

if len(rems) > 0:
    print("{}{}".format(s, rems[0]))
    exit()
else:
    # 前から見ていって，+1するところがあれば，それをいれる
    ans = ''
    for idx in range(len(s) - 1):
        ii = ascii_lowercase.index(s[idx])
        jj = ascii_lowercase.index(s[idx + 1])
        if abs(ii - jj) == 1:
            ans += s[idx]
        else:
            idxx = ascii_lowercase.index(s[idx - 1])
            remm = ascii_lowercase[idx + 1:]
            ans += remm[0]
            print(ans)
            exit()
            # print(remm)
            # print(ii, jj, s[idx], s[idx + 1])
            # print(">")
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
s = list(input())
alph = [chr(i) for i in range(97, 123)]
alph_count = [0] * 26
for i in s:
    alph_count[alph.index(i)] = 1
ans = ["-1"]
if len(s) != 26:
    for i in range(26):
        if alph_count[i] == 0:
            ans = s + [alph[i]]
            break
else:
    for i in range(25, -1, -1):
        c = -1
        for j in range(26):
            if s[i] == alph[j]:
                c = j
            if not c == -1:
                if alph_count[j] == 0:
                    s[i] = alph[j]
                    ans = s[0 : j]
            if not ans[0] == "-1":
                break
        alph_count[c] = 0
        if not ans[0] == "-1":
            break
print("".join(ans))

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
if N == 26:
    if S == list("zyxwvutsrqponmlkjihgfedcba"):
        print(-1)
    else:
        O = [0]*(N+1)
        for i in range(N):
            O[i] = ord(S[i])

        for i in range(N)[::-1]:
            co = [0]*N
            for j in range(N):
                co[j] = O[j]
            if co[i] == 122:
                continue
            co[i] += 1
            if len(set(co[0:i+1])) == len(co[0:i+1]):
                ans = co[0:i+1]
                break

        for i in range(len(ans)):
            ans[i] = chr(ans[i])

        cans = "".join(ans)
        print(cans)

else:
    #a97 z122
    O = [0]*(N+1)
    for i in range(N):
        O[i] = ord(S[i])

    for i in range(97,123):
        if i not in O:
            last = i
            break 
    
    O[N] = i

    for i in range(N+1):
        O[i] = chr(O[i])
    
    ans = "".join(O)
    print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())

def ask_next(s):
  for i in range(ord('a'), ord('z')+1):
    if chr(i) not in s:
      return chr(i)
  return None

ans = ''
if len(s) < 26:
  ans = s + ask_next(s)
else:
  for i in range(24, -1, -1):
    if ord(s[i]) < ord(s[i+1]):
      ans = s[:i] + ask_next(s[:i+1])
      break

if ans: print(ans)
else: print(-1)

Submission status: Wrong Answer

Solution code:
ch = 97
s = input()
if len(s) != 26:
    for i in range(26):
        s_ = chr(ch+i)
        if s_ not in s:
            print(s + s_)
            exit()
if len(s) == 26:
    if s == "".join([chr(ch + i) for i in reversed(range(26))]):
        print(-1)
        exit()
    else:
        for i, si in enumerate(s):
            if si == chr(ch+i):
                continue
            else:
                p = sorted([j for j in s[i:]])[0]
                print(s[:i-1] + p)
                exit()

Submission status: Wrong Answer

Solution code:
ch = 97
s = input()
if len(s) != 26:
    for i in range(26):
        s_ = chr(ch+i)
        if s_ not in s:
            print(s + s_)
            exit()
if len(s) == 26 and s == "".join([chr(ch + i) for i in reversed(range(26))]):
    print(-1)
    exit()
w = ""
for i, si in enumerate(s):
    if si == chr(ch+i):
        continue
    else:
        print(s[:i-1] + chr(ch+i))
        exit()

Submission status: Wrong Answer

Solution code:
#辞書順
#a<b,a*<b(先頭が大きいため)
#a
from itertools import permutations
S=input()
N=len(S)
alp=[0]*26
searched=[0]*26
flag=0
c=0
sub=100
minsub=100
#zxywvutsrqponmlkjihgfedcba→
for i in range(N):
    alp[ord(S[i])-97]=alp[ord(S[i])-97]+1
    #print(alp)
if (max(alp)!=1)or(S=="zyxwvutsrqponmlkjihgfedcba"):
    flag=0
else:
    if N!=26:
        for i in range(26):
            if alp[i]==0:
                c=chr(97+i)
                S="".join((S,c))
                flag=1
                break
    else:
        for i in range(N-1):
            if ord(S[i])>ord(S[i+1]):
                break
        s=S[i+1:]
        #print(s)
        while True:
            if len(s)==0:
                i=i-1
                s=S[i+1:]
            elif len(s)==1:
                i=i-1
                s=S[i+1:]
            else:
                piv=s[0]
                #print(s,S[:i+1],piv)
                for j in range(len(s)-1):
                    if ord(s[j+1])>ord(piv):
                        sub=ord(s[j+1])-ord(piv)
                        #print(sub)
                        if sub<minsub:
                            minsub=sub
                if (minsub!=100):
                    #print(minsub,chr(ord(piv)+minsub))
                    S="".join((S[:i+1],chr(ord(piv)+minsub)))
                    flag=1
                    break

                minsub=100
                sub=0
                i=i-1
                s=S[i+1:]

if flag==0:
    print("-1")
else:
    print(S)

Submission status: Wrong Answer

Solution code:
s = str(input())
ans = ''
if len(s) < 26:
  for i in range(ord('a'), ord('z')+1):
    if chr(i) not in s:
      ans = s + chr(i)
      break
else:
  for i in range(24, -1, -1):
    if ord(s[i]) < ord(s[i+1]):
      ans = s[:i] + chr(ord(s[i]) + 1)
      break
if ans: print(ans)
else: print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
list_s = list(s)
len_s = len(list_s)
check = ['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 range(26):
    if check[i] not in list_s:
        print(s + check[i])
        exit()
for i in range(1, len_s):
    memo = list_s.pop(len_s - i)
    for j in range(check.index(memo) + 1, 26):
        if check[j] not in list_s:
            print(s[:26 - i] + check[j])
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
list_s = list(s)
len_s = len(list_s)
s_sort = sorted(list_s)
check = ['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 range(26):
    if check[i] not in s_sort:
        print(s + check[i])
        exit()
for i in range(1, len_s):
    s_sort.remove(list_s[len_s - i])
    for j in range(check.index(s[len_s - i]) + 1, 26):
        if check[j] not in s_sort:
            print(s[:j - 1] + check[j])
            exit()
print(-1)

Submission status: Wrong Answer

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

for i in range(n):
    for j in range(ord("a"), ord("z")+1):
        if not (chr(j) in s) and \
            s + chr(j) != s_origin and \
                s_origin < s + chr(j):
            print(s + chr(j))
            exit()
    s = s[:-1]

print(-1)

Submission status: Wrong Answer

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

for i in range(n):
    for j in range(ord("a"), ord("z")+1):
        string = chr(j)
        if not (chr(j) in s) and \
            not(s + chr(j) in s_origin) and \
                s_origin < s + chr(j):
            print(s + chr(j))
            exit()
    s = s[:-1]

print(-1)