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

int c(int x)
{
    int w = 0;

    while(x > 0)
    {
        w += x % 2;
        x /= 2;
    }

    return w;
}

int main()
{
    int n, m, *a, w = 0;
    
    std::cin >> n >> m;

    a = new int[n];
    for (int i = 0; i < n; i++)
        std::cin >> a[i];

    int x = m - n + 1;
    for (int i = 0; i < n; i++)
    {
        w += c(x + i) * a[i];
    }

    std::cout << w;
    delete[] a;
}