#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) #define fi first #define se second template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } using ll = long long; using pii = pair; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = 0; //---------------------------------// int main() { int N; cin >> N; vector S(N), T(N); REP(i, N) scanf("%d", &S[i]); REP(i, N) scanf("%d", &T[i]); vector> ans(N, vector(N)); bool yoko = false, tate = false; REP(i, N) { if (S[i] == 2) { REP(j, N) ans[i][j] = 1; yoko = true; } if (T[i] == 2) { REP(j, N) ans[j][i] = 1; tate = true; } } int ansc = 0; if (!yoko || !tate) { if (yoko) { REP(i, N) if (S[i] == 1) ++ansc; } else if (tate) { REP(i, N) if (T[i] == 1) ++ansc; } else { int a[2] {}; REP(i, N) a[0] += S[i] == 1; REP(i, N) a[1] += T[i] == 1; ansc = max(a[0], a[1]); } } REP(i, N) REP(j, N) ansc += ans[i][j]; cout << ansc << endl; return 0; }