"THE MOBILE" (SWEDEN)

In figure 1 you can see a mobile in perfect balance. The mobile have five weights 1 kg, 2 kg ... 5 kg. The distance between two marks is 1 m. You can check the balance through this calculation

-3·3 + -1·5 + 2·(1+2+4)=0
-2·1 + -1·2 + 1·4=0

When you get a mobile problem you will get the structure of the mobile from a character string. The mobile in figure 1 is described in this way

(-3,-1,2(-2,-1,1))

You have to calculate such weights so the mobile is in perfect balance and give the answer as another character string. From figure 1 with the five weights the answer is

(3,5,(1,2,4))

You will now write a program reading a description of a mobile from an input file, calculate the weights and writing the answer to an output file.

• If there are n weights in the mobile you must use the weights from 1 kg to n kg exactly once
• The mobile must be in perfect balance.
• n £ 17
• There will be no more than 7 attachments hanging from any of the bars. The mobile on fig.1 has 2 bars with 3 attachments hanging from each.
• The input string will be given as a single line in the input file MOBILE.IN. All numbers are integers which values are between -50 and 50 (inclusive).
• The output string must be given as a single line in the output file MOBILE.OUT, without spaces.
• You can assume that for each given test data at least one solution exists. If more than one solution is possible, you must output one of them.
Here you will have two additional examples with input and output string.

Input data (file MOBILE.IN)
(-3(-1(-1(-1,1,2),3),2),3(-2,1,2),6(-2,3))

Output data (file MOBILE.OUT)
((((8,6,1),5),10),(9,4,7),(3,2))

Input data (file MOBILE.IN)
(-8,-4(-5,-3,-1,1),-2(-1,1,3),2(-1(-3,-2,1(-2,1,3)),1,3),6)

Output data (file MOBILE.OUT)
(10,(1,2,4,15),(14,5,3),((6,8,(16,11,7)),9,13),12)