AND Array#331

AND Array

6.75 seconds
512 megabytes
Hard

An integer and an array of non-negative integers a_1,a_2,\ldots,a_n are given. All elements of the array are less than 2^b.

Let's define f(s, p) (1\le s\le n, 0\le p < b) as the result of the following pseudocode:

res = 0
x = power(2, p)
for i = s to n:
    if ((x AND a[i]) == 0):
        x = (x OR a[i])
        res = res + i
return res

Here, "power(2, p)" denotes 2^p, "AND" denotes the bitwise AND operation, and "OR" denotes the bitwise OR operation.

The bitwise AND of non-negative integers and is equal to a non-negative integer, in which the binary representation has a one at a certain position only if both binary representations of and have ones at that position. For example, 3_{10} AND 5_{10} = 0011_{2} AND 0101_{2} = 0001_{2} = 1_{10}.

The bitwise OR of non-negative integers and is equal to a non-negative integer, in which the binary representation has a zero at a certain position only if both binary representations of and have zeros at that position. For example, 3_{10} OR 5_{10} = 0011_{2} OR 0101_{2} = 0111_{2} = 7_{10}.

For each from to , find

f(i,0) + f(i, 1) + \ldots + f(i, b-1)

Input

The first line contains two integers and (1 \leq n \leq 10^5, 1 \leq b \leq 20) — the length of array and the limit on the elements of the array, respectively.

The second line contains integers a_1, a_2, \ldots, a_n (0 \leq a_i < 2^b) — the elements of array .

Output

Output integers — the required values.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Note

In the first example, f(1,0)=1+2+5=8, f(1,1)=1+3+5=9, f(1,2)=1+2+3=6, and the first of the required values is equal to 8+9+6 = 23.

Scoring

  1. ( points): n \leq 2\,000;

  2. ( points): a_i = 2^k, where is an integer;

  3. ( points): b \leq 8;

  4. ( points): b \leq 12;

  5. ( points): b \leq 16;

  6. ( points): without additional constraints.