Mirko has been a very good boy, so he got exactly what he wanted for his birthday, a “Young physicist” kit! In the kit, there are $N$ types of resistors, connecting wires and an ohmmeter. If a resistor is of type $i$, it provides a resistance of precisely $R_ i$ ohms.

As we all know, resistors can be connected in two different ways, in series and parallel. Also, we know that the complete circuit of resistors can be replaced with one resistor of the resistance equal to the equivalent resistance of the circuit. When the circuit is series, it is written as (R1-R2-R3-…-RK) and the following formula holds:\begin{equation*} R_{\mathrm{eq}} = R_1 + R_2 + R_3 + \cdots + R_ K \quad . \end{equation*}

When the circuit is parallel, it is written as (R1|R2|R3|…|RK) and the following formula holds:\begin{equation*} R_{\mathrm{eq}} = \frac{1}{1/R_1 + 1/R_2 + 1/R_3 + \cdots + 1/R_ K} \quad . \end{equation*}

Mirko was excited to bring his new toy to school, where he showed it to all his friends. Unfortunately for him, the teacher also noticed the toy. She quickly connected a circuit and is now asking Mirko to tell her the equivalent resistance of the circuit. Help Mirko and answer the teacher’s question!

-----Input-----
The first line of input contains the integer $N$ ($1 \leq $N$ \leq 9$) from the task. The following line contains $N$ real numbers $R_ i$ ($0 < R_ i < 100$) from the task. The last line contains the circuit $S$, that will not be longer than $100000$ characters. $S$ will only consist of the following characters: ‘R’, ‘1’–‘9’, ‘(’, ‘)’, ‘-’ and ‘|’. The number of pairs of brackets will be minimal, and the brackets will be paired properly. Inside of a pair of brackets, there will not be the character ‘-’ and the character ‘|’ at the same time. The circuit will only consist of the resistors from the kit and it is possible that not all types of resistors are used, or that one type of resistor is used several times.

-----Output-----
The first and only line of output must contain the number from the task. An absolute error up to $10^{-5}$ will be accepted.

-----Examples-----
Sample Input 1:
3
2 3 6
(R1-R2-R3)
Sample Output 1:
11.00000

Sample Input 2:
3
2 3 6
(R1|R2|R3)
Sample Output 2:
1.00000

Difficulty: interview

Starter code:

Solutions: