#include #define rep(X, N) for (ll X = 0LL; X < (N); X++) #define ALL(V) (V).begin(), (V).end() #define endl "\n" using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; const double PI = 3.1415926535897932384626; const ll MODN = 1000000007; const ll MODN2 = 998244353; int main(){ int n; cin >> n; vector s(n), t(n); rep(i, n) cin >> s[i]; rep(i, n) cin >> t[i]; vector> v(n, vector(n, -1)); vector row(n), col(n); int ans = 0; int c[3][3] = {{0, 0, 2}, {0, -1, 1}, {2, 1, 1}}; rep(i, n){ rep(j, n){ int tmp = c[s[i]][t[j]]; if(tmp == 0){ }else if(tmp == 1){ ans++; v[i][j] = 1; row[i]++; col[j]++; }else if(tmp == -1){ }else{ assert(false); } } } // Si = 1 かつ Tj = 1 かつ row[i] = 0 かつ col[j] = 0のぶぶんをうめる rep(i, n){ rep(j, n){ if(s[i] == 1 && t[j] == 1 && row[i] == 0 && col[j] == 0){ v[i][j] = 1; ans++; row[i]++; col[j]++; } } } // 残りの部分を埋める rep(i, n){ rep(j, n){ if(v[i][j] == -1){ if(s[i] == 1 && row[i] == 0){ v[i][j] = 1; ans++; row[i]++; col[j]++; }else if(t[j] == 1 && col[j] == 0){ v[i][j] = 1; ans++; row[i]++; col[j]++; } } } } cout << ans << endl; return 0; }