Find the standard deviation (denoted by $ \sigma $) of $ N $ integers. Standard deviation measures how spread out the data is.
Consider the data set $ {x_1, x_2, \ldots, x_N} $.
$ \overline{x} $ denotes the mean (i.e. average) of the data set. In mathematical notation, $ \displaystyle \overline{x} = \frac{1}{N}\sum_{i=1}^N x_i $.
A formula you can use to compute the standard deviation of the data set is: $$ \sigma = \sqrt{\overline{x^2} - \overline{x}^2} = \sqrt{\frac{1}{N} \left(\sum_{i=1}^N x_i^2\right) - \frac{1}{N^2} \left(\sum_{i=1}^N x_i \right)^2} $$
Input
The first line of input contains an integer $ N $.
The second line of input contains $ N $ integers $ x_1, x_2, \ldots, x_N $
which you are to compute the standard deviation for.
Output
Output the standard deviation of $ {x_1, x_2, \ldots, x_N} $. Your output $ X $ will be considered correct if the absolute error is smaller than $ 10^{-6} $.
Constraints
$ 1 \le N \le 10^3 $
$ -10^3 \le x_i \le 10^3 $
You should use long long
instead of int
to store the results of intermediate calculations
to prevent integer overflow.
On most compilers:
int
can store integers from $ -2^{31} $ to $ 2^{31} - 1 $.long long
can store integers from $ -2^{63} $ to $ 2^{63} - 1 $.
Sample Test Cases
Input | Output | |
---|---|---|
5 6 9 4 2 0 |
3.124099870 |
Scoring: Per Case
Authored by s16f22
Appeared in Test Contest 2.5