TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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}.

Submission attempts (in order):
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)

s = input()+chr(ord("a")-1)
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)

Verdicts: Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
import functools
import math
from itertools import combinations
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    ham = combinations(range(1, 30001), 100)
    for x in ham:
        if functools.reduce(math.gcd, x) == 1:
            for y in x:
                xx = list(x)
                xx.remove(y)
                if functools.reduce(math.gcd, [y, sum(xx)]) != 1:
                    break
            else:
                print(' '.join([str(i) for i in x]))
                return


if __name__ == '__main__':
    main()


from sys import stdin
from string import ascii_lowercase


def main():
    word = stdin.readline().rstrip()
    if word == ascii_lowercase[::-1]:
        print(-1)
        return

    spam = sorted(list(set(ascii_lowercase) - set(word)))
    if 1 <= len(spam):
        print(word + spam[0])

    rword = word[::-1]
    tmp = []
    for x in rword:
        if len(tmp) != 0 and x < tmp[-1]:
            print(word[:-len(tmp) - 1] + tmp[0])
            break
        tmp.append(x)


if __name__ == '__main__':
    main()


from sys import stdin
from string import ascii_lowercase
from bisect import bisect_left


def main():
    word = stdin.readline().rstrip()
    if word == ascii_lowercase[::-1]:
        print(-1)
        return

    spam = sorted(list(set(ascii_lowercase) - set(word)))
    if 1 <= len(spam):
        print(word + spam[0])
        return

    rword = word[::-1]
    tmp = []
    for x in rword:
        if len(tmp) != 0 and x < sorted(tmp)[-1]:
            idx = bisect_left(tmp, x)
            print(word[:-len(tmp) - 1] + sorted(tmp)[idx])
            return
        tmp.append(x)


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
s=str(input())
t=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
if len(s)!=26:
  for i in range(26):
    if t[i] not in s:
      s.append(t[i])
      break
  print("".join(s))
else:
  if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    a=[]
    for i in range(26):
      a.append(s[25-i])
      for j in a:
        if s<s[:25-i]+j:
          print(s[:25-i]+j)
          exit()

s=str(input())
t=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
if len(s)!=26:
  s=list(s)
  for i in range(26):
    if t[i] not in s:
      s.append(t[i])
      break
  print("".join(s))
else:
  if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    a=[]
    for i in range(26):
      a.append(s[25-i])
      for j in a:
        if s<s[:25-i]+j:
          print(s[:25-i]+j)
          exit()

Verdicts: Runtime Error

Accepted
Problem: 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}.

Submission attempts (in order):
S = input()
a = []
b = ["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 s in S:
  if s not in a:
    a.append(s)
a.sort()
if len(a) == 0:
  print(-1)
else:
  for i in range(len(a)):
    if a[i] != b[i]:
      print(S+a[i])
      exit()
          

import sys
input = sys.stdin.readline

S = input()

alphabets = set(chr(ord('a')+x) for x in range(26))

def F(S,alphabets):
    if len(S) == 0:
        return -1
    T = F(S[1:],alphabets-set([S[0]]))
    if T == -1:
        larger = [x for x in alphabets if x > S[0]]
        if not larger:
            return -1
        return min(larger)
    return S[0] + T

answer = F(S,alphabets)
print(answer)


Verdicts: Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
import string

S = input()

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

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



import string

S = input()

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

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



Verdicts: Runtime Error

Accepted
Problem: 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}.

Submission attempts (in order):
S = [ord(i)-97 for i in str(input())]
appeared = [False for i in range(26)]
for s in S:
    appeared[s] = True
worst = False
if len(S)<26:
    for i in range(len(appeared)):
        if appeared[i] == False:
            break
    S.append(i)
    
else:
    prev = -1
    for i in [25-k for k in range(26)]:
        if S[i] < prev:
            break
        prev = S[i]
    if i == 0:
        worst=True
    else:
        string = S[i+1:]
        for j in range(len(string)):
            if string[j] < S[i]:
                string[j] = 100
        S = S[:i]+[min(string)]
    

S = [ord(i)-97 for i in str(input())]
appeared = [False for i in range(26)]

if len(S)<26:
    alp="".join([chr(i) for i in range(97,97+26)])
    s = "".join([chr(i+97) for i in S])
    for i in alp:
        if i not in s:
            print(s+i)
            exit()
    """
    for s in S:
    appeared[s] = True
    for i in range(len(appeared)):
        if appeared[i] == False:
            break
    S.append(i)
    print("".join([chr(i+97) for i in S]))
    exit()
    """
    
else:
    s = "".join([chr(i+97) for i in S])
    if s=="".join([chr(i) for i in range(97,97+26)][::-1]):
        print(-1)
        exit()
    
    prev = -1
    for i in [25-k for k in range(26)]:
        if S[i] < prev:
            break
        prev = S[i]
    for i in range(24,-1,-1):
        for j in range(25,i,-1):
            if S[i]<S[j]:
                S = S[:i]+[S[j]]
                print("".join([chr(i+97) for i in S]))
                exit()
    """
    string = S[i+1:]
    for j in range(len(string)):
        if string[j] < S[i]:
            string[j] = 100
    S = S[:i]+[min(string)]
    """


Verdicts: Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
alpha=list("abcdefghijklmnopqrstuvwxyz")
alpha_dict={a:i for i,a in enumerate(alpha)}
alpha = set(alpha)

string = input()

can_use_str = alpha - set(list(string))

if string == "zyxwvutsrqponmlkjihgfedcba":
    print(1)

elif len(can_use_str)==0:
    string_len=len(string)-1
    for i in range(1,string_len):
        if string[string_len-i] < string[string_len-i-1]:
            break
    can = sorted(list(string[string_len - i-1:]))[0]
    print(string[:string_len - i-2]+can)

else:

    print(string)

import copy
alpha=list("abcdefghijklmnopqrstuvwxyz")
alpha_dict={a:i for i,a in enumerate(alpha)}
alpha = set(alpha)

string = input()

can_use_str = alpha - set(list(string))

if string == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)

elif len(can_use_str)==0:
    k = 0
    for i in reversed(range(25)):
        if string[i] < string[i + 1]:
            k = i
            break
    last = sorted(string[k:])
    for i in last:
        if string[k] < i:
            print(string[:k] + i)
            break

else:
    string+=sorted(list(can_use_str))[0]
    print(string)

Verdicts: Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
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)

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


Verdicts: Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
s = input()
if len(s)<26:
  for i in al:
    if i not in s:
      print(s+i)
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    k = []
    for i in range(25, 0, -1):
      k.append(s[i])
      if s[i-1] < s[i]:
        for j in sorted(k):
          if j > s[i-1]:
            print(s[:i-1] + j)
            exit()

al = "abcdefghijklmnopqrstuvwxyz"
s = input()
if len(s)<26:
  for i in al:
    if i not in s:
      print(s+i)
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    k = []
    for i in range(25, 0, -1):
      k.append(s[i])
      if s[i-1] < s[i]:
        for j in sorted(k):
          if j > s[i-1]:
            print(s[:i-1] + j)
            exit()

Verdicts: Runtime Error

Accepted
Problem: 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}.

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

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

Verdicts: Runtime Error

Accepted
Problem: 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}.

Submission attempts (in order):
import string

alp = string.ascii_lowercase

def main():
    s = input()
    if s == alp[::-1]:
        print(-1)
        return
    for i, ss in enumerate( s[::-1] ):
        if s[-(i)] > ss:
            print ( s[:(-i-1)] + s[-1] )
            break

main()



import string

alp = string.ascii_lowercase

def main():
    s = input()
    if len(s) < 26:
        for i in alp:
            if i not in s:
                print (s + i)
                return
    if s == alp[::-1]:
        print(-1)
        return
    L = len(s)
    tmp = []
    tt = ''
    for i, ss in enumerate( s ):
        tmp += [ s[L-i-1] ]
        if s[L-i-1] > s[L-i-2]:
            ans = s[:L-i-2]
            tt = s[L-i-2] 
            break
    tmp.sort()
    for i in tmp:
        if i > tt:
            print (ans + i)
            break
main()



Verdicts: Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
abc="abcdefghijklmnopqrstuvwxyz"
import collections
table=collections.defaultdict(int)
for i in range(26):
  table[abc[i]]=i
table2=collections.defaultdict(int)
s=input()
for i in reversed(range(len(s)+1)):
  k=0
  if i < len(s):
    k=table[s[i]]
  for j in range(k+1,26):
    if abc[j] in s[:i]:
      continue
    else:
      print(s[:i]+abc[j])
      print(i,j)
      exit(0)
print(-1)

abc="abcdefghijklmnopqrstuvwxyz"
import collections
table=collections.defaultdict(int)
for i in range(26):
  table[abc[i]]=i
table2=collections.defaultdict(int)
s=input()
for i in reversed(range(len(s)+1)):
  k=0
  if i < len(s):
    k=table[s[i]]+1
  for j in range(k,26):
    if abc[j] in s[:i]:
      continue
    else:
      print(s[:i]+abc[j])
      exit(0)
print(-1)

Verdicts: Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
s = input()

ans = s
ansa = s
a = 'abcdefghijklmnopqrstuvwxyz'
a = [a[i] for i in range(26)]
if len(s)<26:
    for i in a:
        if ans.count(i) == 0:
            ans += i
            break
else:
    b = 26
    for i in range(1,26):
        if a.index(s[i]) > a.index(s[i-1]):
            b = i
    if b == 26:
        print(-1)
    else:
        s = s[:b]
        for j in a:
            if a.index(j) > a.index(s[b-1]) and j not in s:
                s = s[:b-1]+j
                break
        print(s)


s = input()

ans = s
ansa = s
a = 'abcdefghijklmnopqrstuvwxyz'
a = [a[i] for i in range(26)]
if len(s)<26:
    for i in a:
        if ans.count(i) == 0:
            ans += i
            break
    print(ans)
else:
    b = 26
    for i in range(1,26):
        if a.index(s[i]) > a.index(s[i-1]):
            b = i
    if b == 26:
        print(-1)
    else:
        s = s[:b]
        for j in a:
            if a.index(j) > a.index(s[b-1]) and j not in s:
                s = s[:b-1]+j
                break
        print(s)


Verdicts: Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
s = input()

if len(s) > 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans)
    exit()


for i in range(24,-1,-1):
    for j in range(25,i,-1):
        if s[i]<s[j]:
            print(s[:i]+s[j])
            exit()

print(-1)

s = input()

if len(s) > 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans) 


for i in range(24,-1,-1):
    for j in range(25,i,-1):
        if s[i]<s[j]:
            print(s[:i]+s[j])
            exit()

print(-1)

s = input()

if len(s) < 26:
    a = [0 for _ in range(26)]

    for i in range(len(s)):
        a[ord(s[i]) - ord("a")] += 1

    ans = s
    for i in range(26):
        if a[i] == 0:
            ans += chr(i+ord("a"))
            break

    print(ans)
    exit()


for i in range(24,-1,-1):
    for j in range(25,i,-1):
        if s[i]<s[j]:
            print(s[:i]+s[j])
            exit()

print(-1)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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}.

Submission attempts (in order):
j = input()
lis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
abs = ""
for h in j:
    lis.remove(h)
if not lis:
    ans = "-1"
else:
    ans = "{}{}".format(j, lis[0])
tmp = "zz"
for i in range(len(j)-1, -1, -1):
    if j[i] != "z":

        if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):

            tmp = j[:i]+chr(ord(j[i])+1)
if tmp == "zz" and ans == "-1":
    print("-1")
elif tmp == "zz":
    print(ans)
else:
    print(tmp)

j = input()
lis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
abs = ""
for h in j:
    lis.remove(h)
if not lis:
    ans = "-1"
else:
    ans = "{}{}".format(j, lis[0])
tmp = "zz"
for i in range(len(j)-1, -1, -1):
    if j[i] != "z":

        if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):
            print(j[:i] + chr(ord(j[i]) + 1))
            tmp = j[:i]+chr(ord(j[i])+1)
print(max(ans, tmp))

j = input()
lis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
abs = ""
for h in j:
    lis.remove(h)
if not lis:
    ans = "-1"
else:
    ans = "{}{}".format(j, lis[0])
tmp = "zz"
for i in range(len(j)-1, -1, -1):
    if j[i] != "z":

        if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):
            print(j[:i] + chr(ord(j[i]) + 1))
            tmp = j[:i]+chr(ord(j[i])+1)
print(min(ans, tmp))

j = input()
lis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
abs = ""
for h in j:
    lis.remove(h)
if not lis:
    ans = "-1"
else:
    ans = "{}{}".format(j, lis[0])
tmp = "zz"
for i in range(len(j)):
    try:
        if tmp > j[:i] + sorted(filter(lambda x: x > j[i], j[i+1:]))[0]:
            tmp = j[:i] + sorted(filter(lambda x: x > j[i], j[i+1:]))[0]
    except:
        pass
if tmp == "zz" and ans == "-1":
    print("-1")
elif tmp == "zz":
    print(ans)
elif ans == "-1":
    print(tmp)
else:
    print(min(ans, tmp))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
S = input()

# 1 <= |S| <= 26
# lowercase

import sys
import copy

def next_permutation(a):
    for i in reversed(range(len(a) - 1)):
        if a[i] < a[i + 1]:
            break
    else:
        return False

    j = next(j for j in reversed(range(i + 1, len(a))) if a[i] < a[j])
    a[i], a[j] = a[j], a[i]
    a[i + 1:] = reversed(a[i + 1:])
    return True

if len(S) == 26:
    sl = list(S)
    if next_permutation(sl):
        np = "".join(sl)
        for b in range(0, 26):
            if np[b] != S[b]:
                print(np[:b+1])
                exit()

    else:
        print(-1)
        exit()

S = input()

# 1 <= |S| <= 26
# lowercase

import sys
import copy

def next_permutation(a):
    for i in reversed(range(len(a) - 1)):
        if a[i] < a[i + 1]:
            break
    else:
        return False

    j = next(j for j in reversed(range(i + 1, len(a))) if a[i] < a[j])
    a[i], a[j] = a[j], a[i]
    a[i + 1:] = reversed(a[i + 1:])
    return True

if len(S) == 26:
    sl = list(S)
    if next_permutation(sl):
        np = "".join(sl)
        for b in range(0, 26):
            if np[b] != S[b]:
                print(np[:b+1])
                exit()

    else:
        print(-1)
        exit()
else:
    hist = set(S)
    for c in range(0, 27):
        cand = chr(c+ord('a'))
        if cand not in hist:
            print(S+cand)
            sys.exit()

Verdicts: Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
s=input()
n=len(s)
ls=[0]*26

for i in range(n):
  ls[ord(s[i])-97]=i+1
if n<26:
  for i in range(26):
    if ls[i]==0:
      x=i
      break
  print(s+chr(x+97))
else:
  for i in range(24,-1,-1):
    if ls[i+1]>ls[i]:
      

from bisect import bisect
s=input()
n=len(s)
ls=[0]*26
if s == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
if n<26:
  for i in range(n):
    ls[ord(s[i])-97]=i+1
  for i in range(26):
    if ls[i]==0:
      x=i
      break
  print(s+chr(x+97))
else:
  for i in range(n):
    ls[i] = ord(s[i])-97
  if ls[25]>ls[24]:
    print(s[:24]+s[25])
  else:
    tmp = []
    for i in range(24,-1,-1):
      tmp.append(ls[i+1])
      if ls[i+1]>ls[i]:
        tmps = sorted(tmp)
        x = bisect(tmps,ls[i])
        print(s[:i]+chr(tmps[x]+97))
        break

Verdicts: Runtime Error

Accepted
Problem: 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}.

Submission attempts (in order):
# 2019/08/12

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

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

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

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

# 2019/08/12

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

st=set(s)

if len(s)<26:
    for i in range(97,97+26+1):
        if chr(i) in st:continue
        print(s+chr(i))
        exit()

s=list(s)
res=[s.pop()]

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

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

Verdicts: Runtime Error

Accepted
Problem: 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}.

Submission attempts (in order):
ss = input()
ss =list(map(ord, ss))
print(ss)
dic = [i for i in range(97,123)]
for s in ss:
    dic.remove(s)
if len(ss)<26:
    ss.append(min(dic))
else:
    last = ss[-1]
    for s in ss[::-1]:
        if s < last:
            ss = ss[:ss.index(s)] + [last]
            break
    else:
        ss = -1
if ss == -1:
    print(ss)
else:
    print(''.join(list(map(chr,ss))))

ss = input()
ss =list(map(ord, ss))
dic = [i for i in range(97,123)]
print(dic)
for s in ss:
    dic.remove(s)
print(dic)
if len(ss)<26:
    ss.append(min(dic))
else:
    for s in ss[::-1]:
        if len(dic)>0 and s < max(dic):
            ss[ss.index(s)] = max(dic)
            break
        dic.append(ss.pop(ss.index(s)))
    else:
        ss = -1
print(ss if ss == -1 else ''.join(list(map(chr,ss))))

import bisect
ss = input()
ss =list(map(ord, ss))
dic = [i for i in range(97,123)]
# print(dic)
for s in ss:
    dic.remove(s)
# print(dic)
if len(ss)<26:
    ss.append(min(dic))
else:
    for s in ss[::-1]:
        if len(dic)>0 and s < max(dic):
            ss[ss.index(s)] = dic[bisect.bisect_right(dic,s)]
            break
        dic.append(ss.pop(ss.index(s)))
        dic = sorted(dic)
    else:
        ss = -1
print(ss if ss == -1 else ''.join(list(map(chr,ss))))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
s=input()
N=len(s)
alpha="abcdefghijklmnopqrstuvwxyz"
a=[0]*26
for i in range(N):
    for j in range(26):
        if s[i]==alpha[j]:
            a[j]+=1
            break

if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
c=0
lastidx=-1
while True:


    for j in range(lastidx+1,26):
        if a[j]==0 :
            print(s[:c]+alpha[j])
            exit()
    lastidx=alpha.index(s[-1+c])
    a[lastidx] -= 1
    c-=1

s=input()
N=len(s)
alpha="abcdefghijklmnopqrstuvwxyz"
a=[0]*26
for i in range(N):
    for j in range(26):
        if s[i]==alpha[j]:
            a[j]+=1
            break

if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
c=0
lastidx=-1
while True:
    for j in range(lastidx+1,26):
        if a[j]==0 :
            print(s[:N+c]+alpha[j])
            exit()
    lastidx=alpha.index(s[-1+c])
    a[lastidx] -= 1
    c-=1


Verdicts: Wrong Answer

Accepted
Problem: 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}.

Submission attempts (in order):
S=list(input())
m=list('abcdefghijklmnopqrstuvwxyz')[::-1]

if len(S)<26:
  for i in m[::-1]
        if i not in S:
            S.append(i)
            break
    print(''.join(S))
else:
    x=S[-1]
    for i in range(24,-1,-1):
        if x>S[i]:
            y=m.index(S[i])
            S=S[:i]
            for j in range(y-1,-1,-1):
                if m[j] not in S:
                    S.append(m[j])
                    break
            break
        else:
            x=S[i]
        
        if i==0:
            print(-1)
            exit()
    print(''.join(S))

S=list(input())
m=list('abcdefghijklmnopqrstuvwxyz')[::-1]

if len(S)<26:
    for i in m[::-1]:
        if i not in S:
            S.append(i)
            break
    print(''.join(S))
else:
    x=S[-1]
    for i in range(25)[::-1]:
        if x>S[i]:
            y=m.index(S[i])
            S=S[:i]
            for j in range(y)[::-1]:
                if m[j] not in S:
                    S.append(m[j])
                    break
            break
        else:
            x=S[i]
        
        if i==0:
            print(-1)
            exit()
    print(''.join(S))

Verdicts: Runtime Error

Accepted
Problem: 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}.

Submission attempts (in order):
# -*- coding: utf-8 -*-
import copy
s = list(input())

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

if len(s) == 26:
    for i in range(26):
        if s[i] == 'z':
            tmp = i
            break
    ans = s[:tmp]
    ans.append(min(s[tmp:]))
    print(''.join(ans))
    exit()


t = copy.deepcopy(s)
#print(t)

for i in reversed(range(0, len(s))):
    #print(t[i])
    if t[i] != 'z' and len(set(s)) < 26:
        j = 1
        while True:
            if not chr(ord('a') + j) in s:
                t[i] = chr(ord('a') + j)
                break
            else:
                j += 1
        break
ans1 = ''.join(t)

for i in range(26):
    if not chr(ord('a') + i) in s:
        s.append(chr(ord('a') + i))
        break
ans2 = ''.join(s)
print(min(ans1, ans2))


# -*- coding: utf-8 -*-
import copy
s = list(input())

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

if len(s) == 26:
    for i in reversed(range(0, 26)):
        #for j in range(1, ord('z') - ord(s[i])):
        for j in range(ord(s[i]) + 1, ord('z') + 1):
            if not chr(j) in s[:i]:
                s[i] = chr(j)
                print(''.join(s[:i + 1]))
                exit()

for i in range(26):
    if not chr(ord('a') + i) in s:
        s.append(chr(ord('a') + i))
        break
ans2 = ''.join(s)
print(ans2)


Verdicts: Wrong Answer

Accepted