namespace AtCoder; #nullable enable using System.Numerics; static class Extensions { public static T[] Repeat(this int time, Func F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } class AtCoder { object? Solve() { var n = Int(); var xz = n.Repeat(Int); var az = n.Repeat(Int); var max = long.MaxValue / 8; var ans = new long[n + 1]; for (var i = 1; i <= n; i++) ans[i] = max; ans[0] = 0; var sxorz = new int[n]; sxorz[0] = az[0]; for (var i = 1; i < n; i++) sxorz[i] = sxorz[i - 1] ^ az[i]; for (var i = 0; i < n; i++) { for (var j = i; j < n; j++) { var xor = sxorz[j]; if (i > 0) xor ^= sxorz[i - 1]; ans[j + 1] = Math.Min(ans[j + 1], ans[i] + xz[j] - xz[i] + xor); } } return ans[n]; } public static void Main() => new AtCoder().Run(); public void Run() { var res = Solve(); if (res != null) { if (res is bool yes) res = yes ? "Yes" : "No"; sw.WriteLine(res); } sw.Flush(); } string[] input = Array.Empty(); int iter = 0; readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false }; #pragma warning disable IDE0051 string String() { while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0); return input[iter++]; } T Input() where T : IParsable => T.Parse(String(), null); int Int() => Input(); void Out(object? x, string? separator = null) { separator ??= Environment.NewLine; if (x is System.Collections.IEnumerable obj and not string) { var firstLine = true; foreach (var item in obj) { if (!firstLine) sw.Write(separator); firstLine = false; sw.Write(item); } } else sw.Write(x); sw.WriteLine(); } #pragma warning restore IDE0051 }