Resistor Circuit

Compute the equivalent resistance of a nested series-parallel resistor circuit described by a bracketed string.

Easy3StackMathNo attempts yetTime limit1sMemory limit64 MB

Problem

Mirko got a "Young physicist" kit for his birthday. The kit holds NN types of resistors, connecting wires, and an ohmmeter. A resistor of type ii has a resistance of exactly RiR_i ohms.

Resistors are connected in two ways, in series and in parallel. A whole circuit of resistors can be replaced by a single resistor whose resistance equals the equivalent resistance of that circuit. A series circuit is written as (R1-R2-R3-...-RK), and its equivalent resistance is

Req=R1+R2+R3++RKR_{eq} = R_1 + R_2 + R_3 + \dots + R_K

A parallel circuit is written as (R1|R2|R3|...|RK), and its equivalent resistance is

Req=11R1+1R2+1R3++1RKR_{eq} = \frac{1}{\dfrac{1}{R_1} + \dfrac{1}{R_2} + \dfrac{1}{R_3} + \dots + \dfrac{1}{R_K}}

Mirko brought the kit to school and the teacher noticed it. She built one circuit and is asking Mirko for its equivalent resistance. Help him answer.

Input

The first line contains the number of resistor types NN. (1N91 \le N \le 9)

The second line contains NN real numbers RiR_i. (0<Ri<1000 < R_i < 100)

The third line contains the string SS describing the circuit. SS is at most 100,000 characters long and consists only of the characters R, the digits 1 to 9, (, ), -, and |. The number of bracket pairs is minimal and the brackets are paired correctly. No pair of brackets contains both - and |. The circuit uses only resistors from the kit. Some types may go unused, and a type may be used several times.

Output

Print the equivalent resistance of the circuit, rounded to exactly five decimal places. Pad with zeros so that five digits always follow the decimal point.