Codeforces Round 437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)
F
Hex Dyslexia
Codeforces
未评级
原题
← E→
翻译中…

Copying large hexadecimal (base 16) strings by hand can be error prone, but that doesn't stop people from doing it. You've discovered a bug in the code that was likely caused by someone making a mistake when copying such a string. You suspect that whoever copied the string did not change any of the digits in the string, nor the length of the string, but may have permuted the digits arbitrarily. For example, if the original string was $0*abc*$ they may have changed it to $*a*0*cb*$ or $0*bca*$, but not $*abc*$ or $0*abb*$.

翻译中…

Unfortunately you don't have access to the original string nor the copied string, but you do know the length of the strings and their numerical absolute difference. You will be given this difference as a hexadecimal string $*S*$, which has been zero-extended to be equal in length to the original and copied strings. Determine the smallest possible numerical value of the original string.

翻译中…

Input

翻译中…

Input will contain a hexadecimal string $*S*$ consisting only of digits $0$ to $9$ and lowercase English letters from $*a*$ to $*f*$, with length at most $14$. At least one of the characters is non-zero.

翻译中…

Output

翻译中…

If it is not possible, print "NO" (without quotes).

翻译中…

Otherwise, print the lowercase hexadecimal string corresponding to the smallest possible numerical value, including any necessary leading zeros for the length to be correct.

翻译中…

Note

翻译中…

The numerical value of a hexadecimal string is computed by multiplying each digit by successive powers of $16$, starting with the rightmost digit, which is multiplied by $16^{0}$. Hexadecimal digits representing values greater than $9$ are represented by letters: $*a* = 10, *b* = 11, *c* = 12, *d* = 13, *e* = 14, *f* = 15$.

翻译中…

For example, the numerical value of $0*f*1*e*$ is $0·16^{3} + 15·16^{2} + 1·16^{1} + 14·16^{0} = 3870$, the numerical value of $00*f*1$ is $0·16^{3} + 0·16^{2} + 15·16^{1} + 1·16^{0} = 241$, and the numerical value of $100*f*$ is $1·16^{3} + 0·16^{2} + 0·16^{1} + 15·16^{0} = 4111$. Since $3870 + 241 = 4111$ and $00*f*1$ is a permutation of $100*f*$, $00*f*1$ is a valid answer to the second test case.

翻译中…

样例

Input #1
f1e
Output #1
NO
InputCopy OutputCopy
Input #2
0f1e
Output #2
00f1
InputCopy OutputCopy
Input #3
12d2c
Output #3
00314
InputCopy OutputCopy
题目信息
题号
867F
时间限制
3 s
内存限制
256 MB

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