Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def popcount(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

n = int(input())
x = input()
mod = x.count("1")
U = 2**20
C = [0]*U
for i in range(1, U):
  q = popcount(i)
  C[i] = C[i%q] + 1
t_1 = 0
t_2 = 0
for j, s in enumerate(x):
  if s == "1":
    t_1 += pow(2, n-1-j, mod-1)
    t_1 %= mod-1
    t_2 += pow(2, n-1-j, mod+1)
    t_2 %= mod+1
for i in range(n):
  if x[i] == "1":
    temp = t_1
    temp -= pow(2, n-1-i, mod-1)
    temp %= mod-1
  else:
    temp = t_2
    temp += pow(2, n-1-i, mod+1)
    temp %= mod+1
  res = C[temp] + 1
  print(res)

Fixed submission:
def popcount(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

n = int(input())
x = input()
mod = x.count("1")
U = 2**20
C = [0]*U
for i in range(1, U):
  q = popcount(i)
  C[i] = C[i%q] + 1
t_1 = 0
t_2 = 0
for j, s in enumerate(x):
  if s == "1":
    if mod > 1:
      t_1 += pow(2, n-1-j, mod-1)
      t_1 %= mod-1
    t_2 += pow(2, n-1-j, mod+1)
    t_2 %= mod+1
for i in range(n):
  if x[i] == "1":
    if mod == 1:
      print(0)
      continue
    temp = t_1
    temp -= pow(2, n-1-i, mod-1)
    temp %= mod-1
  else:
    temp = t_2
    temp += pow(2, n-1-i, mod+1)
    temp %= mod+1
  res = C[temp] + 1
  print(res)
Buggy python submission (verdict: Runtime Error):
for i in"_"*365:print(i%26+1)

Fixed submission:
import sys
input = sys.stdin.readline

d = int(input())
C = tuple(map(int, input().split()))
S = tuple(tuple(map(int, input().split())) for _ in range(d))
ans = 0
R = [0]*26
for i in range(1, d+1):
  M = -float("inf")
  idx = -1
  for t in range(26):
    L = list(R)
    L[t] = i
    temp = S[i-1][t]
    for j, (c, l) in enumerate(zip(C, L)):
      temp -= c*(i-l)
    if M < temp:
      M = temp
      idx = t
  R[idx] = i
  print(idx+1)
Buggy python submission (verdict: Runtime Error):
?ddd1+**+p

Fixed submission:
a = int(input())
ans = a + a**2 + a*a*a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
  from collections import Counter
  n = int(input())
  A = tuple(map(int, input().split()))
  C = Counter(A)
  def f(n):
      divisors = []
      for i in range(1, int(n**0.5)+1):
          if n % i == 0:
              divisors.append(i)
              if i != n // i:
                  divisors.append(n//i)
      return divisors

  ans = 0
  for a in A:
      for j in f(a):
          if j == a:
              if C[j] > 1:
                  break
          else:
              if C[j] > 0:
                  break
      else:
          ans += 1
  print(ans)
if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
A = sorted(map(int, input().split()))
U = 10**6
B = [0]*(U+1)
C = Counter(A)
ans = 0
for a in A:
  if B[a]:
    continue
  if C[a] == 1:
    ans += 1
  for j in range(a, U+1, a):
    B[j] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
  from collections import Counter
  n = int(input())
  A = list(map(int, input().split()))
  C = Counter(A)
  def f(n):
      divisors = []
      for i in range(1, int(n**0.5)+1):
          if n % i == 0:
              divisors.append(i)
              if i != n // i:
                  divisors.append(n//i)
      return divisors

  ans = 0
  for a in A:
      for j in f(a):
          if j == a:
              if C[j] > 1:
                  break
          else:
              if C[j] > 0:
                  break
      else:
          ans += 1
  print(ans)
if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
A = sorted(map(int, input().split()))
U = 10**6
B = [0]*(U+1)
C = Counter(A)
ans = 0
for a in A:
  if B[a]:
    continue
  if C[a] == 1:
    ans += 1
  for j in range(a, U+1, a):
    B[j] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
def f(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
    
ans = 0
for a in A:
    for j in f(a):
        if j == a:
            if C[j] > 1:
                break
        else:
            if C[j] > 0:
                break
    else:
        ans += 1
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
A = sorted(map(int, input().split()))
U = 10**6
B = [0]*(U+1)
C = Counter(A)
ans = 0
for a in A:
  if B[a]:
    continue
  if C[a] == 1:
    ans += 1
  for j in range(a, U+1, a):
    B[j] = 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from itertools import accumulate

n, k = map(int, input().split())
A = tuple(map(int, input().split()))
for _ in range(k):
  C = [0]*n
  for i, a in enumerate(A):
    C[max(0, i-a)] += 1
    if i+a < n-1:
      C[i+a+1] -= 1
  A = tuple(accumulate(C))
  if min(A) == n:
    break
print(*A)

Fixed submission:
import sys
input = sys.stdin.readline
from itertools import accumulate

n, k = map(int, input().split())
A = tuple(map(int, input().split()))
for _ in range(k):
  C = [0]*n
  for i, a in enumerate(A):
    C[max(0, i-a)] += 1
    if i+a < n-1:
      C[i+a+1] -= 1
  A = tuple(accumulate(C))
  if min(A) == n:
    break
print(*A)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353
n, s = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1
for i, a in enumerate(A):
    for j in range(s+1):
        if j >= a:
            dp[i+1][j] = dp[i][j]*2 + dp[i][j-a]
        else:
            dp[i+1][j] = dp[i][j]*2
        dp[i+1][j] %= MOD
ans = dp[n][s]
print(ans)

Fixed submission:
MOD = 998244353
n, s = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1
for i, a in enumerate(A):
    for j in range(s+1):
        if j >= a:
            dp[i+1][j] = dp[i][j]*2 + dp[i][j-a]
        else:
            dp[i+1][j] = dp[i][j]*2
        dp[i+1][j] %= MOD
ans = dp[n][s]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n, k = map(int, input().split())
A = [0] + list(map(int, input().split()))
def f(i):
  if i == 1:
    return A
  L = [-1]*(n+1)
  if i & 1:
    F = f(i-1)
    for j in range(n+1):
      L[j] = A[F[j]]
  else:
    F = f(i//2)
    for j in range(n+1):
      L[j] = F[F[j]]
  return L
F = f(k)
ans = F[1]
print(ans)

Fixed submission:
n, k = map(int, input().split())
A = list(map(int, input().split()))
D = [1]
seen = [0]*n
seen[0] = 1
now = 0
while True:
    now = A[now] - 1
    D.append(now+1)
    if seen[now]:
        break
    seen[now] = 1
f = D.index(D[-1])
if k < f:
    print(D[k])
else:
    cycle = len(D) - f - 1
    k -= f
    print(D[f + k%(cycle)])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, a, b, c = map(int, input().split())
S = [input().rstrip() for _ in range(n)]
D = ["AB", "BC", "CA"]
X = [a+b, b+c, c+a]
L = []
for i, s in enumerate(S):
  if s == "AC":
    s = "CA"
  k = D.index(s)
  if X[k] == 0:
    print("No")
    exit()
  if X[(k+1)%3] == 1 and X[(k+2)%3] == 1 and i < n-1:
    l = D.index(S[i+1])
    if l == (k+1)%3:
      X[(k+1)%3] += 1
      X[(k+2)%3] -= 1
      L.append(s[1])
    else:
      X[(k+2)%3] += 1
      X[(k+1)%3] -= 1
      L.append(s[0])
  else:
    if X[(k+1)%3] < X[(k+2)%3]:
      X[(k+1)%3] += 1
      X[(k+2)%3] -= 1
      L.append(s[1])
    else:
      X[(k+2)%3] += 1
      X[(k+1)%3] -= 1
      L.append(s[0])
print("Yes")
print(*L, sep="\n")

Fixed submission:
import sys
input = sys.stdin.readline
n, a, b, c = map(int, input().split())
S = [input().rstrip().replace("AC", "CA") for _ in range(n)]
D = ["AB", "BC", "CA"]
X = [a+b, b+c, c+a]
L = []
for i, s in enumerate(S):
  k = D.index(s)
  if X[k] == 0:
    print("No")
    exit()
  if X[(k+1)%3] == 1 and X[(k+2)%3] == 1 and i < n-1:
    l = D.index(S[i+1])
    if l == (k+1)%3:
      X[(k+1)%3] += 1
      X[(k+2)%3] -= 1
      L.append(s[1])
    else:
      X[(k+2)%3] += 1
      X[(k+1)%3] -= 1
      L.append(s[0])
  else:
    if X[(k+1)%3] < X[(k+2)%3]:
      X[(k+1)%3] += 1
      X[(k+2)%3] -= 1
      L.append(s[1])
    else:
      X[(k+2)%3] += 1
      X[(k+1)%3] -= 1
      L.append(s[0])
print("Yes")
print(*L, sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
h, w, k = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(h)]
ans = float("inf")
for i in range(2**(h-1)):
  L = [0]
  cnt = 0
  for j in range(h-1):
    if i>>j & 1:
      L.append(j+1)
      cnt += 1
  L.append(h)
  C = [0]*(len(L)-1)
  for j in range(w):
    D = [0]*(len(L)-1)
    for l in range(len(L)-1):
      a, b = L[l], L[l+1]
      for s in range(a, b):
        D[l] += S[s][j]
    if max(D) > k:
      break
    for l, d in enumerate(D):
      if C[l]+d > k:
        break
    else:
      for l, d in enumerate(D):
        C[l] += d
      continue
    cnt += 1
    for l, d in enumerate(D):
      C[l] = d
  else:
    ans = min(ans, cnt)
print(ans)

Fixed submission:
h, w, k = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(h)]
ans = float("inf")
for i in range(2**(h-1)):
  L = [0]
  cnt = 0
  for j in range(h-1):
    if i>>j & 1:
      L.append(j+1)
      cnt += 1
  L.append(h)
  C = [0]*(len(L)-1)
  for j in range(w):
    D = [0]*(len(L)-1)
    for l in range(len(L)-1):
      a, b = L[l], L[l+1]
      for s in range(a, b):
        D[l] += S[s][j]
    if max(D) > k:
      break
    for l, d in enumerate(D):
      if C[l]+d > k:
        break
    else:
      for l, d in enumerate(D):
        C[l] += d
      continue
    cnt += 1
    for l, d in enumerate(D):
      C[l] = d
  else:
    ans = min(ans, cnt)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
  U = 2*10**6+2
  MOD = 10**9+7

  fact = [1]*(U+1)
  fact_inv = [1]*(U+1)

  for i in range(1,U+1):
      fact[i] = (fact[i-1]*i)%MOD
  fact_inv[U] = pow(fact[U], MOD-2, MOD)

  for i in range(U,0,-1):
      fact_inv[i-1] = (fact_inv[i]*i)%MOD

  def comb(n, k):
      if k < 0 or k > n:
          return 0
      z = fact[n]
      z *= fact_inv[k]
      z %= MOD
      z *= fact_inv[n-k]
      z %= MOD
      return z

  ans = 0
  r1, c1, r2, c2 = map(int, input().split())
  for i in range(c1, c2+1):
    ans += comb(i+r2+1, i+1) - comb(i+r1, i+1)
    ans %= MOD
  print(ans)
  
if __name__ == "__main__":
  main()

Fixed submission:
U = 2*10**6+2
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[k]
    z %= MOD
    z *= fact_inv[n-k]
    z %= MOD
    return z
  
ans = 0
r1, c1, r2, c2 = map(int, input().split())
for i in range(c1, c2+1):
  ans += comb(i+r2+1, i+1) - comb(i+r1, i+1)
  ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
U = 2*10**6+2
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[k]
    z %= MOD
    z *= fact_inv[n-k]
    z %= MOD
    return z
  
ans = 0
r1, c1, r2, c2 = map(int, input().split())
for i in range(c1, c2+1):
  ans += comb(i+r2+1, i+1) - comb(i+r1, i+1)
  ans %= MOD
print(ans)

Fixed submission:
U = 2*10**6+2
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[k]
    z %= MOD
    z *= fact_inv[n-k]
    z %= MOD
    return z
  
ans = 0
r1, c1, r2, c2 = map(int, input().split())
for i in range(c1, c2+1):
  ans += comb(i+r2+1, i+1) - comb(i+r1, i+1)
  ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
INF = 10**10

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
dp = [INF]*(h+1)
dp[0] = 0
for i in range(n):
  a, b = AB[i]
  for j in range(h+1):
    if j <= a:
      dp[j] = min(dp[j], b)
    else:
      dp[j] = min(dp[j], dp[j-a]+b)
print(dp[h])

Fixed submission:
import sys
input = sys.stdin.readline

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
dp = [float("inf")]*(h+1)
dp[0] = 0
for i in range(n):
  a, b = AB[i]
  for j in range(h+1):
    if j <= a:
      dp[j] = min(dp[j], b)
    else:
      dp[j] = min(dp[j], dp[j-a]+b)
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
dp = [float("inf")]*(h+1)
dp[0] = 0
for i in range(n):
  a, b = AB[i]
  for j in range(h+1):
    if j <= a:
      dp[j] = min(dp[j], b)
    else:
      dp[j] = min(dp[j], dp[j-a]+b)
print(dp[h])

Fixed submission:
import sys
input = sys.stdin.readline

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
dp = [float("inf")]*(h+1)
dp[0] = 0
for i in range(n):
  a, b = AB[i]
  for j in range(h+1):
    if j <= a:
      dp[j] = min(dp[j], b)
    else:
      dp[j] = min(dp[j], dp[j-a]+b)
print(dp[h])
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7
n = int(input())
F = [1]*(n+1)
for i in range(n):
  F[i+1] = F[i]*(i+1) % MOD
X = list(map(int, input().split()))
D = [X[i+1]-X[i] for i in range(n-1)]
T = [1]*n
for i in range(2, n):
  T[i] = T[i-1]*i+F[i-1]
  T[i] %= MOD
t = 1
for i in range(1, n-1):
  t *= (n-i) % MOD
  T[n-1-i] *= t % MOD
ans = 0
for i in range(1, n):
  ans += D[i-1]*T[i]
  ans %= MOD
print(ans)

Fixed submission:
MOD = 10**9+7
n = int(input())
F = [1]*(n+1)
for i in range(n):
  F[i+1] = F[i]*(i+1)
  F[i+1] %= MOD
X = list(map(int, input().split()))
D = [X[i+1]-X[i] for i in range(n-1)]
T = [1]*n
for i in range(2, n):
  T[i] = T[i-1]*i+F[i-1]
  T[i] %= MOD
t = 1
for i in range(1, n-1):
  t *= (n-i)
  t %= MOD
  T[n-1-i] *= t
  T[n-1-i] %= MOD
ans = 0
for i in range(1, n):
  ans += D[i-1]*T[i]
  ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
M=10**9+7;n,k,*A=map(int,open(0).read().split());C=[[0]*(n+1)for _ in"_"*(n+1)]
for i in range(n+1):
 for j in range(n):C[i][j]=(1,C[i-1][j-1]+C[i-1][j])[j>0]%M
F=[[0]*(n+1)for _ in"_"*n];F[0][0]=1
for i in range(k):
 for j in range(n+1):
  for m in range(j+1):F[i+1][j]+=C[j][m]*F[i][m]*C[n-j+m][A[i]-j+m]
print(F[k][n]%M)

Fixed submission:
import sys
input = sys.stdin.readline
U = 1000
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[k]
    z %= MOD
    z *= fact_inv[n-k]
    z %= MOD
    return z

n, k = map(int, input().split())
A = list(map(int, input().split()))
F = [[0]*(n+1) for _ in range(k+1)]
F[0][0] = 1
for i in range(k):
  for j in range(n+1):
    for m in range(j+1):
      F[i+1][j] += comb(j, m) * F[i][m] * comb(n-(j-m), A[i]-(j-m))
    F[i+1][j] %= MOD
ans = F[k][n]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
M=10**9+7;n,k,*A=map(int,open(0).read().split());B=[1];I=[1]*(n+1)
for i in range(1,n+1):B+=[B[-1]*i%M]
for i in range(n+1,0,-1):I[i-1]=pow(B[n],M-2,M)%M if i>n else I[i]*i%M
C=lambda n,k:(B[n]*I[k]*I[n-k],0)[k<0];F=[[0]*(n+1)for _ in"_"*(k+1)];F[0][0]=1
for i in range(k):
 for j in range(n+1):
  for m in range(j+1):F[i+1][j]+=C(j,m)*F[i][m]*C(n-j+m,A[i]-j+m)%M
print(F[k][n]%M)

Fixed submission:
import sys
input = sys.stdin.readline
U = 1000
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[k]
    z %= MOD
    z *= fact_inv[n-k]
    z %= MOD
    return z

n, k = map(int, input().split())
A = list(map(int, input().split()))
F = [[0]*(n+1) for _ in range(k+1)]
F[0][0] = 1
for i in range(k):
  for j in range(n+1):
    for m in range(j+1):
      F[i+1][j] += comb(j, m) * F[i][m] * comb(n-(j-m), A[i]-(j-m))
    F[i+1][j] %= MOD
ans = F[k][n]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
import numpy as np

def gcd_list(numbers):
    return reduce(gcd, numbers)
  
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n, m = map(int, input().split())
A = list(map(lambda x: int(x)//2, input().split()))
g = gcd_list(A)
A = np.array(A)
A //= g
A = A.tolist()
l = lcm_list(A)
if l%2 == 0:
  print(0)
else:
  print(((m//(l*g))+1)//2)

Fixed submission:
from fractions import gcd
from functools import reduce

def lcm(x, y):
  g = gcd(x, y)
  x //= g
  y //= g
  if x&y&1:
    l = x*y*g
    if l > 10**9:
      return 0
    return l
  return 0
n, m = map(int, input().split())
A = list(map(lambda x: int(x)//2, input().split()))
k = reduce(lcm, A)
if k == 0:
  print(0)
else:
  print(((m//k)+1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)
  
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n, m = map(int, input().split())
A = list(map(lambda x: int(x)//2, input().split()))
g = gcd_list(A)
l = lcm_list(A)
if (l//g)%2 == 0:
  print(0)
else:
  print(((m//l)+1)//2)

Fixed submission:
from fractions import gcd
from functools import reduce

def lcm(x, y):
  g = gcd(x, y)
  x //= g
  y //= g
  if x&y&1:
    l = x*y*g
    if l > 10**9:
      return 0
    return l
  return 0
n, m = map(int, input().split())
A = list(map(lambda x: int(x)//2, input().split()))
k = reduce(lcm, A)
if k == 0:
  print(0)
else:
  print(((m//k)+1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)
  
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n, m = map(int, input().split())
A = list(map(lambda x: int(x)//2, input().split()))
g = gcd_list(A)
l = lcm_list(A)
if (l//g)%2 == 0:
  print(0)
else:
  print(((m//l)+1)//2)

Fixed submission:
from fractions import gcd
from functools import reduce

def lcm(x, y):
  g = gcd(x, y)
  x //= g
  y //= g
  if x&y&1:
    l = x*y*g
    if l > 10**9:
      return 0
    return l
  return 0
n, m = map(int, input().split())
A = list(map(lambda x: int(x)//2, input().split()))
k = reduce(lcm, A)
if k == 0:
  print(0)
else:
  print(((m//k)+1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import numpy as np

n = int(input())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
for i in range(0, -n, -1):
  C = np.roll(A, i) ^ B
  if np.array_equiv(C, C[-1]):
    print(-i, C[-1])

Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
C = [0]*(3*n)
for i in range(n):
  C[i] = B[i]^B[(i+1)%n]
  C[i+n] = A[i]^A[(i+1)%n]
  C[i+n+n] = C[i+n]

def z_algo(S):
    N = len(S)
    A = [0]*N
    A[0] = N
    i, j = 1, 0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        A[i] = j
        if not j:
            i += 1
            continue
        k = 1
        while i+k < N and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A  

P = z_algo(C)
for i, p in enumerate(P[n:n+n]):
  if p >= n:
    x = A[i]^B[0]
    print(i, x)
Buggy python submission (verdict: Runtime Error):
2
1
2 0
1
1 0

Fixed submission:
n = int(input())
A = [0]*n
for i in range(n):
  a = int(input())
  A[i] = [ tuple(map(int, input().split())) for _ in range(a) ]
ans = 0
for i in range(2**n):
  P = [2]*n
  f = False
  for j in range(n):
    if i >> j & 1:
      if P[j] != 2 and P[j] ^ 1:
          f = True
          break
      P[j] = 1
      for x, y in A[j]:
        if P[x-1] != 2 and P[x-1] ^ y:
          f = True
          break
        P[x-1] = y
  if f:
    continue
  c = bin(i).count("1")
  if P.count(1) <= c:
    ans = max(ans, c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))
ans = 0
for j in range(61):
  c = 0
  for i in A:
    if i>>j & 1:
      c += 1
  ans += 2**j*((n-c)*c)
  ans %= MOD
print(ans%MOD)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
ans = 0
for j in range(61):
  c = 0
  for i in A:
    if i>>j & 1:
      c += 1
  ans += 2**j*((n-c)*c)
print(ans%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ans = 0
for j in range(61):
  c = 0
  for i in A:
    if i>>j & 1:
      c += 1
  ans += 2**j*((n-c)*c)
print(ans%(10**9+7))

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
ans = 0
for j in range(61):
  c = 0
  for i in A:
    if i>>j & 1:
      c += 1
  ans += 2**j*((n-c)*c)
print(ans%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ans = 0
for j in range(61):
  c = 0
  for i in A:
    if i>>j & 1:
      c += 1
  ans += 2**j*((n-c)*c)
print(ans%(10**9+7))

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
ans = 0
for j in range(61):
  c = 0
  for i in A:
    if i>>j & 1:
      c += 1
  ans += 2**j*((n-c)*c)
print(ans%(10**9+7))