#P5985. [PA 2019] Muzyka pop

[PA 2019] Muzyka pop

Description

Given nn integers a1..na_{1..n}, find nn non-negative integers b1..nb_{1..n} to maximize the value of $a_1\times \operatorname{f(b_1)}+a_2\times \operatorname{f(b_2)}+...+a_n\times \operatorname{f(b_n)}$, where f(x)\operatorname{f(x)} is the number of 11 bits in the binary representation of xx.

The nn non-negative integers b1..nb_{1..n} you find must satisfy 0b1<b2<...<bnm0\le b_1<b_2<...<b_n\le m.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers a1,a2,...,ana_1, a_2, ..., a_n.

Output Format

Output one integer in one line, which is the maximum value of $a_1\times \operatorname{f(b_1)}+a_2\times \operatorname{f(b_2)}+...+a_n\times \operatorname{f(b_n)}$.

3 5
2 -1 3
9

Hint

For 100%100\% of the testdata, 1n2001\le n\le 200, n1m1018n-1\le m\le 10^{18}, and ai1014|a_i|\le 10^{14}.


Explanation

Let b1=3,b2=4,b3=5b_1=3, b_2=4, b_3=5. Then the answer is 2×2+(1)×1+3×2=92\times 2+(-1)\times 1+3\times 2=9.

Translated by ChatGPT 5