// #pragma GCC optimize("O3,unroll-loops") #include // #include using namespace std; #if __cplusplus >= 202002L using namespace numbers; #endif int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int n; cin >> n; vector pos(n), a(n); copy_n(istream_iterator(cin), n, pos.begin()); copy_n(istream_iterator(cin), n, a.begin()); vector pref(n + 1); for(auto i = 0; i < n; ++ i){ pref[i + 1] = pref[i] ^ a[i]; } const long long inf = 3e18; vector dp(n + 1, inf); dp[0] = 0; for(auto l = 0; l < n; ++ l){ for(auto r = l + 1; r <= n; ++ r){ dp[r] = min(dp[r], dp[l] + (pref[r] ^ pref[l]) + pos[r - 1] - pos[l]); } } cout << dp[n] << "\n"; return 0; } /* */