#include using namespace std; typedef long long ll; typedef pair P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) templateostream& operator<<(ostream& os,const pair& a) {os << "(" << a.first << ", " << a.second << ")";return os;} const char newl = '\n'; int main() { 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> f(n,vector(n,false)); for (int i = 0;i < n;++i) if (s[i] == 2) for (int j = 0;j < n;++j) f[i][j] = true; for (int i = 0;i < n;++i) if (t[i] == 2) for (int j = 0;j < n;++j) f[j][i] = true; int a = 0,b = 0; for (int i = 0;i < n;++i) if (s[i] == 1) { bool g = false; for (int j = 0;j < n;++j) if (f[i][j]) g = true; if (!g) a++; } for (int i = 0;i < n;++i) if (t[i] == 1) { bool g = false; for (int j = 0;j < n;++j) if (f[j][i]) g = true; if (!g) b++; } int cnt = 0; for (int i = 0;i < n;++i) for (int j = 0;j < n;++j) if (f[i][j]) cnt++; cout << cnt+max(a,b) << newl; }