#pragma GCC optimize("Ofast") #include using namespace std; typedef long long int ll; typedef unsigned long long int ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } inline double time() { return static_cast(chrono::duration_cast(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector x(n), a(n); for (int i = 0; i < n; ++i) { cin >> x[i]; } for (int i = 0; i < n; ++i) { cin >> a[i]; } vector dp(n+1, 2e18); dp[0] = 0; for (int i = 0; i < n; ++i) { ll dif = 0; ll cur = 0; for (int j = i; j < n; ++j) { cur ^= a[j]; dp[j+1] = min(dp[j+1], dp[i]+cur+dif); if (j+1 < n) dif += x[j+1] - x[j]; } } cout << dp[n] << endl; }