100 atcoder#ABC182C. [ABC182C] To 3

[ABC182C] To 3

Score : 300300 points

Problem Statement

Given is a positive integer NN, where none of the digits is 00. Let kk be the number of digits in NN. We want to make a multiple of 33 by erasing at least 00 and at most k1k-1 digits from NN and concatenating the remaining digits without changing the order. Determine whether it is possible to make a multiple of 33 in this way. If it is possible, find the minimum number of digits that must be erased to make such a number.

Constraints

  • 1N<10181 \le N \lt 10^{18}
  • None of the digits in NN is 00.

Input

Input is given from Standard Input in the following format:

NN

Output

If it is impossible to make a multiple of 33, print -1; otherwise, print the minimum number of digits that must be erased to make such a number.

35
1

By erasing the 55, we get the number 33, which is a multiple of 33. Here we erased the minimum possible number of digits - 11.

369
0

Note that we can choose to erase no digit.

6227384
1

For example, by erasing the 88, we get the number 622734622734, which is a multiple of 33.

11
-1

Note that we must erase at least 00 and at most k1k-1 digits, where kk is the number of digits in NN, so we cannot erase all the digits. In this case, it is impossible to make a multiple of 33 in the way described in the problem statement, so we should print -1.