In the event of technical difficulties with Szkopuł, please contact us via email at firstname.lastname@example.org.
If you are familiar with IRC chat, the support team is also reachable on PIRC network (
#szkopul channel. If you are not, just use email.
Please do not ask us things like "how to solve task XYZ?".
Please remember that the support team has to sleep sometimes or go to work in real life.
The firm of Bytel starts to produce series-parallel electronic circuits. Each such a circuit consists of electronic units, connections between them, and two power connections. A series-parallel circuit may consist of:
The circuits are assembled on two-sided printed-circuit boards. The problem is to determine which connections should run on the top and which on the bottom side of the board. For technical reasons as many connections as possible should run on the bottom side but to each unit at least one must come from the top side of the board.
Write a program which:
From the standard input one should read the description of a series-parallel circuit. The description is in a recursive form:
The total number of letters occurring in the description of a circuit does not exceed , and the recursive depth of the description does not exceed .
Your program should write to the standard output. In the first line there should be one integer equal to the minimal number of connections that must run on the top side of the board.
For the input data:
R 3 S 2 X R 2 S 2 X X S 2 X X S 3 X X X R 2 X X
the correct result is:
Task author: Marcin Kubica.