1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5+5; 4 int id[maxn]; 5 vector<int> ve; 6 int main() { 7 int n; scanf("%d",&n); 8 for (int i = 1; i <= n; ++i) { 9 int x; scanf("%d",&x); 10 id[x] = i; 11 } 12 for (int i = 1; i <= n; ++i) { 13 int x; scanf("%d",&x); 14 x = id[x]; 15 if (i == 1) ve.push_back(x); 16 else { 17 if (x > ve[ve.size()-1]) ve.push_back(x); 18 else { 19 ve[lower_bound(ve.begin(),ve.end(),x)-ve.begin()] = x; 20 } 21 } 22 } 23 printf("%d",ve.size()); 24 return 0; 25 }