The problem in brief
A meteorologist's year of ice-purity measurements has been polluted: his intern sometimes faked readings with ice from his own fridge. You receive the measurements on one line and must print the suspicious ones, using the interquartile range rule: any value below or above is an outlier. The program reads standard input and writes the outliers on one line. The sample has 1000 values and 13 outliers.
How you are scored
A hidden set of tests on the Yandex judge compares your output line with the expected one. The tests are not public, so we validate on the statement's sample (reproduced exactly) and on self-made tests. Two details decide whether you pass: which quartile definition you use and how you print the values.
The key idea
Quartiles and IQR are robust statistics. The mean and the standard deviation are dragged around by the very outliers you are looking for: one value at moves the mean and inflates the standard deviation so much that nothing looks unusual any more (this is why the z-score method in the statement needs roughly normal, clean data). Quartiles, in contrast, depend only on the ranks of the middle of the data. You can make the 13 outliers as extreme as you like, and will not move. That is what makes the fences
trustworthy. For normally distributed data, , so the fences sit at about , and only 0.7 % of clean points fall outside them.

On the sample, , , , so and . The ten negative purities and 27.256 fall below ; 1348.399 and 1455.191 lie above . Notice that 1325.914 and 79.269 are close but inside: the fences are strict.
Which quartile?
There is no single definition of a quartile for a finite list. Two common ones:
- Linear interpolation (numpy's default, Excel's
PERCENTILE.INC): sort the values as , the -quantile sits at position , interpolated between the two neighbouring order statistics. - Tukey's hinges, which match the statement's wording ("the middle of the lower half"): is the median of the lower half, the median of the upper half.
On the sample both give the same 13 outliers (the quartiles differ only in the second decimal). On random inputs with a few outliers they disagree in 6 to 12 % of cases, almost always on a value sitting right at a fence. We use linear interpolation, which is what nearly every contestant (and very likely the reference solution) gets from np.percentile or pandas.quantile. Be aware that this is a guess about a hidden test set: if your solution fails on a borderline test, the definition is the first thing to switch.
The full solution
tokens = sys.stdin.read().split()
values = [float(t) for t in tokens]
s = sorted(values)
q1, q3 = percentile(s, 0.25), percentile(s, 0.75) # linear interpolation
iqr = q3 - q1
lo, hi = q1 - 1.5 * iqr, q3 + 1.5 * iqr
print(" ".join(t for t, v in zip(tokens, values) if v < lo or v > hi))
Three details matter:
- Keep the input order: the expected output lists 1455.191 first, then the negative values, in the order they were read, not sorted.
- Print the original strings, not re-formatted floats. Printing
f"{v:g}"would turn 1455.191 into1455.19and fail; printing the token you read is always exact. - Strict inequalities: values exactly on a fence are not outliers ("outside the range").
The whole program is because of the sort, instant for any realistic .
Results
| check | result |
|---|---|
| statement sample (1000 values, 13 outliers) | identical output |
our percentile against np.percentile on 2000 random lists | identical to |
| hand-made edge cases (all equal values, IQR = 0, negative and scientific notation) | pass |
| linear vs Tukey quartiles, random inputs, / / | differ on 12.3 % / 8.7 % / 6.5 % |
printing re-formatted floats (%g) instead of the tokens | fails the sample |
What to remember
- Detect outliers with robust statistics (median, quartiles, IQR, MAD): the mean and standard deviation are distorted by the very points you want to find.
- The 1.5 IQR rule is about for normal data; it is the rule behind the whiskers of a box plot.
- Quantile definitions differ on finite samples: know which one your library uses, and expect them to matter only on borderline cases.
- In judged programs, output formatting is part of the answer: keep the input order and echo the original tokens.