Alpha-ville and Beta-ville
InterviewTime limit1sMemory limit512 MB
Given a waiting list of N numbers and M friend numbers, find the fewest swaps that move every friend ahead of all non-friends.
Problem
Minkyu and his friends live in two villas right next to each other, Alpha-ville and Beta-ville. Alpha-ville is a cheap, good villa, so it is very popular and many people line up to move in. Minkyu's friends also have numbers on the Alpha-ville waiting list. Friends who fail to get into Alpha-ville will have to move into the more expensive Beta-ville. Minkyu feels sorry for them and wants to rearrange the waiting list without the landlord noticing, so that more friends can get into Alpha-ville.
The waiting list shows the waiting numbers of the people in the order they will move in, from left to right. The waiting numbers are distinct integers from to .
Each time Minkyu changes the list, he can choose two numbers and swap their positions. If he changes the list too often, the landlord may notice, so Minkyu wants to change it as little as possible. Print the minimum number of swaps needed so that all of Minkyu's friends move in before everyone who is not his friend.
Input
The first line contains and , the number of numbers on the waiting list and the number of Minkyu's friends, separated by a space. ()
The second line contains the integers written on the waiting list.
The third line contains integers, the waiting numbers of Minkyu's friends.
Output
Print the minimum number of changes needed so that all friends move in first.