#P8584. Interstellar Signpost Calculation

    ID: 21750 Type: Default 1000ms 256MiB

Interstellar Signpost Calculation

Interstellar Signpost Calculation

In the year 2102, humanity has established an interstellar channel from Earth to the star (\alpha) in Virgo that spans hundreds of light years. Along the channel, there are many signposts. The (i^{\text{th}}) signpost displays a fraction (\frac{a_i}{b_i}) and an operator (either (+) or (-)).

Initially, you hold the number 0. As you walk along the channel, when you reach each signpost, you update your number by performing the operation indicated on the signpost between your current number and the fraction on the signpost. If the result is an integer, keep it as an integer; otherwise, represent it as an irreducible fraction.

Determine the final number you are holding when you reach the end of the channel.

inputFormat

The first line contains an integer (n) (1 \le n \le 10^5) that represents the number of signposts. Each of the following (n) lines contains two integers (a_i) and (b_i) (with (b_i \neq 0)) and a character (either '+' or '-') separated by spaces. The signpost instructs you to update the current number by performing the operation: current number ( \text{op} ) (\frac{a_i}{b_i}).

outputFormat

Output the final number after processing all the signposts. If the final result is an integer, output it as an integer. Otherwise, output it as an irreducible fraction in the form (p/q) (with no extra spaces).

sample

3
2 3 +
1 6 -
3 3 +
3/2