100 atcoder#ABC182C. [ABC182C] To 3
[ABC182C] To 3
Score : points
Problem Statement
Given is a positive integer , where none of the digits is . Let be the number of digits in . We want to make a multiple of by erasing at least and at most digits from and concatenating the remaining digits without changing the order. Determine whether it is possible to make a multiple of in this way. If it is possible, find the minimum number of digits that must be erased to make such a number.
Constraints
- None of the digits in is .
Input
Input is given from Standard Input in the following format:
Output
If it is impossible to make a multiple of , print -1
; otherwise, print the minimum number of digits that must be erased to make such a number.
35
1
By erasing the , we get the number , which is a multiple of . Here we erased the minimum possible number of digits - .
369
0
Note that we can choose to erase no digit.
6227384
1
For example, by erasing the , we get the number , which is a multiple of .
11
-1
Note that we must erase at least and at most digits, where is the number of digits in , so we cannot erase all the digits.
In this case, it is impossible to make a multiple of in the way described in the problem statement, so we should print -1
.