You and your friends are at the table, playing an old and interesting game - the Call of Cthulhu.
There is a mechanism in the game: rolling the dice. You use a notation to communicate the type of dice that needs to be rolled - the operator “d”. “xdy” means that an y-sided dice should be rolled x times and the sum of the results is taken.
Formally, for any two integers x,y satisfying x≥0 and y≥1 , “xdy” means the sum of x random integers in the range of [1,y]. It’s obvious that either x<0 or y<1 makes the expression xdy illegal. For example: “2d6” means that rolling a 6-sided dice 2 times. At this time, the result can be at least [1,1]=2, and at most [6,6]=12. The results of rolling can be used extensively in many aspects of the game. In particular, the precedence of “d” is above “*”. Since the operator “d” does not satisfy the associative law, it’s necessary to make sure that “d” is right-associative.
Now the game has reached its most exciting stage. You are facing the Great Old One - Cthulhu. Because the spirit has been greatly affected, your sanity value needs to be deducted according to the result of rolling. If the sanity value loses too much, you will fall into madness. As a player, you want to write a program for knowing the minimum and maximum loss of sanity value before rolling, in order to make a psychological preparation.
The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown. ----H. P. Lovecraft
Input
There are multiple sets of input, at most 30 cases.
Each set of input contains a string of only ‘+’, ‘-’, ‘*’, ‘d’, ‘(’, ‘)’ and integers without spaces, indicating the expression of this sanity loss. The length of the expression will be at most 100.
It is guaranteed that all expressions are legal, all operators except for ‘(’ and ‘)’ are binary, and all intermediate results while calculating are integers in the range of [−2147483648,2147483647].
The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of infinity, and it was not meant that we should voyage far. ----H. P. Lovecraft
Output
For each set of data, output a line of two integers separated by spaces, indicating the minimum and maximum possible values of the sanity loss.
样例输入
3d6*5
2d3d4
样例输出
15 90
2 24
题意:
定义一种运算d,a d b表示 [1,b]的范围内随机a次,a∈[0,+∞),b∈[1,+∞)
这些随机数的和。运算优先级高于乘法
In particular, the precedence of “d” is above “*”.