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
2016-02-22 22:54:51 newbie
easy one !! cost 3 WA due to 1e7+7 mistakenly took it as default(1e9+7)
2016-02-13 14:39:29 Umesh Malhotra
Beware: TLE with cin>> but AC with scanf
2016-01-28 11:40:37 ayush sinha
time O(32n)
2016-01-26 21:46:31 varun yadav
took me a little time,, but then i knew the statement is incomplete here :p finally AC in one go
2016-01-25 18:48:39
Should be moved to tutorials.....simple O(n) solution works
2016-01-23 10:40:00
Time Limit strict for python,near to O(N) giving TLE
2016-01-18 14:19:52 DHEERAJ KUMAR
I wonder why people want output in that format. :(
2015-12-31 11:37:24
Very nice problem.. Failed when I tried it a month ago.. Today after 1 month and a better knowledge of bit manipulation.. --> AC with O(n)
2015-12-09 16:46:48 The_ROCK
should mention "ordered pairs" in problem statement
too strict TL
2015-12-07 18:40:05 Mayank Garg
@Filip O(n) possible !!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.