题目描述
Problem Description
In the year 2102, humanity has established an interstellar passage from Earth to the star Alpha in the Virgo constellation. This passage stretches for hundreds of light-years.
Along this passage, there are numerous signposts. The \(i\)-th signpost displays a fraction \(\dfrac{a_i}{b_i}\) and a fractional operator, either \(+\) or \(-\).
Initially, you hold the number \(0\). As you walk along the passage, each time you reach a signpost, you perform the operation indicated by the signpost between the number you hold and the fraction on the signpost, and you replace the number you hold with the result. It is important to note that if the result of the calculation is not an integer, it will be kept in its simplest fractional form; otherwise, it will be kept as an integer.
You want to know what number you will be holding when you reach the end of the passage.
Input Format
The first line contains a single positive integer \(n\), indicating that there are \(n\) signposts in the passage.
Lines \(2\) to \(n+1\) each contain three positive integers \(a_i, b_i, opt_i\), representing that the \(i\)-th signpost displays the fraction \(\dfrac{a_i}{b_i}\) and the operator \(opt_i\).
Here, the operators \(+\) and \(-\) are represented by \(1\) and \(2\), respectively.
Output Format
Output a single number.
If the final result can be represented as an integer, output an integer \(ans\) representing the result.
Otherwise, if the final result must be represented as a fraction, output the fraction in the form \(a/b\), ensuring that \(\dfrac{a}{b}\) is in its simplest form, i.e., \(\gcd(a, b) = 1\).
Note that the result may be negative, in which case the negative sign should be retained. For example, if the result is \(-\dfrac{11451}{4}\), output -11451/4.
Sample Input and Output
Sample Input #1
3
3 5 1
4 7 2
7 3 1
Sample Output #1
248/105
Sample Input #2
4
6 7 1
8 3 2
9 14 2
5 17 1
Sample Output #2
-1541/714
Sample Input #3
3
7 4 1
3 8 2
3 8 2
Sample Output #3
1
Notes
For \(20\%\) of the data, the operators are only addition.
For another \(20\%\) of the data, the operators are only subtraction.
For \(100\%\) of the data, it is guaranteed that \(1 \leq n \leq 10^3\), \(0 \leq a \leq 1000\), \(0 < b \leq 1000\), and the answer as well as all intermediate values (integer parts/numerators/denominators) do not exceed \(2 \times 10^9\).
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分