Problem:
Score : 400 points

Problem Statement

One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N.
He is interested in properties of the sequence a.

For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its beauty is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.)

Find the maximum possible value for him.

Constraints

2 \leq N \leq 1000

1 \leq a_i \leq 10^9

1 \leq K \leq N(N+1)/2

All numbers given in input are integers

Input

Input is given from Standard Input in the following format:

N K
a_1 a_2 ... a_N

Output

Print the answer.

Sample Input 1

4 2
2 5 2 5

Sample Output 1

12

There are 10 nonempty contiguous subsequences of a. Let us enumerate them:

contiguous subsequences starting from the first element: \{2\}, \{2, 5\}, \{2, 5, 2\}, \{2, 5, 2, 5\}

contiguous subsequences starting from the second element: \{5\}, \{5, 2\}, \{5, 2, 5\}

contiguous subsequences starting from the third element: \{2\}, \{2, 5\}

contiguous subsequences starting from the fourth element: \{5\}

(Note that even if the elements of subsequences are equal, subsequences that have different starting indices are considered to be different.)

The maximum possible bitwise AND of the beauties of two different contiguous subsequences is 12.
This can be achieved by choosing \{5, 2, 5\} (with beauty 12) and \{2, 5, 2, 5\} (with beauty 14).

Sample Input 2

8 4
9 1 8 2 7 5 6 4

Sample Output 2

32

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

//#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



int main() {
	ll i, j, n, d, k, cnt = 0;
	string s;
	vector<ll>list;
	ll sum = 0;

	cin >> n >> k;

	rep(i, 0, n) {
		ll num;
		cin >> num;
		list.push_back(num);
		sum += num;
	}
	
	
	sort(list.begin(), list.end());
	vector<ll>list2;

	//if (k - 1 < n) {
	//	for (i = 0; i < k - 1; i++) {
	//		list2.push_back(list[i]);
	//	}
	//}
	//else {
	//	ll sumc = 0, ib = 0, ccnt = 0;

	//	while (ccnt< k - 1)
	//	{


	//		for (i = ib; i < n; i++) {
	//							
	//			list2.push_back(list[i] + sumc);
	//			ccnt++;
	//			if (ccnt >= k - 1) break;
	//		}

	//		sumc += list[ib];
	//		ib++;

	//	}

	//}

	if (k - 1 < n) {
		for (i = 0; i < k - 1; i++) {
			ll sumb = sum;
			sumb -= list[i];
			list2.push_back(sumb);
		}
	}
	else {
		ll sumc = sum, ib = 0, ccnt = 0;

		while (ccnt< k - 1)
		{


			for (i = ib; i < n; i++) {
				ll sumb = sumc;
				sumb -= list[i];
				list2.push_back(sumb);
				ccnt++;
				if (ccnt >= k - 1) break;
			}

			sumc -= list[ib];
			ib++;

		}

	}


	for (i = 0; i < list2.size(); i++) {
		sum &= list2[i];
	}


	cout << sum << endl;

	




	getchar();
	getchar();
	return 0;
}