Problem:
Score: 600 points

Problem Statement

We have N non-negative integers: A_1, A_2, ..., A_N.

Consider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.

Let the beauty of the painting be the \mbox{XOR} of the integers painted in red, plus the \mbox{XOR} of the integers painted in blue.

Find the maximum possible beauty of the painting.

What is \mbox{XOR}?

The bitwise \mbox{XOR} x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non-negative integers x_1, x_2, \ldots, x_n is defined as follows:

When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

0 \leq A_i < 2^{60}\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible beauty of the painting.

Sample Input 1

3
3 6 5

Sample Output 1

12

If we paint 3, 6, 5 in blue, red, blue, respectively, the beauty will be (6) + (3 \oplus 5) = 12.

There is no way to paint the integers resulting in greater beauty than 12, so the answer is 12.

Sample Input 2

4
23 36 66 65

Sample Output 2

188

Sample Input 3

20
1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181

Sample Output 3

2012721721873704572

A_i and the answer may not fit into a 32-bit integer type.

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

#if true && UTAKA_LOCAL
//#if false
#define UTAKA_DEBUG
#endif

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Text;

namespace UtakaApp
{
    public partial class Program
    {
        public const string ContestName = "abc141";
        public const string ProblemName = "F";

        public static void Main(string[] args)
        {
#if UTAKA_LOCAL
//#if false
            new TestCaseCheckerForAtCoder().TestProblems();
#else
            var console = new MyConsole();
            new Program().Solve(System.Console.In, console);
            console.Flush();
#endif
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        }

        public void Solve(TextReader textReader, IConsole console)
        {
            var cin = new ConsoleInput(textReader);

            int N = cin.ReadInt;
            long[] A = cin.ReadLongArray(N);

            long s = 0;
            for (int row = 0; row < N; row++)
            {
                s ^= A[row];
            }

            // sでビットが立っていないところは関係ないので消す
            for (int row = 0; row < N; row++)
            {
                A[row] &= ~s;
            }

            int rank = GaussJordanBit.CalcReverse(A, 60, false);

            long x = 0;

            for (int row = 0; row < N; row++)
            {
                x = LongMax(x, x ^ A[row]);
//                x ^= A[row];
            }

            long ans = s + x * 2;
            console.WriteLine(ans.ToString());
        }

        long LongMax(long x, long y)
        {
            return (x > y) ? x : y;
        }

        [Conditional("UTAKA_DEBUG")]
        public void DebugWriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ")
        {
            var sb = new StringBuilder();
            foreach (T v in A)
            {
                sb.Append(v);
                sb.Append(" ");
            }

            if (sb.Length > 0)
            {
                sb.Length--;
            }

            Console.WriteLine(sb.ToString());
        }
    }

    /// 0 1 の掃き出し法
    public static class GaussJordanBit
    {
        /// 桁の大きい方から掃き出す
        /// rankを返す
        public static int CalcReverse(long[] A, int n, bool isExtended = false)
        {
            int m = A.Length;

            int rank = 0;

            for (int col = n; col >= 0; col--)
            {
                if (isExtended && col == 0) break;

                int pivot = -1;

                for (int row = rank; row < m; row++)
                {
                    if ((A[row] & 1L << col) != 0)
                    {
                        pivot = row;
                        break;
                    }
                }

                if (pivot == -1) continue;

                Swap(ref A[pivot], ref A[rank]);

                for (int row = 0; row < m; row++)
                {
                    if (row != rank && (A[row] & 1L << col) != 0)
                    {
                        A[row] ^= A[rank];
                    }
                }

                rank++;
            }

            return rank;
        }

        public static int LinearEquationReverse(long[] inputA, bool[] b, int n, out bool[] result)
        {
            int m = inputA.Length;

            // 拡張する ただしinputAに1列分の余裕が必要
            long[] A = new long[m];

            for (int row = 0; row < m; row++)
            {
                A[row] |= (A[row] << 1) & (b[row] ? 1 : 0);
            }

            // out引数に値を入れておく
            result = new bool[m];

            // 解があるか求める
            int rank = CalcReverse(A, n, true);

            for (int row = rank; row < m; row++)
            {
                if ((A[row] & 1) > 0) return -1;
            }

            // 解を求める
            for (int row = 0; row < rank; row++)
            {
                result[row] = (A[row] & 1) != 0;
            }

            return rank;
        }


        /// 掃き出す
        /// rankを返す
        public static int Calc(long[] A, int n, bool isExtended = false)
        {
            int m = A.Length;

            int rank = 0;

            for (int col = 0; col < n; col++)
            {
                if (isExtended && col == n - 1) break;

                int pivot = -1;

                for (int row = rank; row < m; row++)
                {
                    if ((A[row] & 1L << col) != 0)
                    {
                        pivot = row;
                        break;
                    }
                }

                if (pivot == -1) continue;

                Swap(ref A[pivot], ref A[rank]);

                for (int row = 0; row < m; row++)
                {
                    if (row != rank && (A[row] & 1L << col) != 0)
                    {
                        A[row] ^= A[rank];
                    }
                }

                rank++;
            }

            return rank;
        }

        public static int LinearEquation(long[] inputA, bool[] b, int n, out bool[] result)
        {
            int m = inputA.Length;

            // 拡張する ただしinputAに1列分の余裕が必要
            long[] A = new long[m];

            for (int row = 0; row < m; row++)
            {
                if (b[row])
                {
                    A[row] |= 1L << n;
                }
            }

            // out引数に値を入れておく
            result = new bool[m];

            // 解があるか求める
            int rank = Calc(A, n, true);

            for (int row = rank; row < m; row++)
            {
                if ((A[row] & 1L << n) > 0) return -1;
            }

            // 解を求める
            for (int row = 0; row < rank; row++)
            {
                result[row] = (A[row] & 1L << n) != 0;
            }

            return rank;
        }

        public static void Swap<T>(ref T a, ref T b)
        {
            T c = a;
            a = b;
            b = c;
        }
    }


    public partial class Program
    {
        public const int ModLarge = 1000000007;
    }

    public class ConsoleInput
    {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;

        public ConsoleInput(TextReader stream, char separator = ' ')
        {
            _separator = separator;
            _stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0)
                {
                    return inputStream.Dequeue();
                }

                var tmp = _stream.ReadLine().Split(_separator);
                for (var i = 0; i < tmp.Length; ++i)
                {
                    inputStream.Enqueue(tmp[i]);
                }

                return inputStream.Dequeue();
            }
        }

        public string ReadLine => _stream.ReadLine();
        public int ReadInt => int.Parse(Read);
        public long ReadLong => long.Parse(Read);
        public double ReadDouble => double.Parse(Read);

        public string[] ReadStrArray(long N)
        {
            var ret = new string[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = Read;
            }

            return ret;
        }

        public int[] ReadIntArray(long N)
        {
            var ret = new int[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = ReadInt;
            }

            return ret;
        }

        public long[] ReadLongArray(long N)
        {
            var ret = new long[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = ReadLong;
            }

            return ret;
        }
    }

    public interface IConsole
    {
        void Flush();
        void Write(string str);
        void WriteLine(string str);
    }

    public class MyConsole : IConsole
    {
        public MyConsole()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(sw);
        }

        public void Flush()
        {
            Console.Out.Flush();
        }

        public void Write(string str)
        {
            Console.Write(str);
        }

        public void WriteLine(string str)
        {
            Console.WriteLine(str);
        }
    }

#if UTAKA_LOCAL

    public class DebugConsole : IConsole
    {
        private readonly StringBuilder mSb;

        public DebugConsole()
        {
            mSb = new StringBuilder();
        }

        public void Flush()
        {
            // 何もしない
        }

        public void Write(string str)
        {
            mSb.Append(str);
        }

        public void WriteLine(string str)
        {
            mSb.AppendLine(str);
        }

        public string GetAllOutput()
        {
            return mSb.ToString();
        }
    }

#endif

#if UTAKA_LOCAL

    public class TestCaseCheckerForAtCoder
    {
        private string DirectoryPath => $"../../../../{Program.ContestName}/{Program.ProblemName}";

        private string GetInputFilePath(int testCaseNumber)
        {
            //return $"{DirectoryPath}/sample-{testCaseNumber}.in";
            return $"{DirectoryPath}/in_{testCaseNumber}.txt";
        }

        private string GetOutputFilePath(int testCaseNumber)
        {
            //return $"{DirectoryPath}/sample-{testCaseNumber}.out";
            return $"{DirectoryPath}/out_{testCaseNumber}.txt";
        }

        public bool TestProblem(int testCaseNumber)
        {
            var inputFilePath = GetInputFilePath(testCaseNumber);
            var outputFilePath = GetOutputFilePath(testCaseNumber);

            TextReader inputStream = new StreamReader(inputFilePath);

            var debugConsoleWriter = new DebugConsole();

            new Program().Solve(inputStream, debugConsoleWriter);

            var output = debugConsoleWriter.GetAllOutput();

            TextReader outputStream = new StreamReader(outputFilePath);
            var outputAnswer = outputStream.ReadToEnd();

            Dbg.WriteLine(output);
            Dbg.WriteLine(outputAnswer);

            var isCorrect = output == outputAnswer;

            return isCorrect;
        }

        public void TestProblems()
        {
            var isSuccessAll = true;

            var testCaseNumber = 1;
            while (true)
            {
                var inputFileName = GetInputFilePath(testCaseNumber);
                if (!File.Exists(inputFileName))
                {
                    break;
                }

                Console.WriteLine($"TestCase {testCaseNumber} =====================================================");

                var result = TestProblem(testCaseNumber);

                if (result)
                {
                    Console.WriteLine("Success");
                }
                else
                {
                    isSuccessAll = false;
                    Console.WriteLine("Failure *****");
                }

                testCaseNumber++;
            }

            if (isSuccessAll)
            {
                Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
            }
        }
    }

#endif

#if UTAKA_LOCAL

    public static class Dbg
    {
        public static void WriteLine(string str)
        {
            Console.WriteLine(str);
        }

        public static void Write(string str)
        {
            Console.Write(str);
        }
    }
#else
    public static class Dbg
    {
        public static void WriteLine(string str)
        {
        }

        public static void Write(string str)
        {
        }
    }

#endif
}