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:
word = input()
alphabet = set('abcdefghijklmnopqrstuvwxyz')
used = set(word)
available = alphabet - used

if available:
    print(word + sorted(list(available))[0])
else:
    available.add(word[-1])
    word = word[:-1]
    for i in reversed(range(len(word)-1)):
        kouho = sorted(list(available))[0]
        if word[-1] < kouho:
            word = word[:-1] + kouho
            print(word)
            break
        available.add(word[-1])
        word = word[:-1]
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
s=input()
t="abcdefghijklmnopqrstuvwxyz"
if s==t[::-1]:print(-1);exit()
if len(s)<26:
  for i in t:
    if not i in s:print(s+i);exit()
else:
  for i in range(25):
    if s[-i-2]<s[-1-i]:
      t=s[:-i-2]
      a=sorted(list(s[-1-i:]))
      print(t+a[0]);exit()

Submission status: Wrong Answer

Solution code:
s=input()
t="abcdefghijklmnopqrstuvwxyz"
if s==t[::-1]:print(-1);exit()
if len(s)<26:
  for i in t:
    if not i in s:print(s+i);exit()
else:
  for i in range(25):
    if s[-i-2]<s[-1-i]:
      t=s[:-i-1]
      a=sorted(list(s[-1-i:]))
      print(t+a[0]);exit()

Submission status: Wrong Answer

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

S = input()

end = "abcdefghijklmnopqrstuvwxyz"[::-1]

if S == end:
  print(-1)
  exit()

lastChar = S[-1]
set_used = set(S)

if len(S)<len(end): #付け加える文字が残っている場合
  for i in range(ord('a'), ord('z')+1):
    if not chr(i) in set_used:
      print(S + chr(i))
      exit()
else: #全文字使っている場合、全探索
  prevord = -1
  for i, c in enumerate(S[::-1]): #iは後ろから何文字目か(0-indexed)
    if ord(c)<prevord: #Si, Si+1が昇順だったら
      #Siを、i-1までで一度も使っていない一番若い文字に変える
      ansS_exceptLast = S[0:-i-1]
      for cc in (ord(c)+1, ord('z')+1):
        if not chr(cc) in ansS_exceptLast:
          print(ansS_exceptLast+chr(cc))
          exit()
    else:
      prevord = ord(c)

Submission status: Wrong Answer

Solution code:
wrd = [chr(i+97) for i in range(26)]
S = input()
ans = ''
for s in S:
    wrd.remove(s)

if(S=='zyxwvutsrqponmlkjihgfedcba'):
    print(-1)
elif(len(S)<26):
    print(S+wrd[0])
else:
    '''
    min_s = S[-1]
    for i in range(len(S)-1,-1,-1):
        if(min_s>S[i]):
            ans = S[:i]+min_s
            break
    '''
    print(ans)

Submission status: Wrong Answer

Solution code:
wrd = [chr(i+97) for i in range(26)]
S = input()
ans = ''
for s in S:
    wrd.remove(s)

if(S=='zyxwvutsrqponmlkjihgfedcba'):
    print(-1)
elif(len(S)<26):
    print(S+wrd[0])
else:
    min_s = S[-1]
    for i in range(len(S)-1,-1,-1):
        if(min_s>S[i]):
            ans = S[:i]+min_s
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
wrd = [chr(i+97) for i in range(26)]
S = input()
flag = False
ans = ''
for s in S:
    if(s in wrd):
        wrd.remove(s)
    else:
        flag = True
        break

if(S=='zyxwvutsrqponmlkjihgfedcba' or flag):
    print(-1)
elif(len(S)<26):
    print(S+wrd[0])
else:
    min_s = S[-1]
    for i in range(len(S)-1,-1,-1):
        if(min_s>S[i]):
            ans = S[:i]+min_s
            break
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
length_s =len(s)
alphabet_small = [chr(i) for i in range(97, 97+26)]
if length_s < 26:
    for alphabet in alphabet_small:
        if alphabet not in s:
            print(s+alphabet)
            exit()
for i in range(length_s-1):
    if s[i] > s[i+1]:
        ans = s[:i-1] + min(s[i+1:])
        print(ans)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
S = input()

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

set_char = set("abcdefghijklmnopqrstuvwxyz") - set(S)
if 0 == len(set_char):
	for i in range(1, 26 + 1):
		#print(min(set_char))
		if set_char and ord(S[-i]) < ord(min(set_char)):
			print(S[: - i] + min(set_char))
			break
		set_char |= {S[-i]}
else:
	print(S + min(set_char))

Submission status: Wrong Answer

Solution code:
S = input()

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

set_char = sorted(set("abcdefghijklmnopqrstuvwxyz") - set(S))
if 0 == len(set_char):
	for i in range(1, 26 + 1):
		#print(min(set_char))
		if set_char and ord(S[-i]) < ord(min(set_char)):
			print(S[: - i] + min(set_char))
			break
		set_char += {S[-i]}
else:
	print(S + min(set_char[0]))

Submission status: Wrong Answer

Solution code:
S = input()

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

set_char = sorted(set("abcdefghijklmnopqrstuvwxyz") - set(S))
if 0 == len(set_char):
	for i in range(1, 26 + 1):
		#print(min(set_char))
		if set_char and ord(S[-i]) < ord(min(set_char)):
			print(S[: - i] + min(set_char))
			break
		set_char += {S[-i]}
else:
	print(S + set_char[0])

Submission status: Wrong Answer

Solution code:
S = list(input())
S = [ord(x) for x in S]
S_exist = sorted(S)
if len(S_exist) != 26:
    for i in range(len(S_exist)):
        if S_exist[i] != i+97:
            S.append(i+97)
            break
    if len(S_exist) == len(S):
        S.append(max(S_exist)+1)
    print("".join(map(str, [chr(x) for x in S])))
else:
    S.reverse()
    if S == S_exist:
        print(-1)
    else:
        flag = 0
        for i in range(25):
            if S[i] > S[i+1]:
                a = S[i+1]
                for j in range(len(S[:i+2])-1, -1, -1):
                    if S[j] > a:
                        S = [S[j]] + S[i+2:]
                        flag = 1
                        break
            if flag == 1:
                break
        S.reverse()
        print("".join(map(str, [chr(x) for x in S])))

Submission status: Wrong Answer

Solution code:
S = list(input())
S = [ord(x) for x in S]
S_exist = sorted(S)
if len(S_exist) != 26:
    for i in range(len(S_exist)):
        if S_exist[i] != i+97:
            S.append(i+97)
            break
    if len(S_exist) == len(S):
        S.append(max(S_exist)+1)
    print("".join(map(str, [chr(x) for x in S])))
else:
    S.reverse()
    if S == S_exist:
        print(-1)
    else:
        for i in range(25):
            if S[i] > S[i+1]:
                S = [min(S[:i+1])] + S[i+2:]
                break
        S.reverse()
        print("".join(map(str, [chr(x) for x in S])))

Submission status: Wrong Answer

Solution code:
S = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
if S == alpha[::-1]:
    print(-1)
else:
    rest = sorted(list(set(alpha) - set(S)))
    if rest:
        print(S + rest[0])
    else:
        for i in range(len(S)-1, 0, -1):
            if S[i-1] < S[i]:
                break
        rest = sorted(S[i:])
        print(S[:i-1] + rest[0])

Submission status: Wrong Answer

Solution code:
S = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
if S == alpha[::-1]:
    print(-1)
else:
    rest = sorted(list(set(alpha) - set(S)))
    if rest:
        print(S + rest[0])
    else:
        for i, s in enumerate(S):
            if s == 'z':
                break
        rest = sorted(S[i:])
        print(S[:i-1] + rest[0])

Submission status: Wrong Answer

Solution code:
S = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
if S == alpha[::-1]:
    print(-1)
else:
    rest = sorted(list(set(alpha) - set(S)))
    if rest:
        print(S + rest[0])
    else:
        for i, s in enumerate(S):
            if s == 'z':
                break
        rest = sorted(S[i:])
        print(S[:i] + rest[0])

Submission status: Wrong Answer

Solution code:
s = str(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
if len(s) < 26:
    toappend = ""
    for i in alpha:
        if i not in s:
            toappend = i
            break
    s += toappend
    print(s)
else:
    s = s[::-1]
    ckd = []
    for i in range(26):
        for j, it in enumerate(ckd):
            if s[i] < it:
                temp = ckd[j] + s[i+1:]
                print(temp[::-1])
                exit()
        ckd.append(s[i])

Submission status: Wrong Answer

Solution code:
s = str(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
if len(s) < 26:
    toappend = ""
    for i in alpha:
        if i not in s:
            toappend = i
            break
    s += toappend
    print(s)
else:
    temp = 0
    for i in range(len(s)-1, 0, -1):
        if s[i] < s[i-1]:
            temp += 1
        else:
            temp += 1
            break
    if temp == 25:
        print(-1)
    else:
        ans = ""
        for i in range(26 - temp-1):
            ans += s[i]
        temp2 = s[26-temp-1]
        ans += chr(ord(temp2) + 1) 
        print(ans)

Submission status: Wrong Answer

Solution code:
s = input().rstrip()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) == 26:
    s = s[::-1]
    seen = []
    for i in range(25):
        for j, item in enumerate(seen):
            if s[i] < item:
                ns = seen[j] + s[i+1:]
                print(ns[::-1])
                exit()
        seen.append(s[i])
else:
    alphabets = set(s)
    for item in "abcdefghijklmnopqrstuvwxyz":
        if item not in alphabets:
            print(s + item)
            exit()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():

  # a〜z
  l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

  s=S()
  if s=='atcoder':
    exit()

  if s=='zyxwvutsrqponmlkjihgfedcba':
    return -1

  if len(s)!=26:
    for x in s:
      l.remove(x)
    return s+l[0]

  else:
    for i in range(1,len(s)):
      x=s[-i]
      for j in range(len(s)-i)[::-1]:
        if x>s[j]:
          return s[:j]+x

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():

  # a〜z
  l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

  s=S()
  if s=='atcoder':
    exit()

  if s=='zyxwvutsrqponmlkjihgfedcba':
    return -1

  if len(s)!=26:
    for x in s:
      l.remove(x)
    return s+l[0]

  else:
    x=s[-1]
    for i in range(len(s)-1)[::-1]:
      if x>s[i]:
        return s[:i]

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():

  # a〜z
  l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

  s=S()
  if s=='atcoder':
    exit()

  if s=='zyxwvutsrqponmlkjihgfedcba':
    return -1

  if len(s)!=26:
    for x in s:
      l.remove(x)
    return s+l[0]+l[0]

  else:
    x=s[-1]
    for i in range(len(s)-1)[::-1]:
      if x>s[i]:
        return s[:i]+x

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():

  # a〜z
  l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

  s=S()
  if s=='atcoder':
    exit()

  if s=='zyxwvutsrqponmlkjihgfedcba':
    return -1

  if len(s)!=26:
    for x in s:
      l.remove(x)
    return s+l[0]

  else:
    x=s[-1]
    for i in range(len(s)-1)[::-1]:
      if x>s[i]:
        return s[:i]+x

print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)!=26:
    c = sorted(set("abcdefghijklmnopqrstuvwxyz")-set(s))[0]
    print(s+c)
elif s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    s=list(s)
    m=s.pop()
    while 1:
        q=s.pop()
        if m<q:m=q
        else:print("".join(s)+m);break

Submission status: Wrong Answer

Solution code:
s=input()
def main(s):
    m = s.pop()
    while s:
        p = s.pop()
        if m>p:return "".join(s)+m
if len(s)!=26:
    c = sorted(set("abcdefghijklmnopqrstuvwxyz")-set(s))[0]
    print(s+c)
elif s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    print(main(list(s)))

Submission status: Wrong Answer

Solution code:
S = input()
a = list('abcdefghijklmnopqrstuvwxyz')
b = 'zyxwvutsrqponmlkjihgfedcba'

if len(S) == 26:
    if S == b:
        print(-1)
        exit()
    S = list(S)
    i = -1
    while ord(S[i])+1 == ord(S[i-1]):
        i -= 1
    S[i-1] = chr(ord(S[i-1])+1)
    while i < 0:
        S[i] = ''
        i += 1
    print(''.join(S))
    exit()
S = list(S)
print(''.join(S)+[x for x in a if not(x in S)][0])

Submission status: Wrong Answer

Solution code:
S = raw_input()

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

for i in range(len(S)):
    for j in range(97,97+26):
        if S[i] == chr(j):
            flag[j-97] = 1


if len(S) == 26:
    ans = []
    flag = [0 for i in range(26)]
    for i in range(len(S)-1):
        if S[i] < S[i+1]:
            for j in range(97,97+26):
                if S[i] == chr(j):
                    flag[j-97] = 1
                    ans.append(S[i])
                    break
            else:
                break
    if len(ans) == 0:
        print -1
    else:
        del ans[-1]
        for i in range(26):
            if flag[i] == 0:
                ans += chr(i+97)
                break
        ans = ''.join(ans)
        print ans
else:
    for i in range(26):
        if flag[i] == 0:
            S += chr(i+97)
            break
    print S

Submission status: Wrong Answer

Solution code:
S = input()

def solve(S):
    if len(S) < 26:
        return S + min(set(chr(ord('a') + i) for i in range(26)) - set(S))
    for i in range(len(S) - 1, 0, -1):
        if S[i - 1] < S[i]:
            return S[:i - 1] + min(S[i:])
    return "-1"

print(solve(S))

Submission status: Wrong Answer

Solution code:
S = input()

def solve(S):
    C = set(chr(ord('a') + i) for i in range(26))

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

    for i in range(25):
        if S[i] > S[i + 1]:
            if i == 0:
                return "-1"
            else:
                return S[:i - 1] + min(s for s in S[i:] if s > S[i - 1])

print(solve(S))

Submission status: Wrong Answer

Solution code:
S = input()

def solve(S):
    C = [chr(ord('a') + i) for i in range(26)]

    if len(S) < 26:
        for c in C:
            if c not in S:
                return S + c

    for i in range(25):
        if S[i] > S[i + 1]:
            if i == 0:
                return "-1"
            else:
                return S[:i - 1] + min(S[i - 1:])

print(solve(S))

Submission status: Wrong Answer

Solution code:
S = input()

def solve(S):
    C = [chr(ord('a') + i) for i in range(26)]

    if len(S) < 26:
        for c in C:
            if c not in S:
                return S + c

    for i in range(25):
        if S[i] > S[i + 1]:
            if i == 0:
                return "-1"
            else:
                return S[:i - 1] + min(S[i:])

print(solve(S))

Submission status: Wrong Answer

Solution code:
S = input()
if len(S) < 26:
    for i in range(26):
        c = chr(ord('a') + i)
        if c not in S:
            print(S + c)
            quit()
for i in range(25):
    if S[i] > S[i + 1]:
        if i == 0:
            print(-1)
            quit()
        for j in range(26):
            c = chr(ord('a') + j)
            if c not in S[:i]:
                print(S[:i - 1] + c)
                quit()

Submission status: Wrong Answer

Solution code:
S = input()
if len(S) < 26:
    for i in range(26):
        c = chr(ord('a') + i)
        if c not in S:
            print(S + c)
            quit()
for i in range(25):
    if S[i] > S[i + 1]:
        for j in range(26):
            c = chr(ord('a') + j)
            if c not in S[:i]:
                print(S[:i - 1] + c)
                quit()
print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

def next_tasai(S):
  if S == 'zyxwvutsrqponmlkjihgfedcba':
    return -1
  
  A = 'abcdefghijklmnopqrstuvwxyz'
  Aset = set([a for a in A])
  Sset = set([s for s in S])
  
  if (Aset-Sset):
    l = min(Aset-Sset)
    answer = S+l
    return answer
  else:
    i=-1
    while True:
      if S[i] < S[i-1]:
        i-=1
      else:
        key = min([s for s in S[i-1:] if s>S[i-1]])
        return S[:i-1] + key + ''.join(sorted([s for s in S[i-1:].replace(key,'')])) 
      
print(next_tasai(S))

Submission status: Wrong Answer

Solution code:
check='abcdefghijklmnopqrstuvwxyz'
s=input()
l=len(s)
if l<=25:
  for i in range(25):
    if check[i] not in s:
      print(s+check[i])
      break
else:
  s2=''.join(map(str,sorted(s,reverse=True)))
  if s==s2:
    print(-1)
  else:
    for i in range(25):
      if s[-(i+1)]>s[-(i+2)]:
        tmp1=s[:-(i+2)]
        tmp2=s[-(i+2):]
        break
    base=tmp2[0]
    minc=0
    for i in range(1,len(tmp2)):
      tmpv=ord(tmp2[i])-ord(base)
      if tmpv>0 and tmpv<minc:
        minc=tmpv
    print(tmp1+chr(ord(base)+minc))

Submission status: Wrong Answer

Solution code:
check='abcdefghijklmnopqrstuvwxyz'
s=input()
l=len(s)
if l<=25:
  for i in range(25):
    if check[i] not in s:
      print(s+check[i])
      break
else:
  s2=''.join(map(str,sorted(s,reverse=True)))
  if s==s2:
    print(-1)
  else:
    for i in range(25):
      if s[-(i+1)]>s[-(i+2)]:
        tmp1=s[:-(i+2)]
        tmp2=s[-(i+2):]
        break
    base=tmp2[0]
    minc=10**9
    for i in range(1,len(tmp2)):
      if abs(ord(base)-ord(tmp2[i]))<minc:
        minc=abs(ord(base)-ord(tmp2[i]))
    print(tmp1+chr(ord(base)+minc))

Submission status: Wrong Answer

Solution code:
s = input()

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


if len(s)!=26:
    for i in range(26):
        if chr(97+i) not in s:
            print(s+chr(97+i))
            exit()
else:
    for i in range(25):
        if s[24-i]<s[25-i]:
            m = s[25-i]
            for x in s[25-1:]:
                if x > s[24-i]:
                    m = min(m, x)
            print(s[:24-i]+m)
            exit()

Submission status: Wrong Answer

Solution code:
s = input()

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


if len(s)!=26:
    for i in range(26):
        if chr(97+i) not in s:
            print(s+chr(97+i))
            exit()
else:
    for i in range(25):
        if s[24-i]<s[25-i]:
            print(s[:24-i]+min(s[25-i:]))
            exit()

Submission status: Wrong Answer

Solution code:
s = input() #+ chr(96)
#print(s)
 
for j in reversed(range(len(s)-1)):
    sets=set(s[:j])
    #print(sets)
    for i in range(ord(s[j]) + 1,123):
        if chr(i) not in sets:
            print(s[:j] + chr(i))
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s = input() #+ chr(96)
print(s)
 
for j in reversed(range(len(s)-1)):
    sets=set(s[:j])
    #print(sets)
    for i in range(ord(s[j]) + 1,123):
        if chr(i) not in sets:
            #print(s[:j] + chr(i))
            exit()
print(-1)

Submission status: Wrong Answer

Solution code:
s=input()
t="abcdefghijklmnopqrstuvwxyz"
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s)<26:
    print(s+min(set(t)-set(s)))
else:
    ans=""
    for i in range(25):
        if s[i]<s[i+1]:
            ans+=s[i]
        else:
            print(ans[:-1]+min(set(t)-set(ans)))
            exit()

Submission status: Wrong Answer

Solution code:
s=input()
t="abcdefghijklmnopqrstuvwxyz"
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s)<26:
    print(s+min(set(t)-set(s)))
else:
    ans=""
    for i in range(25):
        if s[i]<s[i+1]:
            ans+=s[i]
        else:
            print(ans+min(set(t)-set(ans)))
            exit()

Submission status: Wrong Answer

Solution code:
s=input()
t="abcdefghijklmnopqrstuvwxyz"
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s)<26:
    print(s+min(set(t)-set(s)))
else:
    ans=""
    for i in range(26):
        if s[i]==t[i]:
            ans+=s[i]
        else:
            print(ans[:-1]+min(s[i+2:]))
            exit()

Submission status: Wrong Answer

Solution code:
s=input()
t="abcdefghijklmnopqrstuvwxyz"
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s)<26:
    print(s+min(set(t)-set(s)))
else:
    ans=""
    for i in range(26):
        if s[i]==t[i]:
            ans+=s[i]
        else:
            print(ans[:-1]+min(s[i+1:]))
            exit()

Submission status: Wrong Answer

Solution code:
a = set(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"])
s = input()
for i in range(len(s)):
    a.remove(s[i])
b = list(a)
b.sort()
if b:
    print(s+b[0])
else:
    print(-1)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

if len(inp) == len(alp):
    prev = inp[0]
    for index, char in enumerate(inp[1:]):
        if prev > char:
            print(inp[:index - 1] + min(inp[index:]))
            break
        prev = char

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

Submission status: Wrong Answer

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

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

if len(inp) == len(alp):
    prev = inp[0]
    for index, char in enumerate(inp[1:]):
        if prev > char:
            index -= 1
            print(inp[:index] + min(inp[index:]))
            break
        prev = char

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

Submission status: Wrong Answer

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

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

if len(inp) == len(alp):
    prev = inp[0]
    for index, char in enumerate(inp[1:]):
        if prev > char:
            print(inp[:index] + min(inp[index:]))
            break
        prev = char

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

Submission status: Wrong Answer

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

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

if len(inp) == len(alp):
    prev = inp[0]
    for index, char in enumerate(inp[1:]):
        if prev > char:
            print(inp[:index] + min(inp[index:]))
            break
        prev = char

else:
    for v1, v2 in zip(sorted(list(inp)), alp):
        if v1 != v2:
            print(inp + v2)
            break

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N = input()
p = list("abcdefghijklmnopqrstuvwxyz")

if len(N) != 26:
    for i in N:
        p.pop(p.index(i))
    if p == []:
        print(-1)
        exit()
    print(N+p[0])
else:
    tmp = 0
    a = list("zyxwvutsrqponmlkjihgfedcba")
    if a == N:
        print("-1")
        exit()
    for i in range(25,-1,-1):
        for c in N:
            if c not in N[:i] and c > N[i]:
                print(N[:i]+c)
                exit()

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
l = [0 for i in range(26)]
if N < 26:
    for i in range(N):
        l[ord(S[i])-97] += 1
    for i in range(26):
        if l[i] == 0:
            print(S+str(chr(i+97)))
            break
elif S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    m = 0
    for i in reversed(range(26)):
        if m > ord(S[i])-97:
            id = i
            break
        m = ord(S[i])-97
    for i in range(id,26):
        l[ord(S[i])-97] += 1
    a = 0
    for i in range(len(l)):
        if l[i] == 1 and a == 0:
            a += 1
            continue
        if l[i] == 1 and a == 1:
            s = chr(i+97)
            break
    print(S[:id]+str(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
t="abcdefghijklmnopqrstuvwxyz"
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s)<26:
    print(s+min(set(t)-set(s)))
else:
    ans=""
    for i in range(26):
        if s[i]==t[i]:
            ans+=s[i]
        else:
            print(ans[:-1]+min(s[i:]))
            exit()

Submission status: Wrong Answer

Solution code:
import sys
S=input()
N=len(S)
if S=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
dp=[0]*26
for i in range(N):
    t=ord(S[i])-ord('a')
    dp[t]+=1
if N<26:
    for i in range(26):
        if dp[i]==0:
            break
    print(S+alpha[i])
    sys.exit()
C=S[::-1]
for j in range(N):
    if ord(C[j])>ord(C[j+1]):
        break
T=C[:j+1]
U=C[j+1:]
U=U[::-1]
num=27
for i in range(len(T)):
    if ord(U[-1])<ord(T[i]):
        num=min(num,ord(T[i])-ord('a'))
print(U+alpha[num])