#include <iostream>
using namespace std;
int main()
{
    int n;   cin >> n;
    int arr[2*n] , copy[n + 1];
    int answer = 0;
    copy[0] = -1;
    for ( int i = 0 ; i < 2*n ; i ++ )
    {
        cin >> arr[i];
    }

    for ( int i = 1 ; i < n + 1 ; i ++ )
    {
        cin >> copy[i];
    }

    for ( int i = 0 ; i < 2*n ; i ++ )
    {
        if ( copy[arr[i]] == -1 )
        {
            copy[arr[i]] = i;
        }

        else 
        {
            answer += abs (copy[arr[i]] - i);
        }
    }

    cout << answer;

    return 0;
}