#P5283. Maximizing Zongzi Flavor Sum

    ID: 18516 Type: Default 1000ms 256MiB

Maximizing Zongzi Flavor Sum

Maximizing Zongzi Flavor Sum

Little Zong loves zongzi and is making them at home! In front of her, there are \(n\) different types of fillings arranged in a row and numbered from \(1\) to \(n\). The \(i\)-th filling has a nonnegative integer property \(a_i\). There are infinitely many of each filling, so she never runs out of ingredients.

She intends to make \(k\) zongzi. To make one, she selects two integers \(l\) and \(r\) with \(1 \leq l \leq r \leq n\) and mixes all fillings in the range \([l, r]\). The tastiness of the resulting zongzi is defined as the xor sum of the properties of the chosen fillings, i.e. \(a_l \oplus a_{l+1} \oplus \cdots \oplus a_r\) (here \(\oplus\) denotes the bitwise XOR operation).

Moreover, Little Zong does not want to use the same set of fillings for making more than one zongzi, which means the chosen contiguous segments must be distinct. Since every segment \([l, r]\) is naturally unique, your task is to help her choose \(k\) (not necessarily disjoint) segments so that the sum of their tastiness values is maximized.

Note: If \(k\) is larger than the total number of possible segments, only the available segments can be chosen.

inputFormat

The first line contains two integers \(n\) and \(k\) \((1 \leq n \leq 2000,\ 1 \leq k \leq \frac{n(n+1)}{2})\) representing the number of fillings and the number of zongzi to make.

The second line contains \(n\) nonnegative integers \(a_1, a_2, \ldots, a_n\) representing the property values of the fillings.

outputFormat

Output a single integer, which is the maximum possible sum of the tastiness values of the chosen \(k\) zongzi.

sample

3 2
1 2 3
6

</p>