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:
from itertools import accumulate
N, K = map(int, input().split())
As = list(map(int, input().split()))

subsecs = []
S = [0] + list(accumulate(As))
for f in range(1, N+1):
    for t in range(f, N+1):
        subsecs.append(S[t] - S[f-1])

ans = 0
digit = 1 << 30
for d in range(31):
    nsubsecs = []
    for subsec in subsecs:
        if subsec & digit:
            nsubsecs.append(subsec)
    if len(nsubsecs) >= K:
        ans += digit
        subsecs = nsubsecs
    digit >>= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
As = list(map(int, input().split()))

subsecs = []
S = [0] + list(accumulate(As))
for f in range(1, N+1):
    for t in range(f, N+1):
        subsecs.append(S[t] - S[f-1])

ans = 0
digit = 2 << 30
for d in range(31):
    nsubsecs = []
    for subsec in subsecs:
        if subsec & digit:
            nsubsecs.append(subsec)
    if len(nsubsecs) >= K:
        ans += digit
        subsecs = nsubsecs
    digit >>= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))

lis=[]
for i in range(n):
    now=0
    for j in range(i,n):
        now+=a[j]
        lis.append(now)

lis.sort()
bi=[]

mx=40
for i in range(len(lis)):
    num=lis[i]
    keta=[0]*mx

    for j in reversed(range(mx)):
        if num%2==1:
            keta[j]+=1
        num//=2
        if num==0:
            break
    bi.append(keta)

anslis=[]
thr=0
for j in range(mx):
    cnt=0
    for i in range(len(bi)):
        if lis[i]<thr:
            continue
        b=bi[i]
        if b[j]==1:
            cnt+=1

    if cnt>=k:
        thr+=(1<<(mx-j-1))

print(thr)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))

lis=[]
for i in range(n):
    now=0
    for j in range(i,n):
        now+=a[j]
        lis.append(now)

lis.sort()
bi=[]

mx=40
for i in range(len(lis)):
    num=lis[i]
    keta=[0]*mx

    for j in reversed(range(mx)):
        if num%2==1:
            keta[j]+=1
        num//=2
        if num==0:
            break
    bi.append(keta)

anslis=[]
thr=0
for j in range(mx):
    cnt=0
    for i in range(len(bi)):
        if lis[i]<=thr:
            continue
        b=bi[i]
        if b[j]==1:
            cnt+=1

    if cnt>=k:
        thr+=(1<<(mx-j-1))

print(thr)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))

lis=[]
for i in range(n):
    now=0
    for j in range(i,n):
        now+=a[j]
        lis.append(now)

lis.sort()

print(lis)

keta=[0]*30

for i in range(len(lis)):
    num=lis[i]

    for j in reversed(range(30)):
        if num%2==1:
            keta[j]+=1
        num//=2
        if num==0:
            break

anslis=[]
for j in reversed(range(30)):




    if keta[j] >= k:
        anslis.append(j)
        break

Submission status: Wrong Answer

Solution code:
def dwacon5th_prelims_b():
    n, k = (int(x) for x in input().split())
    A = [int(x) for x in input().split()]
    B = []

    for i in range(n):
        cum = 0
        for a in A[i:]:
            cum += a
            B.append(cum)
    B.sort(reverse=True)

    bit = [0]*32
    cand = B
    for i in range(31, -1, -1):
        nx = []
        for b in cand:
            if (b >> i) & 1: nx.append(b)
        if len(nx) >= k:
            cand = nx
            bit[i] = 1

    ans = int(''.join([str(x) for x in reversed(bit)]), base=2)
    print(ans)

if __name__ == '__main__':
   dwacon5th_prelims_b()

Submission status: Wrong Answer

Solution code:
def dwacon5th_prelims_b():
    n, k = (int(x) for x in input().split())
    A = [int(x) for x in input().split()]
    B = []

    for i in range(n):
        cum = 0
        for a in A[i:]:
            cum += a
            B.append(cum)
    B.sort(reverse=True)

    bit = [0]*31
    cand = B
    for i in range(30, -1, -1):
        nx = []
        for b in cand:
            if (b >> i) & 1: nx.append(b)
        if len(nx) >= k:
            cand = nx
            bit[i] = 1

    ans = int(''.join([str(x) for x in reversed(bit)]), base=2)
    print(ans)

if __name__ == '__main__':
   dwacon5th_prelims_b()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))

l=[]
for i in range(n):
  s=0
  for j in range(i,n):
    s+=a[j]
    l.append(s)

t=0
for i in range(30,-1,-1):
  t+=2**i
  c=0
  for j in l:
    if t==j&t:
      c+=1
  if c<k:
    t-=2**i
print(t)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
stand_bit = [set()]*42
acc = [0]*(n+1)
for i in range(1, n+1):
    acc[i] += a[i-1] + acc[i-1]
set_ans = set()
for i in range(n):
    for j in range(i, n):
        tmp = acc[j+1] - acc[i]
        set_ans.add(tmp)
        s = tmp
        index = 41
        while s:
            if s & 1:
                stand_bit[index].add(tmp)
            s = s >> 1
            index -= 1
for i in range(42):
    if len(set_ans & stand_bit[i]) >= k:
        set_ans &= stand_bit[i]
ans_list = list(set_ans)
ans = ans_list[0]
for i in ans_list:
    ans &= i
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
stand_bit = [set() for i in range(42)]
acc = [0 for i in range(n+1)]
for i in range(1, n+1):
    acc[i] += a[i-1] + acc[i-1]
set_ans = set()
for i in range(n):
    for j in range(i, n):
        tmp = acc[j+1] - acc[i]
        set_ans.add(tmp)
        s = tmp
        index = 41
        while s:
            if s & 1:
                stand_bit[index].add(tmp)
            s = s >> 1
            index -= 1

ans_list = list(set_ans)
ans = ans_list[0]
for i in ans_list:
    ans &= i
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
*a,=map(int,input().split())

cum=[0]
for i in range(N):
  cum.append(cum[-1]+a[i])
  
res=[]
for i in range(1,N+1):
  for j in range(1,N+1):
    res.append(cum[j]-cum[i-1])
    
res= sorted(res,reverse=True)

#n1,n2 = res[0],res[K-1]
#print(2**(n2.bit_length()-1))
#print(n1,n2)

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

Submission status: Wrong Answer

Solution code:
def calc_beauty_list(N, A):
    cumsum = [0 for _ in range(N)]
    cumsum[0] = A[0]
    for n in range(1, N):
        cumsum[n] = cumsum[n - 1] + A[n]
    beauty_list = [0 for _ in range(N * (N + 1) // 2)]
    index = 0
    for left in range(N):
        for right in range(left, N):
            beauty = cumsum[right]
            if left > 0:
                beauty -= cumsum[left - 1]
            beauty_list[index] = beauty
            index += 1
    return beauty_list


def main():
    MAX_BIT = 30
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    beauty_list = calc_beauty_list(N, A)
    # K個の論理積の最大値の計算
    #     2進表記して上位ビットから見ていく（高々数十ビット程度）。
    #     K個以上ビットが立っている桁に当たったら、ビットが立っていない数を消す。
    #         最終桁に行く前にK個になったら、それらの論理積を出して終了。
    #         最終桁まで行き、
    #             それまでK個以上のビットが立ってたことがないなら 0 が答え。
    #             そうでなければ、残っている中から適当にK個選んで論理積を出す。
    usable_flag = [1 for _ in range(N * (N + 1) // 2)]
    found_k_bit = False
    for shift in range(MAX_BIT - 1, -1, -1):
        cnt = len([b for b, u in zip(beauty_list, usable_flag) if u == 1 and (b >> shift & 1 == 1)])
        if cnt >= K:
            found_k_bit = True
            for n, b in enumerate(beauty_list):
                if b >> shift & 1 == 0:
                    usable_flag[n] = 0
        if cnt == K:
            found_k_bit = True
            break
    if not found_k_bit:
        print(0)
    else:
        ans = (1 << MAX_BIT) - 1
        cnt = 0
        for n, b in enumerate(beauty_list):
            if usable_flag[n] == 1 and cnt <= K:
                ans &= b
                cnt += 1
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def calc_beauty_list(N, A):
    cumsum = [0 for _ in range(N)]
    cumsum[0] = A[0]
    for n in range(1, N):
        cumsum[n] = cumsum[n - 1] + A[n]
    beauty_list = [0 for _ in range(N * (N + 1) // 2)]
    index = 0
    for left in range(N):
        for right in range(left, N):
            beauty = cumsum[right]
            if left > 0:
                beauty -= cumsum[left - 1]
            beauty_list[index] = beauty
            index += 1
    return beauty_list


def main():
    MAX_BIT = 30
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    beauty_list = calc_beauty_list(N, A)
    # K個の論理積の最大値の計算
    #     2進表記して上位ビットから見ていく（高々数十ビット程度）。
    #     K個以上ビットが立っている桁に当たったら、ビットが立っていない数を消す。
    #         最終桁に行く前にK個になったら、それらの論理積を出して終了。
    #         最終桁まで行き、
    #             それまでK個以上のビットが立ってたことがないなら 0 が答え。
    #             そうでなければ、残っている中から適当にK個選んで論理積を出す。
    usable_flag = [1 for _ in range(N * (N + 1) // 2)]
    found_k_bit = False
    for shift in range(MAX_BIT - 1, -1, -1):
        cnt = len([b for b, u in zip(beauty_list, usable_flag) if u == 1 and (b >> shift & 1 == 1)])
        if cnt >= K:
            found_k_bit = True
            for n, b in enumerate(beauty_list):
                if b >> shift & 1 == 0:
                    usable_flag[n] = 0
        if cnt == K:
            found_k_bit = True
            break
    if not found_k_bit:
        print(0)
    else:
        ans = (1 << MAX_BIT) - 1
        cnt = 0
        for n, b in enumerate(beauty_list):
            if usable_flag[n] == 1 and cnt <= K:
                ans &= b
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

A=list(map(int,input().split()))
two=[2**i for i in range(44)][::-1]

sums=[0]
for a in A:
    sums.append(sums[-1]+a)

log=[]

for i in range(N):
    for j in range(i,N+1):
        if sums[j]-sums[i]!=0:
            log.append(sums[j]-sums[i])
log.sort()

ans=0
for t in two:
    count=0
    for item in log:
        if item>=t:
            count+=1
    if count>=K:
        ans+=t
        log=list(filter(lambda x: x>=t, log))
        log=list(map(lambda x: x%t, log))
    
    #print(log)

print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
for i in range(n):
  a[i+1]+=a[i]
d=[]
for i,x in enumerate(a):
  for y in a[:i]:
    d+=[x-y]
ans=0
t=2**41
for _ in range(41):
  cnt=0
  for j in d:
    cnt+=(ans+t)&j==(ans+t)
  if cnt>=k:ans+=t
  t//=2
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
cusum = [A[0]]
for i in range(1, N):
    cusum += [cusum[-1]+A[i]]
B = []
for i in range(N):
    B += [cusum[i]]
    for j in range(i+1, N):
        B += [cusum[j] - cusum[i]]
B = sorted(B, reverse=True)
ans = B[0]
for i in range(1, K):
    ans = ans & B[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(n):
    b[i + 1] = b[i] + a[i]
m = int(math.log2(b[n]))
x = pow(2, m)
s = [[] for _ in range(m + 2)]
for i in range(n):
    for j in range(i + 1, n + 1):
        s[0].append(b[j] - b[i])
c = 0
ans = 0
for i in range(1, m + 2):
    for j in s[c]:
        if j >= x:
            s[i].append(j - x)
    if len(s[i]) >= k:
        c = i
        ans += x
    x //= 2
print(ans)

Submission status: Wrong Answer

Solution code:
def calc_beauty_list(N, A):
    cumsum = [0 for _ in range(N)]
    cumsum[0] = A[0]
    for n in range(1, N):
        cumsum[n] = cumsum[n - 1] + A[n]
    beauty_list = [0 for _ in range(N * (N + 1) // 2)]
    index = 0
    for left in range(N):
        for right in range(left, N):
            beauty = cumsum[right]
            if left > 0:
                beauty -= cumsum[left - 1]
            beauty_list[index] = beauty
            index += 1
    return beauty_list


def main():
    MAX_BIT = 30
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    beauty_list = calc_beauty_list(N, A)
    # K個の論理積の最大値の計算
    #     2進表記して上位ビットから見ていく（高々数十ビット程度）。
    #     K個以上ビットが立っている桁に当たったら、ビットが立っていない数を消す。
    #         最終桁に行く前にK個になったら、それらの論理積を出して終了。
    #         最終桁まで行き、
    #             それまでK個以上のビットが立ってたことがないなら 0 が答え。
    #             そうでなければ、残っている中から適当にK個選んで論理積を出す。
    usable_flag = [1 for _ in range(N * (N + 1) // 2)]
    found_k_bit = False
    for shift in range(MAX_BIT - 1, -1, -1):
        cnt = len([b for b, u in zip(beauty_list, usable_flag) if u == 1 and (b >> shift & 1 == 1)])
        if cnt >= K:
            found_k_bit = True
            for n, b in enumerate(beauty_list):
                if b >> shift & 1 == 0:
                    usable_flag[n] = 0
        if cnt == K:
            break
    if not found_k_bit:
        print(0)
    else:
        ans = (1 << MAX_BIT) - 1
        cnt = 0
        for n, b in enumerate(beauty_list):
            if usable_flag[n] == 1 and cnt <= K:
                ans &= b
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

SA = [0]
for i in range(N):
    SA.append(SA[-1]+A[i])

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


ans = 0
for i in range(31, -1, -1):
    B = 1 << i
    ind = bisect.bisect_left(C, B)
    if len(C)-ind >= K:
        ans += B
        C = C[ind:]
    for j in range(len(C)):
        C[j] &= B-1
    C.sort()
    # print(i, B, C)
print(ans)

Submission status: Wrong Answer

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

SA = [0]
for i in range(N):
    SA.append(SA[-1]+A[i])

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


ans = 0
for i in range(30, -1, -1):
    B = 1 << i
    ind = bisect.bisect_left(C, B)
    if len(C)-ind >= K:
        ans += B
        C = C[ind:]
    for j in range(len(C)):
        C[j] &= B-1
    C.sort()
print(ans)

Submission status: Wrong Answer

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

SA = [0]
for i in range(N):
    SA.append(SA[-1]+A[i])

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


ans = 0
for i in range(30, -1, -1):
    B = 1 << i
    ind = bisect.bisect_left(C, B)
    if len(C)-ind >= K:
        ans += B
        C = C[ind:]
        for j in range(len(C)):
            C[j] &= B-1
        C.sort()
print(ans)

Submission status: Wrong Answer

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

SA = [0]
for i in range(N):
    SA.append(SA[-1]+A[i])

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


ans = 0
for i in range(30, -1, -1):
    B = 1 << i
    ind = bisect.bisect_left(C, B)
    if len(C)-ind >= K:
        C = C[ind:]
        ans += B
        for j in range(len(C)):
            C[j] ^= B
        C.sort()
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

C = [0] + list(accumulate(A))
S = []

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

for i in range(32)[::-1]:
    tmp = []
    for s in S:
        if (s >> i) & 1:
            tmp.append(s)

    if len(tmp) >= K:
        S = tmp[:]

res = 2**32 - 1

for i in range(K):
    res &= S[i]

print(res)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

C = [0] + list(accumulate(A))
S = []

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

for i in range(32)[::-1]:
    tmp = []
    for s in S:
        if (s >> i) & 1:
            tmp.append(s)
    if len(tmp) >= K:
        S = tmp[:]

res = 2**31 - 1
for i in range(K):
    res &= S[i]

print(res)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

def splitbit(n):
    for i in range(61):
        if not n & (1 << i):
            xor_l[i] = 0

N, K = getNM()
A = getList()

imos = copy.deepcopy(A)
imos.insert(0, 0)

for i in range(N):
    imos[i + 1] += imos[i]

num = []
for i in range(1, N + 1):
    for j in range(i, N + 1):
        num.append(imos[j] - imos[i - 1])
num.sort(reverse = True)

xor_l = [1] * 61
for i in range(K):
    splitbit(num[i])

ans = 0
for i in range(61):
    if xor_l[i] == 1:
        ans += 2 ** i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    R = [0] + list(accumulate(A))
    subs = []
    for left in range(n):
        for right in range(left + 1, n + 1):
            subs.append(R[right] - R[left])
    subs.sort(reverse=True)

    res = subs[0]
    for i in range(1, k):
        res &= subs[i]
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    R = [0] + list(accumulate(A))
    res = []
    for left in range(n):
        for right in range(left + 1, n + 1):
            res.append(R[right] - R[left])
    res.sort(reverse=True)
    print(res[k - 1])


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    R = [0] + list(accumulate(A))
    sub = []
    sub_L = n
    while len(sub) <= k:
        for left in range(n - sub_L + 1):
            sub_sum = R[left + sub_L] - R[left]
            sub.append(sub_sum)
        sub_L -= 1
    sub.sort(reverse=True)

    res = sub[0]
    for i in range(1, k):
        res &= sub[i]
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from collections import deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
#print(a)
s = sum(a)
ans = deque([0]*k)

for i in range(n):
  for j in range(i, n):
    #print(a[i:j+1])
    beauty = sum(a[i:j+1])
    #print(beauty)
    temp = bisect_left(ans, beauty)
    if temp != 0:
      ans.insert(temp, beauty)
      ans.popleft()
      #ans[temp-1]=beauty
    #print(ans)

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
stand_bit = [set() for i in range(42)]
acc = [0 for i in range(n+1)]
acc[0] = 0
for i in range(1, n+1):
    acc[i] += a[i-1] + acc[i-1]
set_ans = set()
for i in range(n):
    for j in range(i, n):
        set_ans.add(acc[j+1] - acc[i])
        s = acc[j+1] - acc[i]
        index = 41
        while s :
            if s & 1:
                stand_bit[index].add(acc[j+1] - acc[i])
            s = s >> 1
            index -= 1
print(1)
exit()
for i in range(42):
    if len(set_ans & stand_bit[i]) >= k:
        set_ans &= stand_bit[i]
ans_list = list(set_ans)
ans = ans_list[0]
for i in ans_list:
    ans &= i
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
def ACC1(l):
  N = len(l)
  ret = [0]*(N+1)
  for i in range(N):
    ret[i+1] = ret[i]+l[i]
  return ret

N,K = IL()
A = IL()
ACC = ACC1(A)
SUMS = []
for i in range(N+1):
  for j in range(i+1,N+1):
    SUMS.append(ACC[j]-ACC[i])
ans = 0

for k in range(30)[::-1]:
  HERE = list(filter(lambda x: (x>>k)&1, SUMS))
  if len(HERE)>=K:
    ans += 1<<k
    SUMS = HERE
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
def ACC1(l):
  N = len(l)
  ret = [0]*(N+1)
  for i in range(N):
    ret[i+1] = ret[i]+l[i]
  return ret

N,K = IL()
A = IL()
ACC = ACC1(A)
SUMS = []
for i in range(N+1):
  for j in range(i+1,N+1):
    SUMS.append(ACC[j]-ACC[i])
ans = 0
for k in range(30)[::-1]:
  HERE = list(filter(lambda x: (x>>k)&1, SUMS)) 
  if len(HERE)>=K:
    ans += 1<<k
    SUMS = HERE
print(ans)