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()))
x=[]
for i in range(n):
    v=0
    for j in range(i,n):
        v+=a[j]
        x.append(v)
x.append(0)
x.sort()
r=len(bin(x[-1]))-2
x.reverse()
ans=0
w=-1
# 高い位からk個立つか調べる。
for i in range(r-1,-1,-1):
    cnt=0
    for j in range(w+1,len(x)):
        if (x[j]>>i)&1:
            cnt+=1
            if ans==0:
                w=j
            if cnt==k:
                if ans==0:
                    w -= k
                ans+=pow(2,i)
                break
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n,k= map(int, input().split())
a= list(map(int, input().split()))
x=[]
for i in range(n):
    v=0
    for j in range(i,n):
        v+=a[j]
        x.append(v)
x.append(0)
x.sort()
r=len(bin(x[-1]))-2
x.reverse()
ans=0
# 高い位からk個立つか調べる。
for i in range(r-1,-1,-1):
    cnt=0
    w=-1
    for j in range(w+1,len(x)):
        if (x[j]>>i)&1:
            cnt+=1
            if ans==0:
                w=j
            if cnt==k:
                if ans==0:
                    w -= k
                ans+=pow(2,i)
                break
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n,k= map(int, input().split())
a= list(map(int, input().split()))
x=[]
for i in range(n):
    v=0
    for j in range(i,n):
        v+=a[j]
        x.append(v)
x.sort()
r=len(bin(x[-1]))-2
x.reverse()
ans=0
w=-1
# 高い位からk個立つか調べる。
for i in range(r-1,-1,-1):
    cnt=0
    for j in range(w+1,len(x)):
        if (x[j]>>i)&1:
            cnt+=1
            w=j
            if cnt==k:
                ans+=pow(2,i)
                w-=k
                break
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n,k= map(int, input().split())
a= list(map(int, input().split()))
x=[]
for i in range(n):
    v=0
    for j in range(i,n):
        v+=a[j]
        x.append(v)
x.sort()
r=len(bin(x[-1]))-2
x.reverse()
ans=0
# 高い位からk個立つか調べる。
for i in range(r-1,-1,-1):
    cnt=0
    w=-1
    for j in range(w+1,len(x)):
        if (x[j]>>i)&1:
            cnt+=1
            w=j
            if cnt==k:
                ans+=pow(2,i)
                w-=k
                break
        else:
            break
print(ans)

Submission status: Wrong Answer

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

S = []
for l in range(0, N):
  temp = 0
  for r in range(l, N):
    temp += A[r]
    S.append(temp)

S.sort(reverse=True)
ans = S[0]
for s in S[:K]:
  ans &= s

print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7
INF = 10 ** 12
import sys
sys.setrecursionlimit(1000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))

    subarray = []
    for i in range(n):
        subarray.append(a[i])
        sub = a[i]
        for j in range(i - 1,-1,-1):
            sub += a[j]
            subarray.append(sub)
    
    for bit in range(37,-1,-1):
        next = []
        for sub in subarray:
            if (sub>>bit)&1:
                next.append(sub)
        if len(next) >= k:
            subarray = next
    
    ans = subarray[0]
    for i in range(1,len(subarray)):
        ans &= subarray[i]
    print(ans)   
if __name__ =='__main__':
    main()

Submission status: Wrong Answer

Solution code:
print(32)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
A = list(map(int,input().split()))
P = [0]+A
for i in range(1,n+1):
    P[i] += P[i-1]
temp = []
for i in range(n+1):
    for j in range(i+1, n+1):
        temp.append(P[j]-P[i])
print(temp)
ans = 0
for i in range(40, -1, -1):
    cur = ans+2**i
    cnt = 0
    for j in range(len(temp)):
        if temp[j]&cur == cur:
            cnt += 1
        if cnt >= k:
            break
    if cnt == k:
        ans += 2**i
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from itertools import accumulate


class SegmentTree():
    '''
    非再帰
    segment tree
    '''

    def __init__(self, n, func, init=float('inf')):
        '''
        n->配列の長さ
        func:func(a,b)->val,　func=minだとRMQになる
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(n-1).bit_length()
        self.init = init
        self.data = [init]*(2*self.n)
        self.func = func

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n-1] = v

    def build(self):
        '''
        setの後に一斉更新
        '''
        for k in reversed(range(self.n-1)):
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のfuncを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.init
        while L < R:
            if R & 1:
                R -= 1
                ret = self.func(ret, self.data[R-1])
            if L & 1:
                ret = self.func(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


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

A_acc = [0]+list(accumulate(A))
cand = []

for l in range(N):
    for r in range(l+1, N+1):
        cand.append(A_acc[r]-A_acc[l])
cand = sorted(cand)

Seg = SegmentTree(len(cand), lambda x, y: x & y, init=2**20-1)
for i, c in enumerate(cand):
    Seg.set(i, c)
Seg.build()
ans = 0
for i in range(len(cand)-K+1):
    ans = max(ans, Seg.query(i, i+K+1))
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from itertools import accumulate


class SegmentTree():
    '''
    非再帰
    segment tree
    '''

    def __init__(self, n, func, init=float('inf')):
        '''
        n->配列の長さ
        func:func(a,b)->val,　func=minだとRMQになる
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(n-1).bit_length()
        self.init = init
        self.data = [init]*(2*self.n)
        self.func = func

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n-1] = v

    def build(self):
        '''
        setの後に一斉更新
        '''
        for k in reversed(range(self.n-1)):
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のfuncを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.init
        while L < R:
            if R & 1:
                R -= 1
                ret = self.func(ret, self.data[R-1])
            if L & 1:
                ret = self.func(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


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

A_acc = [0]+list(accumulate(A))
cand = []

for l in range(N):
    for r in range(l+1, N+1):
        cand.append(A_acc[r]-A_acc[l])
cand = sorted(cand)

Seg = SegmentTree(len(cand), lambda x, y: x & y, init=2**10-1)
for i, c in enumerate(cand):
    Seg.set(i, c)
Seg.build()
ans = 0
for i in range(len(cand)-K+1):
    ans = max(ans, Seg.query(i, i+K+1))
print(ans)

Submission status: Wrong Answer

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

A_acc = [0]+list(accumulate(A))
cand = []

for l in range(N):
    for r in range(l+1, N+1):
        cand.append(A_acc[r]-A_acc[l])
cand = sorted(cand)

# print(cand)
ans = int(reduce(lambda x, y: x & y, cand[-K:], cand[-1]))
print(ans)

Submission status: Wrong Answer

Solution code:

from collections import Counter
n,k = map(int,input().split())
B = list(map(int,input().split()))

class Range_BIT:
    def __init__(self, n):
        self.n = n
        self.bit0 = [0]*(n+1)
        self.bit1 = [0]*(n+1)
    
    def _Add(self, k, x, is_bit0=True):
        if is_bit0 == True:
            data = self.bit0
        else:
            data = self.bit1
        while k <= self.n:
            data[k] += x
            k += k & -k
    
    def _Get(self, data, k):
        s = 0
        while k:
            s += data[k]
            k -= k&-k
        return s
    
    """ 配列の獲得 """
    def Array(self):
        array = [0]*(n+1)
        for i in range(self.n):
            array[i] = self.Get(i+1,i+2)
        return array[:-1]
    
    """ 区間[l:r)に対してxを加算 """
    def Add(self, l, r, x):
        self._Add(l, -x*(l-1), is_bit0=True)
        self._Add(r, x*(r-1), is_bit0=True)
        self._Add(l, x, is_bit0=False)
        self._Add(r, -x, is_bit0=False)
    
    """ 区間[l:r)の総和 """
    def Get(self, l, r):
        Pi = self._Get(self.bit1, r-1)*(r-1) - self._Get(self.bit1, l-1)*(l-1)
        Qi = self._Get(self.bit0, r-1) - self._Get(self.bit0, l-1)
        return Pi+Qi

rbit = Range_BIT(n)
ans = []
for i, b in enumerate(B):
    rbit.Add(i+1, i+2, b)
for i in range(1, n+1):
    for j in range(i, n+1):
        ans.append(rbit.Get(i,j+1))
ctr = Counter(ans)
ret = 0
for k,v in ctr.items():
    if v>=2:
        ret = max(ret, k)
print(ret)

Submission status: Wrong Answer

Solution code:
import copy
N, K = map(int,input().split())
a = list(map(int,input().split()))
# まず累積和で美しさを全列挙
S = [0]*N
S[0] = a[0]
for k in range(1,N):
    S[k] = S[k-1] + a[k]
S = [0] + S
T = []
for k in range(N):
    for l in range(k+1,N+1):
        T.append(S[l]-S[k])
U = []
C = [0]*33
for e in T:
    t = []
    for d in range(32,-1,-1):
        if e >= 2**d:
            t.append(1)
            C[d] += 1
            e -= 2**d
        else:
            t.append(0)
    U.append(t[::-1])

d = -1
for k in range(32,-1,-1):
    if C[k] >= K:
        d = k
        break

if d == -1:
    print(0)
    exit(0)

ans = 2**d

V = []
for e in U:
    if e[d] == 1:
        V.append(e[:d+1])

W = copy.deepcopy(V)
for k in range(d-1,-1,-1):
    n = []
    for e in W:
        if e[k] == 1:
            n.append(e)
    if len(n) >= K:
        ans += 2**k
        W = copy.deepcopy(n)
    else:
        for l in range(k-1,-1,-1):
            c = 0
            for e in W:
                if e[l] == 1:
                    c += 1
            if c >= K:
                ans += 2**c
        break
    break

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] 
nums = []
for i in range(n):
    for j in range(i+1,n+1):
        nums.append(a[j]-a[i])
nums.sort(reverse = True)
ans =nums[0]
for i in range(k-1):
    ans &= nums[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
sal = [0] * (n*(n+1)//2)
l = 0
for i in range(n):
  for j in range(i,n):
    sal[l] = sum(a[i:j+1])
    l += 1
ans = 0
for i in range(40)[::-1]:
    cnt = 0
    temp = ans + 2**i
    for j in a:
        if temp&j == temp:
            cnt += 1
    if cnt >= k:
        ans = temp
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    acc = list(accumulate([0] + A))
    S = []
    for i in range(N):
        for j in range(i+1, N+1):
            S.append(acc[j] - acc[i])
    S.sort(reverse=True)
    ans = S[0]
    for i in range(1, K):
        ans &= S[i]
    cur = ans
    for i in range(N-K+1):
        cur ^= S[i]
        cur &= S[i+K]
        ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    acc = list(accumulate([0] + A))
    S = []
    for i in range(N):
        for j in range(i+1, N+1):
            S.append(acc[j] - acc[i])
    dp = [[0]*(K+1) for _ in range(N*(N+1)//2 + 1)]
    for i in range(1, N*(N+1)//2 + 1):
        dp[i][1] = max(dp[i-1][1], S[i-1])
    for i in range(1, N*(N+1)//2 + 1):
        for j in range(2, K+1):
            dp[i][j] = max(dp[i-1][j-1] & S[i-1], dp[i-1][j])
    print(dp[-1][-1])


if __name__ == '__main__':
    main()

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]
sal = [0] * (n*(n+1)//2)
l = 0
for i in range(n):
  for j in range(i,n):
    sal[l] = s[j+1] - s[i]
    l += 1
sal.sort(reverse = True)
ans = sal[0]
for i in range(1,k):
    ans = ans & sal[i]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    acc = list(accumulate([0] + A))
    S = []
    for i in range(N):
        for j in range(i+1, N+1):
            S.append(acc[j] - acc[i])
    S.sort(reverse=True)
    ans = S[0]
    for s in S[1:K]:
        ans &= s
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a = [int(item) for item in input().split()]
cuma = [0]
for item in a:
    cuma.append(cuma[-1] + item)
b = []
for i in range(n):
    for j in range(i + 1, n+1):
        b.append(cuma[j] - cuma[i])
ans = 0
for i in range(12, -1, -1):
    subset = []
    for item in b:
        if item & 1 << i: 
            subset.append(item)
    if len(subset) >= k:
        ans |= 1 << i
        b = subset[:]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)

def search(i, L, Lnum, K):
    if i == 40:
        if Lnum >= K: return 1
        else: return 0
    add = pow(2, 40 - i)
    nextK = []
    count = 0
    for l in L:
        if l & add == add:
            nextK.append(l)
            count += 1
    #print(i, L)
    if count >= K: return add + search(i+1, nextK, count, K)
    else: return search(i+1, L, Lnum, K)


def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    sumA = [0] * (N + 1)
    for i, a in enumerate(A): sumA[i+1] = sumA[i] + a
    subA = []
 
    for i in range(N):
        for j in range(i+1, N+1): subA.append(sumA[j] - sumA[i])

    print(search(0, subA, N * (N - 1) // 2, K) - 1)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, k = LI()
A = LI()
acc = [0] + list(accumulate(A))
L = []
for i in range(n):
    for j in range(i + 1, n + 1):
        L += [acc[j] - acc[i]]

ans = 0
for l in range(max(L).bit_length() - 1, -1, -1):
    new_L = []
    for e in L:
        if e >> l & 1:
            new_L += [e]
    if len(new_L) >= k:
        ans |= 1 << l
        L = new_L
    elif ans:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from queue import Queue
N, K = map(int, input().split())
A = list(map(int, input().split()))
all_sum = []
sum_array = [0] * (N+1)
for i in range(N):
    sum_array[i+1] = sum_array[i] + A[i]

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

all_sum.sort()
tmp = 1
ans = 0
pre_idx = 0
tmp1 = 0
l = len(all_sum)
i = 0
k_list = []
for i in all_sum:
    k_list.append(i)
    if len(k_list) == K:
        tmp = k_list[0]
        k_list = k_list[1:]
        for q in range(K-1):
            tmp &= k_list[q]
        ans = max(ans, tmp)
    
print(ans)

Submission status: Wrong Answer

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

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

all_sum.sort()
tmp = 1
ans = 0
k_list = [0] * K
pre_idx = 0
tmp1 = 0
all_sum.append(10**20)
l = len(all_sum)
i = 0
while i < l:
    if all_sum[i] >= tmp:
        tmp *= 2
        if i - pre_idx >= K:
            tmp1 = all_sum[i-1]
            for j in range(i-2,i-K-1,-1):
                tmp1 &= all_sum[j]
            ans = max(ans, tmp1)
    else:
        i += 1
    if i-1 == l:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import bisect
import math

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

s = [a[0]]
for i in range(1, N):
    s.append(s[i-1] + a[i])
ps = copy.copy(s)
for i in range(N):
    ps = [ps[j] - ps[0] for j in range(1, N-i)]
    s += ps

ans = 0
s.sort()

while s[-1] != 0:
    n = int(math.log2(s[-1]))
    ind = bisect.bisect_left(s, 2**n)
    if len(s) - ind == K:
        temp = s[-1]
        for i in range(1, K):
            temp &= s[-i-1]
        print(ans + temp)
        exit()
    elif len(s) - ind > K:
        ans += 2**n
        s = [x & (2**n-1) for x in s[ind:]]
    else:
        while len(s) - ind < K:
            n -= 1
            ind = bisect.bisect_left(s, 2**n)
            if s[ind] == 0:
                print(ans)
                exit()
        s = [x & (2**n-1) for x in s]
    s.sort()
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n,k = LI()
    a = LI()
    acc = [0] + list(itertools.accumulate(a))
    lis = []
    for i in range(n):
        for j in range(i + 1, n + 1):
            lis.append(acc[j] - acc[i])
    lis.sort()
    ans = deque()
    for l in lis:
        ans.append(l)
    ansnum = 0
    N = len(bin(acc[-1])) - 2
    for i in range(N):
        tmp = deque()
        lenans = len(ans)
        for _ in range(lenans):
            p = ans.popleft()
            if (1 << (N - 1 - i)) & p:
                ans.append(p)
                tmp.append(p)
        if len(ans) < k:
            while tmp:
                t = tmp.pop()
                ans.append(p)
        else:
            ansnum |= (1 << (N - 1 - i))
    print(ansnum)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
Acum = [0]
for a in A:
    Acum.append(Acum[-1] + a)

Apair = []
for i, al in enumerate(Acum):
    for ar in Acum[i + 1:]:
        Apair.append(ar - al)
Apair = np.asarray(Apair, dtype=np.int64)


d = 45  # 10*9*1000 = 1<<40ぐらい
ans = 0
while d:
    Atmp = np.bitwise_and(np.right_shift(Apair, d), 1)
    if np.count_nonzero(Atmp) >= K:
        ans += 2 ** d
        Apair = Apair[np.nonzero(Atmp)]
    d -= 1
    if Apair.size < K:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
Acum = [0]
for a in A:
    Acum.append(Acum[-1] + a)

Apair = []
for i, al in enumerate(Acum):
    for ar in Acum[i + 1:]:
        Apair.append(ar - al)
Apair = np.asarray(Apair, dtype=np.int64)


d = 40  # 10*9*1000 = 1<<40ぐらい
ans = 0
while d:
    Atmp = np.bitwise_and(np.right_shift(Apair, d), 1)
    if np.count_nonzero(Atmp) >= K:
        ans += 2 ** d
        Apair = Apair[np.nonzero(Atmp)]
    d -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate, combinations

read = sys.stdin.read

N, K, *a = map(int, read().split())

a = accumulate([0] + a)
seq = []
for i, j in combinations(a, 2):
    seq.append(j - i)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate, combinations

read = sys.stdin.read

N, K, *a = map(int, read().split())

a = accumulate([0] + a)
seq = []
for i, j in combinations(a, 2):
    seq.append(j - i)

m = (10 ** 9 * 1000).bit_length()
answer = 0
bit = 1 << m
for _ in range(m):
    tmp = bit + answer
    if len([i for i in seq if i & tmp == tmp]) >= K:
        answer = tmp
    bit >>= 1

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int,input().split())
A = list(map(int,input().split()))
S = [0]
for i in range(n):
    S.append(A[i] + S[-1])
B = []
for i in range(len(S)):
    for j in range(i+1, len(S)):
        B.append(S[j] - S[i])
B.sort()
# print(B)

A = [0] * 33

import bisect
i = 32
ans = 0
for i in range(32, -1, -1):
    ans += 2**i
    c = 0
    for j in range(len(B)):
        if B[j] & ans == ans:
            c += 1
    # print(i, c)
    if c < k:
        ans -= 2**i
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate,combinations
n,k = map(int,input().split())
a = list(map(int,input().split()))
acc = [0]+list(accumulate(a))
ls = a[:]
for i,j in combinations(acc,2):
  ls.append(j-i)
x = max(ls).bit_length()
ans = 0
for i in range(x-1,-1,-1):
  cnt = 0
  for j in acc:
    if ans & j == ans:
      cnt += 1
  if cnt >= k:
    ans += 2**i
print(ans)

Submission status: Wrong Answer

Solution code:
import datetime
nk = input().split()
seisuuretu = input().split()

for i in range(len(seisuuretu)):
    seisuuretu[i] = int(seisuuretu[i])

list_max = []
beautiful_list = []
print(datetime.datetime.now())
for start in range(len(seisuuretu) + 1):
    for end in range(len(seisuuretu) + 1):
        if start < end:
            temp_pattern = bin(sum(seisuuretu[start:end]))[2:]
            beautiful_list.append(temp_pattern)
            list_max.append(len(temp_pattern))
print(datetime.datetime.now())

list_max = -max(list_max)

status = True
while status == True:
    temp = []
    count = 0
    len_all = 0
    for i in beautiful_list:
        try:
            if int(i[list_max]) == 1:
                count += 1
                temp.append(i)
        except:
            continue
    if count > int(nk[1]):
        list_max += 1
        beautiful_list = temp
    elif count == int(nk[1]):
        beautiful_list = temp
        num_count = True
        for num in beautiful_list:
            if num_count == True:
                ronriseki = int(num, 2)
            else:
                ronriseki = ronriseki & int(num, 2)
            num_count = False
        print(ronriseki)
        status = False
    elif list_max == -1:
        num_count = True
        for num in beautiful_list:
            if num_count == True:
                ronriseki = int(num, 2)
            else:
                ronriseki = ronriseki & int(num, 2)
            num_count = False
        print(ronriseki)
        status = False
    else:
        list_max += 1

Submission status: Wrong Answer

Solution code:
nk = input().split()
seisuuretu = input().split()

for i in range(len(seisuuretu)):
    seisuuretu[i] = int(seisuuretu[i])

all_seisuuretu = []

for start in range(len(seisuuretu) + 1):
    for end in range(len(seisuuretu) + 1):
        if start < end:
            all_seisuuretu.append(seisuuretu[start:end])

list_max = []
beautiful_list = []
for pattern in all_seisuuretu:
    temp_pattern = bin(sum(pattern))[2:]
    beautiful_list.append(temp_pattern)
    list_max.append(len(temp_pattern))

list_max = -max(list_max)

ronriseki_num = []
status = True
while status == True:
    temp = []
    count = 0
    len_all = 0
    for i in beautiful_list:
        try:
            if int(i[list_max]) == 1:
                count += 1
                temp.append(i)
                if count == int(nk[1]):
                    ronriseki_num.append(-list_max)
        except:
            continue
    if count > int(nk[1]):
        beautiful_list = temp
        list_max += 1
    elif count == int(nk[1]):
        beautiful_list = temp
        num_count = True
        for num in ronriseki_num:
            if num_count == True:
                ronriseki = 2 ** (num - 1)
            else:
                ronriseki = ronriseki + 2 ** (num - 1)
            num_count = False
        print(ronriseki)
        status = False
    elif list_max == -1:
        num_count = True
        for num in ronriseki_num:
            if num_count == True:
                ronriseki = 2 ** (num - 1)
            else:
                ronriseki = ronriseki + 2 ** (num - 1)
            num_count = False
        print(ronriseki)
        status = False
    else:
        list_max += 1

Submission status: Wrong Answer

Solution code:
nk = input().split()
seisuuretu = input().split()

for i in range(len(seisuuretu)):
    seisuuretu[i] = int(seisuuretu[i])

all_seisuuretu = []

for start in range(len(seisuuretu) + 1):
    for end in range(len(seisuuretu) + 1):
        if start < end:
            all_seisuuretu.append(seisuuretu[start:end])

list_max = []
beautiful_list = []
for pattern in all_seisuuretu:
    temp_pattern = bin(sum(pattern))[2:]
    beautiful_list.append(temp_pattern)
    list_max.append(len(temp_pattern))

list_max = -max(list_max)

status = True
while status == True:
    temp = []
    count = 0
    len_all = 0
    for i in beautiful_list:
        try:
            if int(i[list_max]) == 1:
                count += 1
                temp.append(i)
                if count > int(nk[1]):
                    list_max += 1
                    break
        except:
            continue
    if count > int(nk[1]):
        beautiful_list = temp
    elif count == int(nk[1]):
        beautiful_list = temp
        num_count = True
        for num in beautiful_list:
            if num_count == True:
                ronriseki = int(num, 2)
            else:
                ronriseki = ronriseki & int(num, 2)
            num_count = False
        print(ronriseki)
        status = False
    elif list_max == -1:
        num_count = True
        for num in beautiful_list:
            if num_count == True:
                ronriseki = int(num, 2)
            else:
                ronriseki = ronriseki & int(num, 2)
            num_count = False
        print(ronriseki)
        status = False
    else:
        list_max += 1

Submission status: Wrong Answer

Solution code:
nk = input().split()
seisuuretu = input().split()

for i in range(len(seisuuretu)):
    seisuuretu[i] = int(seisuuretu[i])

all_seisuuretu = []

for start in range(len(seisuuretu) + 1):
    for end in range(len(seisuuretu) + 1):
        if start < end:
            all_seisuuretu.append(seisuuretu[start:end])

list_max = []
beautiful_list = []
for pattern in all_seisuuretu:
    temp_pattern = bin(sum(pattern))[2:]
    beautiful_list.append(temp_pattern)
    list_max.append(len(temp_pattern))

list_max = -max(list_max)

status = True
while status == True:
    temp = []
    count = 0
    len_all = 0
    for i in beautiful_list:
        try:
            if int(i[list_max]) == 1:
                count += 1
                temp.append(i)
                if count > int(nk[1]):
                    break
        except:
            continue
    if count > int(nk[1]):
        list_max += 1
        beautiful_list = temp
    elif count == int(nk[1]):
        beautiful_list = temp
        num_count = True
        for num in beautiful_list:
            if num_count == True:
                ronriseki = int(num, 2)
            else:
                ronriseki = ronriseki & int(num, 2)
            num_count = False
        print(ronriseki)
        status = False
    elif list_max == -1:
        num_count = True
        for num in beautiful_list:
            if num_count == True:
                ronriseki = int(num, 2)
            else:
                ronriseki = ronriseki & int(num, 2)
            num_count = False
        print(ronriseki)
        status = False
    else:
        list_max += 1