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
#include <iostream>
#include <vector>

int translateToBits(int givenNumber)
{
	int finalResult=0;
	while (givenNumber != 0)
	{
		if (givenNumber % 2 == 1)
			finalResult++;
	}

	return finalResult;
}

int main()
{
	int n, m, bitSongResult=0;
	std::cin >> n >> m;
	std::vector<int> numberOnSecond(n, 0);

	for (int i = 0; i < n; i++)
	{
		int seconds; 
		std::cin >> seconds;
		numberOnSecond.push_back(seconds);
	}

	m -= n;

	for (int& s : numberOnSecond)
	{
		bitSongResult += s * translateToBits(m);
		m++;
	}

	std::cout << "\n" << bitSongResult << "\n";

	return 0;
}