Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
T = int(input())

for _ in range(T):
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    DP = [set() for _ in range(N+1)]
    DP[N].add(0)
    for i in range(N-1, -1, -1):
        if S[i] == '0':
            for x in DP[i+1]:
                DP[i].add(x)
                DP[i].add(x ^ A[i])
        else:
            if A[i] in DP[i+1]:
                for x in DP[i+1]:
                    DP[i].add(x)

    if 0 in DP[0]:
        print(0)
    else:
        print(1)

Fixed submission:
T = int(input())

for _ in range(T):
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    l = []
    ans = 0
    
    for a, s in zip(A[::-1], S[::-1]):
        for b in l:
            a = min(a, a^b)
        if a != 0:
            if s == '1':
                ans = 1
            l.append(a)
    
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
T = int(input())

for _ in range(T):
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    DP = [set() for _ in range(N+1)]
    DP[N].add(0)
    for i in range(N-1, -1, -1):
        if S[i] == '0':
            for x in DP[i+1]:
                DP[i].add(x)
                DP[i].add(x ^ A[i])
        else:
            if A[i] in DP[i+1]:
                for x in DP[i+1]:
                    DP[i].add(x)

    if 0 in DP[0]:
        print(0)
    else:
        print(1)

Fixed submission:
T = int(input())

for _ in range(T):
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    l = []
    ans = 0
    
    for a, s in zip(A[::-1], S[::-1]):
        for b in l:
            a = min(a, a^b)
        if a != 0:
            if s == '1':
                ans = 1
            l.append(a)
    
    print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = map(int,input().split())
ans = int(A*B)
print(ans)

Fixed submission:
A, B = input().split()
A = int(A)
C, D = B.split('.')
B = 100 * int(C) + int(D)
ans = A * B // 100
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
A = list(map(int,input().split()))
A = [0] + A
L = []
S = set()
i = 1
cnt = 0
while not i in S or cnt != K:
    S.add(i)
    L.append(i)
    cnt += 1
    i = A[i]

if cnt == K:
    print(i)
else:
    j = L.index(i)
    ans = L[(j + (K - j) % (cnt - j)) % cnt]
    print(ans)

Fixed submission:
N, K = map(int,input().split())
A = list(map(int,input().split()))
A = [0] + A
L = []
S = set()
i = 1
cnt = 0
while (not i in S) and cnt != K:
    S.add(i)
    L.append(i)
    cnt += 1
    i = A[i]

if cnt == K:
    print(i)
else:
    j = L.index(i)
    ans = L[(j + (K - j) % (cnt - j)) % cnt]
    print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int,input().split())
L = []
def dfs(List):
    if len(List) == N - 1:
        L.append([0] + List)
    else:
        k = List[-1]
        for i in range(M-k):
            n_L = List[:]
            n_L.append(k+i)
            dfs(n_L)
for i in range(M):
    dfs([i])

MAX = 0
for l in L:
    cnt = 0
    for _ in range(Q):
        a, b, c, d = map(int,input().split())
        if l[b-1] - l[a-1] == c:
            cnt += d
    MAX = max(cnt, MAX)
print(MAX)

Fixed submission:
N, M, Q = map(int,input().split())
L = []
def dfs(List):
    if len(List) == N - 1:
        L.append([0] + List)
    else:
        k = List[-1]
        for i in range(M-k):
            n_L = List[:]
            n_L.append(k+i)
            dfs(n_L)
for i in range(M):
    dfs([i])

Qs = []
for _ in range(Q):
    Qs.append(list(map(int,input().split())))

MAX = 0
for l in L:
    cnt = 0
    for a, b, c, d in Qs:
        if l[b-1] - l[a-1] == c:
            cnt += d
    MAX = max(cnt, MAX)
print(MAX)

Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int,input().split())
L = []
def dfs(List):
    if len(List) == N - 1:
        L.append([0] + List)
    else:
        k = List[-1]
        for i in range(M-k):
            n_L = List[:]
            n_L.append(k+i)
            dfs(n_L)
for i in range(M):
    dfs([i])

MAX = 0
for l in L:
    cnt = 0
    for _ in range(Q):
        a, b, c, d = map(int,input().split())
        if l[b-1] - l[a-1] == c:
            cnt += d
    MAX = max(cnt, MAX)
print(MAX)

Fixed submission:
N, M, Q = map(int,input().split())
L = []
def dfs(List):
    if len(List) == N - 1:
        L.append([0] + List)
    else:
        k = List[-1]
        for i in range(M-k):
            n_L = List[:]
            n_L.append(k+i)
            dfs(n_L)
for i in range(M):
    dfs([i])

Qs = []
for _ in range(Q):
    Qs.append(list(map(int,input().split())))

MAX = 0
for l in L:
    cnt = 0
    for a, b, c, d in Qs:
        if l[b-1] - l[a-1] == c:
            cnt += d
    MAX = max(cnt, MAX)
print(MAX)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
B = [i for i in range(1,N+1)]
C = zip(A, B)
C = sorted(C, reverse = True)
A, B = zip(*C)
dp = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
    for j in range(i + 2):
        if j == 0:
            dp[0][i-j+1] = dp[0][i-j] + A[i] * (N - (i - j) - B[i])
        elif j == i+1:
            dp[j][0] = dp[j-1][0] + A[i] * (B[i] - j)
        else:
            dp[j][i-j+1] = max(dp[j][i-j] + A[i] * (N - (i - j) - B[i]), dp[j-1][i-j+1] + A[i] * (B[i] - j))
ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = [i for i in range(1,N+1)]
C = zip(A, B)
C = sorted(C, reverse = True)
A, B = zip(*C)
dp = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
    for j in range(i + 2):
        if j == 0:
            dp[0][i-j+1] = dp[0][i-j] + A[i] * (N - (i - j) - B[i])
        elif j == i+1:
            dp[j][0] = dp[j-1][0] + A[i] * (B[i] - j)
        else:
            dp[j][i-j+1] = max(dp[j][i-j] + A[i] * (N - (i - j) - B[i]), dp[j-1][i-j+1] + A[i] * (B[i] - j))
ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

P = [A[0]]
Q = [A[1]]
for i in range(2,N):
    if i % 2 == 0:
        P.append(P[-1] + A[i])
    else:
        Q.append(Q[-1] + A[i])

if N % 2 == 0:
    ans = max(P[-1],Q[-1])
    for i in range(N//2-1):
        ans = max(ans,P[i]+Q[-1]-Q[i])
else:
    ans = max(Q[-1],P[-1] - min(A[0::2]))
    ans = max(ans, Q[-2]-Q[0]+A[0]+A[-1])
    for i in range(N//2-1):
        ans = max(ans,P[i]+Q[-1]-Q[i])
    for i in range(N//2-1):
        ans = max(ans,P[-1]-P[i+1]+Q[i])
print(ans)

Fixed submission:
from collections import defaultdict
INF = 10 ** 15
N = int(input())
A = list(map(int,input().split()))
dp_take = defaultdict(lambda: -INF)
dp_not = defaultdict(lambda: -INF)
dp_take[(0,0)] = 0
dp_not[(0,0)] = 0

for i in range(N):
    for j in range((i + 1) // 2 - 1, (i + 2) // 2 + 1):
        if j > 0:
            dp_take[(i+1, j)] = max(dp_take[(i+1, j)], dp_not[(i, j-1)] + A[i])
        dp_not[(i+1, j)] = max(dp_not[(i, j)], dp_take[(i, j)])

print(max(dp_take[(N, N//2)], dp_not[(N, N//2)]))
Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int,input().split())

S = [set() for i in range(N)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return set([i for i in range(self.n) if self.find(i) == root])
    

UFT = UnionFind(N)

for _ in range(M):
    A, B = map(int,input().split())
    S[A-1].add(B-1)
    S[B-1].add(A-1)
    UFT.union(A-1,B-1)
for _ in range(K):
    C, D = map(int,input().split())
    S[C-1].add(D-1)
    S[D-1].add(C-1)

ans = []
for i in range(N):
    ans.append(UFT.size(i) - len(UFT.members(i) & S[i]) - 1)
print(*ans)

Fixed submission:
N, M, K = map(int,input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

UFT = UnionFind(N)
ans = [0 for _ in range(N)]

for _ in range(M):
    A, B = map(int,input().split())
    ans[A-1] -= 1
    ans[B-1] -= 1
    UFT.union(A-1, B-1)

for _ in range(K):
    C, D = map(int,input().split())
    if UFT.same(C-1, D-1):
        ans[C-1] -= 1
        ans[D-1] -= 1

ans = [UFT.size(i) + ans[i] - 1 for i in range(N)]

print(*ans)
Buggy python submission (verdict: Runtime Error):
N, R = map(int,input().split())
if N >= 10:
    print(R)
else:
    print(R + 100 * (10 - K))

Fixed submission:
N, R = map(int,input().split())
if N >= 10:
    print(R)
else:
    print(R + 100 * (10 - N))
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int,input().split())
mod = 10 ** 9 + 7

def permutation(n,r):
    perm = 1
    for integer in range(n-r+1, n+1):
        perm *= integer
    return perm

def RepeatSquaring(x, n, m):
  ans = 1
  while(n > 0):
    if(bin(n & 1) == bin(1)):
      ans = (ans*x)%m
    x = (x*x)%m
    n = n >> 1
  return ans

def cmb(n, r, mod):
    nume = permutation(n,r)
    deno = permutation(r,r)
    return (nume * RepeatSquaring(deno, mod-2, mod)) % mod

ans = RepeatSquaring(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod)

print(ans)

Fixed submission:
n, a, b = map(int,input().split())
mod = 10 ** 9 + 7

def permutation(n,r,mod):
    perm = 1
    for integer in range(n-r+1, n+1):
        perm *= integer
        perm %= mod
    return perm

def RepeatSquaring(x, n, m):
  ans = 1
  while(n > 0):
    if(bin(n & 1) == bin(1)):
      ans = (ans*x)%m
    x = (x*x)%m
    n = n >> 1
  return ans

def cmb(n, r, mod):
    nume = permutation(n,r,mod)
    deno = permutation(r,r,mod)
    return (nume * RepeatSquaring(deno, mod-2, mod)) % mod

ans = (RepeatSquaring(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod)) % mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
word_list = []
count_list = []
for i in range(N):
    tmp = input()
    if tmp in word_list:
        count_list[word_list.index(tmp)] += 1
    else:
        word_list.append(tmp)
        count_list.append(1)
        
MAX = -1
for i in range(len(count_list)):
    if count_list[i]>MAX:
        MAX = count_list[i]

        
ans_list = []
for i in range(len(count_list)):
    if count_list[i]==MAX:
        ans_list.append(word_list[i])

ans_list.sort()

for ans in ans_list:
    print(ans)

Fixed submission:
N = int(input())
S = []
for i in range(N):
    S.append(input())
S.sort()
MAX = 0
cnt = 0
WORD = []
for i in range(N):
    if i == 0:
        cnt = 1
        MAX = 1
        WORD.append(S[i])
    elif S[i] == S[i-1]:
        cnt+=1
        if cnt == MAX:
            WORD.append(S[i])
        if cnt > MAX:
            MAX = cnt
            WORD.clear()
            WORD.append(S[i])
    else:
        cnt = 1
        if cnt == MAX:
            WORD.append(S[i])

for ans in WORD:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
word_list = []
count_list = []
for i in range(N):
    tmp = input()
    if tmp in word_list:
        count_list[word_list.index(tmp)] += 1
    else:
        word_list.append(tmp)
        count_list.append(1)
        
MAX = -1
for i in range(len(count_list)):
    if count_list[i]>MAX:
        MAX = count_list[i]

        
ans_list = []
for i in range(len(count_list)):
    if count_list[i]==MAX:
        ans_list.append(word_list[i])

ans_list.sort()

for ans in ans_list:
    print(ans)

Fixed submission:
N = int(input())
S = []
for i in range(N):
    S.append(input())
S.sort()
MAX = 0
cnt = 0
WORD = []
for i in range(N):
    if i == 0:
        cnt = 1
        MAX = 1
        WORD.append(S[i])
    elif S[i] == S[i-1]:
        cnt+=1
        if cnt == MAX:
            WORD.append(S[i])
        if cnt > MAX:
            MAX = cnt
            WORD.clear()
            WORD.append(S[i])
    else:
        cnt = 1
        if cnt == MAX:
            WORD.append(S[i])

for ans in WORD:
    print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
for i in range(len(S)):
    print(x,end="")

Fixed submission:
S = input()
for i in range(len(S)):
    print("x",end="")
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
P = list(map(int,input().split()))
MAX = 0
for i in range(N-K+1):
    tmp = sum(P[i:i+K])
    if MAX < tmp:
        MAX = tmp
print((MAX+K)/2)

Fixed submission:
N, K = map(int,input().split())
P = list(map(int,input().split()))
LIST = [0]
for i in range(N):
    LIST.append(LIST[i]+P[i])
MAX = 0
for i in range(N-K+1):
    tmp = LIST[i+K]-LIST[i]
    if MAX < tmp:
        MAX = tmp
print((MAX+K)/2)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
P = list(map(int,input().split()))
MAX = 0
for i in range(N-K+1):
    tmp = sum(P[i:i+K])
    if MAX < tmp:
        MAX = tmp
print((MAX+K)/2)

Fixed submission:
N, K = map(int,input().split())
P = list(map(int,input().split()))
LIST = [0]
for i in range(N):
    LIST.append(LIST[i]+P[i])
MAX = 0
for i in range(N-K+1):
    tmp = LIST[i+K]-LIST[i]
    if MAX < tmp:
        MAX = tmp
print((MAX+K)/2)
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int,input().split())
A = []
B = []
dp = [None for i in range(2*10**4)]
dp[0] = 0
for i in range(N):
    tmp_A, tmp_B = map(int,input().split())
    A.append(tmp_A)
    B.append(tmp_B)
for i in range(2*10**4):
    for j in range(N):
        if i-A[j]<0:
            pass
        elif dp[i-A[j]]!=None:
            if dp[i]==None:
                dp[i]=dp[i-A[j]]+B[j]
            else:
                dp[i]=min(dp[i],dp[i-A[j]]+B[j])

ans = 10**16
for i in range(H,2*10**4):
    if dp[i]!=None:
        if dp[i]<ans:
            ans = dp[i]
print(ans)

Fixed submission:
H, N = map(int,input().split())
A = []
B = []
dp = [None for i in range(2*10**4)]
dp[0] = 0
for i in range(N):
    tmp_A, tmp_B = map(int,input().split())
    A.append(tmp_A)
    B.append(tmp_B)
for i in range(2*10**4):
    for j in range(N):
        if i-A[j]<0:
            pass
        elif dp[i-A[j]]!=None:
            if dp[i]==None:
                dp[i]=dp[i-A[j]]+B[j]
            else:
                dp[i]=min(dp[i],dp[i-A[j]]+B[j])

ans = 10**16
for i in range(H,2*10**4):
    if dp[i]!=None:
        if dp[i]<ans:
            ans = dp[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import fraction
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fraction.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

LCM = lcm_list(A)
ans = 0

for i in range(N):
    ans+=LCM//A[i]
print(ans%mod)

Fixed submission:
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

LCM = lcm_list(A)
ans = 0

for i in range(N):
    ans+=LCM//A[i]
print(ans%mod)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)#fraction

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

LCM = lcm_list(A)
ans = 0

for i in range(N):
    ans+=LCM//A[i]
print(ans%mod)

Fixed submission:
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

LCM = lcm_list(A)
ans = 0

for i in range(N):
    ans+=LCM//A[i]
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10000
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f

dp = [[INF for i in range(N)] for j in range(1 << N)]

for i in range(N):
    dp[1 << i][i] = i

for i in range(1 << N):
    for j in range(N):
        if i >> j & 1:
            if (popcount(i) - j) % 2 != 0:
                num = A[j]
            else:
                num = B[j]
            cnt = 0
            for k in range(N):
                if not (i >> k & 1):
                    if (popcount(i) - k) % 2 == 0:
                        num2 = A[k]
                    else:
                        num2 = B[k]
                    if num <= num2:
                        dp[i | 1 << k][k] = min(dp[i | 1 << k][k], dp[i][j] + cnt)
                    cnt += 1

ans = INF
for i in range(N):
    ans = min(ans, dp[(1 << N) - 1][i])

if ans == INF:
    print(-1)
else:
    print(ans)

Fixed submission:
INF = 10000
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f

dp = [[INF for i in range(N)] for j in range(1 << N)]

for i in range(N):
    dp[1 << i][i] = i

for i in range(1 << N):
    for j in range(N):
        if i >> j & 1:
            if (popcount(i) - j) % 2 != 0:
                num = A[j]
            else:
                num = B[j]
            cnt = 0
            for k in range(N):
                if not (i >> k & 1):
                    if (popcount(i) - k) % 2 == 0:
                        num2 = A[k]
                    else:
                        num2 = B[k]
                    if num <= num2:
                        dp[i | 1 << k][k] = min(dp[i | 1 << k][k], dp[i][j] + cnt)
                    cnt += 1

ans = INF
for i in range(N):
    ans = min(ans, dp[(1 << N) - 1][i])

if ans == INF:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import queue

H, W = map(int,input().split())
MAP = []
INF = 10 ** 8
x = 0
y = 1
dx = [1,0,-1,0]
dy = [0,1,0,-1]


for _ in range(H):
    MAP.append(list(input()))

def bfs(A,B):
    que = queue.Queue()
    d = [[INF for i in range(W)] for j in range(H)]
    que.put(A)
    d[A[x]][A[y]] = 0
    
    while que:
        p = que.get()
        if p == B:
            break
        for i in range(4):
            nx = p[x] + dx[i]
            ny = p[y] + dy[i]
            if 0 <= nx < H and 0 <= ny < W and MAP[nx][ny] != "#" and d[nx][ny] == INF:
                que.put([nx,ny])
                d[nx][ny] = d[p[x]][p[y]] + 1
    
    return d[B[x]][B[y]]

print(bfs([0,0],[H-1,0]),bfs([0,0],[0,W-1]),bfs([0,0],[H-1,W-1]),bfs([H-1,0],[0,W-1]),bfs([H-1,0],[H-1,W]),bfs([0,W-1],[H-1,W-1]))

Fixed submission:
import queue
 
H, W = map(int,input().split())
MAP = []
INF = 10 ** 8
x = 0
y = 1
dx = [1,0,-1,0]
dy = [0,1,0,-1]
 
 
for _ in range(H):
    MAP.append(list(input()))
 
def bfs(S):
    que = queue.Queue()
    d = [[INF for i in range(W)] for j in range(H)]
    que.put(S)
    d[S[x]][S[y]] = 0
    
    while not que.empty():
        p = que.get()
        for i in range(4):
            nx = p[x] + dx[i]
            ny = p[y] + dy[i]
            if 0 <= nx < H and 0 <= ny < W and MAP[nx][ny] != "#" and d[nx][ny] == INF:
                que.put([nx,ny])
                d[nx][ny] = d[p[x]][p[y]] + 1
    
    MAX = -1
    for i in range(H):
        for j in range(W):
            if d[i][j] != INF and MAX < d[i][j]:
                MAX = d[i][j]
    return MAX

ans = -1

for i in range(H):
    for j in range(W):
        if MAP[i][j] != "#":
            tmp = bfs([i,j])
            if ans < tmp:
                ans = tmp

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
from math import gcd
from functools import reduce

N, M = map(int,input().split())
a = list(map(int,input().split()))
a = np.array(a)
a = a // 2

def solve(p, q):
    cnt = 1
    while p % 2 == 0 and q % 2 == 0:
        cnt <<= 1
        p >>= 1
        q >>= 1
    if (p - q) % 2 != 0:
        return 0
    return p * q * cnt // gcd(p, q)
k = reduce(solve, a)
if k == 0:
    print(0)
else:
    ans = int((M / k + 1) / 2)
    print(ans)

Fixed submission:
from fractions import gcd
from functools import reduce

N, M = map(int,input().split())
a = list(map(int,input().split()))
a = [x // 2 for x in a]

def solve(p, q):
    g = gcd(p, q)
    p //= g
    q //= g
    if (p - q) % 2 == 1:
        return 0
    return p * q * g

k = reduce(solve, a)
if k == 0:
    print(0)
else:
    print(M // k - M // (k * 2))

Buggy python submission (verdict: Runtime Error):
import numpy as np
from math import gcd
from functools import reduce

N, M = map(int,input().split())
a = list(map(int,input().split()))
a = np.array(a)
a = a // 2

def solve(p, q):
    cnt = 1
    while p % 2 == 0 and q % 2 == 0:
        cnt <<= 1
        p >>= 1
        q >>= 1
    if (p - q) % 2 != 0:
        return 0
    return p * q * cnt // gcd(p, q)
k = reduce(solve, a)
if k == 0:
    print(0)
else:
    ans = (M / k + 1) // 2
    print(ans)

Fixed submission:
from fractions import gcd
from functools import reduce

N, M = map(int,input().split())
a = list(map(int,input().split()))
a = [x // 2 for x in a]

def solve(p, q):
    g = gcd(p, q)
    p //= g
    q //= g
    if (p - q) % 2 == 1:
        return 0
    return p * q * g

k = reduce(solve, a)
if k == 0:
    print(0)
else:
    print(M // k - M // (k * 2))

Buggy python submission (verdict: Runtime Error):
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
A = list(map(int,input().split()))
LCM = lcm_list(A)
print(int(((2*M)/LCM+1)/2))

Fixed submission:
from fractions import gcd
from functools import reduce

N, M = map(int,input().split())
a = list(map(int,input().split()))
a = [x // 2 for x in a]

def solve(p, q):
    g = gcd(p, q)
    p //= g
    q //= g
    if (p - q) % 2 == 1:
        return 0
    return p * q * g

k = reduce(solve, a)
if k == 0:
    print(0)
else:
    print(M // k - M // (k * 2))

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
A = list(map(int,input().split()))
LCM = lcm_list(A)
print(int(((2*M)/LCM+1)/2))

Fixed submission:
from fractions import gcd
from functools import reduce

N, M = map(int,input().split())
a = list(map(int,input().split()))
a = [x // 2 for x in a]

def solve(p, q):
    g = gcd(p, q)
    p //= g
    q //= g
    if (p - q) % 2 == 1:
        return 0
    return p * q * g

k = reduce(solve, a)
if k == 0:
    print(0)
else:
    print(M // k - M // (k * 2))