The Outlier Guard

Your team runs a public scoreboard for a daily guessing game. Most guesses are reasonable, but a few wild ones can throw things off. To keep the board fair, you “cap” every new guess to stay close to a typical value learned from past data.

You are asked to learn the median from yesterday’s scores, then clamp each new score so it stays within a band of size T around that median.

The first line of the input contains a single integer n - the number of scores from yesterday. The second line contains n space-separated numbers - the scores from yesterday.

The third line contains a number T - the allowed distance from the median.

The fourth line contains an integer q - the number of new scores you need to normalize today. The next q lines contain the new scores to clamp.

Compute the median from yesterday (if n is odd, it’s the middle value after sorting; if n is even, it’s the average of the two middle values).

After that, normalize the q values to make sure each of those is within the median ± T  range and print them.

Input

Output

5
10 11 12 13 14
1.5
4
20
9
12
10.2

13.5
10.5
12
10.5

4
5 7 9 100
2
3
3
9
15

6
9
10

6
1.2 1.2 1.5 1.8 2.0 2.4
0.35
4
1.1
1.6
2.2
1.3

1.3
1.6
2.0
1.3

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue