Data ScienceEasyOutputStatistics

Rainfall Summary

Turn a messy list of daily rainfall readings into the four numbers every report starts with: mean, median, mode and standard deviation.

50 ptsEstimated time: 15 min

Statement

Story

A weather station logs the rainfall (in millimetres) of every day of the season, in the order the readings arrived. Before the data goes into a dashboard, the analyst wants a one-glance summary.

Task

Read the readings and print four statistics, one per line, in this order:

  1. mean: the sum divided by the count
  2. median: the middle value of the sorted readings; for an even count, the average of the two middle values
  3. mode: the most frequent value; if several values share the highest frequency, print the smallest of them
  4. standard deviation: the population standard deviation, sqrt( Σ(x − mean)² / n ) (divide by n, not n − 1)

Input

  • Line 1: n (1 ≤ n ≤ 5000)
  • Line 2: n numbers, each with at most 2 decimal places and |x| ≤ 100000, in no particular order

Output

Four lines with the four numbers. Print at least 4 decimals; any answer within 0.0001 of the exact value is accepted.

Example

8
2 4 4 4 5 5 7 9

Output:

5
4.5
4
2

(The mean is 40 / 8 = 5, the two middle values 4 and 5 give 4.5, the value 4 appears three times, and the squared distances from 5 add up to 32, so σ = √(32 / 8) = 2.)

Sample input

8
2 4 4 4 5 5 7 9

Hints

Stuck? Hints are optional, and each one lowers the points you earn for solving this challenge.

  1. Hint 1Costs 5 points

    Sign in to reveal hints.

  2. Hint 2Costs 5 points

    Reveal the previous hint first

  3. Hint 3Costs 10 points

    Reveal the previous hint first

Lessons that teach this

Stuck on the ideas rather than the puzzle? These lessons cover what you need.