Tree of Resistors
Let's build a tree with the following structure: starting at the root, there is one vertex. From this vertex, A_1 edges branch out. From each of these A_1 leaves, A_2 edges emerge. Continuing this pattern, from the A_1A_2 vertices at level 2 (where the root is level 0, the next A_1 vertices are level 1, and so on), A_3 edges emerge. This process continues up to level N. The entire tree is then symmetrically mirrored, except for the level numbered N, creating a lace-like structure of edges, with 1 vertex at levels 0 and 2N.
Each edge connecting levels I and I+1 has a uniform resistance R_i. Your task is to determine the resistance between the vertices at levels 0 and 2N.
Input
The input begins with an integer N (N ≤ 50). The next line contains N integers, representing the number of edges emerging from level 0, level 1, level 2, and so on. Following this, there are 2N integers, each indicating the resistance of the conductors connecting levels 0 and 1, level 1 and level 2, and so forth. Constraints are 1 ≤ A_i ≤ 50 and 1 ≤ R_i ≤ 100.
Output
Output a single number representing the total resistance of the system. The result should be printed with up to 200 decimal places, but if the desired precision is reached earlier, trailing zeros should not be included.