A recipe-scaling app tracks ingredient amounts as fractions (e.g. 1/2 cup, 3/4 teaspoon). Given a list of fractions, compute their sum and report it in lowest terms.
Each fraction is given as a numerator and a positive denominator (the numerator may be negative, representing a deduction). Output the reduced sum as p/q where q > 0 and gcd(|p|, q) = 1. If the reduced denominator is 1, output just the integer p (no slash). If the sum is exactly zero, output 0.
Input format
Line 1: an integer n.
Next n lines: two space-separated integers a and b — the fraction a/b.
Output format
The sum of all n fractions, reduced to lowest terms, per the rules above.
Constraints
- 1 <= n <= 20
- -1000 <= a <= 1000
- 1 <= b <= 1000