Submit solution


Points: 3
Time limit: 3.3s
Memory limit: 333M

Author:
Problem types

You are given a positive integer, N. Determine the minimum number of digits of N which must be replaced with 3's to make N divisible by 3.

Constraints

1 \le N < 10^{1\,000\,000}

Input Specification

The first line contains one integer, N.

Output Specification

Output one line containing one integer, the minimum number of digits of N which must be replaced with 3's to make N divisible by 3. It can be shown that it is always possible to make N divisible by 3.

Sample Input 1

31415

Sample Output 1

1

Explanation for Sample 1

If you replace the last digit of 31415 with a 3, you get 31413, which is divisible by 3. (31413 = 3 \times 10471)

It can be shown that this is the minimal number of digit replacements.

Sample Input 2

42

Sample Output 2

0

Explanation for Sample 2

42 is already divisible by 3, so no digit replacements are required.


Comments

There are no comments at the moment.