#00061D

P-Dioda

A diode is an element of an electrical circuit whose role is to (in the branch where it is located) pose very little resistance to a current coming in one direction, and very large resistance when it is coming in the opposite direction. An ideal diode is an idealization of this - when the current is moving in one direction: R = 0, and in the other: R → ∞.


You are given parameters of a circuit containing resistors and ideal diodes. Your task is to calculate the equivalent resistances for both directions of the current.


InputThe elements of the circuit are input in sets, in this format:
PAR
<e1>
<e2>
...
PAR

indicates a parallel connection, and:
SER
<e1>
<e2>
...
SER

indicates a serial connection.
In this format, ei can be:
- an integer R (10 <= R <= 10000), meaning that a resistor of resistance R is on that place;
- 'D' - meaning that a directly polarised diode is located on that place;
- 'ID' - meaning that an inversely polarised diode is located on that place;
- A set of elements.
The input ends when the set that was opened first gets closed.
The amount of sets will not exceed 1000. The amount of elements within each set will not exceed 20.

OutputWrite two real numbers, rounded to three decimals, separated by a space, to the standard output. The numbers represent the equivalent resistances for direct and inverse current directions, respectively. Solutions deviating from the correct one by 0.001 will be accepted.

Input:
PAR
20
SER
PAR
10
D
PAR
10
SER
PAR

Output:
6.667 10.000
Explanation: The circuit diagram of this example is:

Image: circuit-example


We may notice that when the current is direct, it will pass through the diode without resistance, hence forming a short circuit around the second resistor, so it is eliminated from the circuit; we are left with two parallel-connected resistors of 20 and 10 ohms.
When the current is inverse, it will not enter the branch with the diode, so this situation is equivalent to the diode not being there in the first place. It is a parallel connection of a resistor of 20 ohms and a serial connection of two 10-ohm resistors.

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.