Submit solution

Points: 12 (partial)
Time limit: 1.0s
Memory limit: 1G

Author:
Problem types

You are given an array of N positive integers, a1,a2,aN. 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 a which contain at least two elements. Since this value may be huge, output it modulo 109+7.

Constraints

1N2×105
0ai<230

Subtask 1 [20%]

1N2000

Subtask 2 [80%]

No additional constraints.

Input Specification

The first line contains one integer, N, the length of the array.

The next line contains N space-separated integers, a1,a2,,aN, 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 109+7.

Sample Input 1

Copy
5
3 1 4 1 5

Sample Output 1

Copy
64

Explanation for Sample 1

The following are the values of every subsequence containing at least two elements:

Format:
s2min2(s)max2(s)=v

Where s2 represents a subsequence of a containing at least two elements, min2 is the second minimum, is the bitwise xor operator, max2 is the second maximum, and v is the resulting value of s2.

[3,1]31=2
[3,4]43=7
[3,1]31=2
[3,5]53=6

[1,4]41=5
[1,1]11=0
[1,5]51=4

[4,1]41=5
[4,5]54=1

[1,5]51=4

Subsequences with 3 elements are omitted since they all have a value of 0.

[3,1,4,1]13=2
[3,1,4,5]34=7
[3,1,1,5]13=2
[3,4,1,5]34=7
[1,4,1,5]14=5

[3,1,4,1,5]14=5

Total value of all subsequences with at least two elements: 2+7+2+6+5+0+4+5+1+4+2+7+2+7+5+5=64

Sample Input 2

Copy
10
5 1 29 8 7 10 48 15 33 59

Sample Output 2

Copy
30210

Sample Input 3

Copy
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

Copy
119486481

Explanation for Sample 3

Remember to output the answer modulo 109+7.


Comments

There are no comments at the moment.