Note: This is an approximate problem. There is no exact solution. You must find the most optimal solution. Please, take a look at the sample explanation to ensure that you understand the problem correctly.
Problem statement
You are given an array A of N elements and two integers L and R.
Choose an array B which is a permutation of array [1, 2, 3, …., N - 1, N] and build an array C as C[i] = A[B[i]].
The goal is to maximize the value of array function Z
Z=R∑i=LR∑j=ij∑k=iC[k]⊕k⊕(i+j) , ⊕ represents bitwise-xor operator.
Input
Output
Constraints
1≤N≤1031≤L≤R≤N1≤A[i]≤104
Verdit and Scoring