P23735 [AtCoder] [ABC033C] Rewriting a Formula
普及-
题目描述

Problem Description

Given a formula $ S $ that satisfies the following constraints:

  • The operators are only + (addition) and * (multiplication). Multiplication is calculated first.
  • There are no parentheses.
  • Each term is a single-digit integer.

For example, formulas like 1+3*4*0, 1+2+3+4+5 satisfy these conditions, but formulas like 12+3+5, 4*6*7-3, (3+4)*5+2 do not satisfy the conditions and will not be given as input.

You want to rewrite some of the digits in the formula to 0 to make the value of the formula $ 0 $. Find the minimum number of digits that must be rewritten to 0 to achieve this.

Input Format

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

$ S $

  • The first line contains a formula $ S $ that satisfies the conditions in the problem statement (the length of $ S $ is between $ 1 $ and $ 100,000 $).

Output Format

Output the minimum number of digits that must be rewritten to 0 in one line.

Make sure to include a newline at the end of the output.

Sample Input and Output

Sample Input #1

0+0+2*0

Sample Output #1

0

Sample Input #2

3*1+1*2

Sample Output #2

2

Sample Input #3

3*1*4+0+2*0+5*2+9*8*6+1+3

Sample Output #3

5

Notes/Hints

Sample Explanation 1

The given formula is already $0\ +\ 0\ +\ 2\ *\ 0\ =\ 0$, so no digits need to be rewritten.

Sample Explanation 2

For example, rewriting the first and fifth characters of the input to 0 results in $0\ *\ 1\ +\ 0\ *\ 2\ =\ 0$, making the value $ 0 $.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
0+0+2*0
样例输出
0