Fair Fit, Off the Chart

Your KNN matcher compares people by two features - foot length in centimeters and budget in dollars. Sometimes the price sensor reports budgets you’ve never seen in your preexisting data. Dollars can swamp centimeters, and KNN won’t judge fairly unless both features are scaled. You decide to scale using min–max computed from the preexisting data and then apply that scaling to new readings, even if they fall outside the known range.

You are asked to read some preexisting data and then scale new entries. Compute the minimum and maximum for each column using the preexisting data only, then transform every new row with (v - min) / (max - min). Values may be less than 0 or greater than 1; do not clip. If a column in the preexisting data is flat - all values equal - its scaled value is for every new row.

The first line of the input contains a single integer n representing how many rows of preexisting data you have. Each of the next n lines contains two floating-point numbers - foot length in centimeters and budget in dollars.

The next line contains a single integer q representing how many new rows you want to scale. Each of the next q lines contains two floating-point numbers - foot length and budget - to be scaled using the min and max computed from the preexisting data.

The program should print q lines. Each line should contain two floating-point numbers - the scaled foot length and the scaled budget for the corresponding new row.

Input

Output

3
0 0
5 10
10 20
3
-5 10
10 25
5 5

-0.5 0.5
1 1.25
0.5 0.25

2
24 100
26 100
3
23 100
27 100
25 120

-0.5 0
1.5 0
0.5 0

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