#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int s[550], t[550]; int b[550][550]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < n; i++) { cin >> t[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { b[i][j] = 2; } } int co = 0; for (int i = 0; i < n; i++) { if (s[i] == 0) { for (int j = 0; j < n; j++) { b[i][j] = 0; } } if (s[i] == 2) { int c = n; for (int j = 0; j < n; j++) { if (b[i][j] == 1) { c--; } b[i][j] = 1; } co += c; } } for (int i = 0; i < n; i++) { if (t[i] == 0) { for (int j = 0; j < n; j++) { b[j][i] = 0; } } if (t[i] == 2) { int c = n; for (int j = 0; j < n; j++) { if (b[j][i] == 1) { c--; } b[j][i] = 1; } co += c; } } set h, w; for (int i = 0; i < n; i++) { if (s[i] == 1) { bool bo = true; for (int j = 0; j < n; j++) { if (b[i][j] == 1) { bo = false; } } if (bo) { h.insert(i); } } } for (int i = 0; i < n; i++) { if (t[i] == 1) { bool bo = true; for (int j = 0; j < n; j++) { if (b[j][i] == 1) { bo = false; } } if (bo) { w.insert(i); } } } cout << co + max(h.size(), w.size()) << endl; }