AtCoder Beginner Contest 182
C
To 3
AtCoder
⌀ 274
原题
← BD →
翻译中…

Problem Statement

翻译中…

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

翻译中…

Constraints

翻译中…
  • $1 \le N \lt 10^{18}$
  • None of the digits in $N$ is $0$.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
35
Output #1
1
By erasing the $5$, we get the number $3$, which is a multiple of $3$. Here we erased the minimum possible number of digits - $1$.
Input #2
369
Output #2
0
Note that we can choose to erase no digit.
Input #3
6227384
Output #3
1
For example, by erasing the $8$, we get the number $622734$, which is a multiple of $3$.
Input #4
11
Output #4
-1
Note that we must erase at least $0$ and at most $k-1$ digits, where $k$ is the number of digits in $N$, so we cannot erase all the digits. In this case, it is impossible to make a multiple of $3$ in the way described in the problem statement, so we should print `-1`.
题目信息
题号
abc182_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。