ADAMOLD - Ada and Mold

As you might already know, Ada the Ladybug is a farmer. She has a long furrow in which she grows vegetable (while each vegetable is identified by a bloom-value). The more vegetable is in the furrow the bigger risk of mold there is. More specifically the mold-value can be obtained as sum of xor of all pairs of vegetable's bloom-values.

Ada has bought a few wooden separators which could possibly reduce the mold-value. It works in following manner: she can put the separators between some plants, dividing the furrow into multiple segments. The mold-value will then becomes the sum of mold-values of all the segments (independently). Can you find the minimal possible mold-value?

Input

The first line of input contains two integers N, K: 1 ≤ K < N ≤ 5000, the length of furrows and the number of separators.

The next lines will contain N numbers 0 ≤ Ai ≤ 109, the bloom-values of vegetable.

Output

Output the minimal possible mold-value.

Example Input

6 1
1 2 3 4 5 6

Example Output

12

Example Input 1

4 3
5 3 5 3

Example Output 1

0

Example Input 2

7 2
5 3 5 3 5 3 4

Example Output21

24

Example Input 3

9 4
1 2 3 4 5 6 7 666 1024

Example Output 3

8

Example Input 4

30 8
629470789 417274987 617986533 841737683 297969800 432044389 708142005 156958893 499363651 434034331 176735187 525172817 747109631 949700868 259681519 357968078 818249370 456939952 450487335 529013233 327250536 90354657 643708145 141755216 656041628 661580907 204072850 469709611 834069223 681347499

Example Output 4

16154467281

Added by:Morass
Date:2017-10-15
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All

hide comments
2017-10-15 13:58:42 wisfaq
Thanks

Last edit: 2017-10-15 14:17:53
2017-10-15 12:51:27
@wisfaq: Good day to you. No, you don't have use all separators, you only have to minimize the answer :))
2017-10-15 12:47:05 wisfaq
It's unclear if all separators have to be used.
Suppose I have plants abcd and two separators(|) is |abcd| allowed?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.