Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

ids = [x for x in range(n)]

store = list()
store.append(0)

for i in range(1, n+1):
    tmpcmb = list(itertools.combinations(ids, i))

    for k, i in enumerate(tmpcmb):
        tmpv = 0
        tmpc = 0
        for j in i:
            tmpv += v[j]
            tmpc += c[j]
        store.append(tmpv - tmpc)

result = max(store)
print(result)


Fixed submission:
import itertools
import sys

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

ids = [x for x in range(n)]

diff = [tmpv - tmpc for tmpv, tmpc in zip(v, c)]

result = 0

for i in range(1, n+1):
    tmp = list(itertools.combinations(diff, i))
    tmpMax = max([sum(x) for x in tmp])
    if tmpMax > result:
        result = tmpMax
    # store.extend([sum(x) for x in tmp])
    # print(store)
    # for x, y in zip(vset, cset):
    #     store.append(sum(x)-sum(y))

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import sys

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

ids = [x for x in range(n)]
# print(ids)
# sys.exit()
cmb = list()
for i in range(1, n+1):
    cmb += list(itertools.combinations(ids, i))
# print(cmb)

store = [0]*len(cmb)
store.append(0)

for k, i in enumerate(cmb):
    tmpv = 0
    tmpc = 0
    for j in i:
        tmpv += v[j]
        tmpc += c[j]
    store[k] = tmpv - tmpc

# print(store)
result = max(store)
print(result)


Fixed submission:
import itertools
import sys

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

ids = [x for x in range(n)]

diff = [tmpv - tmpc for tmpv, tmpc in zip(v, c)]

result = 0

for i in range(1, n+1):
    tmp = list(itertools.combinations(diff, i))
    tmpMax = max([sum(x) for x in tmp])
    if tmpMax > result:
        result = tmpMax
    # store.extend([sum(x) for x in tmp])
    # print(store)
    # for x, y in zip(vset, cset):
    #     store.append(sum(x)-sum(y))

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
import re

n = int(input())
s = input()

cntList = list()
for i in range(n+1):
    tmp = len(re.findall('#', s[:i]))
    tmp += len(re.findall('\.', s[i:]))
    cntList.append(tmp)

print(min(cntList))


Fixed submission:
import re

n = int(input())
s = input()
left = 0
right = len(re.findall('\.', s))

cnt = [left + right]
for i in range(n):
    if s[i] == '#':
        left += 1
    else:
        right -= 1
    cnt.append(left + right)

print(min(cnt))
Buggy python submission (verdict: Time Limit Exceeded):
A, B, Q = map(int, input().split())
s = [0]*A
for i in range(A):
    s[i] = int(input())
t = [0]*B
for i in range(B):
    t[i] = int(input())
x = [0]*Q
for i in range(Q):
    x[i] = int(input())

result = [100000]*Q
c = 0
for c, k in enumerate(x):
    shrine_f = 0
    temple_f = 0
    cand = list()
    # shrine first, get the min distance shrines
    s0 = [abs(s[i]-k) for i in range(A)]
    # print('s0', s0)
    min_s = min(s0)
    cand_s = [i for i, e in enumerate(s0) if e == min_s]
    # print(cand_s)
    for i in cand_s:
        t1 = [abs(t[j]-s[i]) for j in range(B)]
        cand.append(min_s + min(t1))

    # temple first
    t0 = [abs(t[i] - k) for i in range(B)]
    # print('t0', t0)
    min_t = min(t0)
    cand_t = [i for i, e in enumerate(t0) if e == min_t]
    # print(cand_t)
    for i in cand_t:
        s1 = [abs(s[j] - t[i]) for j in range(A)]
        # print('s1', s1)
        cand.append(min_t + min(s1))

    # print('cand', cand)
    result[c] = min(cand)

for i in result:
    print(i)


Fixed submission:
import bisect

A, B, Q = map(int, input().split())
s = [0]*A
for i in range(A):
    s[i] = int(input())
t = [0]*B
for i in range(B):
    t[i] = int(input())
X = [0]*Q
for i in range(Q):
    X[i] = int(input())

INF = 10 ** 18
s = [-INF] + s + [INF]
t = [-INF] + t + [INF]

for x in X:
    sr, tr = bisect.bisect_right(s, x), bisect.bisect_left(t, x)
    res = INF
    for S in [s[sr-1], s[sr]]:
        for T in [t[tr-1], t[tr]]:
            d1, d2 = abs(S-x)+abs(T-S), abs(T-x)+abs(S-T)
            res = min(res, d1, d2)
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, Q = map(int, input().split())
s = [0]*A
for i in range(A):
    s[i] = int(input())
t = [0]*B
for i in range(B):
    t[i] = int(input())
x = [0]*Q
for i in range(Q):
    x[i] = int(input())

result = [0]*Q
c = 0
for k in x:
    cand = list()
    for sk in s:
        for tk in t:
            if abs(sk-k) < abs(tk-k):
                cand.append(abs(sk-k)+abs(sk-tk))
            else:
                cand.append(abs(tk - k) + abs(sk - tk))
    result[c] = min(cand)
    c += 1

for i in result:
    print(i)

Fixed submission:
import bisect

A, B, Q = map(int, input().split())
s = [0]*A
for i in range(A):
    s[i] = int(input())
t = [0]*B
for i in range(B):
    t[i] = int(input())
X = [0]*Q
for i in range(Q):
    X[i] = int(input())

INF = 10 ** 18
s = [-INF] + s + [INF]
t = [-INF] + t + [INF]

for x in X:
    sr, tr = bisect.bisect_right(s, x), bisect.bisect_left(t, x)
    res = INF
    for S in [s[sr-1], s[sr]]:
        for T in [t[tr-1], t[tr]]:
            d1, d2 = abs(S-x)+abs(T-S), abs(T-x)+abs(S-T)
            res = min(res, d1, d2)
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

N = int(input())
A = list(map(int, input().split()))
gcd_max = 0
for i in range(N):
    a_temp = A[:i]
    a_temp.extend(A[i + 1:])
    gcd_temp = a_temp[0]
    for a in a_temp:
        gcd_temp = fractions.gcd(gcd_temp, a)
        if gcd_temp <= gcd_max:
            break
    else:
        gcd_max = gcd_temp
print(gcd_max)


Fixed submission:
import fractions

N = int(input())
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i in range(0, N - 1):
    L[i + 1] = fractions.gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
    R[i - 1] = fractions.gcd(R[i], A[i])
print(max([fractions.gcd(L[i], R[i]) for i in range(N)]))
Buggy python submission (verdict: Runtime Error):
times = [int(input()) for _ in range(5)]
fraction = max([10 - t % 10 for t in times if t % 10 != 0])
if fraction == 10:
    fraction = 0
print(sum([(t - t % 10) + ((t % 10 + 9) // 10) * 10 for t in times]) - fraction)



Fixed submission:
times = [int(input()) for _ in range(5)]
fractions = [10 - t % 10 for t in times if t % 10 != 0]
if fractions:
    fraction = max(fractions)
else:
    fraction = 0
print(sum([(t - t % 10) + ((t % 10 + 9) // 10) * 10 for t in times]) - fraction)
Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)[:K]
B = sorted(map(int, input().split()), reverse=True)[:K]
C = sorted(map(int, input().split()), reverse=True)[:K]

AB = sorted([a + b for a in A for b in B], reverse=True)[:K]
ABC = sorted([ab + c for ab in AB for c in C], reverse=True)[:K]
for v in ABC:
    print(v)


Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

for cakes in A, B, C:
    cakes.sort(reverse=True)

cake_values = []
for i in range(len(A)):
    if i + 1 > K:
        break
    for j in range(len(B)):
        if (i + 1) * (j + 1) > K:
            break
        for k in range(len(C)):
            if (i + 1) * (j + 1) * (k + 1) > K:
                break
            cake_values.append(A[i] + B[j] + C[k])
cake_values.sort(reverse=True)
for i in range(K):
    print(cake_values[i])
Buggy python submission (verdict: Runtime Error):
        H,W = map(int,input().split())
        s = [list(input()) for _ in range(H)]
        dir4 = ((0, 1), (0, -1), (1, 0), (-1, 0))
        for i in range(H):
            for j in range(W):
                if s[i][j] == ".": continue
                cnt = 0
                for d in dir4:
                    nx = i + d[0]
                    ny = j + d[1]
                    if not (0 <= nx < H): continue
                    if not (0 <= ny < W): continue
                    if s[nx][ny] == "#": cnt += 1
                if cnt == 0:
                    print("No")
                    exit()
        print("Yes")


Fixed submission:
def main():
    input = sys.stdin.readline
    try:
        H,W = map(int,input().split())
        s = [list(input()) for _ in range(H)]
        dir4 = ((0, 1), (0, -1), (1, 0), (-1, 0))
        for i in range(H):
            for j in range(W):
                if s[i][j] == ".": continue
                cnt = 0
                for d in dir4:
                    nx = i + d[0]
                    ny = j + d[1]
                    if not (0 <= nx < H): continue
                    if not (0 <= ny < W): continue
                    if s[nx][ny] == "#": cnt += 1
                if cnt == 0:
                    print("No")
                    exit()
        print("Yes")
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    input = sys.stdin.readline
    input = open("stdin.txt").readline
    try:
        N = int(input())
        A1 = list(map(int, input().split()))
        A2 = list(map(int, input().split()))
        
        if N == 1:
            print(A1[0] + A2[0])
            return
        dp = [[0]*2 for _ in range(N-1)]
        dp[0][0] = A1[0] + A1[1]
        dp[0][1] = A1[0] + A2[0]

        for i in range(1, N - 1):
            dp[i][0] = dp[i-1][0] + A1[i+1]
            dp[i][1] = max(dp[i-1][0], dp[i-1][1]) + A2[i]
        
        ans = max(dp[N-2][0], dp[N-2][1]) + A2[N-1]
        print(ans)
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()


Fixed submission:
def main():
    input = sys.stdin.readline
    try:
        N = int(input())
        A1 = list(map(int, input().split()))
        A2 = list(map(int, input().split()))
        
        if N == 1:
            print(A1[0] + A2[0])
            return
        dp = [[0]*2 for _ in range(N-1)]
        dp[0][0] = A1[0] + A1[1]
        dp[0][1] = A1[0] + A2[0]

        for i in range(1, N - 1):
            dp[i][0] = dp[i-1][0] + A1[i+1]
            dp[i][1] = max(dp[i-1][0], dp[i-1][1]) + A2[i]
        
        ans = max(dp[N-2][0], dp[N-2][1]) + A2[N-1]
        print(ans)
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    input = sys.stdin.readline
    try:
        a, b, c = map(int, input().split())
        for i in range(a, 100000000, a):
            if i % b == c:
                print("YES")
                break
        else:
            print("NO")

    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()


Fixed submission:
def main():
    input = sys.stdin.readline
    try:
        a, b, c = map(int, input().split())
        for i in range(a, a * b, a):
            if i % b == c:
                print("YES")
                break
        else:
            print("NO")

    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = input()
s = list(a)

i = 0
while i<len(s) and s[i] == '.':
  i+=1
j = n-1
while i>=0 and s[j] == '#':
  j-=1

s = s[i:j+1]
print(min(s.count('#'),s.count('.')))


Fixed submission:
n = int(input())
a = input()
s = a

i = 0
while i<len(s) and s[i] == '.':
  i+=1
j = n-1
while j>=0 and s[j] == '#':
  j-=1

s = s[i:j+1]
r = min(s.count('#'), s.count('.'))

w = s.count('.')
b = 0
c = 0
for i in range(len(s)):
  if s[i] == '#':
    b += 1
  else:
    w -= 1
  r = min(r, w+b)

print(r)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = input()
s = list(a)

i = 0
while i<len(s) and s[i] == '.':
  i+=1
j = n-1
while i>=0 and s[j] == '#':
  j-=1

s = s[i:j]
print(min(s.count('#'),s.count('.')))


Fixed submission:
n = int(input())
a = input()
s = a

i = 0
while i<len(s) and s[i] == '.':
  i+=1
j = n-1
while j>=0 and s[j] == '#':
  j-=1

s = s[i:j+1]
r = min(s.count('#'), s.count('.'))

w = s.count('.')
b = 0
c = 0
for i in range(len(s)):
  if s[i] == '#':
    b += 1
  else:
    w -= 1
  r = min(r, w+b)

print(r)
Buggy python submission (verdict: Runtime Error):
from math import *
from functools import *

n = int(input())
print(reduce(gcd, map(int, input().split())))


Fixed submission:
from fractions import *
from functools import *

n = int(input())
print(reduce(gcd, map(int, input().split())))
Buggy python submission (verdict: Runtime Error):
import math

n, m = list(map(int, input().split()))
s = input()
t = input()

l = n * m // math.gcd(n,m)

a = l // n
b = l // m

for i in range(0, l, a*b):
    if s[i // a] != t[i // b]:
        print(-1)
        break
else:
    print(l)

Fixed submission:
import fractions

n, m = list(map(int, input().split()))
s = input()
t = input()

l = n * m // fractions.gcd(n,m)

a = l // n
b = l // m

for i in range(0, l, a*b):
    if s[i // a] != t[i // b]:
        print(-1)
        break
else:
    print(l)
Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))

if m == 1:
    print(0)
    exit()

x.sort()

z = []
for i in range(len(x) - 1):
    z.append(abs(x[i] - x[i + 1]))

z.sort()
for _ in range(n - 1):
    z.pop()

print(sum(z))

Fixed submission:
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))

if m == 1:
    print(0)
    exit()

x.sort()

z = []
for i in range(len(x) - 1):
    z.append(abs(x[i] - x[i + 1]))

z.sort()
for _ in range(n - 1):
    if len(z) > 0:
        z.pop()

print(sum(z))
Buggy python submission (verdict: Runtime Error):
ab, bc, ca = list(map(int, input().split()))

print(int(ab * bc / 2)

Fixed submission:
ab, bc, ca = list(map(int, input().split()))
 
print(int(ab * bc / 2))
Buggy python submission (verdict: Runtime Error):
import math

n, x = list(map(int, input().split()))

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

ans = 1000000001
for i in range(n):
    v = abs(x - a[i])

    if v < ans:
        ans = v

    gcd = math.gcd(v, ans)
    if gcd < ans:
        ans = gcd

print(ans)

Fixed submission:
n, x = list(map(int, input().split()))

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

def gcd(la, lb):
    if la < lb:
        tmp = a
        la = lb
        lb = tmp

    r = la % lb

    while r != 0:
        la = lb
        lb = r
        r = la % lb

    return lb

ans = 1000000001
for i in range(n):
    v = abs(x - a[i])

    if v < ans:
        ans = v

    g = gcd(v, ans)
    if g < ans:
        ans = g

print(ans)
Buggy python submission (verdict: Runtime Error):
1, y1, x2, y2 = list(map(int, input().split()))

xx = x2 - x1
yy = y2 - y1

x3 = x2 - yy
y3 = y2 + xx
x4 = x3 - xx
y4 = y3 - yy

print(x3, y3, x4, y4)

Fixed submission:
x1, y1, x2, y2 = list(map(int, input().split()))

xx = x2 - x1
yy = y2 - y1

x3 = x2 - yy
y3 = y2 + xx
x4 = x3 - xx
y4 = y3 - yy

print(x3, y3, x4, y4)
Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))

print(a[0] * a[1] - (1 * a[0]) - (1 * a[1

Fixed submission:
a = list(map(int, input().split()))

print(a[0] * a[1] - (1 * a[0]) - (1 * a[1]) + 1)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = N % K
if A == 0:
    print(0)
else:
    else(1)

Fixed submission:
N, K = map(int, input().split())
A = N % K
if A == 0:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for ai in a:
   for i in range(1,int(ai**0.5)+1):
    if ai%i==0:
        d[i] += 1
        if i!=ai//i:
            d[ai//i] += 1

sd=sorted(d.items(),key=lambda x:x[0],reverse=True)
for k,v in sd:
    if v==n or v==n-1:
        print(k)
        break

Fixed submission:
def gcd(a,b):
    while a%b!=0:
        a,b = b,a%b
    return b
n = int(input())
a = list(map(int,input().split()))
right,left = [0]*n,[0]*n
left[0],right[n-1] = a[0],a[n-1]
for i in range(1,n):
    left[i] = gcd(left[i-1],a[i])
for i in range(n-2,-1,-1):
    right[i] = gcd(right[i+1],a[i])
ans = max(left[-2],right[1])
for i in range(1,n-1):
    ans = max(ans,gcd(right[i+1],left[i-1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = len(S)
zc,oc = 0,0
for i in range(N):
    if S[i]=='1':
        oc += 1
    else:
        zc += 1
print(2*min(oc,zc))

Fixed submission:
S = input()
N = len(S)
zc,oc = 0,0
for i in range(N):
    if S[i]=='1':
        oc += 1
    else:
        zc += 1
print(2*min(oc,zc))
Buggy python submission (verdict: Runtime Error):
N=int(input())
btc=380000
ans=0
for i in range(N):
  x,u=map(str,input().split())
  x = int(x)
  if u=='BTC':
    x *= btc
  ans += x
print(ans)

Fixed submission:
N = int(input())
btc = 380000
ans = 0
for i in range(N):
    x,u = map(str,input().split())
    x = float(x)
    if u=='BTC':
        x *= btc
    ans += x
print(ans)
Buggy python submission (verdict: Runtime Error):
x.t = map(int,input().split())
print(x/t)

Fixed submission:
t,x = map(int,input().split())
print(t/x)
Buggy python submission (verdict: Runtime Error):
if S[0:7]=='keyence':
    OK = True
elif S[l-7:]=='keyence':
    OK = True
elif S[l-6:]=='eyence' and S[0]=='k':
    OK = True
elif S[l-5:]=='yence' and S[:2]=='ke':
    OK = True
elif S[l-4:]=='ence' and S[:3]=='key':
    OK = True
elif S[l-3:]=='nce' and S[:4]=='keye':
    OK = True
elif S[l-2:]=='ce' and S[:5]=='keyen':
    OK = True
elif S[l-1:]=='e' and S[:6]=='keyenc':
    OK = True
else:
    OK = False
print('YES' if OK else 'NO')



Fixed submission:
S = input()
l = len(S)
OK = False
if S[0:7]=='keyence':
    OK = True
elif S[l-7:]=='keyence':
    OK = True
elif S[l-6:]=='eyence' and S[0]=='k':
    OK = True
elif S[l-5:]=='yence' and S[:2]=='ke':
    OK = True
elif S[l-4:]=='ence' and S[:3]=='key':
    OK = True
elif S[l-3:]=='nce' and S[:4]=='keye':
    OK = True
elif S[l-2:]=='ce' and S[:5]=='keyen':
    OK = True
elif S[l-1:]=='e' and S[:6]=='keyenc':
    OK = True
else:
    OK = False
print('YES' if OK else 'NO')
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(int(input()) for i in range(N))
h.sort(reverse=True)
cnt = 0
ans = []
dif = float('inf') 
for i in range(N):
    if K-1<=i:
        if dif>ans[0]-h[i]:
            dif = ans[0]-h[i]
        del ans[0]
    ans.append(h[i])
print(dif) 

Fixed submission:
N,K = map(int,input().split())
h = list(int(input()) for i in range(N))
h.sort(reverse=True)
dif = float('inf') 
for i in range(K-1,N):
    dif = min(dif,h[i-K+1]-h[i])
print(dif)
Buggy python submission (verdict: Runtime Error):
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
s = subs[:]
for i in range(n+1):
    subs = list(filter(lambda x:(x//m)%2==1,s))
    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)


Fixed submission:
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 &= t[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
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,m = 0,2**n
for i in range(n)[::-1]:
    subs = list(filter(lambda x:x-(2**i)>=0,s))
    l = len(subs)
    if l>=K:
        s = subs[:]
    else:
        m //= 2
for i in range(n+1):
    subs = list(filter(lambda x:x%(2**m)==1,s))
    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)


Fixed submission:
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 &= t[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    if b==0:
        return a
    else:
        return gcd(b, a%b)
N,M = map(int,input().split())
S,T = input(),input()
lcm = N*M//gcd(N,M)
s = ['*']*lcm
for i in range(N):
    n = i*(lcm//N)
    if s[n]=='*' or s[n]==S[i]:
        s[n] = S[i]
OK = True
for i in range(M):
    n = i*(lcm//M)
    if not (s[n]=='*' or s[n]==T[i]):
        OK = False
print(lcm if OK else -1)


Fixed submission:
def gcd(a, b):
    if b==0:
        return a
    else:
        return gcd(b, a%b)
N,M = map(int,input().split())
l = gcd(N,M)
S,T = input(),input()
OK = True
for i in range(l):
    ns = i*(N//l)
    nt = i*(M//l)
    if not S[ns]==T[nt]:
        OK = False
print((N*M)//l if OK else -1)

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    if b==0:
        return a
    else:
        return gcd(b, a%b)

N,M = map(int,input().split())
S,T = input(),input()
lcm = N*M//gcd(N,M)
s = ['*']*lcm
for i in range(N):
    n = 0 if i==0 else i*(len(s)//N)
    if s[n]=='*' or s[n]==S[i]:
        s[n] = S[i]
OK = True
for i in range(M):
    n = 0 if i==0 else i*(len(s)//M)
    if not (s[n]=='*' or s[n]==T[i]):
        OK = False
print(lcm if OK else -1)


Fixed submission:
def gcd(a, b):
    if b==0:
        return a
    else:
        return gcd(b, a%b)
N,M = map(int,input().split())
l = gcd(N,M)
S,T = input(),input()
OK = True
for i in range(l):
    ns = i*(N//l)
    nt = i*(M//l)
    if not S[ns]==T[nt]:
        OK = False
print((N*M)//l if OK else -1)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
div = 1
for i in range(2,M//N+1):
    if M%i==0:
        div = i
print(div)


Fixed submission:
N,M = map(int,input().split())
div = 1
for i in range(2,M//N+1)[::-1]:
    if M%i==0:
        div = i
        break
print(div)