#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif void solve() { int N; cin >> N; vector S(N), 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)); for (int i = 0; i < N; i++) { if (S[i] == 2) for (int j = 0; j < N; j++) ans[i][j] = 1; if (T[i] == 2) for (int j = 0; j < N; j++) ans[j][i] = 1; } vector> count(N, vector(N)); for (int i = 0; i < N; i++) if (S[i] == 1) { bool f = false; for (int j = 0; j < N; j++) { if (ans[i][j] == 1) f = true; } if (!f) { for (int j = 0; j < N; j++) count[i][j]++; } } for (int i = 0; i < N; i++) if (T[i] == 1) { bool f = false; for (int j = 0; j < N; j++) { if (ans[j][i] == 1) f = true; } if (!f) { for (int j = 0; j < N; j++) count[j][i]++; } } const auto Dec = [&](int i, int j) -> void { for (int k = 0; k < N; k++) count[i][k]--; for (int k = 0; k < N; k++) count[k][j]--; }; for (int z : {2, 1}) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (count[i][j] == z) { ans[i][j] = 1; Dec(i, j); } } } } debug(ans); int sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { sum += ans[i][j]; } } cout << sum << endl; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while (tt--) { solve(); } }