#P1874. 快速求和

快速求和

Description

Given a numeric string, make it equal to a given target number using the minimum number of additions. Each addition means inserting a plus sign at some position in the string. After all required plus signs are inserted, evaluate it as ordinary addition.

For example, consider the string 12. With 00 additions, we get the number 1212. If we insert 11 plus sign, we get 33. Therefore, in this case, the minimum number of additions to obtain the number 33 is 11.

Another example: consider the string 303 and the target number 66. The optimal way is not 3+0+3, but 3+03. This works because a leading 00 in a number does not change its value.

Input Format

The first line: a string ss.

The second line: an integer nn.

Output Format

Output a single integer on one line, the minimum number of additions to make ss equal to nn. If it is impossible to make ss equal to nn, output 1-1.

99999
45

4

Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that 1len(s)401 \le \operatorname{len}(s) \le 40, 1n1051 \le n \le 10^5.

Translated by ChatGPT 5