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



Sample input:
4 2
2 5 2 5


Sample output:
12

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[0]*(n+1)
f=[]
for i in range(1,n+1):
  s[i]+=s[i-1]+a[i-1]
for i in range(n+1):
  for j in range(i+1,n+1):
    f.append(s[j]-s[i])
f.sort()
ans=f[-1]
for i in range(2,k+1):
  ans&=f[-i]
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import *
from bisect import *
N,K=map(int,input().split())
A=list(map(int,input().split()))

ruiA=[0 for i in range(N+1)]
for i in range(0,N):
    ruiA[i+1]=ruiA[i]+A[i]


nlst=[]

for i in range(len(ruiA)-1):
    for m in range(i+1,len(ruiA)):
        nlst.append(ruiA[m]-ruiA[i])
nlst.sort(reverse=True)

lenbin=32
for i in range(len(nlst)):
    lst=[]
    for m in range(lenbin):
        lst.append((nlst[i]>>m)&1)
    nlst[i]=list(reversed(lst))
    #print(nlst[i])
lenbinst=0
use=set([i for i in range(len(nlst))])
while lenbinst<lenbin:
    idx=-1
    count=0
    dellst=set()
    for m in use:
        if nlst[m][lenbinst]==1:
            count+=1
    if count>=K:
        if len(nlst)!=count:
            for m in use:
                if nlst[m][lenbinst]!=1:
                    dellst.add(m)
    use=use-dellst
    lenbinst+=1
valuelst=[0 for i in range(lenbin)]
nlst=[nlst[i] for i in use]

for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1

for i in range(lenbin):
    if valuelst[i]>=K:
        newlst=[i for i in nlst if i[idx]==1]
        if len(newlst)>=K:
            nlst=newlst

valuelst=[0 for i in range(lenbin)]
for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1
value=0
for i in range(lenbin):
    if valuelst[i]>=K:
        value+=2**i
print(value)

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import *
from bisect import *
N,K=map(int,input().split())
A=list(map(int,input().split()))

ruiA=[0 for i in range(N+1)]
for i in range(0,N):
    ruiA[i+1]=ruiA[i]+A[i]


nlst=[]

for i in range(len(ruiA)-1):
    for m in range(i+1,len(ruiA)):
        nlst.append(ruiA[m]-ruiA[i])
nlst.sort(reverse=True)

lenbin=32
for i in range(len(nlst)):
    lst=[]
    for m in range(lenbin):
        lst.append((nlst[i]>>m)&1)
    nlst[i]=list(reversed(lst))
    #print(nlst[i])
lenbinst=0
print(nlst)
use=set([i for i in range(len(nlst))])
while lenbinst<lenbin:
    idx=-1
    count=0
    dellst=set()
    for m in use:
        if nlst[m][lenbinst]==1:
            count+=1
    if count>=K:
        if len(nlst)!=count:
            for m in use:
                if nlst[m][lenbinst]!=1:
                    dellst.add(m)
    use=use-dellst
    lenbinst+=1
valuelst=[0 for i in range(lenbin)]
nlst=[nlst[i] for i in use]

for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1

for i in range(lenbin):
    if valuelst[i]>=K:
        newlst=[i for i in nlst if i[idx]==1]
        if len(newlst)>=K:
            nlst=newlst

valuelst=[0 for i in range(lenbin)]
for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1
value=0
for i in range(lenbin):
    if valuelst[i]>=K:
        value+=2**i
print(value)

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import *
from bisect import *
N,K=map(int,input().split())
A=list(map(int,input().split()))

ruiA=[0 for i in range(N+1)]
for i in range(0,N):
    ruiA[i+1]=ruiA[i]+A[i]


nlst=[]

for i in range(len(ruiA)-1):
    for m in range(i+1,len(ruiA)):
        nlst.append(ruiA[m]-ruiA[i])
nlst.sort(reverse=True)

lenbin=31
for i in range(len(nlst)):
    lst=[]
    for m in range(lenbin):
        lst.append((nlst[i]>>m)&1)
    nlst[i]=list(reversed(lst))
    #print(nlst[i])
lenbinst=0
#print(nlst)
use=set([i for i in range(len(nlst))])
while lenbinst<lenbin:
    idx=-1
    count=0
    dellst=set()
    for m in use:
        if nlst[m][lenbinst]==1:
            count+=1
    if count>=K:
        if len(nlst)!=count:
            for m in use:
                if nlst[m][lenbinst]!=1:
                    dellst.add(m)
    use=use-dellst
    lenbinst+=1
valuelst=[0 for i in range(lenbin)]
nlst=[nlst[i] for i in use]

for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1

for i in range(lenbin):
    if valuelst[i]>=K:
        newlst=[i for i in nlst if i[idx]==1]
        if len(newlst)>=K:
            nlst=newlst

valuelst=[0 for i in range(lenbin)]
for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1
value=0
for i in range(lenbin):
    if valuelst[i]>=K:
        value+=2**i
print(value)

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import *
from bisect import *


N,K=map(int,input().split())
A=list(map(int,input().split()))

ruiA=[0 for i in range(N+1)]
for i in range(0,N):
    ruiA[i+1]=ruiA[i]+A[i]


lst=[]

for i in range(len(ruiA)-1):
    for m in range(i+1,len(ruiA)):
        lst.append(ruiA[m]-ruiA[i])


lst=Counter(lst)
for l in lst:
    if lst[l]>2:
        lst[l]=2
nlst=[]
for l in lst:
    for i in range(lst[l]):
        nlst.append(l)
nlst.sort(reverse=True)

dic={}
for i in nlst:
    a=len(bin(i))
    if not a in dic:
        dic.update({a:[i]})
    else:
        dic[a].append(i)
idx=-1
for i,d in enumerate(dic):
    if len(dic[d])>=2:
        idx=d
        break

if idx != -1:
    nlst=dic[idx]

lenbin=40
for i in range(len(nlst)):
    a=bin(nlst[i])[2:]
    nlst[i]=[0 for i in range(lenbin-len(a))]+list(map(int,list(a)))
lenbinst=0
while lenbinst<lenbin:
    idx=-1
    for i in range(lenbinst,lenbin):
        count=0
        for m in range(len(nlst)):
            if nlst[m][i]==1:
                count+=1
        if count>=K:
            idx=i

    if idx==-1:
        if lenbinst==0:
            print(0)
            exit()
        else:
            lenbinst+=1
    else:
        nlst=[i for i in nlst if i[idx]==1]
        lenbinst=idx+1

valuelst=[0 for i in range(lenbin)]

for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1


for i in range(lenbin):
    if valuelst[i]>=K:
        newlst=[i for i in nlst if i[idx]==1]
        if len(newlst)>=K:
            nlst=newlst

valuelst=[0 for i in range(lenbin)]
for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1



value=0

for i in range(lenbin):
    if valuelst[i]>=K:
        value+=2**i

print(value)

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import *
from bisect import *


N,K=map(int,input().split())
A=list(map(int,input().split()))

ruiA=[0 for i in range(N+1)]
for i in range(0,N):
    ruiA[i+1]=ruiA[i]+A[i]


lst=[]

for i in range(len(ruiA)-1):
    for m in range(i+1,len(ruiA)):
        lst.append(ruiA[m]-ruiA[i])


lst=Counter(lst)
for l in lst:
    if lst[l]>2:
        lst[l]=2
nlst=[]
for l in lst:
    for i in range(lst[l]):
        nlst.append(l)
nlst.sort(reverse=True)

dic={}
for i in nlst:
    a=len(bin(i))
    if not a in dic:
        dic.update({a:[i]})
    else:
        dic[a].append(i)
idx=-1
for i,d in enumerate(dic):
    if len(dic[d])>=2:
        idx=d
        break

if idx != -1:
    nlst=dic[idx]

lenbin=31
for i in range(len(nlst)):
    a=bin(nlst[i])[2:]
    nlst[i]=[0 for i in range(lenbin-len(a))]+list(map(int,list(a)))
lenbinst=0
while lenbinst<lenbin:
    idx=-1
    for i in range(lenbinst,lenbin):
        count=0
        for m in range(len(nlst)):
            if nlst[m][i]==1:
                count+=1
        if count>=K:
            idx=i

    if idx==-1:
        if lenbinst==0:
            print(0)
            exit()
        else:
            lenbinst+=1
    else:
        nlst=[i for i in nlst if i[idx]==1]
        lenbinst=idx+1

valuelst=[0 for i in range(lenbin)]

for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1


for i in range(lenbin):
    if valuelst[i]>=K:
        newlst=[i for i in nlst if i[idx]==1]
        if len(newlst)>=K:
            nlst=newlst

valuelst=[0 for i in range(lenbin)]
for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1



value=0
for i in range(lenbin):
    if valuelst[i]>=K:
        value+=2**i

print(value)

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import *
from bisect import *


N,K=map(int,input().split())
A=list(map(int,input().split()))

ruiA=[0 for i in range(N+1)]
for i in range(0,N):
    ruiA[i+1]=ruiA[i]+A[i]


lst=[]

for i in range(len(ruiA)-1):
    for m in range(i+1,len(ruiA)):
        lst.append(ruiA[m]-ruiA[i])


lst=Counter(lst)
for l in lst:
    if lst[l]>2:
        lst[l]=2
nlst=[]
for l in lst:
    for i in range(lst[l]):
        nlst.append(l)
nlst.sort(reverse=True)

dic={}
for i in nlst:
    a=len(bin(i))
    if not a in dic:
        dic.update({a:[i]})
    else:
        dic[a].append(i)
idx=-1
for i,d in enumerate(dic):
    if len(dic[d])>=2:
        idx=d
        break

if idx != -1:
    nlst=dic[idx]

lenbin=31
for i in range(len(nlst)):
    a=bin(nlst[i])[2:]
    nlst[i]=[0 for i in range(lenbin-len(a))]+list(map(int,list(a)))
lenbinst=0
while lenbinst<lenbin:
    idx=-1
    for i in range(lenbinst,lenbin):
        count=0
        for m in range(len(nlst)):
            if nlst[m][i]==1:
                count+=1
        if count>=K:
            idx=i

    if idx==-1:
        if lenbinst==0:
            print(0,"unko")
            exit()
        else:
            lenbinst+=1
    else:
        nlst=[i for i in nlst if i[idx]==1]
        lenbinst=idx+1

valuelst=[0 for i in range(lenbin)]

for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1


for i in range(lenbin):
    if valuelst[i]>=K:
        newlst=[i for i in nlst if i[idx]==1]
        if len(newlst)>=K:
            nlst=newlst

valuelst=[0 for i in range(lenbin)]
for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1



value=0
for i in range(lenbin):
    if valuelst[i]>=K:
        value+=2**i

print(value)

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import *
from bisect import *


N,K=map(int,input().split())
A=list(map(int,input().split()))

ruiA=[0 for i in range(N+1)]
for i in range(0,N):
    ruiA[i+1]=ruiA[i]+A[i]


lst=[]

for i in range(len(ruiA)-1):
    for m in range(i+1,len(ruiA)):
        lst.append(ruiA[m]-ruiA[i])


lst=Counter(lst)
for l in lst:
    if lst[l]>2:
        lst[l]=2
nlst=[]
for l in lst:
    for i in range(lst[l]):
        nlst.append(l)
nlst.sort(reverse=True)

dic={}
for i in nlst:
    a=len(bin(i))
    if not a in dic:
        dic.update({a:[i]})
    else:
        dic[a].append(i)
idx=-1
for i,d in enumerate(dic):
    if len(dic[d])>=2:
        idx=d
        break

if idx != -1:
    nlst=dic[idx]

lenbin=31
for i in range(len(nlst)):
    a=bin(nlst[i])[2:]
    nlst[i]=[0 for i in range(lenbin-len(a))]+list(map(int,list(a)))
lenbinst=0
while lenbinst<lenbin:
    idx=-1
    for i in range(lenbinst,lenbin):
        count=0
        for m in range(len(nlst)):
            if nlst[m][i]==1:
                count+=1
        if count>=K:
            idx=i

    if idx==-1:
        if lenbinst==0:
            print(0,"unko")
            exit()
        else:
            lenbinst+=1
    else:
        nlst=[i for i in nlst if i[idx]==1]
        lenbinst=idx+1
value=0
valuelst=[0 for i in range(lenbin)]

for n in nlst:
    for i,a in enumerate(list(reversed(n))):
        if a:
            valuelst[i]+=1
for i in range(lenbin):
    if valuelst[i]>=K:
        value+=2**i

print(value)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from itertools import accumulate

def solve(N: int, K: int, a: "List[int]"):
    accum = [0] + list(accumulate(a))
    sum_list = []
    for i in range(0,N):
        for j in range(i+1,N+1):
            sum_list.append(accum[j]-accum[i])
    sum_list.sort(reverse=True)
    sum_list = sum_list[:K]

    answer = sum_list[0]
    if K == 1:
        print(answer)
        return

    for i in range(1,K):
        answer &= sum_list[i]
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import *
N, K = map(int, input().split())
a = list(map(int, input().split()))
a_accum = [0]
for i in range(N):
    a_accum.append(a_accum[-1]+a[i])

l = []
for i in range(N+1):
    for j in range(i+1, N+1):
        l.append(a_accum[j]-a_accum[i])

l.sort()
ans = 0
N = len(l)
for i in range(30, -1, -1):
    if bisect_left(l, ans+2**i) <= N-K:
        ans += 2**i

print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    b.append(x)
ans=0
for i in range(40,0,-1):
  a=b.copy()
  b=[]
  x=0
  s=2**i
  for j in a:
    if j&(ans+s)==ans+s:x+=1
  if x>=k:ans+=s
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    b.append(x)
ans=0
for i in range(40,0,-1):
  a=b
  b=[]
  x=0
  s=2**i
  for j in a:
    if j&(ans+s)==ans+s:x+=1
  if x>=k:ans+=s
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
lists=list(map(int,input().split()))
GG=[]
for i in range(len(lists)+1):
    for j in range(i,len(lists)):
        
        G=sum(lists[i:j+1])
        GG.append(G)
GG=sorted(GG,reverse=True)      
GH=GG[:k]

A=GH[0]
for j in range(1,len(GH)):
    A=A&GH[j]
print(A)

Submission status: Wrong Answer

Solution code:
import bisect
import copy
N,K=map(int,input().split())
a=list(map(int,input().split()))
s=[0]*(N+1)
for i in range(N):
  s[i+1]=s[i]+a[i]
sumList=[]
for i in range(N):
  for j in range(i,N):
    tmp=s[j+1]-s[i]
    sumList.append(tmp)
sumList.sort()
#print(sumList)
tmp=len(bin(sumList[-1]))-2+1
tmp=2**tmp
ans=0
L=len(sumList)
while(L != K and tmp != 0):
  #print(tmp)
  tmpList=[sumList[i] % tmp for i in range(len(sumList)) if sumList[i]%tmp>=(tmp//2)]
  #print(tmpList)
  if len(tmpList)>=K:
    ans+=tmp//2
    #print(tmp//2)
    sumList=copy.copy(tmpList)
    L=len(sumList)
  tmp = tmp // 2
  
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    b.append(x)
ans=0
l=len(b)
for i in range(40,0,-1):
  x=0
  s=2**i
  for j in range(l):
    if b[j]&(ans+s)==ans+s:x+=1
  if x>=k:ans+=s
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    b.append(x)
ans=0
l=len(b)
for i in range(40,0,-1):
  x=0
  s=2**i-1
  for j in range(l):
    if b[j]&(ans+s)==ans+s:x+=1
  if x>=k:ans+=s
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    b.append(x)
ans=0
l=len(b)
for i in range(40,0,-1):
  x=0
  s=2**i-1
  for j in range(l):
    if b[j]%s==0:
      b[j]//=s
      x+=1
  if x>=k:ans+=s
print(s)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    b.append(x)
b.sort(reverse=1)
x=b[0]
for i in range(k):x&=b[i]
print(x)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int, input().split()))
S=[0]*(N+1)
for i in range(N):
    S[i+1]=S[i]+a[i]
    
SA=[]

for i in range(N):
    for j in range(i+1,N+1):
        SA.append(S[j]-S[i])
SA.sort()

ans=SA[-1]
for i in range(1,K):
    ans=ans&SA[-1-i]
    
print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    a = LI()
    s = [0]
    for i in a:
        s.append(s[-1]+i)
    S = []
    for i in range(n):
        for j in range(i+1,n+1):
            S.append(s[j]-s[i])
    for i in range(max(S).bit_length())[::-1]:
        m = 0
        b = 1<<i
        for j in S:
            m += (j&b > 0)
        if m >= k:
            mask = (1<<(i+1))-1
            S = [i&mask for i in S]
            S.sort(reverse = True)
            ans = S[0]
            for i in S[1:k]:
                ans &= i
            print(ans)
            return
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
from itertools import accumulate
As = [0] + list(map(int, input().split()))
As = list(accumulate(As))
L = len(bin(As[-1]))-2
xs = []
for i in range(N+1):
    for j in range(i+1, N+1):
        xs.append(As[j] - As[i])
xs.sort()
ts = set(range(N*(N+1)//2))
for j in range(L-1,-1,-1):
    nts = set()
    for i in ts:
        if (xs[i]>>j)%2:
            nts.add(i)
    if len(nts) >= K:
        ts = nts
c = 0
r = 0
for i in ts:
    c += 1
    if c == K:
        break
    if r == 0:
        r = xs[i]
    else:
        r = r&xs[i]
print(r)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    a = LI()
    s = [0]
    for i in a:
        s.append(s[-1]+i)
    S = []
    for i in range(n):
        for j in range(i+1,n+1):
            S.append(s[j]-s[i])
    S.sort()
    for i in range(S[-1].bit_length())[::-1]:
        l = bisect.bisect_left(S,1<<i)
        m = len(S)-l
        if m >= k:
            mask = (1<<(i+1))-1
            S = [i&mask for i in S]
            S.sort(reverse = True)
            ans = S[0]
            for i in S[1:k]:
                ans &= i
            print(ans)
            return
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    a = LI()
    s = [0]
    for i in a:
        s.append(s[-1]+i)
    S = []
    for i in range(n):
        for j in range(i+1,n+1):
            S.append(s[j]-s[i])
    S.sort(reverse = True)
    ans = S[0]
    for i in S[1:k]:
        ans &= i
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N,K=list(map(int,input().split()))
a = list(map(int,input().split()))
ans = []
for i in range(N):
    for j in range(i+1,N+1):
        ans.append(sum(a[i:j]))
ans.sort(reverse= True)
bit = []
for i in ans:
    bit.append(format(i,'b'))
ind = []
num = 0
maxlen = len(bit[0])
while True:
    i = [i for i in bit if len(i) >= maxlen]
    num = len(i)
    if num >= K:
        break
    maxlen -= 1

ans2 = ans[:num]
ans3 = []
for i in combinations(ans2,K):
    c = ans2[0]
    for i in range(1,len(i)):
        c = c&ans2[i]
    ans3.append(c)
print(max(ans3))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N,K=list(map(int,input().split()))
a = list(map(int,input().split()))
ans = []
for i in range(N):
    for j in range(i+1,N+1):
        ans.append(sum(a[i:j]))
ans.sort(reverse= True)
ans2 = []
c = ans[0] 
for i in range(1,K):
    c = c&ans[i]
print(c)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

S = [0]*(N+1)
for i in range(N):
    S[i+1] = S[i] + A[i]

M = 50
memo = [0]*M
L = []
for i in range(N):
    for j in range(i+1, N+1):
        L.append(S[j]-S[i])
        
for n in L:
    for i in range(M):
        if n&(1<<i):
            memo[i] += 1

p = -1
for i in range(M-1, -1, -1):
    if memo[i] >= K:
        p = i
        break

def f(s, List):
    #Listに含まれる要素の中に1<<sとのANDが正になるものがK個以上あるか判定
    L2 = []
    for n in List:
        if n&(1<<s):
            L2.append(n)
            
    mem = [0]*s
    for n in L2:
        for i in range(s):
            if n&(1<<i):
                mem[i] += 1
                
    p = -1
    for i in range(s-1, -1, -1):
        if mem[i] >= K:
            p = i
            break
            
    return [p, L2]
            
if p < 0:
    ans = 0
else:
    ans = 0
    L2 = L
    while p >= K:
        ans += 1<<p
        t = f(p, L2)
        p = t[0]
        L2 = t[1]
            
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))

bits=[0]*32
def bit_count(a):
    for i in range(32):
        if a&1:
            bits[i]+=1
        a>>=1

B=[]
for s in range(N):
    t=0
    for e in range(s,N):
        t+=A[e]
        B.append(t)
        bit_count(t)

mask=0
for i in range(31,-1,-1):
    mask<<=1
    if bits[i]>=K:
        mask+=1

M=[]
for b in B:
    M.append(b&mask)
M.sort(reverse=True)

ans=(1<<32)-1
for i in range(K):
    ans&=M[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
import fractions
#gcd=fractions.gcd
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a
class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo
show_flg=False
show_flg=True
def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

ans=0

n,k=LI()
a=LI()
ac=[0]
for i in range(n):
    ac.append(ac[-1]+a[i])

v=[]
for l in range(n):
    for r in range(l+1,n+1):
        v.append(ac[r]-ac[l])
v=sorted(v)[::-1]

ans=v[0]
for i in range(1,k):
    ans&=v[i]

print(ans)

#show(v)

Submission status: Wrong Answer

Solution code:
import heapq
N,K=map(int,input().split())
A=list(map(int,input().split()))

B=[]
for s in range(N):
    t=0
    for e in range(s,N):
        t+=A[e]
        heapq.heappush(B,-t)

ans=-heapq.heappop(B)
for i in range(1,K):
    ans&=-heapq.heappop(B)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[]
c=0
for i in range(n):
    for j in range(i,n):
        b=sum(a[i:j+1])
        l.append(b)
l.sort()
for i in range(len(l)):
    l[i]=format(l[i],'b').zfill(len(format(l[-1],'b')))
m=len(l[0])
l=l[::-1]
r=[0]*m
for i in range(m):
    for j in range(len(l)):
        if l[j][i]=='1':
            r[i]+=1
#print(l)
#print(r)
for i in range(m):
    ll=[]
    lll=[]
    if r[i]>=k:
        for j in range(len(l)):
            if l[j][i]=='1':
                ll.append(l[j])
            else:
                lll.append(l[j])
    else:
        ll=l
    l=ll
    if len(l)<k:
        l=l+lll
    elif len(l)==k:
        c+=2**(m-i-1)
        break
    elif len(l)>k:
        c+=2**(m-i-1)
print(c)

Submission status: Wrong Answer

Solution code:
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[]
c=0
for i in range(n):
    for j in range(i,n):
        b=sum(a[i:j+1])
        l.append(b)
l.sort()
for i in range(len(l)):
    l[i]=format(l[i],'b').zfill(len(format(l[-1],'b')))
m=len(l[0])
l=l[::-1]
r=[0]*m
for i in range(m):
    for j in range(len(l)):
        if l[j][i]=='1':
            r[i]+=1
#print(l)
#print(r)
for i in range(m):
    ll=[]
    lll=[]
    if r[i]>=k:
        for j in range(len(l)):
            if l[j][i]=='1':
                ll.append(l[j])
            else:
                lll.append(l[j])
    else:
        ll=l
    l=ll
    if len(l)<k:
        l=l+lll
    elif len(l)==k:
        c+=2**(m-i-1)
        break
    elif len(l)>k:
        c+=2**(m-i-1)

ans=int(l[0],2)
for i in range(len(l)):
    ans&=int(l[i],2)
if len(l)>k:
    print(c)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [0] + [int(a) for a in input().split()]
for i in range(N): A[i+1] += A[i]

S = []
for i in range(N):
    for j in range(i+1, N+1):
        S.append(A[j] - A[i])
l, r = 0, 1<<30
while r - l > 1:
    m = (l+r) // 2
    if len([1 for s in S if m & s == m]) >= K:
        l = m
    else:
        r = m

print(l)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k=map(int,input().split())
data=[]
A=list(map(int,input().split()))
for i in range(n):
    for j in range(i+1,n+1):
        data.append(sum(A[i:j]))
# print(data)
for exp in range(31,-1,-1):
    candi=[]
    count=0
    for i,di in enumerate(data):
        if di>>exp & 1:
            count+=1
            candi.append(di)
    if count >= k:
        data = candi
p=data[0]
for ci in data:
    p=p & ci
print(p)
# print(data)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[0]
for i in range(n):
  s.append(s[-1]+a[i])
l=[]
for i in range(1,n+1):
  for j in range(i):
    l.append(s[i]-s[j])
l.sort(reverse=True)
m=61
ans=0
chk=0
for i in range(7)[::-1]:
  cnt=0
  chk+=2**i
  for j in l:
    if chk & j == chk:
      cnt+=1
  if cnt < k:
    chk-=2**i
print(chk)