LCS Deletion
Difficulty: Hard

You are given two lists, each containg $N$ numbers. The numbers in both lists are a permuation of $1,2,3 \cdots N$. In an operation, Akhil will have to choose the longest common subsequence of both strings and delete that subsequence from the first list. The process is repeated as long as the first list has one or more numbers.

So, for the given input, find the minimal number of operations that will be executed.

**Input Format**  
The first line contains an integer $N$.  
The next two lines contain $N$ integers.

**Constraints**  
$ 1\le N \le 5 \times 10^5$

**Output Format**  
Print the mimimal number of required operations.  

**Sample Input 00**

	3
    1 2 3
    1 2 3

**Sample Output 00**

	1
      
**Sample Input 01**

	4
    1 3 2 4
    3 1 4 2

**Sample Output 01**

	2
    

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
    #include<bits/stdc++.h>

    using namespace std;

    int a[510000];
    int b[510000];
    int arr[510000];

    int MaxInSeq(int N)
    {
        int i;
        set<int> s;
        set<int>::iterator k;
        for (i=0; i<N; i++)
        {
            if (s.insert(arr[i]).second)
            {
                k = s.find(arr[i]);
                k++;  
                if (k!=s.end()) s.erase(k);
            }
        }
        return s.size();
    }


    int main()
    {
        int n;
        cin>>n;
        assert(1<=n);
        assert(n<=500000); 
        for(int i=1 ; i<=n ; i++)
        {
            cin>>a[i];
            assert(1<=a[i]);
            assert(a[i]<=n);
        }
        for(int i=1 ; i<= n ; i++)
        {
            int x;
            cin>>x;
            assert(1<=x);
            assert(x<=n);
            b[x] = i;
        }
        for(int i=1 ; i<=n ; i++)
        {
            a[i] = b[a[i]];
        }
        for(int i=0 ; i<n ; i++)
        {
            arr[i] = n+5 - a[i+1];
        }
        cout<<MaxInSeq(n)<<endl;
        return 0;
    }