#P1237B. Balanced Tunnel
Balanced Tunnel
No submission language available for this problem.
Description
Consider a tunnel on a one-way road. During a particular day, cars numbered from to entered and exited the tunnel exactly once. All the cars passed through the tunnel at constant speeds.
A traffic enforcement camera is mounted at the tunnel entrance. Another traffic enforcement camera is mounted at the tunnel exit. Perfectly balanced.
Thanks to the cameras, the order in which the cars entered and exited the tunnel is known. No two cars entered or exited at the same time.
Traffic regulations prohibit overtaking inside the tunnel. If car overtakes any other car inside the tunnel, car must be fined. However, each car can be fined at most once.
Formally, let's say that car definitely overtook car if car entered the tunnel later than car and exited the tunnel earlier than car . Then, car must be fined if and only if it definitely overtook at least one other car.
Find the number of cars that must be fined.
The first line contains a single integer (), denoting the number of cars.
The second line contains integers (), denoting the ids of cars in order of entering the tunnel. All are pairwise distinct.
The third line contains integers (), denoting the ids of cars in order of exiting the tunnel. All are pairwise distinct.
Output the number of cars to be fined.
Input
The first line contains a single integer (), denoting the number of cars.
The second line contains integers (), denoting the ids of cars in order of entering the tunnel. All are pairwise distinct.
The third line contains integers (), denoting the ids of cars in order of exiting the tunnel. All are pairwise distinct.
Output
Output the number of cars to be fined.
Samples
Note
The first example is depicted below:
Car definitely overtook car , while car definitely overtook cars , , and . Cars and must be fined.
In the second example car was definitely overtaken by all other cars.
In the third example no car must be fined.