All problems

Restricting Which Columns Appear With vars

mediumPythonSeabornvars

Thornbury Labs now records four measurements per sample, and the full grid of every pairing has become too big for one page. Each report therefore names the handful of measurements it cares about, and the grid is built from those alone -- the rest of the columns are ignored entirely. The layout still needs a panel count before it can size the page.

Task: Print how many panels of the reduced grid compare two different measurements.

Input

The first line holds one integer n, the number of samples, where 1 <= n <= 1000. Then come n lines, each holding four numbers separated by single spaces: that sample's a, b, c and d. The final line names the measurements the report wants, separated by single spaces, and may name as few as one of them.

Output

One line holding a whole number, counting only the panels that compare two different named measurements. Panels where a measurement meets itself do not count, and both directions do. A report naming a single measurement therefore has no comparison panels at all.

Example:

Input:
2
1 2 3 4
5 6 7 8
a b

Output:
2

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…