Five Spices, One Decision

A chef explores a cookbook of known recipes. Each recipe records how strong five spices are, and which dish family it belongs to. When a new recipe appears, the chef looks at the k most similar known recipes and let them vote on the family.

Predict each new recipe’s family using the k nearest neighbors in five-dimensional spice space with L1 (Manhattan) distance; that is, the sum of absolute differences across the five spices. If distances or votes tie, prefer recipes that appear earlier in the input.

The first line of the input contains a single integer n representing the number of known recipes. Each of the next n lines contains five floating-point numbers s1 s2 s3 s4 s5 followed by a dish family word, describing one known recipe’s spice levels and family.

The next line contains a single integer k. The following line contains a single integer q representing the number of new recipes to classify. Each of the last q lines contains five floating-point numbers t1 t2 t3 t4 t5 for a new recipe’s spice levels.

For each new recipe, print the predicted dish family on a separate line.

Input

Output

4
0 0 0 0 0 soup
1 0 0 0 0 curry
0 1 0 0 0 curry
2 2 2 2 2 stew
3
2
0.2 0.1 0 0 0
2 1.8 2 2 2

curry
curry

3
0 0 0 0 0 curry
0 0 1 0 0 noodles
0 0 0 1 0 noodles
1
3
0 0 0.4 0 0
0 0 0.9 0 0
0 0 0 1 0

curry
noodles
noodles

3
0 0 0 0 0 curry
1 0 0 0 0 stew
-1 0 0 0 0 noodles
2
1
0 0 0 0 0

curry

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