Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, k = map(int, input().strip().split())
  lp = list(map(lambda c:int(c)-1, input().strip().split()))
  lc = list(map(int, input().strip().split()))
  used = [0] * n
  loops = []
  for i in range(n):
    if used[i] == 1:
      continue
      
    ic = i
    loop = []
    while True:
      loop.append(lc[ic])
      used[ic] = 1      
      ic = lp[ic]
      if used[ic] == 1:
        break
    if len(loop) > 0:
      loops.append(loop)
    
    
  def f(loop, k):
    if max(loop) < 0:
      return max(loop)
    
    score = 0
    if sum(loop) > 0:
      score += (k // len(loop)) * sum(loop)
      k = k % len(loop)
    k = min(k, len(loop)-1)
    loop = 2 * loop
    score += max([sum(loop[i:i+ik]) for i in range(len(loop)//2) for ik in range(1, k+1)])
    return score
  
  print(max([f(loop, k) for loop in loops]))

if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-


def main():
  n, k = map(int, input().strip().split())
  lp = list(map(lambda p:int(p)-1, input().strip().split()))
  lc = list(map(int, input().strip().split()))

  used = [0] * n
  loops = []
  for i in range(n):
    if used[i] == 1:
      continue
      
    ic = i
    loop = []
    while used[ic] == 0:
      loop.append(lc[ic])
      used[ic] = 1      
      ic = lp[ic]
      
    if len(loop) > 0:
      loops.append(loop)
    
  def loop_score(loop, k):
    return (k // len(loop)) * sum(loop)
  
  def path_score(loop, k):
    score = 0
    for i in range(len(loop)):
      cumsum = 0
      for j in range(k):
        cumsum += loop[(i+j) % len(loop)]
        score = max(score, cumsum)
    return score
  
  def calc_score(loop, k):
    if max(loop) < 0:
      return max(loop)
    
    if k < len(loop):
      return path_score(loop, k)
    if k >= len(loop):
      k -= len(loop)
      score = 0
      if sum(loop) > 0:
        score += loop_score(loop, k)
      k %= len(loop)
      k += len(loop)
      score += path_score(loop, k)

    return score
  
  print(max([calc_score(loop, k) for loop in loops]))

if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def p(n, k, mod):
  x = 1
  for ik in range(k):
    x *= (n - ik)
    x %= mod
  return x

MAX = 10 ** 9 + 7
def main():
  n, m = map(int, input().strip().split())
  s = 0
  nck = 1
  mpk = 1
  mkpnk = p(m, n, MAX)
  for k in range(0, n+1):
    if 0 < k <= n:
      nck *= (n - (k-1)) * pow(k, MAX-2, MAX) 
      nck %= MAX
    if 0 < k <= m:
      mpk *= (m - (k-1))
      mpk %= MAX
    if 0 < k <= n:
      mkpnk *= pow(m - (k - 1), MAX-2, MAX) 
      mkpnk %= MAX
    s += nck * ( (-1) ** k) * mpk * (mkpnk) ** 2
    s %= MAX
  print(s)
  

if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def p(n, k, mod):
  x = 1
  for ik in range(k):
    x *= (n - ik)
    x %= mod
  return x

MAX = 10 ** 9 + 7
def main():
  n, m = map(int, input().strip().split())
  s = 0
  nck = 1
  mpk = 1
  mkpnk = p(m, n, MAX)
  for k in range(0, n+1):
    if 0 < k <= n:
      nck *= (n - (k-1)) * pow(k, MAX-2, MAX) 
      nck %= MAX
    if 0 < k <= m:
      mpk *= (m - (k-1))
      mpk %= MAX
    if 0 < k <= n:
      mkpnk *= pow(m - (k - 1), MAX-2, MAX) 
      mkpnk %= MAX
    s += nck * ( (-1) ** k) * mpk * (mkpnk) ** 2
    s %= MAX
  print(s)
  

if __name__=='__main__':
  main()

Buggy python submission (verdict: Runtime Error):
%%writefile e.py
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def p(n, k, mod):
  x = 1
  for ik in range(k):
    x *= (n - ik)
    x %= mod
  return x

MAX = 10 ** 9 + 7
def main():
  n, m = map(int, input().strip().split())
  s = 0
  nck = 1
  mpk = 1
  mkpnk = p(m, n, MAX)
  for k in range(0, n+1):
    if 0 < k <= n:
      nck *= (n - (k-1)) * pow(k, MAX-2, MAX) 
      nck %= MAX
    if 0 < k <= m:
      mpk *= (m - (k-1))
      mpk %= MAX
    if 0 < k <= n:
      mkpnk *= pow(m - (k - 1), MAX-2, MAX) 
      mkpnk %= MAX
    s += nck * ( (-1) ** k) * mpk * (mkpnk) ** 2
    s %= MAX
  print(s)
  

if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def p(n, k, mod):
  x = 1
  for ik in range(k):
    x *= (n - ik)
    x %= mod
  return x

MAX = 10 ** 9 + 7
def main():
  n, m = map(int, input().strip().split())
  s = 0
  nck = 1
  mpk = 1
  mkpnk = p(m, n, MAX)
  for k in range(0, n+1):
    if 0 < k <= n:
      nck *= (n - (k-1)) * pow(k, MAX-2, MAX) 
      nck %= MAX
    if 0 < k <= m:
      mpk *= (m - (k-1))
      mpk %= MAX
    if 0 < k <= n:
      mkpnk *= pow(m - (k - 1), MAX-2, MAX) 
      mkpnk %= MAX
    s += nck * ( (-1) ** k) * mpk * (mkpnk) ** 2
    s %= MAX
  print(s)
  

if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import Counter

def main():
  n = int(input())
  la = sorted(list(map(int, input().split())))
  primes = [la[0]]
  cands = la[1:]
  while len(cands) != 0:
    prime = primes[-1]
    cands = list(filter(lambda x:x%prime != 0, cands))
    if len(cands) == 0:
      break
    primes.append(cands.pop(0))
  print(len(set(primes) - set([k for k, v in Counter(la).items() if v >= 2])))

if __name__=='__main__':
  main()


Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  n = int(input())
  la = sorted(list(map(int, input().split())))
  a_max = max(la)
  dp = numpy.ones(a_max + 1)
  counts = numpy.zeros(a_max + 1)
  for a in la:
    counts[a] += 1
    if counts[a] < 2:
      dp[2*a::a] = 0
  print(len([a for a in la if dp[a]==1 and counts[a] == 1]))

if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import Counter

def main():
  n = int(input())
  la = sorted(list(map(int, input().split())))
  primes = [la[0]]
  cands = la[1:]
  while len(cands) != 0:
    prime = primes[-1]
    cands = list(filter(lambda x:x%prime != 0, cands))
    if len(cands) == 0:
      break
    primes.append(cands.pop(0))
  print(len(set(primes) - set([k for k, v in Counter(la).items() if v >= 2])))

if __name__=='__main__':
  main()


Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  n = int(input())
  la = sorted(list(map(int, input().split())))
  a_max = max(la)
  dp = numpy.ones(a_max + 1)
  counts = numpy.zeros(a_max + 1)
  for a in la:
    counts[a] += 1
    if counts[a] < 2:
      dp[2*a::a] = 0
  print(len([a for a in la if dp[a]==1 and counts[a] == 1]))

if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  MAX = 998244353
  n, m, k = map(int, input().split())
  
  def pow_mod_p(n, k, p):
    x = 1
    while k:
      if k % 2 == 1:
        x *= n
        x %= p
      n **= 2
      n %= p
      k >>= 1
    return x
  
  ncp = m * pow_mod_p(m-1, n-1, MAX)
  divm = pow_mod_p(m-1, MAX-2, MAX)
  cnt = ncp
  cmb = 1
  for ik in range(1, k+1):
    ncp *= divm
    ncp %= MAX
    
    cmb *= ((n-ik) * pow_mod_p(ik, MAX-2, MAX))
    cmb %= MAX
    
    cnt += ncp * cmb
    cnt %= MAX
    
  print(cnt % MAX)

if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  MAX = 998244353
  n, m, k = map(int, input().split())
    
  cnt = 0
  cmb = 1
  for ik in range(k+1):
    ncp = m * pow(m-1, n-ik-1, MAX)
    ncp %= MAX
    
    if ik == 0:
      cmb = 1
    else:
      cmb *= ((n-ik) * pow(ik, MAX-2, MAX))
    cmb %= MAX
    
    cnt += ncp * cmb
    cnt %= MAX
    
  print(cnt % MAX)

if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  q = int(input())
  state = 1
  swap = [0, 2, 1]
  for _ in range(q):
    x = input().strip()
    if x == '1':
      state *= -1
    else:
      _, f, c = x.split(' ')
      f = int(f)
      if state == -1:
        f = swap[int(f)]
      if f == 1:
        s = c + s
      else:
        s += c
  if state == -1:
    s = s[::-1]
  print(s)


  pass

if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  q = int(input())
  state = 1
  swap = [0, 2, 1]
  ss = []
  es = []
  for _ in range(q):
    x = input().strip()
    if x == '1':
      state *= -1
    else:
      _, f, c = x.split(' ')
      f = int(f)
      if state == -1:
        f = swap[int(f)]
      if f == 1:
        ss.append(c)
      else:
        es.append(c)
  s = ''.join(ss[::-1]) + s + ''.join(es)
  if state == -1:
    s = s[::-1]
  print(s)

if __name__=='__main__':
  main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import defaultdict

def main():
  n, m, k = map(int, input().strip().split())
  friends = defaultdict(lambda :{'children':list(), 'x':-1, 'visited':False})
  blocks = defaultdict(list)
  visited = set()
  
  for _ in range(m):
    a, b = map(int, input().strip().split())
    friends[a]['children'].append(b)
    friends[b]['children'].append(a)

  for _ in range(k):
    c, d = map(int, input().strip().split())
    blocks[c].append((d))
    blocks[d].append((c))
    
  def dfs(i, x):
    friends[i]['x'] = x
    friends[i]['visited'] = True
    count = 1
    for child in friends[i]['children']:
      if friends[child]['visited']:
        continue
      count += dfs(child, x)
    return count
  
  num = 1
  size = dict()
  for i in range(1, n+1):
    if friends[i]['visited']:
      continue
    count = dfs(i, num)
    size[num] = count
    num += 1
    
  ans = []
  for i in range(1, n+1):
    nblock = 0
    for ib in blocks[i]:
      if friends[i]['x'] == friends[ib]['x']:
        nblock += 1
    ans.append(size[friends[i]['x']] - len(friends[i]['children']) - nblock - 1)
  print(' '.join(list(map(str, ans))))
  
if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import defaultdict
import sys
sys.setrecursionlimit(10**5+10)

def main():
  n, m, k = map(int, input().strip().split())
  friends = defaultdict(lambda :{'children':list(), 'x':-1, 'visited':False})
  blocks = defaultdict(list)
  visited = set()
  
  for _ in range(m):
    a, b = map(int, input().strip().split())
    friends[a]['children'].append(b)
    friends[b]['children'].append(a)

  for _ in range(k):
    c, d = map(int, input().strip().split())
    blocks[c].append((d))
    blocks[d].append((c))
    
  def dfs(i, x):
    friends[i]['x'] = x
    friends[i]['visited'] = True
    count = 1
    for child in friends[i]['children']:
      if friends[child]['visited']:
        continue
      count += dfs(child, x)
    return count
  
  num = 1
  size = dict()
  for i in range(1, n+1):
    if friends[i]['visited']:
      continue
    count = dfs(i, num)
    size[num] = count
    num += 1
    
  ans = []
  for i in range(1, n+1):
    nblock = 0
    for ib in blocks[i]:
      if friends[i]['x'] == friends[ib]['x']:
        nblock += 1
    ans.append(size[friends[i]['x']] - len(friends[i]['children']) - nblock - 1)
  print(' '.join(list(map(str, ans))))
  
if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

MAX = 10**9 + 7

def pow_mod_p(n, k, p):
  x = 1
  while k:
    if k % 2 == 1:
      x *= n
      x %= p
    n **= 2
    n %= p
    k >>= 1
  return x

def comb_mod_p(n, k, p):
  x = 1
  for ik in range(k):
    x *= ((n-ik) * pow_mod_p(ik+1, p-2, p))
    x %= p
  return x


def main():
  n, a, b = map(int, input().strip().split())
  sum = 1
  for i in range(1, n+1):
    sum *= 2
    sum %= MAX
  sum -= 1
  sum = sum - comb_mod_p(n, a, MAX) - comb_mod_p(n, b, MAX)
  if sum < 0:
    print(MAX + sum)
  else:
    print(sum)


if __name__=='__main__':
  main()


Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

MAX = 10**9 + 7

def pow_mod_p(n, k, p):
  x = 1
  while k:
    if k % 2 == 1:
      x *= n
      x %= p
    n **= 2
    n %= p
    k >>= 1
  return x

def comb_mod_p(n, k, p):
  x = 1
  for ik in range(k):
    x *= ((n-ik) * pow_mod_p(ik+1, p-2, p))
    x %= p
  return x


def main():
  n, a, b = map(int, input().strip().split())
  sum = pow_mod_p(2, n, MAX) - 1
  sum = sum - comb_mod_p(n, a, MAX) - comb_mod_p(n, b, MAX)
  print(sum % MAX)


if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  n = input().strip()[::-1]
  dp = numpy.zeros((len(n), 2), dtype=numpy.int)
  dp[0][0] = int(n[0])
  dp[0][1] = 10 - int(n[0])
  for i, d in enumerate(map(int, n[1:]), 1):
    dp[i][0] = min(dp[i-1][0] + d,      dp[i-1][1] + 1 + d)
    dp[i][1] = min(dp[i-1][0] + 10 - d, dp[i-1][1] + 10 - (d + 1))
  print(min(dp[-1][0], dp[-1][1]+1))  

if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = input().strip()[::-1]
  dp = [[0, 0] for _ in range(len(n))]
  dp[0][0] = int(n[0])
  dp[0][1] = 10 - int(n[0])
  for i, d in enumerate(map(int, n[1:]), 1):
    dp[i][0] = min(dp[i-1][0] + d,      dp[i-1][1] + 1 + d)
    dp[i][1] = min(dp[i-1][0] + 10 - d, dp[i-1][1] + 10 - (d + 1))
  print(min(dp[-1][0], dp[-1][1]+1))  

if __name__=='__main__':
  main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  n = input().strip()[::-1]
  dp = numpy.zeros((len(n), 2), dtype=numpy.int)
  dp[0][0] = int(n[0])
  dp[0][1] = 10 - int(n[0])
  for i, d in enumerate(map(int, n[1:]), 1):
    dp[i][0] = min(dp[i-1][0] + d,      dp[i-1][1] + 1 + d)
    dp[i][1] = min(dp[i-1][0] + 10 - d, dp[i-1][1] + 10 - (d + 1))
  print(min(dp[-1][0], dp[-1][1]+1))  

if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = input().strip()[::-1]
  dp = [[0, 0] for _ in range(len(n))]
  dp[0][0] = int(n[0])
  dp[0][1] = 10 - int(n[0])
  for i, d in enumerate(map(int, n[1:]), 1):
    dp[i][0] = min(dp[i-1][0] + d,      dp[i-1][1] + 1 + d)
    dp[i][1] = min(dp[i-1][0] + 10 - d, dp[i-1][1] + 10 - (d + 1))
  print(min(dp[-1][0], dp[-1][1]+1))  

if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import numpy

def main():
  n, k = map(int, input().strip().split())
  Ps   = numpy.array(input().strip().split(), dtype=int)
  Es   = numpy.zeros(n)
  max = -1
  for i, P in enumerate(Ps):
    Es[i] = 0.5 * (P+1)
  max = -1
  for i in range(n-k+1):
    x = numpy.sum(Es[i:i+k])
    if max < x:
      max = x
  print(max)

if __name__=='__main__':
  main()

Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import numpy

def main():
  n, k = map(int, input().strip().split())
  Ps   = numpy.array(input().strip().split(), dtype=int)
  Es   = numpy.zeros(n+1)
  max = -1
  for i, P in enumerate(Ps):
    Es[i] = 0.5 * (P+1) + Es[i-1]
  max = -1
  for i in range(n-k+1):
    x = Es[i+k-1] - Es[i-1]
    if max < x:
      max = x
  print(max)

if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, d, a = map(int, input().strip().split())
  XsHs = [list(map(int, input().strip().split())) for _ in range(n)]
  XsHs.sort(key = lambda x:x[0])

  queue = list()
  total = 0
  ans = 0
  for x, h in XsHs:
    while True:
      if len(queue) != 0 and queue[0][0] < x:
        total -= queue[0][1]
        del queue[0]
      else:
        break
    h -= total
    if h > 0:
      num = (h+a-1)//a
      ans += num
      total += (num*a)
      queue.append((x+(2*d), num*a))
  print(ans)

if __name__=='__main__':
  main()

Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import deque

def main():
  n, d, a = map(int, input().strip().split())
  XsHs = [list(map(int, input().strip().split())) for _ in range(n)]
  XsHs.sort(key = lambda x:x[0])

  queue = deque()
  total = 0
  ans = 0
  for x, h in XsHs:
    while queue:
      if queue[0][0] < x:
        total -= queue[0][1]
        queue.popleft()
      else:
        break
    h -= total
    if h > 0:
      num = (h+a-1)//a
      ans += num
      total += (num*a)
      queue.append((x+(2*d), num*a))
  print(ans)

if __name__=='__main__':
  main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def calc_gcd(a, b):
  if a > b:
    a, b = b, a
  while True:
    a, b = b%a, a
    if a == 0:
      return b

def calc_lcm(a, b):
  gcd = calc_gcd(a, b)
  return int(a * b / gcd)

def main():
  n = int(input())
  As = list(map(int, input().strip().split()))
  lcm = As[0]
  total = 0
  for a in As[1:]:
    lcm = calc_lcm(lcm, a)
  for a in As:
    total += lcm / a
  print(int(total) % (10**9+7))


if __name__=='__main__':
  main()

Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def calc_gcd(a, b):
  if a > b:
    a, b = b, a
  while True:
    a, b = b%a, a
    if a == 0:
      return b

def calc_lcm(a, b):
  gcd = calc_gcd(a, b)
  return int(a * b // gcd)

def main():
  n = int(input())
  As = list(map(int, input().strip().split()))
  lcm = As[0]
  total = 0
  for a in As[1:]:
    lcm = calc_lcm(lcm, a)
  for a in As:
    total += lcm // a
  print(total % (10**9+7))


if __name__=='__main__':
  main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def calc_gcd(a, b):
  if a > b:
    a, b = b, a
  a, b = b%a, a
  if a != 0:
    return calc_gcd(a, b)
  else:
    return b

def calc_lcm(a, b):
  gcd = calc_gcd(a, b)
  return int(a * b / gcd)

def main():
  n = int(input())
  As = list(map(int, input().strip().split()))
  lcm = As[0]
  total = 0
  for a in As[1:]:
    lcm = calc_lcm(lcm, a)
  for a in As:
    total += lcm / a
  print(int(total) % (10**9+7))


if __name__=='__main__':
  main()

Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def calc_gcd(a, b):
  if a > b:
    a, b = b, a
  while True:
    a, b = b%a, a
    if a == 0:
      return b

def calc_lcm(a, b):
  gcd = calc_gcd(a, b)
  return int(a * b // gcd)

def main():
  n = int(input())
  As = list(map(int, input().strip().split()))
  lcm = As[0]
  total = 0
  for a in As[1:]:
    lcm = calc_lcm(lcm, a)
  for a in As:
    total += lcm // a
  print(total % (10**9+7))


if __name__=='__main__':
  main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import factorial

def main():
  n, k = map(int, input().strip().split())
  As = list(map(int, input().strip().split()))
  As.sort()
  min = 0
  max = 0
  for i in range(n-k+1):
    x = (factorial(n-(i+1)) / factorial(k-1) / factorial((n-(i+1)) - (k-1)))
    min += As[i]      * int(x)
    max += As[-(i+1)] * int(x)
  print((max - min) % (10**9 + 7))

if __name__=='__main__':
  main()


Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import random

MAX = 10**9 + 7

def pow_mod_p(n, k, p):
  x = 1
  while k > 0:
    if k % 2 == 1:
      x *= n
      x %= p
    n **= 2
    n %= p
    k >>= 1
  return x

def comb_mod_p(n, k, p):
  x = 1
  for ik in range(k):
    x *= ((n-ik) * pow_mod_p(ik+1, p-2, p))
    x %= p
  return x

def main():
  n, k = map(int, input().strip().split())
  As = list(map(int, input().strip().split()))
  As.sort()
  min = 0
  max = 0
  x = comb_mod_p(n-1, k-1, MAX)
  for i in range(n-k+1):
    min += As[i]      * int(x)
    min %= MAX
    max += As[-(i+1)] * int(x)
    max %= MAX
    x *= (pow_mod_p(n-(i+1), MAX-2, MAX) * (n-(i+1)-(k-1)))
    x %= MAX
  print((max - min) % (MAX))

if __name__=='__main__':
  main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def lcm(a, b):
  if a > b:
    a, b = b, a
  while True:
    a, b = b%a, a
    if a == 0:
      return b

def gcm(a, b):
  return int(a * b / lcm(a, b))


def main():
  n, m = map(int, input().strip().split())
  As = list(map(int, input().strip().split()))
  x = 1
  for i in range(len(As)):
    x = gcm(x, As[i])
  if sum([(x//A)%2 == 1 for A in As]) == len(As):
    print(int(m/x-0.5)+1)
  else:
    print(0)

if __name__=='__main__':
  main()

Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def gcd(a, b):
  if a > b:
    a, b = b, a
  while True:
    a, b = b%a, a
    if a == 0:
      return b

def lcm(a, b):
  return int(a * b // gcd(a, b))


def main():
  n, m = map(int, input().strip().split())
  As = list(map(int, input().strip().split()))
  x = 1
  for i in range(len(As)):
    x = lcm(x, As[i])
    if m/x < 0.5:
      print(0)
      return
  if sum([(x//A)%2 == 1 for A in As]) == len(As):
    print(int(m/x-0.5+1))
  else:
    print(0)

if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

def prime(ulim=10**5+10):
  cands = [2] + list(range(3, ulim, 2))
  while len(cands) != 0:
    prime = cands.pop(0)
    cands = [x for x in cands if x%prime != 0]
    yield prime

if __name__=='__main__':
  x = int(input())
  for p in prime():
    if p >= x:
      print(p)
      break

Fixed submission:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from math import sqrt

def prime(ulim=10**5+10):
  cands = [2] + list(range(3, ulim, 2))
  primes = []
  while True:
    prime = cands.pop(0)
    primes.append(prime)
    if prime > sqrt(ulim):
      primes += cands
      break
    cands = [x for x in cands if x%prime != 0]
  return primes


if __name__=='__main__':
  x = int(input())
  for p in prime():
    if p >= x:
      print(p)
      break
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy
from math import ceil, floor

def main():
  n  = int(input())
  Ls = list(map(int, input().strip().split()))
  Ls = numpy.sort(numpy.array(Ls))
  counts  = numpy.zeros(2*10**3+1, dtype=numpy.int)
  for L in Ls:
    counts[:L+1] += 1
    
  count =0 
  for i in range(n-2):
    for j in range(i+1, n-1):
      if Ls[i] == Ls[j]:
        x = 2
      else:
        x = 1
      count +=  max((counts[Ls[j]]-x) - counts[Ls[i]+Ls[j]], 0)
  print(count,'x')
  
if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n  = int(input())
  Ls = list(map(int, input().strip().split())) + [2*10**3+1]
  Ls.sort()
  def bs(l, r, x):
    while r - l > 1:
      mid = (r+l)//2
      if Ls[mid] >= x:
        r = mid
      if Ls[mid] <  x:
        l = mid
    return r
  
  count = 0
  for i in range(n-2):
    for j in range(i+1, n-1):
      r = bs(j, len(Ls), Ls[i]+Ls[j])
      count += (r - 1  - j)
  print(count)
  
if __name__=='__main__':
  main()