import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    immutable int MAX = 5010;

    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    auto L = new int[](MAX);
    auto R = new int[](MAX);
    fill(L, MAX);
    fill(R, -1);

    foreach (i; 0..N) {
        L[A[i]] = min(L[A[i]], i);
        R[A[i]] = max(R[A[i]], i);
    }

    auto mem = new int[](N);
    fill(mem, -1);

    int dp(int i) {
        if (i >= N) return 0;
        if (mem[i] >= 0) return mem[i];

        if (L[A[i]] != i)
            return dp(i + 1);
        int tar = R[A[i]];
        int pos = i + 1;
        int score = A[i];
        while (pos < N && pos <= tar) {
            if (L[A[pos]] < i) {
                score = 0;
                break;
            }
            else if (L[A[pos]] == pos) {
                score ^= A[pos];
            }
            tar = max(tar, R[A[pos]]);
            pos += 1;
        }

        return mem[i] = max(dp(i+1), score + dp(tar+1));
    }

    dp(0).writeln;
}
