E

Ensuring Victory

 

Since your team always loses in football, you are now planning to tip the balance in your favor by using a specially designed ball. To this end you construct many balls of varying designs and from several different materials and ask your team to try them out.

 

As expected, the feedback is rather random and inconsistent, with some players liking some of the balls while others not liking those very same ones. Since that is not helping, you decide on a more objective method of finding out which ones are the best. You conduct a series of experiments and observe the behavior of each of these balls when kicked. After the trials, you have worked out for each ball an exact formula that gives the ball's position t seconds after being kicked.

 

Using that, you can determine the behavior of the balls in an actual game accurately on paper. You are interested in knowing the position of the ball as well as the speed at which it is travelling at specific moments in time. The position (which is basically its Euclidean distance from a certain point) is found by simply computing the value from the formula. The speed of the ball is defined as the rate of change of distance with time at that moment (i.e. the derivative of distance with respect to time). Since there are a lot of different balls, you want to automate this process and get the results before the tournament starts.

 

Unfortunately, your football team is not any better at computing than they are at football (you must have guessed that already). So it falls again on you to solve this problem.

 

Input

 

Input file will consist of a number of test cases (<=50). Each test case consists of two lines. The first line is a simple algebraic expression which gives the distance covered by the ball in terms of t. The length of this expression can be at most 200. It will consist of numbers and the operators '*' and '+' and the variable t. The numbers will all be fractional numbers of the format “X/Y”, where X is the numerator and Y the denominator. X and Y in this line will never be negative and Y will never be 0. The expression might also contain parentheses ( '(' and ')' ) to force precedence. The usual rules and precedence of arithmetic apply when using the formula to compute the answer. The next line consists of a single fractional number on a line by itself. It is the value of t. This is also of the form “X/Y”, but here X and Y can also be negative. No input line will be greater than 150 characters in length. There will be no extra whitespace or any blank lines in input.

 

 

Output

 

Output will consist of exactly as many lines as there are cases. For each case, print a line of the form “Case #C: A B”. C is the case (starting from 1), while A and B are fractional numbers in their simplest form. A is the distance of the ball and B is its speed at time t. Both numbers are also of the form “X/Y”. If the value is negative, print it as “-X/Y”. Zero should be printed as “0/1”.

 

 

Note:

  1. As these are specially built balls, their behavior will not always be like what you would expect from an ordinary ball. Don't make any assumptions.
  2. All calculations can be performed without any intermediate fraction, in their reduced forms, overflowing a 32-bit signed integer in their numerators and denominators.
  3. Both the distance and the speed can be negative - these trick footballs can actually move opposite to the direction they were kicked in.
  4. A fractional number X/Y is said to be in its most reduced or simplest form when there is no number other than 1 that evenly divides both X and Y. So, 3/1, 2/5 and 11/17 are in their simplest form but 9/3, 5/20 and 10000/500 are not.

 

Sample Input

Sample Output

((t*t)+2/1)

1/2

((t+t)*2/1)

1/2

(t*1/2)+(t*1/3)

1/4

Case #1: 9/4 1/1

Case #2: 2/1 4/1

Case #3: 5/24 5/6

 


Problemsetter: Muntasir Khan, Special Thanks: Samee Zahur, Jane Alam Jan