#K46072. Weighted Average Calculation
Weighted Average Calculation
Weighted Average Calculation
Given a sequence of numbers and their associated weights, calculate the weighted average defined by the formula below:
\[ \text{Weighted Average} = \frac{\sum_{i=1}^{n} x_i w_i}{\sum_{i=1}^{n} w_i} \]
If the sum of the weights is 0, the weighted average is defined to be 0. The input is provided via standard input and the result must be printed to standard output.
inputFormat
The first line of the input contains a single integer n (1 ≤ n ≤ 105) which denotes the number of items.
Each of the next n lines contains two numbers: x and w, where x is the number and w is its weight. The numbers can be floating-point values.
outputFormat
Output a single line containing the weighted average as a floating-point number.
If the sum of weights is 0, output 0.
## sample3
3 1
5 2
10 5
7.875
</p>