using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int itemCount = int.Parse(Reader.ReadLine()); this.Items = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int ans = GetAns(0, 0); Console.WriteLine(ans); } private Dictionary dic = new Dictionary(); private int GetAns(int idx, int flags) { if(idx >= Items.Length) { return 0; } int key = 1 << idx; if(dic.ContainsKey(flags)) { return dic[flags]; } if((key&flags)!=0) { int ret = GetAns(idx + 1, flags); dic[flags] = ret; return ret; } int ans = 0; for (int i = idx + 1; i < Items.Length; i++) { int subKey = 1 << i; if((flags&subKey)!=0) { continue; } int val = Items[idx] ^ Items[i]; ans = Math.Max(ans, GetAns(idx + 1, flags + key + (1 << i)) + val); } dic[flags] = ans; return ans; } private int[] Items; public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 4 1 2 3 4 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }