eagers

Time limit: 0.4s Memory limit: 256MB Input: Output:

Adin was recently asked whether he would like to “build muscles or build eagers”. He knew how building muscles would help him, but he had to search the internet to learn about building eagers.

It turns out that there is an array of NN integers, A0,A1,...,AN1A_0, A_1, ..., A_{N-1}, called the eager coefficients. Adin wants to split the array AA into exactly KK contiguous, non-empty subarrays. To do this, he chooses K1K-1 split points to divide the array.

Formally, we can define the partition by choosing indices c1,c2,...,cK1c_1, c_2, ..., c_{K-1} such that 0<c1<c2<...<cK1<N0 < c_1 < c_2 < ... < c_{K-1} < N. The ii-th subarray then consists of the elements from index ci1c_{i−1} to ci1c_i − 1 (where c0=0c_0 = 0 and cK=Nc_K = N).

Let valival_i be the bitwise OR of all elements in the ii-th subarray. The final amount of eagers is calculated as the bitwise AND of these subarray values:

ans=val1&val2&...&valKans = val_1 \And val_2 \And ... \And val_K

To truly answer the question, Adin wants to find the maximum possible value for ansans among all valid partitions into KK subarrays. Write a program, eagers, that calculates this value for him.

A subarray is a contiguous sequence of elements from the original array. For example, [2,3][2,3] is a subarray of [1,2,3][1,2,3], but [1,3][1,3] is not.

A bitwise OR (|) is a binary operation that compares two numbers in binary representation, bit by bit. It returns a 00 for each position if both corresponding bits are 00, and 11 otherwise. For example, 4 8794 772=5 0394 \ 879 ∣ 4 \ 772 = 5 \ 039.

A bitwise AND (&)(\And) is a binary operation that compares two numbers in binary representation, bit by bit. It returns a 11 for each position if both corresponding bits are 11, and 00 otherwise. For example, 4 879&4 772=4 6124 \ 879 \And 4 \ 772 = 4 \ 612.

Input data

On one line of standard input the positive integers NN and KK are given. On the next line NN positive integers A0,A1,...,AN1A_0, A_1, ..., A_{N-1} are given.

Output data

On standard output print one number – the maximum possible value for ansans among all possible splits.

Restrictions

  • 1KN1061 \leq K \leq N \leq 10^6
  • 0Ai1090 \leq A_i \leq 10^9
Subtask Points Required subtasks NN AiA_i Other constraints
0 0 - - - The examples.
1 12 00 20\leq 20 109\leq 10^9 -
2 2 - 106\leq 10^6 1\leq 1 -
3 13 22 106\leq 10^6 2\leq 2 -
4 15 00 100\leq 100 2 000\leq 2 \ 000 -
5 11 0,40,4 300\leq 300 2 000\leq 2 \ 000 -
6 12 0,450,4-5 2 000\leq 2 \ 000 2 000\leq 2 \ 000 -
7 13 01,460-1,4-6 105\leq 10^5 109\leq 10^9 -
8 22 070-7 106\leq 10^6 109\leq 10^9 -

Example 1

stdin

7 3
2 1 4 3 2 2 5

stdout

3

Explanation

One of the optimal solutions is to split into the subarrays [2,1,4],[3,2],[2,5][2,1,4],[3,2],[2,5]. Their respective values are 7,3,77, 3, 7. The BITWISE AND of the 33 numbers is exactly 33.

Example 2

stdin

6 2
1 0 0 1 2 2

stdout

2

Explanation

The only optimal solution is to split into the subarrays [1,0,0,1,2][1,0,0,1,2] and [2][2]. Their respective values are 33 and 22, which give a BITWISE AND of 22.

Log in or sign up to be able to send submissions!