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 collections import defaultdict

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

    # make binaries
    binaries = []
    for i in range(N):
        for j in range(i, N):
            binaries.append(sum(a[i:j+1]))

    binaries = sorted(binaries)
    ans = 0
    for i in range(len(binaries) - K +1):
        a = -1
        for b in binaries[i:i+K-1]:
            a &= b
        if ans < a:
            ans = a
    print(a)

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
koho = []
for l in range(n):
    for r in range(l,n):
        koho.append(cum[r+1] - cum[l])
ret = 0
for keta in reversed(range(32)):
    currkoho = []
    for s in koho:
        if s & (1 << keta) != 0:
            currkoho.append(s)
    if len(currkoho) >= k:
        koho = currkoho
        ret += (1 << keta)
print(ret)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
koho = []
for l in range(n):
    for r in range(l,n):
        koho.append(cum[r+1] - cum[l])
ret = 0
print(sorted(koho, reverse = True))
for keta in reversed(range(32)):
    currkoho = []
    for s in koho:
        if s & (1 << keta) != 0:
            currkoho.append(s)
    if len(currkoho) >= k:
        print(currkoho)
        koho = currkoho
        ret += (1 << keta)
print(ret)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
koho = []
for l in range(n):
    for r in range(l,n):
        koho.append(cum[r+1] - cum[l])
ret = 0
for keta in reversed(range(30)):
    currkoho = []
    for s in koho:
        if s & (1 << keta) != 0:
            currkoho.append(s)
    if len(currkoho) >= k:
        koho = currkoho
        ret += (1 << keta)
print(ret)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
slist = []
for l in range(n):
    for r in range(l,n):
        slist.append(cum[r+1] - cum[l])
ret = 0
for keta in reversed(range(27)):
    currkoho = []
    for s in slist:
        if s & (1 << keta) != 0:
            currkoho.append(s)
    if len(currkoho) >= k:
        slist = currkoho
        ret += (1 << keta)
print(ret)

Submission status: Wrong Answer

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

count, sum, start = 0, 0, 0
substring = []
while (True):
    sum += input[count]
    substring.append(sum)
    if start == len(input) - 1:
        break
    if count == len(input) - 1:
        start += 1
        count = start
        sum = 0
        continue

    count += 1
substring.sort(reverse=True)

result = substring[0]
for i in range(1, K):
    result = result & substring[i]

print(result)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
k_num = K * (K + 1) / 2
input = list(map(int, input().split()))

count, sum, start = 0, 0, 0
substring = []
while (True):
    sum += input[count]
    substring.append(sum)
    if start == len(input) - 1:
        break
    if count == len(input) - 1:
        start += 1
        count = start
        sum = 0
        continue

    count += 1
substring.sort(reverse=True)

result = substring[0]
for i in range(1, K):
    result = result and substring[i]

print(result)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def check(subarray, msb, threshold):
    count = 0
    index = 0
    for i, element in enumerate(subarray):
  	    if element >= 2 ** msb:
  	        count += 1
  	        subarray[i] -= 2 ** msb
  	    else:
  	        index = i
  	        break
    return (subarray[:index], 2 ** msb) if count >= threshold else (subarray, 0)

nums = [int(n) for n in input().split()]
array = [int(n) for n in input().split()]
subarray = []
for i in range(nums[0]):
    for j in range(i+1):
	    subarray.append(sum(array[j:j+nums[0]-i]))
subarray.sort(reverse=True)

temp = subarray[0]
msb = 0
while temp // 2 != 0:
    temp = temp // 2
    msb += 1

answer = 0
while msb >= 0:
    subarray, add = check(subarray, msb, nums[1])
    answer += add
    subarray.sort(reverse=True)
    msb -= 1
print(answer)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def check(subarray, msb, threshold):
    count = 0
    index = 0
    for i, element in enumerate(subarray):
  	    if element >= 2 ** msb:
  	        count += 1
  	        subarray[i] -= 2 ** msb
  	    else:
  	        index = i
  	        break
    return (subarray[:index], 2 ** msb) if count >= threshold else (subarray, 0)

nums = [int(n) for n in input().split()]
array = [int(n) for n in input().split()]
subarray = []
for i in range(nums[0]):
    for j in range(i+1):
	    subarray.append(sum(array[j:j+nums[0]-i]))
subarray.sort(reverse=True)

temp = subarray[0]
msb = 0
while temp // 2 != 0:
    temp = temp // 2
    msb += 1
print(subarray)

answer = 0
while msb >= 0:
    subarray, add = check(subarray, msb, nums[1])
    answer += add
    subarray.sort(reverse=True)
    msb -= 1
print(answer)

Submission status: Wrong Answer

Solution code:
import copy
n, k = map(int, input().split())
B = list(map(int, input().split()))
A = []
for l in range(0, n):
	for r in range(l+1, n+1):
		A.append(sum(B[l:r]))
#print(A)
ans = 0
for i in range(31, -1, -1):
	tmp = []
	res = 0
	for a in A:
		if (a >> i) & 1 == 1:
			tmp.append(a)
			res += 1
	if res >= k:
		ans += 1 << i
		A = copy.copy(tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
B = list(map(int, input().split()))
A = []
for l in range(0, n):
	for r in range(l+1, n+1):
		A.append(sum(B[l:r]))
ans = 0
for i in range(35, -1, -1):
	tmp = []
	res = 0
	for a in A:
		if (a >> i) & 1 == 1:
			tmp.append(a)
			res += 1
	if res >= k:
		ans += 1 << i
		A = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
def debug():
    import itertools
    N,K = map(int,input().split())
    a = list(map(int,input().split()))
    beauty = []
    for i in range(N):
        for j in range(i+1,N+1):
            part = a[i:j]
            beauty.append(sum(part))
    choise = [e for e in itertools.combinations(beauty,K)]
    ans = 0
    for pair in choise:
        res = pair[0]
        for i in range(1,len(pair)):
            res = res & pair[i]
        if res > ans :
            ans = res
            adopt = pair
    print(ans)
    print(pair)
    print(sorted(beauty))

def main():
    N,K = map(int,input().split())
    a = list(map(int,input().split()))
    degit = sum(a).bit_length()
    beaty = []
    manage = [[] for i in range(degit)]
    for i in range(N):
        for j in range(i+1,N+1):
            part_sum = sum(a[i:j])
            beaty.append(part_sum)
    for e in beaty:
        for i in range(e.bit_length()):
            judge = pow(2,i)
            if judge == judge & e:
                manage[i].append(e)
    note = []
    flag = True
    for i in range(degit-1,-1,-1):
        if len(manage[i]) >= K and flag:
            note = manage[i]
            flag = False
            if len(note) == K:
                adopt = note
                break
            continue
        note_try = []
        for e in note:
            if manage[i].count(e) > 0:
                note_try.append(e)
        if len(note_try) == K:
            adopt = note_try
            break
        if i == 0:
            adopt = note[:K]
    ans = adopt[0]
    for i in range(1,K):
        ans = ans & adopt[i]
    print(ans)
    
main()

Submission status: Wrong Answer

Solution code:
#横にn個入力
n, k = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
nli = []
b = 0
for i in range(n):
    for j in range(i, n):
        b += a[j]
        nli.append(b)
    b = 0
nli.sort(reverse=True)
m = 41
x = 0

cnt = 0
candili = []
for i in range(m - 1, 0, -1):
    if x == 0:
        for j in range(len(nli)):
            if nli[j] & (x + 2 ** i) == x + 2 ** i:
                candili.append(nli[j])
                cnt += 1
        if cnt >= k:
            x += 2 ** i
            cnt = 0
        else:
            cnt = 0
            candili = []
    else:
        for j in candili:
            if j & (x + 2 ** i) == x + 2 ** i:
                cnt += 1
        if cnt >= k:
            x += 2 ** i
            cnt = 0
        else:
            cnt = 0
print(x)

Submission status: Wrong Answer

Solution code:
#横にn個入力
n, k = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
nli = []
b = 0
for i in range(n):
    for j in range(i, n):
        b += a[j]
        nli.append(b)
    b = 0
nli.sort(reverse=True)
m = 40
x = 0

cnt = 0
candili = []
for i in range(m - 1, 0, -1):
    if x == 0:
        for j in range(len(nli)):
            if nli[j] & (x + 2 ** i) == x + 2 ** i:
                candili.append(nli[j])
                cnt += 1
        if cnt >= k:
            x += 2 ** i
            cnt = 0
        else:
            cnt = 0
            candili = []
    else:
        for j in candili:
            if j & (x + 2 ** i) == x + 2 ** i:
                cnt += 1
        if cnt >= k:
            x += 2 ** i
            cnt = 0
        else:
            cnt = 0
print(x)

Submission status: Wrong Answer

Solution code:
#横にn個入力
n, k = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
nli = []
b = 0
for i in range(n):
    for j in range(i, n):
        b += a[j]
        nli.append(b)
    b = 0
nli.sort(reverse=True)
m = 40
x = 0

cnt = 0
candili = []
for i in range(m - 1, 0, -1):
    if x == 0:
        for j in range(len(nli)):
            if nli[j] & (x + 2 ** i) == x + 2 ** i:
                candili.append(nli[j])
                cnt += 1
        if cnt >= k:
            x += 2 ** i
            cnt = 0
        else:
            cnt = 0
            candili = []
    else:
        for j in candili:
            if j & (x + 2 ** i) == x + 2 ** i:
                cnt += 1
        if cnt >= k:
            x += 2 ** i
            cnt = 0
        else:
            cnt = 0
            candili = []
print(x)

Submission status: Wrong Answer

Solution code:
NK = input().split(" ")
N, K = int(NK[0]), int(NK[1])
at, a = input().split(" "), []
for i in at:
    a.append(int(i))
enum = []
for i in range(0, len(a)):
    for j in range(i+1, len(a)+1):
        enum.append(a[i:j])
enub = []
for i in enum:
    enub.append(sum(i))
enub.sort(reverse=True)
ans = enub[0]
for i in range(K):
    ans = ans & enub[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n,k = li()
a = list(li())

acum = list(accumulate([0]+a))

cand = []
for i in range(n+1):
    for j in range(i+1,n+1):
        cand.append(acum[j] - acum[i])

ans = 0

for mask in range(31, -1, -1):
    satis = sum([bool(ci&(1<<mask)) for ci in cand])

    if satis >= k:
        ans += (1<<mask)
        nex = [ci for ci in cand if ci & (1<<mask)]
        cand = nex
        

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
# import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

S = set()
for i in range(N):
    for j in range(i, N):
        b = A[i:j + 1]
        S.add(sum(b))

S = list(S)

ans = 0
for i in range(37, -1, -1):
    A = [s & (1 << i) for s in S]
    newS = list(compress(S, A))
    if len(newS) >= K:
        ans += (1 << i)
        S = newS

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
# import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

S = set()
for i in range(N):
    for j in range(i, N):
        b = A[i:j + 1]
        S.add(sum(b))

S = list(S)

ans = 0
for i in range(35, -1, -1):
    A = [s & (1 << i) for s in S]
    newS = list(compress(S, A))
    if len(newS) >= K:
        ans += (1 << i)
        S = newS

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
# import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

B = []
S = set()
for i in range(N):
    for j in range(i, N):
        b = A[i:j + 1]
        B.append(b)
        S.add(sum(b))

# print(B)
# print(S)

S = sorted(list(S))


def f(L, b):
    R = []
    for l in L:
        r = 1 if l & (1 << b) != 0 else 0
        R.append(r)
    return R


ans = 0
for i in range(32, -1, -1):
    A = [s & (1 << i) for s in S]
    if len(list(compress(S,A))) >= K:
        ans += (1 << i)
        S = list(compress(S, A))


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
# import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

B = []
S = set()
for i in range(N):
    for j in range(i, N):
        b = A[i:j + 1]
        B.append(b)
        S.add(sum(b))

# print(B)
# print(S)

S = sorted(list(S))

def f(L, b):
    R = []
    for l in L:
        r = 1 if l & (1 << b) != 0 else 0
        R.append(r)
    return R


ans = 0
for i in range(32, -1, -1):
    R = f(S, i)
    if R.count(1) >= K:
        ans += (1 << i)
        S = compress(S,R)

print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
s = []
for i in range(N):
    total = 0
    for j in range(i,N):
        total += a[j]
        s.append(total)
s.sort(reverse=True)
m,n = 1,1
while s[0]>=m:
    n += 1
    m *= 2
for i in range(n)[::-1]:
    t = list(filter(lambda x:x-m>=0,s))
    l = len(t)
    if l>=K:
        break
    else:
        m //= 2
n = i+1
for i in range(n):
    u = list(filter(lambda x:(x//m)%2==1,t))
    l = len(u)
    if l>=K:
        t = u[:]
        if l==K:
            break
    m //= 2
ans = t[0]
for i in range(1,K):
    ans &= s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
s = []
for i in range(N):
    total = 0
    for j in range(i,N):
        total += a[j]
        s.append(total)
s.sort(reverse=True)
m,n = 1,1
while s[0]>=m:
    n += 1
    m *= 2
for i in range(n)[::-1]:
    subs = list(filter(lambda x:x-m>=0,s))
    l = len(subs)
    if l>=K:
        break
    else:
        m //= 2
for i in range(n+1):
    subs = list(filter(lambda x:(x//m)%2==1,subs))
    l = len(subs)
    if l>=K:
        s = subs[:]
        if l==K:
            break
    m //= 2
ans = s[0]
for i in range(1,K):
    ans &= s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
s = []
for i in range(N):
    total = 0
    for j in range(i,N):
        total += a[j]
        s.append(total)
s.sort(reverse=True)
n = 0
while s[0]>=2**n:
    n += 1
l = 0
for i in range(n)[::-1]:
    subs = list(filter(lambda x:x-(2**i)>=0,s))
    l = len(subs)
    if l>=K:
        s = subs[:]
        if l==K:
            break
for i in range(n+1):
    subs = list(filter(lambda x:x%(2**i)==1,s))
    l = len(subs)
    if l>=K:
        s = subs[:]
        if l==K:
            break
ans = s[0]
for i in range(1,K):
    ans &= s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
s = []
for i in range(N):
    total = 0
    for j in range(i,N):
        total += a[j]
        s.append(total)
s.sort(reverse=True)
n = 0
while s[0]>=2**n:
    n += 1
l = 0
ans = 0
for i in range(n,-1,-1):
    subs = []
    for j in range(len(s)):
        if s[j]>=2**i:
            subs.append(s[j]-2**i)
    l = len(subs)
    if l>=K:
        s = subs[:]
        ans += 2**i
        if l==K:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
s = []
for i in range(N):
    total = 0
    for j in range(i,N):
        total += a[j]
        s.append(total)
s.sort(reverse=True)
n = 0
while s[0]>=2**n:
    n += 1
l = 0
for i in range(n+1,-1,-1):
    subs = list(filter(lambda x:x-(2**i)>=0,s))
    l = len(subs)
    if l>=K:
        s = subs[:]
        if l==K:
            break

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
s = []
for i in range(N):
    total = 0
    for j in range(i,N):
        total += a[j]
        s.append(total)
s.sort(reverse=True)
n = 0
while s[0]>=2**n:
    n += 1
l = 0
for i in range(n,-1,-1):
    subs = list(filter(lambda x:x-2**i>=0,s))
    l = len(subs)
    if l>=K:
        s = subs[:]
        if l==K:
            break
ans = s[0]
for i in range(1,K):
    ans &= s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n,kk=map(int,input().split())
ss=input().split()
a=[int(ss[i]) for i in range(n)]
s=[0]*(n+1)
for i in range(n):
    s[i+1]=s[i]+a[i]
b=[None for i in range(n*(n+1)//2)]
k=0
for i in range(n):
    for j in range(i+1,n+1):
        b[k]=s[j]-s[i]
        k+=1
res=0
for i in range(30,-1,-1):
    m=2**i
    cnt=0
    for j in b:
        if j&m>0:
            cnt+=1
    if cnt>=kk:
        bb=[0 for j in range(cnt)]
        k=0
        for j in b:
            if j&m>0:
                bb[k]=j
                k+=1
        b=list(bb)
        res+=m
print(res)

Submission status: Wrong Answer

Solution code:
n,kk=map(int,input().split())
ss=input().split()
a=[int(ss[i]) for i in range(n)]
s=[0]*(n+1)
for i in range(n):
    s[i+1]=s[i]+a[i]
b=[None for i in range(n*(n+1)//2)]
k=0
for i in range(n):
    for j in range(i+1,n+1):
        b[k]=s[j]-s[i]
        k+=1
res=0
for i in range(30,-1,-1):
    m=2**i
    cnt=0
    for j in b:
        if j&m>0:
            cnt+=1
    if cnt>=kk:
        bb=[0 for jj in range(cnt)]
        jjj=0
        for j in b:
            if j&m>0:
                bb[jjj]=j
                jjj+=1
        b=bb
        res+=m
print(res)

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
arr = map(int, raw_input().split())
arr_sub = []
for i in range(n):
    for j in range(n-i):
        arr_sub.append(sum(arr[j:j+i+1]))


def my_binary(n):

    s = ""
    d = 1
    while n != 1:
        s = str(n%2)+s
        n/=2
        d+=1
    s = "1"+s
    return int(s)

# ************
def bitwise_and(lst):
    new = 0
    for num in lst:
        new += my_binary(num)
    new = str(new)
    res = ""
    for i in new:
        if i == str(len(lst)):
            res += "1"
        else:
            res += "0"
    res = str(int(res))
    k = 0
    for i in range(len(res)):
        k += 2**i*int(res[len(res)-1-i])
    return k

max = 0
arr_sub.sort()
# print arr_sub
print bitwise_and(arr_sub[len(arr_sub)-k:len(arr_sub)])

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

accAs = [0] + list(accumulate(As))

Bs = []
for L in range(N):
    for R in range(L, N):
        Bs.append(accAs[R + 1] - accAs[L])

ans = 0
for d in reversed(range(50)):
    num = sum([(B >> d) & 1 for B in Bs])
    if num >= K:
        ans += 1 << d
        Bs = [B if (B >> d) & 1 else 0 for B in Bs]
    elif ans > 0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())

c = list(map(int,input().split()))

d = []

d.append(0)

for i in range(a):
  d.append(d[-1]+c[i])

d.sort()
k = 0
co = 0
for i in range(40,-1,-1):
  for j in range(a):
    if d[j] & 2 ** i == 2 ** i:
      co += 1
  if co >= b:
    k += 2 ** i

print(k)

Submission status: Wrong Answer

Solution code:
def my_and(array, k):
  ret = array[0]
  for i in range(1, k):
    ret &= array[i]
  return ret

N, K = map(int, input().split())
a = list(map(int, input().split()))
b = [0 for i in range(sum(range(N+1)))]
count = 0
for i in range(N):
  for j in range(N-i):
    b[count] = sum(a[i:i+j+1])
    count += 1
b.sort(reverse=True)
print(my_and(b, K))

Submission status: Wrong Answer

Solution code:
N,K = map(int,raw_input().split())
a = map(int,raw_input().split())
x = []
for i in range(N):
  for j in range(i,N):
    y = a[i:j+1]
    x.append(sum(y))
x.sort()
print x[N*(N+1)/2-K]

Submission status: Wrong Answer

Solution code:
from functools import reduce
def cumsum(l):
    c = [0] * len(l)
    for i in range(len(l)):
        c[i] = c[i-1] + l[i]
    return c

N, K = map(int, input().split())
a = [int(i) for i in input().split()]
c = [0] + cumsum(a)

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

ans = 0
for i in range(len(s)-K+1):
    ans = max(ans, reduce(lambda a,b: a & b, s[i:K+i]))
print(ans)

Submission status: Wrong Answer

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

for i in range(N):
  if (i**2-i+2)/2 <= K < (i**2+i+2)/2:
    l = N-i
    break
s = [0 for i in range(N-l+1)]
for i in range(N-l+1):
  s[i] = sum(a[i:i+l])

print(max(s))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ac
from functools import reduce

n,k=map(int,input().split())
*ac,=ac([0]+list(map(int,input().split())))

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

def count_bits(n):
    global l
    v=0
    for i in l:
        if (i&n)==n:v+=1
    return v

ans=0
for i in range(40,-1,-1):
    if count_bits(ans|2<<i)>=k:
        ans|=2<<i

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ac
from functools import reduce

n,k=map(int,input().split())
*ac,=ac([0]+list(map(int,input().split())))

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

v=max(l)
l.sort(key=lambda x:x&v,reverse=True)
print(reduce(lambda x,y:x&y,l[:k]))

Submission status: Wrong Answer

Solution code:
import math
N,M = map(int ,input().split())
_range = math.ceil(math.log2(M))
num = list(map(int,input().split()))

maxlist = []
for i in range(_range + 1):
	maxlist.append(sum(num[_range-i:len(num)-i]))

print(max(maxlist))

Submission status: Wrong Answer

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

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


n2 = n*(n+1)//2

res = 0
for i in range(31):
    p = res + 2**(30-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

Submission status: Wrong Answer

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

b = []
for i in range(n):
    r = 0
    for j in range(n-i):
        r += a[i+j]
        b.append(r)


n2 = len(b)

res = 0
for i in range(41):
    p = res + (1 << (40-i))
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    N, K = map(int, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))

    groupList=[]
    # まずは部分列をつくる
    for i in range(N):
        for j in range(N-i):
            groupList.append(sum(A[j:j+i+1]))
    
    # ビットでandをとって残った物を採用
    for b in range(40,-1,-1):
        checkBit=2**b
        new_group_list = []

        for g in groupList:
            if  checkBit & g == checkBit:
                new_group_list.append(g)

        if len(new_group_list) >= K:
            groupList = new_group_list

    print(min(groupList))

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())

if a == b:
	if a % 4 == 0:
		print("Yes")
	else:
		print("No")
else:
	k = min(a,b)
	a -= 3*k
	b -= 3*k
	if a == 0 or b == 0:
		print("Yes")
	else:
		print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,k=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]

tmp=[]
cnt=0
for i in range(len(data)):
    for j in range(len(data)-i):
        tmp.append(((sum(data[i:1+i+j]))))
        cnt+=1
beat_v=sorted(tmp)
tmp2 = list(map(lambda x: len(bin(x)), beat_v))

#同じ桁のbit列がK個以上あるか探索
cnt2=0
maxbit=tmp2[-1]
res=0
for l in reversed(tmp2):
    if maxbit==l:
        cnt2+=1
    else :
        cnt2=1
    maxbit=l
    if cnt2==k:
        res=maxbit
        break
cnt3=0
for m in reversed(tmp2):
    if m != res:
        cnt3+=1
    else :
        break
        
res_=list(reversed(beat_v))[cnt3:cnt3+k]
result=res_[0]
for g in res_[1:]:
    result=result&g
print(result)

Submission status: Wrong Answer

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

S = list(map(int, input().split()))

A = []

for i in range(N+1):
    for j in range(i):
        A.append(sum(S[j:i]))

A.sort()
A.reverse()

for i in range(len(A)):
        counter = 0
        ans = 0
        for j in range(len(A)):
                if A[i] & A[j] == A[i]:
                        counter += 1
                if counter == K:
                        ans = A[j]
                        break
        if ans != 0:
                break

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,k=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]

tmp=[]
cnt=0
for i in range(len(data)):
    for j in range(len(data)-i):
        tmp.append(((sum(data[i:1+i+j]))))
        cnt+=1
beat_v=sorted(tmp)
tmp2 = list(map(lambda x: len(bin(x)), beat_v))

#同じ桁のbit列がK個以上あるか探索
cnt2=0
maxbit=tmp2[-1]
res=0
for l in reversed(tmp2):
    if maxbit==l:
        cnt2+=1
    else :
        cnt2=1
    maxbit=l
    if cnt2==k:
        res=maxbit
        break
cnt3=0
for m in reversed(tmp2):
    if m != res:
        cnt3+=1
    else :
        break
        
res_=list(reversed(beat_v))[cnt3:cnt3+k]
result=res_[0]
for g in res_:
    result=result&g
print(result)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,k=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]

tmp=[]
cnt=0
for i in range(len(data)):
    for j in range(len(data)-i):
        tmp.append(((sum(data[i:1+i+j]))))
        cnt+=1
beat_v=sorted(tmp)
tmp2 = list(map(lambda x: len(bin(x)), beat_v))

#同じ桁のbit列がK個以上あるか探索
cnt2=0
maxbit=tmp2[-1]
res=0
for l in reversed(tmp2):
    if maxbit==l:
        cnt2+=1
    else :
        cnt2=0
    maxbit=l
    if cnt2==k:
        res=maxbit
        break
cnt3=0
for m in reversed(tmp2):
    if m != res:
        cnt3+=1
    else :
        break
        
res_=list(reversed(beat_v))[cnt3:cnt3+k]
result=res_[0]
for g in res_:
    result=result&g
print(result)