URI Online Judge | 2673

Serial and Parallel Resistors

By Hamilton José Brumatto, UESC BR Brazil

Timelimit: 1

An association of resistors always results in an equivalent resistor. This association can be in parallel, in series or hybrid. See example of a parallel association:


This parallel association is equivalent to a resistor of 10 Ω. We can also consider series associations, as the example below, which results in an equivalent resistance of 40Ω.


Finally, a hybrid association, with series and parallel. The association below results in 50Ω.


To better represent an association we will consider the equivalent resistance Req of a series association between resistors R1 and R2 represented as: Req = R1 - R2. Similarly for the parallel association: Req = R1 | R2. There is no precedence between associations, except when explicitly expressed in parentheses, for example: R1 - R2 | R3 is equivalent to (R1-R2) | R3, and R1 | R2 - R3 is equivalent to (R1 | R2 - R3) These two circuits can be drawn, respectively, as:


In this way a hybrid association is represented by an expression that follows the following rule, considering R the nominal value of a resistance in Ohms (Ω):

exp := R;
exp := exp - exp;
exp := exp | exp;
exp := ( exp ).

The hybrid circuit of the third figure above could be represented by the expression:

Req = 20 - (20 | 20) - 20 = 50

You have been asked for a program where, given the expression of an association, calculate the equivalent resistance.


The input contains several test cases, each test case occupying a line of a maximum of 300 symbols (there is no blank space) and represents a valid expression for the association of resistors, where each resistor value is represented by an integer R (0 < R < 10000). The end of the test cases coincides with the end of the input.


For each test case, the equivalent resistance value with three decimal digits is expected on a single line.

Input Sample Output Sample