Jumpy Humpy

3

53 votes
Data Structures, Dynamic programming, Easy, Stacks
Problem

Humpy likes to jump from one building to another. But he only jumps to next higher building and stops when no higher building is available. Stamina required for a journey is xor of all the heights on which humpy jumps until he stops.

If heights are [1 2 4], and he starts from 1, goes to 2 stamina required is 12=3, then from 2 to 3. Stamina for the entire journey is 124=7. Find the maximum stamina required if can start his journey from any building.

Input

First line: N, no of buildings.

Second line: N integers, defining heights of buildings.

Output

Single Integer that is the maximum stamina required for any journey.

Constraints

1N105

1Heights109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

If he starts from building 1, the stamina required is 1 ^ 2 ^ 3 ^ 8 = 8

From the building 2, the stamina required is 2 ^ 3 ^ 8 = 9

From the building 3, the stamina required is 3 ^ 8 = 11

Similarly, from 8 and 6, stamina required are 8 and 6 respectively.

The maximum stamina required for the journey is from building 3 is 11.

So the answer is 11.

Editor Image

?