#include #include #include #include #include #include #include #include #include #include using namespace std; long long gcd(long long a,long long b){ long long x=max(a,b),y=min(a,b); if(x%y==0)return y; else return gcd(y,x%y); } long long lcm(long long a,long long b){ return (a/gcd(a,b))*b; } int main(){ cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(1) << endl; int n; cin >> n; vector s(n); vector t(n); for(int i = 0; i < n; i++)cin >> s[i]; for(int i = 0; i < n; i++)cin >> t[i]; vector> ans(n,vector(n,0)); //s for(int i = 0; i < n; i++){ if(s[i] == 0){ continue; }else if(s[i] == 2){ for(int j = 0; j < n; j++){ ans[i][j] = 1; } }else if(s[i] == 1){ continue; } } //t for(int i = 0; i < n; i++){ if(t[i] == 0){ for(int j = 0; j < n; j++){ ans[j][i] = 0; } }else if(s[i] == 2){ for(int j = 0; j < n;j++){ ans[i][j] = 1; } }else if(s[i] == 1){ continue; } } for(int i = 0; i < n; i++){ if(s[i] == 1){ bool ok = false; for(int j = 0; j < n; j++){ if(ans[i][j] == 1){ ok = true; break; } } if(!ok){ if(t[i] == 1){ ans[i][i] = 1; }else{ ans[i][0] = 1; } } } if(t[i] == 1){ bool ok = false; for(int j = 0; j < n; j++){ if(ans[j][i] == 1){ ok = true; break; } } if(!ok){ if(s[i] == 1){ ans[i][i] = 1; }else{ ans[0][i] = 1; } } } } //cnt int ans_cnt = 0; for(int i = 0; i < n; i++){ int cnt = 0; for(int j = 0; j < n; j++){ if(ans[i][j] == 1)cnt++; } if(cnt == n){ ans_cnt += n; continue; } if(cnt == 0){ continue; } if(cnt == 1){ ans_cnt += 1; continue; } ans_cnt += 1; } cout << ans_cnt << endl; return 0; }