#include #ifdef LOCAL #include "./debug.cpp" #else #define debug(...) #define print_line #endif using namespace std; using ll = long long; int main() { int N; cin >> N; vector X(N), A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { cin >> X[i]; } vector Xsum1(N + 1, 0), Xsum2(N + 1, 0); for (int i = 0; i < N; i++) { Xsum1[i + 1] = Xsum1[i] ^ X[i]; Xsum2[i + 1] = Xsum2[i] + X[i]; } ll ans = LLONG_MAX; for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { ll x1 = Xsum2[i]; ll x2 = Xsum1[j + 1] ^ Xsum1[i]; ll x3 = Xsum2[N] - Xsum2[j + 1]; ll a1 = A[j] - A[i]; debug(i, j, x1, x2, x3, a1); ans = min(ans, x1 + x2 + x3 + a1); } } cout << ans << endl; }