cho.sh
Notes
Loading...

Number of Expression Values

Time limit

2s

Memory limit

128 MB

Problem

An expression can be written in prefix, infix, or postfix notation depending on where each operator is placed. In prefix notation, the operator comes before its two operands; in infix notation, it comes between them; and in postfix notation, it comes after them.

You are given one expression with no spaces. Each subexpression may be interpreted as prefix, infix, or postfix notation in any combination. Determine how many distinct final values the whole expression can produce. If different evaluation orders produce the same value, count that value only once.

Input

The first line contains an expression with no spaces. Every number in the expression is a single digit from 0 to 9, and every operator is either + or -. The given expression can be interpreted correctly in at least one way, and its length is at most 80.

Output

Print the number of distinct values that the whole expression can produce.