X Olympiad in Informatics 2002/2003

Problem: Printed-Circuit Boards
Author: Marcin Kubica

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.

Task

Write a program which:

Input

From the standard input one should read the description of a series-parallel circuit. The description is in a recursive form: