Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02912 (python)

Fixed submission:
# coding: UTF-8

#import scipy.optimize
from math import ceil,floor
from heapq import heappush, heappop, heapify
    
##################################################################

if __name__ == "__main__":

    Input = [input() for i in range(2)]
    N,M = list(map(int,Input[0].split()))
    A = list(map(int,Input[1].split()))
    A = [-a for a in A]
    heapify(A)
    Use = 0
    while Use < M:
        temp = -1*heappop(A)
        temp = floor(temp/2)
        heappush(A, -temp)
        Use += 1
    print(sum(A)*-1)

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


#import scipy.optimize
import math

    
##################################################################

if __name__ == "__main__":

    Input = [input() for i in range(2)]
    N,M = list(map(int,Input[0].split()))
    A = list(map(int,Input[1].split()))
    A.sort(reverse=True)

    if N==1:
        Money = math.floor(A[0]/(2**M))
        print(Money)
    else:      
        Use = 0
        while Use < M:
            if A[0] == A[1]:
                Usenow = 1
                Use += Usenow
            else:
                Usenow = math.ceil(math.log2(A[0])-math.log2(A[1]))
                Use += Usenow
                if Use > M:
                    Usenow -= Use - M
                    Use = M
            temp = math.floor(A[0]/(2**Usenow))
            for i in range(1,N):
                if temp < A[i]:
                    A[0:i] = A[1:i+1]
                    A[i] = temp
                    break
                else:
                    continue
        print(sum(A))

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


#import scipy.optimize
import math

    
##################################################################

if __name__ == "__main__":

    Input = [input() for i in range(2)]
    N,M = list(map(int,Input[0].split()))
    A = list(map(int,Input[1].split()))
    A.sort(reverse=True)

    if N==1:
        Money = math.floor(A[0]/(2**M))
        print(Money)
    else:      
        Use = 0
        while Use < M:
            if A[0] == A[1]:
                Usenow = 1
            else:
                Usenow = math.ceil(math.log2(A[0])-math.log2(A[1]))
            Use += Usenow
            if Use > M:
                Usenow -= Use - M
            temp = math.floor(A[0]/(2**Usenow))
            for i in range(1,N):
                if temp < A[i]:
                    A[0:i] = A[1:i+1]
                    A[i] = temp
                    break
                else:
                    continue
        print(sum(A))
Problem p03272 (python)

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

print(n - i + 1)

Buggy submission (verdict: Runtime Error):
n, i = map(int, input().split())

print(n - i + 1)
Problem p02897 (python)

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



N = int(input())
print(math.ceil(N/2)/N)

Buggy submission (verdict: Runtime Error):
N = int(input())

ans = 0
for i in range(1,N+1):
	if i%2==1:
      ans += 1
print(ans/N)
Problem p03108 (python)

Fixed submission:
# /user/bin/python
# -*- coding: utf-8 -*-
import sys
 

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

  def root(self, x):
    if self.par[x] < 0:
      return x
    else:
      return self.root(self.par[x])

  def issame(self, x, y):
    if self.root(x) == self.root(y):
      return True
    else:
      return False
  
  def merge(self, x, y):
    x, y = [self.root(x), self.root(y)]
    if x == y:
      return False
    if self.par[x] > self.par[y]:
      x, y = y, x
    self.par[x] += self.par[y]
    self.par[y] = x
    return True

  def size(self, x):
    return -self.par[self.root(x)]


if __name__ == "__main__":
  n,m = map(int, sys.stdin.readline().rstrip().split())
  A = [0] * m
  B = [0] * m
  for i in range(m):
    A[i], B[i] = list(map(int, sys.stdin.readline().rstrip().split()))

  uf = UnionFind(n)
  ans = []
  cur = n * (n-1) // 2

  for i in range(m):
    ans.append(cur)
    a, b = [A[m-i-1]-1, B[m-i-1]-1]

    if not uf.issame(a, b):
      sa = uf.size(a)
      sb = uf.size(b)
      cur -= sa * sb
      uf.merge(a, b)

  ans.reverse()
  for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
# /user/bin/python
# -*- coding: utf-8 -*-
import sys
 

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

  def root(self, x):
    if self.par[x] < 0:
      return x
    else:
      return self.root(self.par[x])

  def issame(self, x, y):
    if self.root(x) == self.root(y):
      return True
    else:
      return False
  
  def merge(self, x, y):
    if x == y:
      return False
    if self.par[x] > self.par[y]:
      x, y = y, x
    self.par[x] += self.par[y]
    self.par[y] = x
    return True

  def size(self, x):
    return -self.par[self.root(x)]


if __name__ == "__main__":
  n,m = map(int, sys.stdin.readline().rstrip().split())
  ab = [[0 for _ in range(2)] for _ in range(m)]
  for i in range(m):
    ab[m-i-1] = list(map(int, sys.stdin.readline().rstrip().split()))

  uf = UnionFind(n)
  ans = []
  cur = n * (n-1) // 2

  for a,b in ab:
    ans.append(cur)

    if uf.issame(a-1, b-1):
      continue

    sa, sb = [uf.size(a-1), uf.size(b-1)]
    cur -= sa * sb
    uf.merge(a-1,b-1)

  for i in ans[::-1]:
    print(i)
Problem p03127 (python)

Fixed submission:
import math
import sys
from operator import itemgetter
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

def gcd(a, b):
	if a > b:
		return gcd(b, a)
	elif a == 0:
		return b
	else:
		return gcd(a, b % a)

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

ans = As[0]
for i in As[1:]:
	ans = gcd(ans, i)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import sys
import random
from operator import itemgetter
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

input().rstrip()
As = list(map(int, input().rstrip().split()))

ans = As[0]
for i in As[1:]:
	ans = math.gcd(ans, i)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import sys
import random
from operator import itemgetter
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

input().rstrip()
As = list(map(int, input().rstrip().split()))

ans = As[0]
for i in As[1:]:
	ans = math.gcd(ans, i)
print(ans)
Problem p02891 (python)

Fixed submission:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

S = input()
K = INT()

N = len(S)
numlist = []
count = 1
if N == 1:
    print(K // 2)
else:
    for i in range(1, N):
        if S[i] == S[i - 1]:
            count += 1
        else:
            numlist.append(count)
            count = 1
    numlist.append(count)
    if len(numlist) == 1:
        ans = (N * K) // 2
    elif S[0] == S[-1]:
        center = numlist[0] + numlist[-1]
        ans = (center // 2) * (K - 1)
        ans += numlist[0] // 2
        ans += numlist[-1] // 2
        for i in range(1, len(numlist)-1):
            ans += (numlist[i] // 2) * K
    else:
        ans = 0
        for i in range(len(numlist)):
            ans += (numlist[i] // 2) * K
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

S = input()
K = INT()

N = len(S)
numlist = []
count = 1
for i in range(1, N):
    if S[i] == S[i - 1]:
        count += 1
    else:
        numlist.append(count)
        count = 1
numlist.append(count)
flag = 0
if S[0] == S[-1] and len(numlist) > 2:
    center = numlist[0] + numlist[-1]
    ans = (center // 2) * (K - 1)
    ans += numlist[0] // 2
    ans += numlist[-1] // 2
    for i in range(1, len(numlist)-1):
        ans += (numlist[i] // 2) * K
    import pdb; pdb.set_trace()
else:
    ans = 0
    for i in range(len(numlist)):
        ans += (numlist[i] // 2) * K
print(ans)
Problem p02990 (python)

Fixed submission:
import sys, math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, K = MAP()
    NK = N - K + 1
    for i in range(K):
        if NK < i + 1:
            print(0)
        else:
            print(combinations_count(NK, i + 1) * combinations_count(K - 1, i) % mod)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys, math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, K = MAP()
    NK = N - K + 1
    for i in range(K):
        print(combinations_count(NK, i + 1) * combinations_count(K - 1, i) % mod)

if __name__ == '__main__':
    main()
Problem p03011 (python)

Fixed submission:
def main():
    p, q, r = map(int, input().split())
    minv = p + q
    if minv > p + r:
        minv = p + r
    if minv > q + r:
        minv = q + r
    print(minv)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    h, w = map(int, input().split())
    ss = [input() for _ in range(h)]

    matl = [[0 for _ in range(w)] for _ in range(h)]
    matr = [[0 for _ in range(w)] for _ in range(h)]
    matu = [[0 for _ in range(w)] for _ in range(h)]
    matd = [[0 for _ in range(w)] for _ in range(h)]

    for j in range(h):
        for i in range(w):
            if ss[j][i] == '#':
                matd[j][i] = 0
            elif j == 0:
                matd[j][i] = 1
            else:
                matd[j][i] = matd[j - 1][i] + 1

            if ss[h - j - 1][i] == '#':
                matu[h - j - 1][i] = 0
            elif h - j == h:
                matu[h - j - 1][i] = 1
            else:
                matu[h - j - 1][i] = matu[h - j][i] + 1

            if ss[j][i] == '#':
                matr[j][i] = 0
            elif i == 0:
                matr[j][i] = 1
            else:
                matr[j][i] = matr[j][i - 1] + 1

            if ss[j][w - i - 1] == '#':
                matl[j][w - i - 1] = 0
            elif w - i == w:
                matl[j][w - i - 1] = 1
            else:
                matl[j][w - i - 1] = matl[j][w - i] + 1

    maxv = 0
    for j in range(h):
        for i in range(w):
            tmp = matu[j][i] + matd[j][i] + matr[j][i] + matl[j][i]
            if tmp > maxv:
                maxv = tmp
    print(maxv - 3)

if __name__ == '__main__':
    main()
Problem p02933 (python)

Fixed submission:
a = int (input())
s = input()
print(s) if a >= 3200 else print("red")

Buggy submission (verdict: Runtime Error):
a = int (input())
s = int (input())
print(s) if a>>3200 else print("red")
Problem p03012 (python)

Fixed submission:
import numpy as np
n = input()
w = list(map(int, input().split()))
w = np.array(w)
print(np.min(np.abs(2 * np.cumsum(w) -np.sum(w))))

Buggy submission (verdict: Runtime Error):
n = input()
w = list(map(int, input().split()))
w = np.array(w)
print(np.min(np.abs(2 * np.cumsum(w) -np.sum(w))))
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
mod = 1000000007
a = [True] * (n + 1)
for i in range(m):
    a[int(input())] = False
dp = [0] * (n + 1)
dp[0] = 1

dp[1] = dp[0] if a[1] else 0

for i in range(2, n + 1):
    if a[i]:
        dp[i] = (dp[i - 1] + dp[i - 2]) % mod

print(dp[n])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
mod = 1000000007

a = [True] * (n + 1)
for i in range(m):
    a[int(input())] = False
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = dp[0] if not 1 in a else 0
for i in range(2, n + 1):
  if a[i]:
      dp[i] = (dp[i - 1] + dp[i - 2]) % mod
  else:
      dp[i]=  0
print(dp(n))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
mod = 1000000007
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = dp[0] if not 1 in a else 0
for i in range(2, n + 1):
    if not i in a:
        dp[i] = (dp[i - 1] + dp[i - 2]) % mod
    else:
        dp[i]=  0
print(do[n])
Problem p03017 (python)

Fixed submission:
n, a, b, c, d = map(int, input().split())
s = input()

judge = True
if "##" in s[a - 1:c] or "##" in s[b - 1:d]:
    judge = False

if judge and c > d:
    if not "..." in s[b - 2:d + 1]:
        judge = False

print("Yes") if judge else print('No')

Buggy submission (verdict: Runtime Error):
judge = True
if "##" in s[a - 1:c] or "##" in s[b - 1:d]:
    judge = False

if judge and c > d:
    if not "..." in s[b - 2:d + 1]:
        judge = False

print("Yes") if judge else print('No')
Problem p03107 (python)

Fixed submission:
s = input()
c0 = s.count('0')
c1 = s.count('1')
print(2 *min(c0, c1))

Buggy submission (verdict: Runtime Error):
s = list(input)
c0 = s.count('0')
c1 = s.count('1')
print(2 *min(c0, c1))

Buggy submission (verdict: Runtime Error):
s = list(input())
k = len(s)
i = 0
while i <= len(s) - 2:
    if int(s[i]) + int(s[i+1]) == 1:
        s.pop(i)
        s.pop(i)
        i -=1
    else:
        i +=1
print(k-len(s))
Problem p03785 (python)

Fixed submission:
n, c, k = map(int, input().split())
T = sorted([int(input()) for _ in range(n)])
bus = 0
cus = 0
lmt = T[0] + k
for t in T:
    if cus == 0 or t > lmt:
        bus += 1
        cus = 1
        lmt = t + k
    else:
        cus +=1
    
    if cus == c:
        cus = 0
print(bus)

Buggy submission (verdict: Runtime Error):
n, c, k = map(int, input().split())
T = sorted([int(input()) for _ in range(n)])
bus = 0
cus = 0
lmt = T[0] + k
for t in T:
    if cus == 0 or t > lmt:
        bus += 1
        cus += 1
        lmt = t + k
    else:
        cus +=1
    
    if cus == 3:
        cus = 0
print(bus)
n, c, k = map(int, input().split())
T = sorted([int(input()) for _ in range(n)])
bus = 0
cus = 0
lmt = T[0] + k
for t in T:
    if cus == 0 or t > lmt:
        bus += 1
        cus += 1
        lmt = t + k
    else:
        cus +=1
    
    if cus == c:
        cus = 0
print(bus)
提出情報
Problem p02880 (python)

Fixed submission:
N = int(input())
lst = []
for m in range(1, 10):
	for n in range(1, 10):
		q = m * n
		lst.append(q)
if N in lst:
	print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
lst = []
for i in range(1,10):
	for k in range(1, 10):
		m = i * k
    	lst.append(m)
if N in lst:
	print('Yes')
else:
	print('No')
Problem p02915 (python)

Fixed submission:
N = int(input())
print(N ** 3)

Buggy submission (verdict: Runtime Error):
print(N ** 3)
Problem p02916 (python)

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

total = 0
pos = 0
while pos< N:
	posB = A[pos] -1
	total = total + B[posB]
	if A[pos] - A[pos - 1] == 1 and pos > 0:
		posC = A[pos] - 2
		total = total + C[posC]
	pos += 1
print(total)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

total = 0
pos = 0
while pos < N:
	posB = A[pos] -1
	total = total + B[posB]
	if A[pos + 1] - A[pos] == 1:
		posC = A[pos + 1] - 2
		total = total + C[posC]
	pos += 1
print(total)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list[map(int, input().split())]
B = list[map(int, input().split())]
C = list[map(int, input().split())]

total = 0
pos = 0
while pos < N:
  total += B[A[pos] - 1]
  if A[pos + 1] - A[pos] == 1:
    total += C[A[pos + 1] - 2]
  pos += 1
print(total)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list[map(int, input().split())]
B = list[map(int, input().split())]
C = list[map(int, input().split())]

total = 0
pos = 0
while pos < N:
  total = total + B[A[pos] - 1]
  if A[pos + 1] - A[pos] == 1:
    total = total + C[A[pos + 1] - 2]
print(total)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list[map(int, input().split())]
B = list[map(int, input().split())]
C = list[map(int, input(),split())]

total = 0
pos = 0
while pos < len(A):
	total = total + B[A[pos] - 1]
	if A[pos + 1] - A[pos] = 1:
		total = total + C[A[pos+1] - 2]
	pos += 1
print(total)
Problem p02987 (python)

Fixed submission:
S = list(input())
result = []
if len(set(S))==2:
  for s in list(set(S)):
    result.append(S.count(s))
  if result[0]==result[1]:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
S = list(input())
result = []
if len(set(S))==2:
  for s in S:
    result.append(S.count(s))
    if result[0]==result[1]:
      print("Yes")
    else:
      print("No")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
S = list(input())
result = []
if len(set(S))==2:
  for s in S:
    result.append(S.count(s))
    if result[0]==result[1]:
      print("Yes")
      exit()
print("No")

Buggy submission (verdict: Runtime Error):
S = list(input())
result = []
if len(set(S))==2:
  for s in S:
    result.append(S.count(s))
    if (result[0]==result[1]) == 2:
      print("Yes")
Problem p02880 (python)

Fixed submission:
import numpy as np
N = int(input())
kuku_array = np.zeros((9, 9))
for i in range(1,10):
  for j in range(i,10):
    kuku_array[i-1][j-1] = i*j
if np.any(kuku_array == N) == True:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
import numpy as np
N = input()
kuku_array = np.zeros((9, 9))
for i in range(9):
  for j in range(9):
    kuku_array[i][j] = i*j
if np.any(kuku_array = N) == True:
  print('Yes')
else:
  print('No')
Problem p02897 (python)

Fixed submission:
N = int(input())
kisuu = -(-N // 2)
print(kisuu / N)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
junb = []
inde = 0
basyo = 0
for touko in A:
    basyo = A.index(str(inde))
    junb.append.basyo
    inde += 1
print(str.junb)

Buggy submission (verdict: Runtime Error):
N = input()
kisuu = -(-N // 2)
print(kisuu / N)

Buggy submission (verdict: Runtime Error):
N = input(int())
kisuu = -(-N // 2)
print(kisuu / N)
Problem p03012 (python)

Fixed submission:
N = int(input())
W = list(map(int,input().split()))
list = []
for n in range(N):
  a = 1
  b = n + 1
  Down = 0
  Up = 0
  while a <= n:
    Down += W[a - 1]
    a += 1
  while b <= N:
    Up += W[b - 1]
    b += 1
  list.append(abs(Down - Up))
list.sort()
print(list[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
W = int,input().split()
list = []
for n in range(N):
  a = 1
  b = n + 1
  Down = 0
  Up = 0
  while a <= n:
    Down += W[a - 1]
    a += 1
  while b <= N:
    Up += W[b - 1]
    b += 1
  list.append(abs(Down - Up))
list.sort()
print(list[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
W = map(int,input().split())
list = []
for n in range(N):
  a = 1
  b = n + 1
  Down = 0
  Up = 0
  while a <= n:
    Down += W[a - 1]
    a += 1
  while b <= N:
    Up += W[b - 1]
    b += 1
  list.append(abs(Down - Up))
list.sort()
print(list[0])
Problem p02881 (python)

Fixed submission:
import math

n = int(input())
tmp_list = []

for i in range(1, int(math.sqrt(n))+1, 1):
    if(n%i==0):
        tmp_list.append(i)

i = tmp_list[len(tmp_list)-1]
j = n//i

print(i+j-2)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
tmp_list = []

for i in range(1, int(math.sqrt(n)), 1):
    if(n%i==0):
        tmp_list.append(i)

i = tmp_list[len(tmp_list)-1]
j = n//i

print(i+j-2)
Problem p02912 (python)

Fixed submission:
import sys
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))

if len(A) == 1:
    A[0] //= (2 ** M)
    print(sum(A))
    sys.exit()

h = [(1/a, a) for a in A]
heapq.heapify(h)

for m in range(M):
    x = heapq.heappop(h)
    _, a = x

    a //= 2

    heapq.heappush(h, (1/a if a > 0 else float('inf'), a))

print(sum([a for _, a in h]))

Buggy submission (verdict: Runtime Error):
import sys
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))

if len(A) == 1:
    A[0] //= (2 ** M)
    print(sum(A))
    sys.exit()

h = [(1/a, a) for a in A]
heapq.heapify(h)

for m in range(M):
    x = heapq.heappop(h)
    _, a = x

    a //= 2

    heapq.heappush(h, (1/a, a))

print(sum([a for _, a in h]))
Problem p02984 (python)

Fixed submission:
from functools import lru_cache
N = int(input())
A = list(map(int, input().split()))

@lru_cache(maxsize=N)
def f(i):
    if i >= 2:
        return f(i - 2) + 2 * A[i - 1] - 2 * A[i - 2]
    total = 0
    for j in range(N):
        if j % 2 == 0:
            total += A[(i + j) % N]
        else:
            total -= A[(i + j) % N]
    return total

B = (f(i) for i in range(N))

print(*B)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

def f(i):
    total = 0
    for j in range(N):
        if j % 2 == 0:
            total += A[(i + j) % N]
        else:
            total -= A[(i + j) % N]
    return total

B = [f(i) for i in range(N)]

print(*B)

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = (B[0] - B[2]) // 2
# A[1] - A[2] = (B[1] - B[3]) // 2
# A[2] - A[3] = (B[2] - B[4]) // 2
# A[3] - A[4] = (B[3] - B[0]) // 2
# A[4] - A[0] - (B[4] - B[1]) // 2

# A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# A[2] - A[3] + A[4] - A[0] + A[1] = B[2]
# A[3] - A[4] + A[0] - A[1] + A[2] = B[3]