#5279. Problem 3. Why Did the Cow Cross the Road III
Problem 3. Why Did the Cow Cross the Road III
Problem 3. Why Did the Cow Cross the Road III
USACO 2017 February Contest, Platinum
Farmer John is continuing to ponder the issue of cows crossing the road through his farm, introduced in the preceding two problems. He realizes now that the threshold for friendliness is a bit more subtle than he previously considered -- breeds and are now friendly if , and unfriendly otherwise.
Given the orderings of fields on either side of the road through FJ's farm, please count the number of unfriendly crossing pairs of breeds, where a crossing pair of breeds is defined as in the preceding problems.
INPUT FORMAT (file friendcross.in):
The first line of input contains () and (). The next lines describe the order, by breed ID, of fields on one side of the road; each breed ID is an integer in the range . The last lines describe the order, by breed ID, of the fields on the other side of the road. Each breed ID appears exactly once in each ordering.
OUTPUT FORMAT (file friendcross.out):
Please output the number of unfriendly crossing pairs of breeds.
SAMPLE INPUT:
4 1 4 3 2 1 1 4 2 3
SAMPLE OUTPUT:
2
In this example, breeds 1 and 4 are unfriendly and crossing, as are breeds 1 and 3.
Problem credits: Brian Dean