Under construction

Still being built. Things may change

Overtaking

Interview

Time limit2sMemory limit128 MB

Summary
Given entry and exit orders of N cars, count how many cars are not part of the longest common subsequence, meaning they overtook someone.
Level

Easy3 of 10

Topics
Dynamic programming, Array, String
Solved
No attempts yet

Problem

In most countries, changing lanes inside a tunnel is prohibited by law. This is why lane markings inside tunnels are solid rather than dashed. Therefore, a car cannot change lanes and pass another car while it is inside the tunnel.

Two police officers, Daegeun and Yeongsik, watched one tunnel to find cars that overtook other cars inside it. Daegeun recorded the license plate numbers in the order the cars entered the tunnel, and Yeongsik recorded them in the order the cars left the tunnel.

After all N cars have passed through, comparing the two lists reveals how many cars must have overtaken at least one other car inside the tunnel. Write a program that computes that number.

Input

The input consists of 2N+1 lines.

The first line contains the number of cars N (1 <= N <= 1,000). The next N lines contain the license plate numbers recorded by Daegeun, in entrance order. The following N lines contain the license plate numbers recorded by Yeongsik, in exit order.

Each license plate number is a string of length between 6 and 8 inclusive, consisting only of uppercase English letters A through Z and digits 0 through 9. No license plate number appears more than once.

Output

Print the number of cars that must have overtaken at least one other car inside the tunnel.

Examples3

  1. Example 1

    Input
    4
    ZG431SN
    ZG5080K
    ST123D
    ZG206A
    ZG206A
    ZG431SN
    ZG5080K
    ST123D
    
    Expected output
    1
    
  2. Example 2

    Input
    5
    ZG508OK
    PU305A
    RI604B
    ZG206A
    ZG232ZF
    PU305A
    ZG232ZF
    ZG206A
    ZG508OK
    RI604B
    
    Expected output
    3
    
  3. Example 3

    Input
    5
    ZG206A
    PU234Q
    OS945CK
    ZG431SN
    ZG5962J
    ZG5962J
    OS945CK
    ZG206A
    PU234Q
    ZG431SN
    
    Expected output
    2