Loading...
Find MinMaxXoR Number
Time: 1 s
Memory: 125 MB
You are given an integer array A. We need to generate a number MinMaxXoR  from array A. We generate number MinMaxXoR  from following steps,
 
  1. SubXor = [] // Initially we have SubXor which is empty
  2. Find the minimum and maximum element of each subarray which length at least 2 in array A and bitwise xor\((\bigoplus)\) between them and store this result in SubXor array.
  3. L = size(SubXor) //store SubXor array size in L
  4.  MinMaxXoR\(SubXor[1] \bigoplus SubXor[2] \bigoplus .......\bigoplus SubXor[L-1] \bigoplus SubXor[L]\) 
Input
The first line contains one integer \(N (2\leq N \leq 5*10^5)\), the number of items in the array.
The second line contains \(N\) integers \(A_1,A_2,....,A_{N-1},A_N(1\leq A_i \leq 10^6)\)
Output
Print a single integer, MinMaxXoR number which is described the statements.
Examples
Input
Output
4
1 2 3 4
4
Input
Output
4
1 3 2 3
3
Input
Output
4
3 2 1 4
5
Notes
In first test case,

\(N=4 , A = [1,2,3,4]\)

Now ,
\(1, 2 => min = 1, max = 2 => xor = 1\bigoplus2 = 3\\ 1,2,3 => min = 1, max = 3 => xor = 1\bigoplus3 = 2\\ 1,2,3,4 => min = 1, max = 4 => xor = 1\bigoplus4 = 5\\ 2,3 => min = 2, max = 3 => xor = 2\bigoplus3 = 1\\ 2,3,4 => min = 2, max = 4 => xor = 2\bigoplus4 = 6\\ 3,4 => min = 3, max = 4 => xor = 3\bigoplus4 = 7\\ So, \\ MinMaxXoR = 3\bigoplus2\bigoplus5\bigoplus1\bigoplus6\bigoplus7\bigoplus = 4\)
 
Problem Info
Problem ID 57
Time Limit 1000 ms
Memory Limit 128000 KB
Moderators AmirHamza
Statistics
Submit
You need to Login or Registration for submit your solution