#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; int main() { int n; cin >> n; vector s(n), t(n); rep(i,n) cin >> s[i]; rep(i,n) cin >> t[i]; int cs = 0, ct = 0; int os = 0, ot = 0; for (int i = 0; i < n; i++) { if (s[i] == 1) cs++; if (s[i] == 2) os++; if (t[i] == 1) ct++; if (t[i] == 2) ot++; } if (!os && !ot) { cout << max(cs, ct) << endl; } else if (os && ot) { cout << (os + ot) * n - os * ot << endl; } else { cout << max(os, ot) * n + (os ? cs : ct) << endl; } return 0; }