Problem A

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


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


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.


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
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