PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000133. XOR lớn nhất của đoạn con (Maximum Xor Subarray)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

XOR lớn nhất của đoạn con (Maximum Xor Subarray)

Maximum Xor Subarray

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn nonnegative integers x1,…,xnx_1,\ldots,x_n, the value of a nonempty contiguous interval [l,r][l,r] is xl⊕xl+1⊕⋯⊕xrx_l\oplus x_{l+1}\oplus\cdots\oplus x_r, where ⊕\oplus denotes bitwise XOR. Find the largest value over all intervals 1≤l≤r≤n1\le l\le r\le n.

Input

First line: integer nn.

Second line: nn integers x1,…,xnx_1,\ldots,x_n.

Output

Print one integer, the maximum interval XOR.

Subtasks

  • Subtask 1 (20 points): 1≤n≤20001\le n\le 2000; 0≤xi≤1090\le x_i\le 10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤2⋅1051\le n\le 2\cdot10^5; 0≤xi≤10230\le x_i\le 1023 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le 2\cdot10^5; 0≤xi≤1090\le x_i\le 10^9 for every 1≤i≤n1\le i\le n.

Example 1

Input

4
5 1 5 9

Output

13

Explanation

Interval [2,4][2,4] has XOR 1⊕5⊕9=131\oplus5\oplus9=13. By length, the values are (5,1,5,9), (4,4,12), (1,13), and (8). Their maximum is 13.

Example 2

Input

1
0

Output

0

Explanation

The only interval contains one element, whose XOR is zero.