DAJ_JMENGMEI @ 2018-10-18 17:14:50
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
#define maxn 100005
int a[maxn],b[maxn],maxl[maxn][3];
void read(int &x)
{
int f=1;x=0;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
x*=f;
}
int main(){
int n;
read(n);
for(int i=1;i<=n;i++){
read(a[i]);
}
for(int i=1;i<=n;i++){
read(b[i]);
}
/* for(int i=0;i<=n;i++)
for(int j=0;i<=2;j++){
cout<<maxl[i][j]<<","
}*/
int count = 1;
int k = 1;
do{
count++;
if(k==1){
for(int i=1;i<=n;i++){
if(a[count]==b[i])
maxl[i][k]=maxl[i-1][k-1]+1;
if(a[count]!=b[i])
maxl[i][k]=max(maxl[i-1][k],maxl[i][k-1]);
}
}
if(k==0){
for(int i=1;i<=n;i++){
if(a[count]==b[i])
maxl[i][k]=maxl[i-1][k+1]+1;
if(a[count]!=b[i])
maxl[i][k]=max(maxl[i-1][k],maxl[i][k+1]);
}
}
if(k==1)
k=0;
}while(count <= n);
int cmp=0;
for(int i=0;i<=n;i++)
for(int j=0;i<=2;j++){
cmp=max(maxl[i][j],cmp);
}
cout<<cmp;
return 0;
}