Codeforces Round 416 (Div. 2)
C
Vladik and Memorable Trip
Codeforces
1900
原题
← BD →
翻译中…

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 $*a*_{*i*}$ 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 $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($0 ≤ *a*_{*i*} ≤ 5000$), where $*a*_{*i*}$ denotes code of the city to which $*i*$-th person is going.

翻译中…

Output

翻译中…

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

翻译中…

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$.

翻译中…

样例

Input #1
6
4 4 2 5 2 3
Output #1
14
InputCopy OutputCopy
Input #2
9
5 1 3 1 5 2 4 2 5
Output #2
9
InputCopy OutputCopy
题目信息
题号
811C
时间限制
2 s
内存限制
256 MB
标签
动态规划
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。