#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
int ctz(unsigned x) { return __builtin_ctz(x); }
int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
int clz(unsigned x) { return __builtin_clz(x); }
int clzll(unsigned long long x) { return __builtin_clzll(x); }
int popcnt(unsigned x) { return __builtin_popcount(x); }
int popcntll(unsigned long long x) { return __builtin_popcountll(x); }
int bsr(unsigned x) { return 31 ^ clz(x); }
int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
int tag[5120];
int a[5120], dp[5120];
int f[5120], c[5120];
int val[5120][5120];
int main() {
  canhazfast();
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++f[a[i]];
  }
  for (int i = 0; i < n; ++i) {
    int v = 0;
    for (int j = i; j < n; ++j) {
      int x = a[j];
      if (i >= tag[x]) v ^= x, tag[x] = i + 1;
      val[i][j + 1] = v;
    }
  }
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1];
    int t = 0, bad = 0;
    fill_n(c, 5000 + 1, 0);
    for (int j = i - 1; j >= 0; --j) {
      int x = a[j];
      if (!c[x]) ++bad;
      if (++c[x] == f[x]) --bad;
      if (!bad) t = max(t, val[j][i]);
      dp[i] = max(dp[i], dp[j] + t);
    }
  }
  cout << dp[n];
  return 0;
}
