BITDIFF - Bit Difference

Given an integer array of N integers, find the sum of bit differences in all the pairs that can be formed from array elements. Bit difference of a pair (x, y) is the count of different bits at the same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 is 111 (first and last bits differ in two numbers).

Input

Input begins with a line containing an integer T (1<=T<=100), denoting the number of test cases. Then T test cases follow. Each test case begins with a line containing an integer N (1<=N<=10000), denoting the number of integers in the array, followed by a line containing N space separated 32-bit integers.

Output

For each test case, output a single line in the format Case X: Y, where X denotes the test case number and Y denotes the sum of bit differences in all the pairs that can be formed from array elements modulo 10000007.

Example

Input:
1
4
3 2 1 4

Output:
Case 1: 22

Added by:imranziad
Date:2015-11-24
Time limit:0.5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY
Resource:AIUB CS Fest 2015 (H.M. Mehrab)

hide comments
2020-09-02 10:08:58
Bitset made it simpler;)
2018-04-29 09:41:41
note that 1e7+7!
2018-02-14 06:37:53
Enjoyed solving it, but thumbs down for idiotic timelimit. Got AC and optimised the runtime by gradually dumbing my code down. No lesson in this.
2017-08-12 15:40:16
O(33nt)
not 32 because of input :)
2017-02-13 09:21:07
easy one forget to print newline cost me 1 WA
2016-12-28 08:01:02
how on earth O(n)?
2016-12-22 19:56:58 Mayank Agarwal
take care of ordered pairs!!
2016-08-24 02:26:09
Extremely strict time limit costed me 3 tle's don't take long long unnecessarily
2016-08-09 17:53:26
ios::sync_with_stdio(false); AC
2016-03-14 17:06:36
Does this ask for the sum of the Hamming weight of the XOR of all pairs or the sum of the XOR-s of all pairs??
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.