#K81962. Sum of XOR Set Bits

    ID: 35870 Type: Default 1000ms 256MiB

Sum of XOR Set Bits

Sum of XOR Set Bits

Given an integer ( N ) and a list of ( N ) integers ( A = [A_0, A_1, \dots, A_{N-1}] ), compute the sum over all ordered pairs ( (i, j) ) of ( f(A_i \oplus A_j) ), where ( \oplus ) denotes the bitwise XOR operation and ( f(X) ) is defined as the number of set bits (i.e., 1 bits) in the binary representation of ( X ). The final answer should be computed modulo ( 10^9 + 7 ).

Input Format: The first line contains an integer ( N ). The next line contains ( N ) space-separated integers representing the array ( A ).

Output Format: Output a single integer, the sum described above, modulo ( 10^9 + 7 ).

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains a single integer ( N ), representing the number of elements in the array.
  2. The second line contains ( N ) space-separated integers ( A_0, A_1, \dots, A_{N-1} ).

outputFormat

Print a single integer which is the sum of ( f(A_i \oplus A_j) ) for all ordered pairs ( (i, j) ), computed modulo ( 10^9 + 7 ).## sample

2
2 4
4

</p>