Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq |S| \leq 26

S is a diverse word.

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

atcoder

Sample Output 1

atcoderb

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

Sample Input 2

abc

Sample Output 2

abcd

Sample Input 3

zyxwvutsrqponmlkjihgfedcba

Sample Output 3

-1

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

Sample Input 4

abcdefghijklmnopqrstuvwzyx

Sample Output 4

abcdefghijklmnopqrstuvx



Sample input:
atcoder


Sample output:
atcoderb

Submission status: Wrong Answer

Solution code:
S = list(input())
alp = ['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 ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)

if ''.join(S) == 'abcdefghijklmnopqrstuvwxyz':
    print('abcdefghijklmnopqrstuvwxz')
    exit(0)

if len(S) != 26:
    for a in alp:
        if not(a in S):
            print(''.join(S) + a)
            exit(0)

for i in range(len(S)):
    if alp.index(S[i]) > alp.index(S[i+1]):
        print(''.join(S[:i-1])+alp[alp.index(S[i])])
        exit(0)

Submission status: Wrong Answer

Solution code:
S = list(input())
alp = ['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 ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)

if ''.join(S) == 'abcdefghijklmnopqrstuvwxyz':
    print('abcdefghijklmnopqrstuvwxz')
    exit(0)

if len(S) != 26:
    for a in alp:
        if not(a in S):
            print(''.join(S) + a)
            exit(0)

for i in range(len(S)):
    if alp.index(S[i]) > alp.index(S[i+1]):
        #S[i] = S[i+1]
        print(''.join(S[:i-1])+alp[i])
        exit(0)

Submission status: Wrong Answer

Solution code:
s = input()
alf = 'abcdefghijklmnopqrstuvwxyz'
pos = {}
pos_alf = {c:i for i,c in enumerate(alf)}

for i,c in enumerate(s):
    if c not in pos:
        pos[c] = []
    pos[c] = i

# if s == 'zyxwvutsrqponmlkjihgfedcba':
#     print(-1)
#     exit()
# el
if len(s) != 26:
    for c in alf:
        if c not in pos:
            print(s+c)
            exit()

tmp = [pos_alf[s[-1]]]
for i in range(len(s)-1)[::-1]:
    if pos_alf[s[i]] < min(tmp):
        d = [j for j in tmp if j > pos_alf[s[i]]]
        print(s[:i]+alf[min(d)])
        break
    else:
        tmp.append(pos_alf[s[i]])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
alf = 'abcdefghijklmnopqrstuvwxyz'
pos = {}
pos_alf = {c:i for i,c in enumerate(alf)}

for i,c in enumerate(s):
    if c not in pos:
        pos[c] = []
    pos[c] = i

# if s == 'zyxwvutsrqponmlkjihgfedcba':
#     print(-1)
#     exit()
# el
if len(s) != 26:
    for c in alf:
        if c not in pos:
            print(s+c)
            exit()

tmp = [pos_alf[s[-1]]]
for i in range(len(s)-1)[::-1]:
    if pos_alf[s[i]] < min(tmp):
        d = [j for j in tmp if j > pos_alf[s[i]]]
        print(s[:i]+alf[d[0]])
        break
    else:
        tmp.append(pos_alf[s[i]])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
alf = 'abcdefghijklmnopqrstuvwxyz'
pos = {}
pos_alf = {c:i for i,c in enumerate(alf)}

for i,c in enumerate(s):
    if c not in pos:
        pos[c] = []
    pos[c] = i

# if s == 'zyxwvutsrqponmlkjihgfedcba':
#     print(-1)
#     exit()
# el
if len(s) != 26:
    for c in alf:
        if c not in pos:
            print(s+c)
            exit()

last = s[-1]
for i in range(len(s)-1)[::-1]:
    if pos_alf[s[i]] < pos_alf[last]:
        print(s[:i]+last)
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
alp=[chr(ord('a') + i) for i in range(26)]
unused=set(alp)

S=input()
if len(S)<26:
  for i in range(len(S)):
    if S[i] in unused:
      unused.remove(S[i])
  unused=list(unused)
  unused.sort()
  print(S+unused[0])
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
s = input()

if len(s)<26:
        st = set(s)
        for c in "abcdefghijklmnopqrstuvwxyz":
                if not c in st:
                        print(s+c)
                        break
        else: print(-1)
else:
        prev = ord('a') - 1
        i = len(s)
        for c in s[::-1]:
                if ord(c)>prev: i -= 1
                else: break
                prev = ord(c)
        if i==0: print(-1)
        else: print(s[:i-1] + s[-1])

Submission status: Wrong Answer

Solution code:
S = input()
al = ['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 al:
    if i not in S:
        print(S+i)
        exit()
tmp = []
N = len(S)
for i in range(N):
    t = S[-1]
    tmp.append(t)
    S = S[:-1]
    if t == 'z' or al[al.index(t)+1] in S:
        continue
    else:
        print(S+al[al.index(t)+1])
        exit()
print(-1)
exit()

Submission status: Wrong Answer

Solution code:
S = input()
al = ['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 al:
    if i not in S:
        print(S+i)
        exit()
tmp = []
N = len(S)
for i in range(N):
    t = S[-1]
    tmp.append(t)
    S = S[:-1]
    if t == 'z' or al[al.index(t)+1] in S:
        continue
    else:
        print(S+al[al.index(t)+1])
        exit()
    if len(S) == 0:
        print(-1)
        exit()

Submission status: Wrong Answer

Solution code:
S = input()
al = ['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 al:
    if i not in S:
        print(S+i)
        exit()
tmp = []
N = len(S)
for i in range(N):
    t = S[-1]
    tmp.append(t)
    S = S[:-1]
    if len(S) == 0:
        print(-1)
        exit()
    if t == 'z' or al[al.index(t)+1] in S:
        continue
    else:
        print(S+al[al.index(t)+1])
        exit()

Submission status: Wrong Answer

Solution code:
S = input()
al = ['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 al:
    if i not in S:
        print(S+i)
        exit()
tmp = []
N = len(S)
for i in range(N):
    tmp.append(S[-1])
    tmp.sort(reverse=True)
    S = S[:-1]
    if len(S) == 0:
        print(-1)
        exit()
    for k in tmp:
        if k not in S and al.index(k) > al.index(S[-1]):
            print(S+k)
            exit()

Submission status: Wrong Answer

Solution code:
S = input()
al = ['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 al:
    if i not in S:
        print(S+i)
        exit()
tmp = []
N = len(S)
for i in range(N):
    tmp.append(S[-1])
    S = S[:-1]
    if len(S) == 0:
        print(-1)
        exit()
    for k in tmp:
        if k not in S and al.index(k) > al.index(S[-1]):
            print(S+k)
            exit()

Submission status: Wrong Answer

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

import string
def f(x):
    for c in string.ascii_lowercase:
        if c in x: continue
        return c
    return None

if n < 26:
    print(S + f(S))
    exit()

i = n-2
while i >= 0:
    if S[i] < S[i+1]: break
    i -= 1
else:
    print(-1)
    exit()

print(S[:i] + f(S[:i+1]))

Submission status: Wrong Answer

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

import string
def f(x):
    for c in string.ascii_lowercase:
        if c in x: continue
        return c
    return None

if n < 26:
    print(S + f(S))
    exit()

i = n-2
while i >= 0:
    if S[i] < S[i+1]: break
    i -= 1
else:
    print(-1)
    exit()

t = S[:i+1]
print(t + f(t))

Submission status: Wrong Answer

Solution code:
s=input()
alp="".join([chr(i) for i in range(97,97+26)])
if len(s)<26:
    for i in alp:
        if i not in s:
            print(s+i)
            exit()
else:
    if s=="".join([chr(i) for i in range(97,97+26)][::-1]):
        print(-1)
        exit()
    else:
        for i in range(24,-1,-1):
            for j in range(i,25):
                if s[i]<s[j]:
                    print(s[:i]+s[j])
                    exit()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    from string import ascii_lowercase
    dic = {a: i for i, a in enumerate(ascii_lowercase)}
    rdic = {i: a for i, a in enumerate(ascii_lowercase)}
    if len(S) != 26:
        for s in ascii_lowercase:
            if s not in S:
                return print(S + s)
    elif S == "zyxwvutsrqponmlkjihgfedcba":
        return print(-1)

    pre = S[-1]
    mi = [pre]
    for i, s in enumerate(S[-2::-1], start=2):
        if s < pre:
            mi = min(mi, key=lambda p: s < p)
            return print(S[:-i] + min(mi))
        pre = s
        mi.append(s)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
alphabets = set(chr(ord("a") + x) for x in range(26))

def F_short(S):
  se = alphabets - set(S)
  x = min(se)
  return S + x

def F_long(S):
  if S == "".join(sorted(alphabets, reverse=True)):
    return "-1"
  
  cand = []
  S = list(S)
  while True:
    x = S[-1]
    if not cand or (x > max(cand)):
      cand.append(S.pop())
      print(cand)
      continue
    y = min(ch for ch in cand if ch > x)
    return "".join(S[:-1]) + y

L = len(S)
ans = F_short(S) if L < 26 else F_long(S)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
n = [ord(c)-ord('a') for c in S]

def next(x):
    if len(x) < 26:
        for c in range(26):
            if not c in x:
                x.append(c)
                return x
    i = 25
    pre = -1
    while i >= 0:
        if x[i] < pre: break
        pre = x[i]
        i -= 1
    if i == -1: return None
    x[i] += 1
    return x[:i+1]

def check(x):
    c = [False]*26
    for i in x:
        if x == -1: continue
        if c[i]: return False
        c[i] = True
    return True

while True:
    n = next(n)
    if n == None:
        print(-1)
        exit()
    if check(n): break

ans = ""
for i in n:
    if i != -1: ans += chr(ord('a') + i)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
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"]
res = ""
if len(s) < 26:
    for i in range(26):
        if L[i] in s:
            continue
        else:
            res += s + L[i]
            break
else:
    ss = sorted(s)
    for i in range(26):
        if s[i] != ss[i]:
            res = "".join(ss[:i + 1])
            break

print(res)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    from string import ascii_lowercase
    dic = {a: i for i, a in enumerate(ascii_lowercase)}
    rdic = {i: a for i, a in enumerate(ascii_lowercase)}
    if len(S) != 26:
        for s in ascii_lowercase:
            if s not in S:
                return print(S + s)
    elif S == "zyxwvutsrqponmlkjihgfedcba":
        return print(-1)

    pre = S[0]
    for i, s in enumerate(S[1:]):
        if pre > s:
            if pre != "z":
                # 'bacdefghijklmnopqrstuvwxyz' -> 'c'
                return print(S[:i] + rdic[(dic[pre] + 1)])
            elif i != 0:
                # 'abcdefghijklmnopqrstuvwzyx' -> 'abcdefghijklmnopqrstuvx'
                return print(S[:i-1] + rdic[dic[S[i-1]] + 1])
            else:
                idx = S.index(s)
                widx = S.index(rdic[dic[s] + 1])
                S = [s for s in S]
                S[idx], S[widx] = S[widx], S[idx]
                return print("".join(S))
        pre = s


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = list(input())

if len(S) < 26:
  ss = list(sorted(S))
  for i in range(len(S)-1):
    if ord(ss[i+1]) - ord(ss[i]) > 1:
      ans = ord(ss[i]) + 1
      break
    elif i + 1 == len(S) - 1 and ord(ss[i+1]) != 122:
      ans = ord(ss[i+1]) + 1
  print("".join(S)+chr(ans))
else:
  ans = -1
  for i in range(len(S) - 1):
    if ord(S[i+1]) - ord(S[i]) > 1:
      ans = ord(S[i]) + 1
      n = i 
      break
  print(ans if ans == -1 else "".join(S[:n]) + chr(ans))

Submission status: Wrong Answer

Solution code:
S = list(input())
alp = ['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 ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)

if len(S) != 26:
    for a in alp:
        if not(a in S):
            print(''.join(S) + a)
            exit(0)

for i in range(len(S)):
    if alp.index(S[i]) < alp.index(S[i+1]):
        S[i]=S[i+1]
        print(''.join(S[:i+1]))
        exit(0)

Submission status: Wrong Answer

Solution code:
# -*- 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))

Submission status: Wrong Answer

Solution code:
s = list(input())
a = [chr(ord('a') + i) for i in range(26)]
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) != 26:
    for i in range(len(a)):
        if a[i] not in s:
            s.append(a[i])
            print("".join(s))
            exit()
else:
    used = [s[25]]
    for i in range(25, 0, -1):
        if a.index(s[i-1]) > a.index(s[i]):
            used.append(s[i-1])
        else:
            for j in range(a.index(s[i-1])+1, 26):
                if a[j] in used:
                    s[i-1] = a[j]
                    print("".join(s[:i]))
                    exit()

Submission status: Wrong Answer

Solution code:
S = list(input())
alp = ['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 ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)

if len(S) != 26:
    for a in alp:
        if not(a in S):
            print(''.join(S) + a)
            exit(0)

for i in range(len(S)):
    if S[i] != alp[i]:
        S[i-1] = alp[i]
        print(''.join(S[:i]))
        exit(0)
else:
    S[-2]=S[-1]
    S[-1]=''
    print(''.join(S))

Submission status: Wrong Answer

Solution code:
S = list(input())

if len(S) < 26:
  ss = list(sorted(S))
  for i in range(len(S)-1):
    if ord(ss[i+1]) - ord(ss[i]) > 1:
      ans = ord(ss[i]) + 1
      break
    elif i + 1 == len(S) - 1 and ord(ss[i+1]) != 122:
      ans = ord(ss[i+1]) + 1
  print("".join(S)+chr(ans))
else:
  ans = -1
  for i in range(len(S) - 1):
    if ord(S[i+1]) - ord(S[i]) > 1:
      ans = ord(S[i]) + 1
      n = i + 1
      break
  print(ans if ans == -1 else "".join(S[:n]) + chr(ans))

Submission status: Wrong Answer

Solution code:
S = list(input())

if len(S) < 26:
  ss = list(sorted(S))
  for i in range(len(S)-1):
    if ord(ss[i+1]) - ord(ss[i]) > 1:
      ans = ord(ss[i]) + 1
      break
    elif i + 1 == len(S) - 1 and ord(ss[i+1]) != 122:
      ans = ord(ss[i+1]) + 1
  print("".join(S)+chr(ans))
else:
  ans = -1
  for i in range(len(S) - 1):
    if ord(S[i+1]) - ord(S[i]) > 1:
      ans = ord(S[i]) + 1
      n = i
      break
  print(ans if ans == -1 else "".join(S[:n]) + chr(ans))

Submission status: Wrong Answer

Solution code:
S = list(input())
alp = ['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 ''.join(S) == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)

if len(S) != 26:
    for a in alp:
        if not(a in S):
            print(''.join(S) + a)
            exit(0)

for i in range(26):
    if S[i] != alp[i]:
        S[i-1] = alp[i]
        print(''.join(S[:i]))
        exit(0)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
if len(s) < 26:
    for i in range(26):
        tmp = chr(i + ord('a'))
        if not tmp in s:
            print(s + tmp)
            exit()
if len(set(s)) == 26:
    for i in reversed(range(len(s))):
        for j in range(ord(s[i]) + 1, ord('z')):
            if s[i] != 'z' and not chr(j) in s[:i]:
                print(s[:i] + chr(j))
                exit()
    print(-1)
    exit()
ans = [i for i in s]
for i in reversed(range(len(s))):
    tmp = chr(ans[i] + 1)
    if not tmp in ans:
        ans[i] = tmp
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
s = str(input())
S = set(list(s))
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

for i in range(26):
    c = chr(i+ord('a'))
    if c not in S:
        print(s+c)
        exit()
else:
    ans = ''
    for i in range(26):
        c = chr(i+ord('a'))
        if s[i] == c:
            ans += c
        else:
            ans = ans[:-1]
            break
    ans += c
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import Counter

s = input().rstrip()
n = len(s)
cnt = Counter(s)

for i in range(97, 97 + 26):
    key = chr(i)
    if key not in s:
        print(s + key)
        exit()

smallest = s[-1]
for i, ch in enumerate(s[::-1]):
    if ch < smallest:
        s = s[:n-i-1] + smallest
        print(s)
        exit()
    smallest = min(smallest, ch)

print(-1)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
backet = [0] * 26
if l != 26:
  for i in s:
    backet[ord(i) - 97] = 1
  for i in range(26):
    if not backet[i]:
      print(s + chr(i + 97))
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    d = []
    for i in s[::-1]:
      s = s[:-1]
      d.sort()
      for j in d:
        if j > ord(i)-97:
          print(s + chr(j+97))
      d.append(ord(i)-97)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
if len(s) < 26:
    for i in range(26):
        tmp = chr(i + ord('a'))
        if not tmp in s:
            print(s + tmp)
            exit()
if len(set(s)) == 26:
    for i in reversed(range(len(s))):
        tmp = chr(ord(s[i]) + 1)
        if s[i] != 'z' and not tmp in s[:i]:
            print(s[:i] + tmp)
            exit()
    print(-1)
    exit()
ans = [i for i in s]
for i in reversed(range(len(s))):
    tmp = chr(ans[i] + 1)
    if not tmp in ans:
        ans[i] = tmp
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
t="abcdefghijklmnopqrstuvwxyz"
s=input()
if s==t[::-1]:print(-1);exit()
if len(s)!=26:
  for i in t:
    if i not in s:print(s+i);exit()
i=25
while s[i-1]>s[i]:i-=1
ss=list(s[i-1:])
ss.sort()
print(s[:i-1]+ss[1])

Submission status: Wrong Answer

Solution code:
t="abcdefghijklmnopqrstuvwxyz"
s=input()
if s==t[::-1]:print(-1);exit()
if len(s)!=26:
  for i in t:
    if i not in s:print(s+i);exit()
i=25
while s[i-1]>s[i]:i-=1
print(s[:i-1]+min(list(s[i:])))

Submission status: Wrong Answer

Solution code:
s = input()
alp = list("abcdefghijklmnopqrstuvwxyz")
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) < 26:
    for i in alp:
        if i not in s:
            print(s+i)
            break
else:
    ans = ""
    for i in range(len(s)-1):
        f = True
        for j in range(i, len(s)-1):
            if ord(s[j]) < ord(s[j+1]):
                f = False
                break
        if f:
            t = sorted(list(s[i:]))
            for k in t:
                if ord(s[i-1]) < ord(k):
                    print(s[:i-1] + k)
                    break
            exit()
    print(s[:-2] + s[len(s)-1] + s[len(s)-2])

Submission status: Wrong Answer

Solution code:
s = input()
alp = list("abcdefghijklmnopqrstuvwxyz")
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) < 26:
    for i in alp:
        if i not in s:
            print(s+i)
            break
else:
    ans = ""
    for i in range(len(s)-1):
        f = True
        for j in range(i, len(s)-1):
            if ord(s[j]) < ord(s[j+1]):
                f = False
                break
        if f:
            t = sorted(list(s[i:]))
            for k in t:
                if ord(s[i-2]) < ord(k):
                    print(s[:i-1] + k)
                    break
            exit()
    print(s[:-2] + s[len(s)-1] + s[len(s)-2])

Submission status: Wrong Answer

Solution code:
s = input()
alp = list("abcdefghijklmnopqrstuvwxyz")
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) < 26:
    for i in alp:
        if i not in s:
            print(s+i)
            break
else:
    ans = ""
    for i in range(len(s)-1):
        f = True
        for j in range(i, len(s)-1):
            if ord(s[j]) < ord(s[j+1]):
                f = False
                break
        if f:
            t = sorted(list(s[i:]))
            print(s[:i-1] + t[0])
            exit()
    print(s[:-2] + s[len(s)-1] + s[len(s)-2])

Submission status: Wrong Answer

Solution code:
import collections
s = input()
alp = list("abcdefghijklmnopqrstuvwxyz")
A = collections.Counter()
for i in alp:
    A[i] = 0
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    ans = ""
    for i in s:
        if i == "z" and len(s) == 26:
            ans = ans[:len(ans)-1]
            break
        ans += i
        A[i] = 1
    for i in A:
        if A[i] == 0:
            ans += i
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s = input()
alp = list("abcdefghijklmnopqrstuvwxyz")
A = collections.Counter()
for i in alp:
    A[i] = 0
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    ans = ""
    for i in s:
        if i == "z":
            ans = ans[:len(ans)-1]
            break
        ans += i
        A[i] = 1
    for i in A:
        if A[i] == 0:
            ans += i
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s  = list(input())
n = len(s)
alp = "abcdefghijklmnopqrstuvwxyz"
alp = list(alp)
co_alp = collections.Counter(alp)
if n==26:
    for i in range(n-1):
        if s[-i-1] >s[-i-2]:
            q = min(s[-i-1:])
            l = s[:-i-2]
            l.append(q)
            print("".join(l))
            break
    else:
        print(-1)
    exit()

for i in range(n):
    co_alp[s[i]]+=1
for w,num in sorted(co_alp.items()):
    if num==1:
        s.append(w)
        break
print("".join(s))

Submission status: Wrong Answer

Solution code:
S = input()

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]
rev = chars[::-1]

c = dict()

for ci in chars:
    c[ci] = 0

ans = None
if S == 'zyxwvutsrqponmlkjihgfedcba':
    ans = -1
elif len(S) < 26:
    for si in S:
        c[si] += 1

    ne = None
    for k in sorted(c.keys()):
        if c[k] == 0:
            ne = k
            break
    ans = S + ne
else:
    if S[-2] < S[-1]:
        ans = S[:-2] + S[-1]
    else:
        S = S[::-1]
        ind = None
        for i in range(len(S)-1):
            if ord(S[i]) > ord(S[i+1]):
                ind = i
                break
        ans_rev = S[0] + S[i+2:]
        ans = ans_rev[::-1]

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]
rev = chars[::-1]

c = dict()

for ci in chars:
    c[ci] = 0

ans = None
if S == 'zyxwvutsrqponmlkjihgfedcba':
    ans = -1
elif len(S) < 6:
    for si in S:
        c[si] += 1

    ne = None
    for k in sorted(c.keys()):
        if c[k] == 0:
            ne = k
            break
    ans = S + ne
else:
    if S[-2] < S[-1]:
        ans = S[:-2] + S[-1]
    else:
        S = S[::-1]
        ind = None
        for i in range(len(S)-1):
            if ord(S[i]) > ord(S[i+1]):
                ind = i
                break
        ans_rev = S[0] + S[i+2:]
        ans = ans_rev[::-1]

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]
rev = chars[::-1]

c = dict()

for ci in chars:
    c[ci] = 0

ans = None
if S == 'zyxwvutsrqponmlkjihgfedcba':
    ans = -1
elif len(S) != 26:
    for si in S:
        c[si] += 1

    ne = None
    for k in sorted(c.keys()):
        if c[k] == 0:
            ne = k
            break
    ans = S + ne
else:
    S = S[::-1]
    sm = S[0]
    sm_ind = -1
    for i, si in enumerate(S):
        if si < sm:
            sm = si
            sm_ind = i
            break
    # print(sm, sm_ind)
    S = S[::-1]
    ans = S[:-4] + S[-1]

print(ans)

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase


def main():
    word = input()
    if len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count_l = list(count.items())
        count_l.sort(key=lambda x: x[0])
        print(count_l)
        add = ""
        for i in range(26):
            if count_l[i][1] == 0:
                add = count_l[i][0]
                break
        print(word + add)
    elif word == ascii_lowercase[::-1]:
        print(-1)
    else:
        is_printed = False
        while len(word) > 0 and not is_printed:
            for c in ascii_lowercase[ascii_lowercase.index(word[-1]) + 1:]:
                if c not in word[:-1]:
                    print(word[:-1] + c)
                    is_printed = True
                    break
            else:
                word = word[:-1]


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase


def main():
    word = input()
    if len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count_l = list(count.items())
        add = ""
        for i in range(26):
            if count_l[i][1] == 0:
                add = count_l[i][0]
                break
        print(word + add)
    elif word == ascii_lowercase[::-1]:
        print(-1)
    else:
        is_printed = False
        while len(word) > 0 and not is_printed:
            for c in ascii_lowercase[ascii_lowercase.index(word[-1]) + 1:]:
                if c not in word[:-1]:
                    print(word[:-1] + c)
                    is_printed = True
                    break
            else:
                word = word[:-1]


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase


def main():
    word = input()
    if len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count_l = list(count.items())
        add = ""
        for i in range(26):
            if count_l[i][1] == 0:
                add = count_l[i][0]
                break
        print(word + add)
    else:
        stop = ascii_lowercase[::-1]
        final_permutation_index = 26
        for i in range(-2, -27, -1):
            if word[i:] not in stop:
                final_permutation_index = 26 + i
                break
        if final_permutation_index == 26:
            print(-1)
        else:
            add = sorted(list(word[final_permutation_index:]))
            final = ""
            delta = float("inf")
            for i in range(len(add)):
                if abs(ord(add[i]) - ord(word[final_permutation_index]) - 1) < delta:
                    final = add[i]
                    delta = abs(ord(add[i]) - ord(word[final_permutation_index]) - 1)
            print(word[:final_permutation_index] + final)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase


def main():
    word = input()
    if len(word) < 26:
        count = {}
        for a in ascii_lowercase:
            count[a] = 0
        for w in word:
            count[w] += 1
        count_l = list(count.items())
        add = ""
        for i in range(26):
            if count_l[i][1] == 0:
                add = count_l[i][0]
                break
        print(word + add)
    else:
        stop = ascii_lowercase[::-1]
        final_permutation_index = 26
        for i in range(-2, -27, -1):
            if word[i:] not in stop:
                final_permutation_index = 26 + i
                break
        if final_permutation_index == 26:
            print(-1)
        else:
            add = sorted(list(word[final_permutation_index + 1:]))[0]
            print(word[:final_permutation_index] + add)


if __name__ == '__main__':
    main()