题目描述
Problem Description
In the night TV show "Good Evening, It's Godzilla," a panel-flipping game is conducted as follows:
As a participant in the game, you start with $0$ yen.
Each panel has a symbol and a non-negative integer written on it. The symbol and non-negative integer on the $i$-th panel are $c_i$ and $a_i$, respectively.
When you open the $i$-th panel, your cash holdings change according to the following rules:
- If $c_i = $
+, your cash increases by $a_i$ yen. - If $c_i = $
-, your cash decreases by $a_i$ yen. - If $c_i = $
*, your cash is multiplied by $a_i$.
You can open any number of the $N$ panels, one at a time in any order, and you can end the game at any time. Your cash can become negative during the game or at the end.
Knowing in advance what is written on each panel, you aim to maximize your cash at the end of the game. Please answer the maximum amount of cash $M$ you can have at the end of the game.
Input Format
The input is given from the standard input in the following format:
$ N $ $ c_1 $ $ a_1 $ $ : $ $ c_N $ $ a_N $
Output Format
Output the maximum amount of cash $M$ at the end of the game.
Sample Input and Output
Sample Input #1
4
+ 100
- 80
* 3
+ 300
Sample Output #1
1200
Sample Input #2
3
- 314
- 159
- 265
Sample Output #2
0
Sample Input #3
4
* 8
+ 7
* 0
* 5
Sample Output #3
280
Notes/Hints
Constraints
- $1 \leq N \leq 1000$
- $0 \leq a_i \leq 1000$
- $ c_i $ is one of
+,-,*. - The maximum amount of cash $M$ at the end of the game does not exceed $10^9$.
Sample Explanation 1
By opening the panels " $ +100 $ ", " $ +300 $ ", and " $ *3 $ " in order and then ending the game, you can obtain $1200$ yen.
Sample Explanation 2
You can also end the game without opening any panels.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分