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]1+R∑i=LR∑j=i(C[i]∧C[j])⌋×103 , ∧ represents bitwise-xor operator.
Input
Output
Constraints
N=1041≤L≤R≤N1≤A[i]≤106
Verdit and Scoring