## JDCC '16 Contest 4 P2 - Phi Circuits

View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Tyler invented a special kind of circuit he calls a "Phi circuit." A Phi circuit behaves very differently from a regular circuit. In a Phi circuit, diodes receive current equaling the sum of the current received by the previous two electrical components. Resistors receive current equaling the absolute difference of the current received by the previous two electrical components.

Tyler has a special kind of LED (light emitting diode) that emits 1 lumen of light for every 1 ampere of current it receives. Given a linear circuit described by a series of resistors and LEDs determine the total number of lumens outputted by the LEDs in the circuit.

#### Input

Each test case contains a sequence of the characters P, L, and R describing the circuit. The first two components are marked P for power source and have 1 ampere of current passing through them. All subsequent components are either LEDs or resistors, marked L or R respectively. The circuit does not contain more than 60 components.

#### Output

For each test case, output the total number of lumens produced by the circuit.

#### Sample Input

PPLLLLL

#### Sample Output

31

#### Sample Input

PPRRLLRR

#### Sample Output

3

#### Explanation of Sample Input

In the first case, the first LED has amperes of current and hence outputs 2 lumens. The next four LEDs receive 3, 5, 8, and 13 amperes respectively, for a total of lumens.

In the second case, the first resistor carries amperes and the second carries ampere. Then the first LED carries ampere and the second receives amperes, for a total of 3 lumens of light.