text: # Problem Monk loves cakes!He visits the Binary Bakery to buy some of his favorite cheesecakes.The owner of the bakery, Bob, is a clever man.He does not want Monk to finish all his cheesecakes.Hence, he plays a game.The Monk is given N numbers and has to select K of these numbers.For each number that Monk chooses, he will get as many cheesecakes as the number of 1's in the Binary representation of the number i.e.the number of bits that are set.Help Monk find the maximum number of cakes that he can have.Input: The first line of input contains T.T test cases follow.First line of each test cases contains 2 space-separated integers N and K.The next line contains N space-separated integers.Output: For each test cases, print the answer in a new line.Constraints: 1 ≤ T ≤ 10 1 ≤ N ≤ 10^3 0 ≤ K ≤ N 0 ≤ Numbers ≤ 10^5 SAMPLE INPUT 1 4 2 6 1 2 0 SAMPLE OUTPUT 3 Explanation He chooses numbers 6 (110) and 1 (001) with 2 and 1 set bits respectively.# Solution def count(num): tmp=num cnt=0 while(tmp!=0): if tmp & 1 == 1: cnt=cnt+1 tmp=tmp >> 1 #print cnt return cnt T=int(raw_input()) for i in xrange(T): N,K=map(int,raw_input().split()) Nums=raw_input().split() NumsList=map(int,Nums) l=len(NumsList) cntList=list() for j in xrange(l): cntList.append(count(NumsList[j])) cntList.sort() #print cntList j=0 s=0 while j < K : s=s+cntList[l-1-j] j=j+1 print s