You are given an array of positive integers,
. Let the value of a collection of at least two numbers be the bitwise xor of its second minimum and second maximum. Determine the sum of the values of all subsequences of
which contain at least two elements. Since this value may be huge, output it modulo
.
Constraints
Subtask 1 [20%]
Subtask 2 [80%]
No additional constraints.
Input Specification
The first line contains one integer, , the length of the array.
The next line contains space-separated integers,
, the array of positive integers.
Output Specification
Output one line containing one integer, the sum of the values of all subsequences which contain at least two elements, modulo .
Sample Input 1
5
3 1 4 1 5
Sample Output 1
64
Explanation for Sample 1
The following are the values of every subsequence containing at least two elements:
Format:
Where represents a subsequence of
containing at least two elements,
is the second minimum,
is the bitwise xor operator,
is the second maximum, and
is the resulting value of
.
Subsequences with elements are omitted since they all have a value of
.
Total value of all subsequences with at least two elements:
Sample Input 2
10
5 1 29 8 7 10 48 15 33 59
Sample Output 2
30210
Sample Input 3
50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 1000000000 1000000000
Sample Output 3
119486481
Explanation for Sample 3
Remember to output the answer modulo .
Comments