Hide

Problem A
Stats

Imagine you have a dataset consisting of non-negative integers, and you want to calculate the mean (average), median (middle value), and mode (most common value) of the integers in your dataset.

However, your data is in an unusual format. You have a list that tells how many of each integer are in the dataset. For example, the list

$75,42,19,87,4$

means that there are $75$ zeros in your dataset, $42$ ones, $19$ twos, etc.

Input

The list of counts in each dataset is given as a comma-separated list, all on one line. Each dataset input is on a separate line. The end of the file indicates the end of the input. The total number of elements represented by your list will be odd (in other words, the sum of the list will be odd), meaning the exact median can be found. There will always be a unique mode. Each element in the given list will be a non-negative integer less than $2^{31}$, and the given list will have at most $1\, 024$ elements.

Output

The output should be formatted on one line per input list, as in the sample output below. Mean may contain any number of digits after the decimal point, but must be within $\pm 0.001$ of the true mean. (The mean is rounded to the $4$-th decimal place in the sample below, but this is not required.) Median and mode should be printed as integers.

Sample Input 1 Sample Output 1
75,42,19,87,4
0,1,2,3,4,5,6,7,88,9
4165,68,156,65,46,1,6846,4,46,1,6546,486,16,4,465456,456,77
0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
mean = 1.5727 median = 1 mode = 3
mean = 7.4000 median = 8 mode = 8
mean = 13.7019 median = 14 mode = 14
mean = 7.0000 median = 7 mode = 7

Please log in to submit a solution to this problem

Log in