#include #define rep(a,n) for (ll a = 0; a < (n); ++a) using namespace std; //using namespace atcoder; using ll = long long; typedef pair P; typedef pair PP; typedef vector > Graph; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e18; int now[510][510]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); //input ll n; cin >> n; vectors(n),t(n); rep(i,n)cin>>s[i]; rep(i,n)cin>>t[i]; rep(i,n)rep(j,n)now[i][j]=-1; vectortate(n,false),yoko(n,false);//確定したか rep(i,n){ if(s[i]==0){ tate[i]=true; rep(j,n){ now[i][j]=0; } } if(s[i]==2){ tate[i]=true; rep(j,n){ now[i][j]=1; } } if(t[i]==0){ yoko[i]=true; rep(j,n){ now[j][i]=0; } } if(t[i]==2){ yoko[i]=true; rep(j,n){ now[j][i]=1; } } } rep(i,n){ if(s[i]==1){ bool flag = false; rep(j,n){ if(now[i][j]==1){ flag=true; } } if(flag){ tate[i]=true; rep(j,n){ if(now[i][j]==-1){ now[i][j]=0; } } } } if(t[i]==1){ bool flag = false; rep(j,n){ if(now[j][i]==1){ flag=true; } } if(flag){ yoko[i]=true; rep(j,n){ if(now[j][i]==-1){ now[j][i]=0; } } } } } ll cnt_tate = 0; ll cnt_yoko = 0; rep(i,n){ if(!tate[i]){ cnt_tate++; } if(!yoko[i]){ cnt_yoko++; } } ll cnt = 0; rep(i,n)rep(j,n)if(now[i][j]==1)cnt++; cout << cnt + max(cnt_tate,cnt_yoko) << endl; return 0; }