Language: C++

//	Totally unrelated and not AT ALL stolen from hohohaha's template
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>

using namespace std;

#pragma GCC optimize("03")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define arctan atan
#define arccos acos
#define arcsin asin
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define vt vector
#define pr pair
#define u_map unordered_map
#define endl "\n"
//	Until next time, remember:
//			You are closer than you think.
//						_Dan Lok_

typedef double db;			typedef long long ll;		typedef long double ld;			typedef string str;
typedef pr<int, int> pii;	typedef pr<ll,ll> pll;		typedef pr<ld,ld> pdd;
typedef vt<int> vi;			typedef vt<ll> vll;			typedef vt<bool> vb;
typedef vt<str> vs;			typedef vt<pii> vpii;		typedef vt<pll> vpll;
typedef map<int, int> mii;	typedef map<int, bool> mib;	typedef map<int, str> mis;		typedef map<int, char> mic;
typedef complex<db> cpx;	typedef vt<cpx> vcpx;
//const int mod = 1e9+7;		const ll inf = 9223372036854775807;
#define pi 3.1415926535897932	//faster than pi = acos(-1); but sometimes doesn't work
//	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	srand(chrono::steady_clock::now().time_since_epoch().count());
//	freopen("input.txt","r",stdin);

const int MAX_N = 1007;
//const int MAX_K = MAX_N*(MAX_N-1) / 2;
ll a[MAX_N];
int n,k, last = 40;
vll beauty;

void make_beauties()
{
	for(int i = 1; i < n+1; ++i)
	{
		ll sum = 0;
		for(int j = i; j < n+1; ++j)
		{
			sum += a[j];
			beauty.pb(sum);
		}
		
	}
}

vll subset()
{
	vll ans;
	for(int i = last; i > -1; --i)
	{
		ll cunt = 0;
		for(ll& j: beauty)
		{
			if (j & (1LL << i)) ++cunt;
		}
		
		if (cunt >= k)
		{
			for(ll j : beauty)
			{
				if (j & (1LL << i)) ans.pb(j);
			}
			
			last = i-1;
			return ans;
		}
	}
	return ans;
}

ll MAX_AND(){
	vll temp;
  
    while ((int)beauty.size() >= k) { 
  
        temp   = beauty; 
        beauty = subset(); 
    } 
  
    ll ans = temp[0]; 
    for (int i = 1; i < min(k,temp.size()); ++i) 
        ans &= temp[i]; 
  
    return ans; 
}

void input()
{
	cin >> n >> k;
	for(int i = 1; i < n+1; ++i)
	{
		cin >> a[i];
	}
	make_beauties();
	cout << MAX_AND();
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("FILE.inp","r",stdin); freopen("FILE.out","w",stdout);
//	freopen("input.txt","r",stdin);
	input();
	return 0;
}
// with the aura of Dora, AC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1!!!!!!!!!!!!!!!!!!!!!!!!!
// Why is there node one in my row of exclamation marks?



Compiler output:
a.cc: In function 'll MAX_AND()':
a.cc:98:28: error: no matching function for call to 'min(int&, std::vector<long long int>::size_type)'
   98 |     for (int i = 1; i < min(k,temp.size()); ++i)
      |                         ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:98:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'})
   98 |     for (int i = 1; i < min(k,temp.size()); ++i)
      |                         ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:98:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   98 |     for (int i = 1; i < min(k,temp.size()); ++i)
      |                         ~~~^~~~~~~~~~~~~~~