#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 //#define MOD 1000000007 #define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 const double EPS = 1e-10; using ll = long long; using Pi = pair; using Pl = pair; int main(){ int n; cin >> n; vector s(n),t(n); rep(i,n) cin >> s[i]; rep(i,n) cin >> t[i]; vector> a(n,vector(n)); bool s2 = false,t2 = false; rep(i,n){ if(s[i] == 2){ rep(j,n){ a[i][j] = 1; } s2 = true; } } rep(i,n){ if(t[i] == 2){ rep(j,n){ a[j][i] = 1; } t2 = true; } } vector s3(n,false),t3(n,false); if(!s2 && !t2){ rep(i,n){ if(s[i] == 1){ rep(j,n){ if(t[i] == 1 && !t3[i]){ t3[i] = true; a[i][j] = 1; break; } } } } rep(j,n){ if(!t3[j] && t[j] == 1){ rep(i,n){ if(s[i] == 1){ a[i][j] = 1; break; } } } } } else if(s2){ rep(i,n){ if(s[i] == 1) a[i][0] = 1; } } else if(t2){ rep(i,n){ if(t[i] == 1) a[0][i] = 1; } } int ans = 0; rep(i,n)rep(j,n) ans += a[i][j]; cout << ans << endl; }