Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:

Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code ai is known (the code of the city in which they are going to).

Train chief selects some number of disjoint segments of the original sequence of people (covering entire sequence by segments is not necessary). People who are in the same segment will be in the same train carriage. The segments are selected in such way that if at least one person travels to the city x, then all people who are going to city x should be in the same railway carriage. This means that they can’t belong to different segments. Note, that all people who travel to the city x, either go to it and in the same railway carriage, or do not go anywhere at all.

Comfort of a train trip with people on segment from position l to position r is equal to XOR of all distinct codes of cities for people on the segment from position l to position r. XOR operation also known as exclusive OR.

Total comfort of a train trip is equal to sum of comfort for each segment.

Help Vladik to know maximal possible total comfort.

Input

First line contains single integer n (1 ≤ n ≤ 5000) — number of people.

Second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 5000), where ai denotes code of the city to which i-th person is going.

Output

The output should contain a single integer — maximal possible total comfort.

Examples

Input

6
4 4 2 5 2 3


Output

14


Input

9
5 1 3 1 5 2 4 2 5


Output

9

Note

In the first test case best partition into segments is: [4, 4] [2, 5, 2] [3], answer is calculated as follows: 4 + (2 xor 5) + 3 = 4 + 7 + 3 = 14

In the second test case best partition into segments is: 5 1 [3] 1 5 [2, 4, 2] 5, answer calculated as follows: 3 + (2 xor 4) = 3 + 6 = 9.
import java.util.*;
public class C416_ {
    static int n;
    static int a[];
    static int comf[];
    static int first[];
    static int last[];
    static int maxA;
    static int interval[];
    static ArrayList<Interval> intervals;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new int[n];
        for(int i = 0; i < n; ++i) {
            a[i] = sc.nextInt();
            maxA = Integer.max(maxA, a[i]);
        }
        first = new int[maxA + 1];
        last = new int[maxA + 1];
        interval = new int[maxA + 1];
        Arrays.fill(first, n);
        Arrays.fill(last, -1);
        Arrays.fill(interval, -1);
        for(int i = 0; i < n; ++i) {
            first[a[i]] = Integer.min(first[a[i]], i);
            last[a[i]] = Integer.max(last[a[i]], i);
        }
//        System.out.println(Arrays.toString(first));
//        System.out.println(Arrays.toString(last));
        
        solve();
        System.out.println(comf[comf.length - 1]);
    }
    
    static void solve() {
        intervals = new ArrayList<>();
        ArrayList<Integer> set = new ArrayList<>();
        for(int i = 0; i <= maxA; ++i) {
            if(last[i] != -1) {
                set.add(i);
            }
        }
        set.sort((a,b) -> Integer.compare(last[a] - first[a], last[b] - first[b]));
        //if(n==5000) System.out.println(set.size());
        for(int i = 0; i < set.size(); i++) {
            if(interval[set.get(i)] == -1) {
                calc(set.get(i));
            }
        }
        Collections.sort(intervals);
        int m = intervals.size();
        if(m == 0) {
            comf = new int[] {0};
            return;
        }
        comf = new int[m];
        comf[0] = intervals.get(0).xor;
        for(int i = 1; i < m; ++i) {
            comf[i] = comf[i - 1];
            // bin search of last interval that do not overlap this interval
            int l = 0;
            int r = i - 1;
            while(l < r) {
                int mid = (l + r + 1) / 2;
                if(intervals.get(mid).r < intervals.get(i).l) {
                    l = mid;
                } else {
                    r = mid - 1;
                }
            }
            if(intervals.get(l).r < intervals.get(i).l) {
                comf[i] = Integer.max(comf[i], comf[l] + intervals.get(i).xor);
            } else {
                comf[i] = Integer.max(comf[i], intervals.get(i).xor);
            }
//            System.out.println(intervals.get(i).val + " " + comf[i]);
        }
    }
    
    static void calc(int val) {
        int num = intervals.size();
        interval[val] = num;
        int l = first[val];
        int r = last[val];
        int xor = val;
        int i = l + 1;  // moves forward
        int j = l;  // moves backward
        int k = 5000;
        while(k >= 0 && (i < r || j > l)) {
            k--;
            int cur;
            boolean forward = false;
            if(i < r) {
                cur = a[i];
                i++;
                forward = true;
            } else {
                cur = a[j];
                j--;
            }
            if(interval[cur] == -1) {//first[cur] < l || last[cur] > r) {
                interval[cur] = num;
                xor ^= cur;
                l = Integer.min(l, first[cur]);
                r = Integer.max(r,last[cur]);
            } else //{
//                if(interval[cur] == -1) {
//                    System.out.println(forward + " Error " + cur + " not used yet.");
//                    System.out.println(first[val] + " " + last[val]);
//                    System.out.println(l + " " + r);
//                    System.out.println(first[cur] + " " + last[cur]);
              //  } else 
                    if(interval[cur] != num) {
                    xor ^= intervals.get(interval[cur]).xor;
                    if(forward) {
                        i = intervals.get(interval[cur]).r + 1;
                    } else {
                        j = intervals.get(interval[cur]).l - 1;
                    }
               // }
            }
        }
        if(i < r || j > l) {
            System.out.println("k == " + k);
        }
        intervals.add(new Interval(l, r, xor));
       // System.out.println(intervals);
    }
    
    static class Interval implements Comparable<Interval> {
        int l;
        int r;
        int xor;
        Interval(int l, int r, int xor) {
            this.l = l;
            this.r = r;
            this.xor = xor;
        }
        @Override
        public int compareTo(Interval arg0) {
            return Integer.compare(r, arg0.r);
        }
        @Override
        public String toString() {
            return "[l=" + l + ",r=" + r + ",xor=" + xor + "]";
        }
    }
}
