#include using namespace std; //#define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector #define mat vector > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair pll; typedef long double ld; typedef complex comp; const ll INF=1e9+7; const ll MOD=998244353; const int MAX=200010; signed main(){ cin.tie(0); ios::sync_with_stdio(false); ll n;cin>>n; vector >a(n,vector(n)); vectors(n); vectort(n); rep(i,n)cin>>s[i]; rep(i,n)cin>>t[i]; ll z=0,y=0; ll cnt1=0,cnt0=0; rep(i,n){ if(s[i]==2){ z=1; rep(j,n){ a[i][j]=1; } }else if(s[i]==1){ cnt1++; } if(t[i]==2){ rep(j,n){ a[j][i]=1; } y=1; }else if(t[i]==1){ cnt0++; } } ll ans=0; rep(i,n){ rep(j,n){ ans+=a[i][j]; } } if(z){ if(y){ }else{ ans+=cnt1; } }else{ if(z)ans+=cnt0; else ans+=max(cnt0,cnt1); } cout<