#include using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define FOR(i,n,j) for(int i=(j);i<(n);++i) #define ssort(n) sort((n).begin(),(n).end()) #define rsort(n) sort((n).begin(),(n).end(),greater()) #define mp make_pair using ll=long long; using ld=long double; typedef pair P; typedef pair COST; #define repl(i,n) for(ll i=0;i<(n);++i) #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define YES cout << "YES" << endl #define NO cout << "NO" << endl using Graf=vector>; #define MAX 1000000007 int main() { int n; cin >> n; vector s(n),t(n); rep(i,n)cin >> s[i]; rep(i,n)cin >> t[i]; vector num_s(n,0),num_t(n,0); int count=0; int coun_s,coun_t;int coun_s2,coun_t2; coun_s=0;coun_t=0; coun_s2=0;coun_t2=0; int flag=0; rep(i,n){ if(s[i]==1){ coun_s++; }else if(s[i]==2){ flag=1; coun_s2++; } } rep(i,n){ if(t[i]==1){ coun_t++; }else if(t[i]==2){ coun_t2++; if(flag==1||flag==3){ flag=3; }else{ flag=2; } } } if(flag==0){ cout << max(coun_s,coun_t) << endl; }else if(flag==1){ cout << coun_s+coun_s2*n << endl; }else if(flag==2){ cout << coun_t+coun_t2*n << endl; }else{ cout << coun_s*n+coun_t*n-(coun_s2*coun_t2) << endl; } }