#include using namespace std; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector x(n), a(n); cin >> x >> a; vector s(n + 1); for(int i = 0; i < n; i++){ s[i + 1] = s[i] ^ a[i]; } vector dp(n + 1, 1ll << 60); dp[0] = 0; for(int i = 0; i < n; i++){ for(int j = i; j < n; j++){ dp[j + 1] = min(dp[j + 1], dp[i] + (s[j + 1] ^ s[i]) + x[j] - x[i]); } } cout << dp[n] << '\n'; }