AtCoder Grand Contest 022
A
Diverse Word
AtCoder
⌀ 738
原题
←B →
翻译中…

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.

翻译中…

样例

Input #1
atcoder
Output #1
atcoderb
`atcoderb` is the lexicographically smallest diverse word that is lexicographically larger than `atcoder`. Note that `atcoderb` is lexicographically smaller than `b`.
Input #2
abc
Output #2
abcd
Input #3
zyxwvutsrqponmlkjihgfedcba
Output #3
-1
This is the lexicographically largest diverse word, so the answer is `-1`.
Input #4
abcdefghijklmnopqrstuvwzyx
Output #4
abcdefghijklmnopqrstuvx
题目信息
题号
agc022_a
时间限制
2 s
内存限制
256 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。