# Mean, Medium, Mode

### [Mean](http://mathworld.wolfram.com/ArithmeticMean.html) ($$\mu$$)

The average of all the integers in a set of values. Here is the basic formula for calculating the *mean* of a set of $$n$$ values: $$\mu = \frac{\sum\_{i=1}^n x\_i}{n}$$, where $$x$$is the $$i^{th}$$element of the set.&#x20;

### [Median](http://mathworld.wolfram.com/StatisticalMedian.html)

The midpoint value of a data set for which an equal number of samples are *less than* and *greater than* the value. For an odd sample size, this is the middle element of the sorted sample; for an even sample size, this is the *average* of the $$2$$ middle elements of the sorted sample.&#x20;

### [Mode](http://mathworld.wolfram.com/Mode.html)

The element(s) that occur most frequently in a data set. For the set $${1, 1, 1, 2, 2, 3, 4, 4}$$, the mode is $$1$$ because the number $$1$$ appears three times in the set and every other number in the set has a frequency $$< 3$$. In contrast, the set $${1, 2, 3, 4}$$ is [multimodal](http://mathworld.wolfram.com/Multimodal.html) because no number in the set appears more than $$1$$ time, so every number in the set is a valid *mode*.&#x20;

### [Precision and Scale](https://en.wikipedia.org/wiki/Significant_figures)

These are important terms to understand when formatting your output:

* *Precision* refers to the number of significant digits in a number. For example, the numbers $$123.45$$ and $$0.012345$$ both have a precision of $$5$$.
* *Scale* refers to the number of significant digits to the *right* of the decimal point. For example, the number $$123.45$$ has a scale of $$2$$ decimal places. This term is sometimes misrepresented as *precision* in documentation.&#x20;

```
num = int(input())
values = list(map(int, input().split()))

mean = sum(values)/num
print(mean)

values.sort()
if num % 2 == 0:
    v1 = values[int(num/2)-1]
    v2 = values[int(num/2)]
    median = (v1+v2)/2
else:
    c = floor(num % 2) + 1
    median = values[c]
print(median)

mode = max(values, key=lambda n: values.count(n))
print(mode)

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://stephanosterburg.gitbook.io/scrapbook/math/hackerrank/mean-medium-mode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
