CF865E.Hex Dyslexia

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 0abc0abc they may have changed it to a0cba0cb or 0bca0bca , but not abcabc or 0abb0abb .

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 SS , 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 will contain a hexadecimal string SS consisting only of digits 00 to 99 and lowercase English letters from aa to ff , with length at most 1414 . At least one of the characters is non-zero.

输出格式

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.

输入输出样例

  • 输入#1

    f1e
    

    输出#1

    NO
    
  • 输入#2

    0f1e
    

    输出#2

    00f1
    
  • 输入#3

    12d2c
    

    输出#3

    00314
    

说明/提示

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

For example, the numerical value of 0f1e0f1e is 0163+15162+1161+14160=38700·16^{3}+15·16^{2}+1·16^{1}+14·16^{0}=3870 , the numerical value of 00f100f1 is 0163+0162+15161+1160=2410·16^{3}+0·16^{2}+15·16^{1}+1·16^{0}=241 , and the numerical value of 100f100f is 1163+0162+0161+15160=41111·16^{3}+0·16^{2}+0·16^{1}+15·16^{0}=4111 . Since 3870+241=41113870+241=4111 and 00f100f1 is a permutation of 100f100f , 00f100f1 is a valid answer to the second test case.

首页