P23673 [AtCoder] 2525 String Decomposition
普及+
题目描述

Problem Description

Niwango, an employee of dwango, is developing a new SNS called 2525SNS. 2525SNS is a groundbreaking SNS where only 2525 strings can be posted.

In this problem, a string that is represented by one or more repetitions of 25 is called a 2525 string. For example, 25, 2525, 2525252525252525 are 2525 strings, but an empty string, 2255, 2552, 252 are not 2525 strings.

First, Niwango decided to create several 2525 strings. He wants to decompose a string $ s $ into one or more subsequences such that each decomposed subsequence is a 2525 string.

What is the minimum number of subsequences needed to achieve this? If it is impossible to decompose the string in such a way, output -1. Refer to the explanation of Sample 1 for decomposition.

Input Format

The input is given from the standard input in the following format:

$ s $

Output Format

Output the answer.

Sample Input and Output

Sample Input #1

225525

Sample Output #1

2

Sample Input #2

52

Sample Output #2

-1

Sample Input #3

2255252252222555552522255255

Sample Output #3

5

Sample Input #4

25252

Sample Output #4

-1

Notes/Hints

Constraints

  • $1 \leq |s| \leq 2,525$
  • $ s $ consists only of 2 and 5

Sample Explanation 1

  • If decomposed into one subsequence, 225525 is not a 2525 string, so it does not satisfy the condition.
  • Other decompositions include, for example, $ ( $25, 2525$ ) $ and $ ( $25, 25, 25$ ) $. Show correct and incorrect examples of decomposition for each. Note that the relative order of appearance in $ s $ must be preserved within each subsequence.
  • By decomposing into two subsequences as $ ( $25, 2525$ ) $, each subsequence can be made into a 2525 string.

Sample Explanation 2

  • There are two ways to decompose, but it is impossible to decompose such that each subsequence is a 2525 string.
  • Note that it is impossible to create 25 by decomposing into 5 and 2 and then swapping their order.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
225525
样例输出
2