#pragma GCC optimize("O3") #include #define ll long long #define rep(i,n) for(ll i=0;i<(n);i++) #define pll pair #define pii pair #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define endl '\n' #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define lb(c,x) distance(c.begin(),lower_bound(all(c),x)) #define ub(c,x) distance(c.begin(),upper_bound(all(c),x)) using namespace std; int main(){ ll n; cin >> n; vector> a(n,vector(n,-1)); vector s(n),t(n),used_s(n),used_t(n); rep(i,n){ cin >> s[i]; if(s[i]==0){ rep(j,n){ a[i][j]=0; } used_s[i]=1; } if(s[i]==2){ rep(j,n){ a[i][j]=1; } used_s[i]=1; } } rep(i,n){ cin >> t[i]; if(t[i]==0){ rep(j,n){ a[j][i]=0; } used_t[i]=1; } if(t[i]==2){ rep(j,n){ a[j][i]=1; } used_t[i]=1; } } rep(i,n){ if(used_s[i]==0){ bool ok=false; rep(j,n){ if(a[i][j]==1) ok=true; } if(ok){ used_s[i]=1; } } if(used_t[i]==0){ bool ok=false; rep(j,n){ if(a[j][i]==1) ok=true; } if(ok) used_t[i]=1; } } rep(i,n){ rep(j,n){ if(used_s[i]==0 && used_t[j]==0){ a[i][j]=1; used_s[i]=1; used_t[i]=1; } } } rep(i,n){ if(used_s[i]==0){ bool ok=false; rep(j,n){ if(a[i][j]==1) ok=true; } if(ok){ used_s[i]=1; } } if(used_t[i]==0){ bool ok=false; rep(j,n){ if(a[j][i]==1) ok=true; } if(ok) used_t[i]=1; } } ll ans=0; rep(i,n){ if(used_s[i]==0) ans++; if(used_t[i]==0) ans++; } rep(i,n)rep(j,n){ if(a[i][j]==1) ans++; } cout << ans << endl; return 0; }