Thermostat Reality Check

A building’s thermostat sometimes spits out impossible readings below L or above U. Before your system compares readings with k-NN, it first pulls them back to reality so neighbors are judged fairly.

You are asked to read an initial set of readings with targets, then answer queries using k-NN Regression, where all features are confined to [L, U] before comparison. Predictions are the mean of the k nearest targets under the standard Euclidean distance. If several candidates are at the same distance around the cutoff, pick the item that appears earlier in the input. You may assume n ≥ k.

The first line of the input contains five values n d k L U. Each of the next n lines contains d floating-point numbers followed by a floating-point target.

The next line contains a single integer q representing how many new readings to predict. Each of the next q lines contains d floating-point numbers to compare against the initial set after applying the same clipping rule.

The program should print q lines. Each line should contain a single floating-point number - the predicted target.

Input

Output

4 1 2 0 10
-5 0
0 0
10 10
15 10
3
-2
12
6

0
10
10

5 2 3 0 10
-5 5 4
2 8 6
9 12 9
11 -2 1
5 5 5.5
2
7 20
-3 -3

6.8333333333
5.1666666667

6 1 3 0 10
-3 0.0
0 1.0
4 4.0
9 9.0
12 9.5
15 10.0
2
-5
11

1.6666666667
9.5

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