All problems

Full Multinomial Classification

hardPythonNaive Bayes

A message has arrived and Halyard Mail's filter has to name one label for it. The archive work is already done: every label comes with a prior, and every word in the message comes with one likelihood per label, lined up in the label order. Real messages on this queue run to several hundred words, so whatever the filter does internally has to survive that many words without every label ending up indistinguishable.

Task: Print the label the filter picks for this message.

Input

The first line holds one integer k, the number of labels. The second line holds the k label names separated by single spaces; a name contains no spaces. The third line holds the k priors in that same order. The fourth line holds one integer m, the number of words. Each of the next m lines holds a word followed by its k likelihoods, again in label order. Every word on the list counts; the word itself is there only for readability.

Output

One line holding the chosen label. If two labels finish level, print whichever is named earlier on the second line.

Example:

Input:
2
spam ham
0.4 0.6
2
free 0.1 0.01
money 0.05 0.02

Output:
spam

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…