LISA  Pocket Money
Young people spend a lot of money on things like sweets, music CDs, mobile phones and so on. But most young girls/boys have one problem: Their pocket money is not enough for all these jolly things. Little Lisa Listig is one of these poor girls with a small pocket money budget. Last month her pocket money lasted only one week. So she decided to enter into negotiations with her father. Her father Tomm  a mathematician  had an incredibly ingenious idea: He wrote down some fancy digits with operators (+,*) in between them on a sheet of paper and allowed Lisa to insert brackets. Then he declared that the result of that arithmetic expression is Lisa's new pocket money. Now it's Lisa's task to maximize her pocket money. As her father was surprised what a huge sum of money Lisa got for her result, he decided to minimize the result of the expression for his son Manfred. Now it's your task to calculate the results obtained by Lisa and her father.
Input
The first line of input contains the number of testcases k ( k< 5000 ). Each of the following k lines consists of an arithemtic expression. This expression consists of numbers (09) seperated by one of the two operators '*' and '+'. There are no spaces between the characters. Each line contains less than 100 characters.
Output
For each expression output the result obtained by Lisa and the result obtained by her father separated by one space. The results of the calculations are smaller than 2^{64}.
Example
Input: 1 1+2*3+4*5 Output: 105 27
Two possible expressions for the first testcase:
105 = (1+2)*(3+4)*5 27 = 1+2*3+4*5
hide comments
siddharth9820:
20161002 14:07:27
O(n^3), just be careful with the data types. 

Nallagatla Manikanta:
20160812 09:26:40
accepted in one go :) 

mkfeuhrer:
20160711 20:52:38
learnt something new !! nice MCM:) 

aexpo:
20160627 13:33:10
oh my god :)


kartikay singh:
20160315 08:24:54
A Naive implementation of MCM ....) 

sai krishna:
20160222 17:57:36
19.80 using TOP DOWN wondering how it accepted ;) 

bunnycoder:
20160113 22:01:06
matrix chain as easy as it gets


hashem sllat:
20151020 21:28:02
Last edit: 20151020 21:28:52 

Shashank Tiwari:
20150916 19:04:57
solved it with dp in o(n^3) solution 

!!AV!!:
20150603 23:14:33
classical DP problem 
Added by:  Simon 
Date:  20050517 
Time limit:  32s 
Source limit:  8082B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL GOSU JSRHINO 
Resource:  Ulm Algorithm Course SoSe 2005 