#include using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define chmax(x,y) x = max(x,y) using ll = long long; using P = pair; int main(){ int n; cin>>n; int s[n+1],t[n+1]; rep(i,n) cin>>s[i+1]; rep(i,n) cin>>t[i+1]; int a[n+1][n+1]; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ a[i][j] = -1; } } for(int i=1;i<=n;i++){ if(s[i]==0){ for(int j=1;j<=n;j++){ a[i][j] = 0; } }else if(s[i]==2){ for(int j=1;j<=n;j++){ a[i][j] = 1; } } } for(int i=1;i<=n;i++){ if(t[i]==0){ for(int j=1;j<=n;j++){ a[j][i] = 0; } }else if(t[i]==2){ for(int j=1;j<=n;j++){ a[j][i] = 1; } } } for(int i=1;i<=n;i++){ if(s[i]==1){ for(int j=1;j<=n;j++){ if(t[j]==1){ a[i][j] = 1; t[j] = -1; break; } } } } int ans = 0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(a[i][j]!=-1) ans += a[i][j]; } } cout << ans << endl; }