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

Fixed submission:
import math
from operator import mul
from functools import reduce

def comb(n, r):
  r = min(r, n-r)
  if r==0: return 1
  over = reduce(mul, range(n, n-r, -1))
  under = reduce(mul, range(1, r+1))
  return over//under

n, k = map(int, input().split())
mod = 10**9+7

for i in range(1, k+1):
  if i <= n-k+1:
    ans = comb(n-k+1, i) * comb(k-1, i-1)
    ans %= mod
  else:
    ans = 0
  print(ans)

Buggy submission (verdict: Runtime Error):
import math
mod = 10**9+7

def comb(n, r):
  return (math.factorial(n)) / (math.factorial(n-r)) / (math.factorial(r))

n, k = map(int, input().split())


for i in range(1, k+1):
  if i <= n-k+1:
    ans = comb(n-k+1, i)%mod * comb(k-1, i-1)%mod
    ans %= mod
  else:
    ans = 0
  print(int(ans))

Buggy submission (verdict: Runtime Error):
import math

def comb(n, r):
  return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))

n, k = map(int, input().split())
mod = 10**9+7

for i in range(1, k+1):
  if i <= n-k+1:
    ans = comb(n-k+1, i) * comb(k-1, i-1)
    ans %= mod
  else:
    ans = 0
  print(int(ans))

Buggy submission (verdict: Runtime Error):
import math

def comb(n, r):
  return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))

n, k = map(int, input().split())
mod = 10**9+7

for i in range(1, min(n-k+2, k+1)):
  ans = comb(n-k+1, i) * comb(k-1, i-1)
  ans %= mod
  print(int(ans))

Buggy submission (verdict: Runtime Error):
import math

def comb(n, r):
  return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))

n, k = map(int, input().split())
mod = 10**9+7

for i in range(1, k+1):
  ans = comb(n-k+1, i) * comb(k-1, i-1)
  ans %= mod
  print(int(ans))
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))


def count_steps(NN):

    steps = [0] * (NN + 3)
    steps[1] = 1
    steps[2] = 2
    for i in range(3, NN + 1):
        steps[i] = steps[i - 1] + steps[i - 2]
    return steps[NN]

if m == 0:
    ans = count_steps(n)
else:
    if a[0] == 1:
        ans = 1
    else:
        ans = count_steps(a[0] - 1)

    for i in range(1, len(a)):
        temp = a[i] - a[i - 1] - 2
        if temp < 0:
            ans = 0
        elif temp == 0:
            ans *= 1
        else:
            ans *= count_steps(temp)

    temp = n - a[-1] - 1
    if temp > 0:
        ans *= count_steps(temp)
print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))


def count_steps(NN):

    steps = [0] * (NN + 3)
    steps[1] = 1
    steps[2] = 2
    for i in range(3, NN + 1):
        steps[i] = steps[i - 1] + steps[i - 2]
    return steps[NN]

if a[0] == 1:
    ans = 1
else:
    ans = count_steps(a[0]-1)

for i in range(1, len(a)):
    temp = a[i]-a[i-1]-2
    if temp < 0:
        ans = 0
    elif temp==0:
        ans *= 1
    else:
        ans *= count_steps(temp)

temp = n-a[-1]-1
if temp>0:
    ans *= count_steps(temp)
print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))


def count_steps(NN):

    steps = [0] * (NN + 3)
    steps[1] = 1
    steps[2] = 2
    for i in range(3, NN + 1):
        steps[i] = steps[i - 1] + steps[i - 2]
    return steps[NN]

if a[0] == 1:
    ans = 1
else:
    ans = count_steps(a[0]-1)

for i in range(1, len(a)):
    temp = a[i]-a[i-1]-2
    if temp < 0:
        ans = 0
    elif temp==0:
        ans *= 1
    else:
        ans *= count_steps(temp)

ans *= count_steps(n-a[-1]-1)
print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))


def count_steps(NN):
    NN -= 1
    steps = [0] * (NN + 3)
    steps[1] = 1
    steps[2] = 2
    for i in range(3, NN + 1):
        steps[i] = steps[i - 1] + steps[i - 2]
    return steps[NN]

if a[0] == 1:
    ans = 1
else:
    ans = count_steps(a[0])

for i in range(1, len(a)):
    ans *= count_steps(a[i]-a[i-1]-1)
ans *= count_steps(n-a[-1])
print(ans%1000000007)
Problem p03041 (python)

Fixed submission:

n,k = map(int, input().split())
s = input()

s_temp = s.swapcase()

ans = s[:k-1]+s_temp[k-1]+s[k:]

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n-1)]

graph = [[] for _ in range(n)]
for i in range(n-1):
    graph[uvw[i][0]-1].append((uvw[i][1]-1, uvw[i][2]))
    graph[uvw[i][1]-1].append((uvw[i][0]-1, uvw[i][2]))

stack = [0]
visited = []
ans = [0]*n
while stack:
    node = stack.pop()
    visited.append(node)
    for child in graph[node]:
        if child[0] not in visited:
            stack.append(child[0])
            if child[1]%2 == 0:
                ans[child[0]] = ans[node]
            else:
                ans[child[0]] = (ans[node]+1)%2

[print(ans[i]) for i in range(n)]

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

s_temp = s.swapcase()

ans = s[:k]+s_temp[k]+s[k+1:]

print(ans)
Problem p02725 (python)

Fixed submission:
k,n = map(int,input().split(" "))
alist = list(map(int, input().split(" ")))
glist = []
for i in range(n-1):
  glist.append(alist[i+1]-alist[i])
glist.append(k+alist[0]-alist[n-1])

print(k-max(glist))

Buggy submission (verdict: Runtime Error):
k,n = map(int,input().split(" "))
alist = list(map(int, input().split(" ")))
glist = []
for i in range(n-1):
  glist.append(alist[i+1]-alist[i])
glist.append(k+a[0]-a[n-1])

print(k-max(glist))

Buggy submission (verdict: Runtime Error):
k ,n  = map(int, input().split(" "))
alist = list(map(int, input().split(" "))
glist =  []
for i in range(n-1):
    glist.append(alist[i+1]-alist[i])
glist.append(k+alist[0]-alist[n-1])

print(int(k-max(glist)))
Problem p02571 (python)

Fixed submission:
def main():
    s = list(input())
    t = list(input())
    lt = len(t)
    ls = len(s)
    ans = 1000
    
    
    def dis(a, b):
        d = 0
        for ai, bi in zip(a, b):
            if ai == bi:
                continue
            d += 1
        return d
    
    for i in range(ls-lt+1):
        ans = min(ans, dis(s[i:i+lt], t))
    
    print(ans)
        
    

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from numba import njit


@njit
def main():
    s = input()
    t = input()
    ans = 1000

    for i in [1, 2, 3]:
        ans += 1
    
    print(ans)
        
    
main()

Buggy submission (verdict: Runtime Error):
from numba import njit

def dis(a, b):
  d = 0
  for ai, bi in zip(a, b):
    if ai == bi:
      continue
      d += 1
      return d

@njit
def main():
    s = list(input())
    t = list(input())
    lt = len(t)
    ls = len(s)
    ans = 1000

    for i in prange(ls-lt+1):
        ans = 1
    
    print(ans)
        
    

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from numba import njit

def dis(a, b):
  d = 0
  for ai, bi in zip(a, b):
    if ai == bi:
      continue
      d += 1
      return d

@njit
def main():
    s = list(input())
    t = list(input())
    lt = len(t)
    ls = len(s)
    ans = 1000

    for i in prange(ls-lt+1):
        ans = min(ans, dis(s[i:i+lt], t))
    
    print(ans)
        
    

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from numba import njit

@njit(cache = True)
def dis(a, b):
  d = 0
  for ai, bi in zip(a, b):
    if ai == bi:
      continue
      d += 1
      return d

@njit
def main():
    s = list(input())
    t = list(input())
    lt = len(t)
    ls = len(s)
    ans = 1000

    for i in prange(ls-lt+1):
        ans = min(ans, dis(s[i:i+lt], t))
    
    print(ans)
        
    

if __name__ == "__main__":
    main()
Problem p02595 (python)

Fixed submission:
def main():
    n, d = map(int, input().split())
    dis = d**2
    ans = 0
    for _ in range(n):
        x, y = map(int, input().split())
        if x**2 + y**2 <= dis:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, d = map(int, input().split())
    is_shorter = lambda dis, x, y : dis**2 <= (x**2 + y**2)
    ans = sum([is_shorter(d, map(int, input().split())) for _ in range(n)])
    print(ans)

if __name__ == "__main__":
    main()
Problem p02685 (python)

Fixed submission:
def main():
    n, m, k = map(int, input().split())
    mod = 998244353
    ans = 0
    m1 = [None]*(n+1)
    kaizyo = [None]*(n+1)
    nm1 = 1
    kai = 1
    for i in range(n+1):
        m1[i] = nm1
        nm1 *= m-1
        nm1 %= mod
        kaizyo[i] = kai
        kai *= i+1
        kai %= mod
    
    def comb(a, b):
        return (kaizyo[a]*fermat(kaizyo[a-b]*kaizyo[b], mod))%mod

    for i in range(k+1):
        ans += m*m1[n-i-1]*comb(n-1, i)
        ans %= mod
    
    print(ans)

def fermat(x, p):
    """
    1/x (mod p) を返す
        x**(p-1) ≡ 1    [if gcd(x, p) == 1]
        x**(p-2) ≡ 1/x
        繰返し二乗法 
            ex: x**50  = (x**25)**2
                x**25  = (x**12)**2 * x
                x**12  = (x**6)**2
                x**6   = (x**3)**2
    """
    times = []
    mod = p
    p -= 2
    while p > 1:
        times.append(p%2)
        p //= 2
    x %= mod
    out = x
    for i in times[::-1]:
        if i:
            out = (x*pow(out, 2, mod))%mod
        else:
            out = pow(out, 2, mod)
    return out



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    def kaizyo(x):
        ans = 1
        for i in range(2, x+1):
            ans *= i
        return ans

    n, m, k = map(int, input().split())
    MAX = 998244353
    ans = 0
    kaizyos = [None]*n
    ki = 1
    kaizyos[0] = ki
    for i in range(1, n):
        ki *= i
        ki %= MAX
        kaizyos[i] = ki
    def comb(a, b):
        return kaizyos[a]//(kaizyos[b]*kaizyos[a-b])
    ruizyos = [None]*(k+1)
    ruizyo = 1
    for i in range(n-1-k):
        ruizyo *= m-1
        ruizyo %= MAX
    ruizyos[0] = ruizyo
    for i in range(n-k, n):
        ruizyo *= m-1
        ruizyo
        ruizyos[i-n-k+1] = ruizyo
    pattern = lambda x: (comb(n-1, x)*m*ruizyos[x])%MAX
    for i in range(k+1):
        ans += pattern(i)
        ans %= MAX
    print(ans)


if __name__ == "__main__":
    main()
Problem p02725 (python)

Fixed submission:
k, n = map(int, input().split())
a = list(map(int, input().split()))
ans = a[-1] - a[0]
for i in range(1, n):
    start = a[i]
    end = a[i-1]+k
    ans = min(ans, end-start)
print(ans)

Buggy submission (verdict: Runtime Error):
def main():
    x, y = map(int, input().split())
    a = list(map(int, input().split()))
    cost = 10*10
    for i in range(n-1):
        cost = min(cost, k - abs(a[i]-a[i+1]))
    print(min(cost, k-abs(a[0]+k-a[n-1])))

if __name__ == "__main__":
    main()
Problem p02757 (python)

Fixed submission:
def main():
    n, p = map(int, input().split())
    s = input()
    mu = [None]*n
    ans = 0
    c = [0]*p
    if 10%p == 0:
        ss = map(int, s)
        ss = list(ss)
        for i in range(n):
            if ss[i]%p == 0:
                ans += i+1
        print(ans)
        return
    sr = s[::-1]
    ssr = map(int, sr)
    tens = 1
    v = 0
    for i, si in enumerate(ssr):
        v = (v + (si%p)*tens)%p
        mu[i] = v
        c[v] += 1
        tens *= 10
        tens %= p
    c[0] += 1
    for i in c:
        if i:
            ans += ((i-1)*i)//2
        
    print(ans)
    

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, p = map(int, input().split())
    s = input()
    mu = [None]*n
    ans = 0
    c = [0]*p
    ss = map(int, s)
    if 10%p == 0:
        for i in range(n):
            if ss[i]%p == 0:
                ans += i+1
        print(ans)
        return
    num = int(s)
    keta = n-1
    for i, si in enumerate(ss):
        v = num%p
        mu[i] = v
        c[v] += 1
        num -= si*10**keta
        keta -= 1
    c[0] += 1
    for i in mu:
        c[i] -= 1
        ans += c[i]
        
    print(ans)
    

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, p = map(int, input().split())
    s = input()
    mu = [None]*n
    ans = 0
    c = [0]*p
    ss = map(int, s)
    if 10%p == 0:
        for i in range(n):
            if ss[i]%p == 0:
                ans += i+1
        print(ans)
        return
    num = int(s)
    keta = n-1
    for i, si in enumerate(ss):
        v = num%p
        mu[i] = v
        c[v] += 1
        num -= si*10**keta
        keta -= 1
    c[0] += 1
    for i in mu:
        c[i] -= 1
        ans += c[i]
        
    print(ans)
    

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, p = map(int, input().split())
    s = input()
    mu = [None]*n
    ans = 0
    c = [0]*p
    if 10%p == 0:
        for i in range(n):
            if int(s[i])%p == 0:
                ans += i+1
        print(ans)
        return
    num = int(s)
    keta = n-1
    for i in range(n):
        v = num%p
        mu[i] = v
        c[v] += 1
        num -= si*10**keta
        keta -= 1
    c[0] += 1
    for i in mu:
        c[i] -= 1
        ans += c[i]
        
    print(ans)
    

if __name__ == "__main__":
    main()
Problem p02763 (python)

Fixed submission:
def main():
    n = int(input())
    a = ord("a")
    orda = lambda x: ord(x)-a
    s = list(map(orda, list(input())))
    q = int(input())
    bits = [BIT(n) for _ in range(26)]
    for i, si in enumerate(s, 1):
        bits[si].add(i, 1)
    for _ in range(q):
        t, i, c = input().split()
        i = int(i)
        if t == "1":
            bits[s[i-1]].add(i, -1)
            bits[ord(c)-a].add(i, 1)
            s[i-1] = ord(c)-a
        else:
            c = int(c)
            cnt = 0
            for bit in bits:
                is_in = bit.sum_(c) - bit.sum_(i-1)
                if is_in:
                    cnt += 1
            print(cnt)
            
            
class BIT:
    __slots__ = ["length", "data"]
    def __init__(self, length):
        self.data = [0]*(length+1)
        self.length = length
    
    def add(self, i, x):
        while i < self.length+1:
            self.data[i] += x
            i += i&-i
    
    def sum_(self, i):
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i&-i
        return x


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = ord("a")
    orda = lambda x: ord(x)-a
    s = list(map(orda, list(input())))
    q = int(input())
    bits = [BIT(n) for _ in range(26)]
    for i, si in enumerate(s, 1):
        bits[si].add(i, 1)
    for _ in range(q):
        t, i, c = input().split()
        i = int(i)
        if t == "1":
            bits[s[i-1]].add(i, -1)
            bits[ord(c)-a].add(i, 1)
            si[i-1] = ord(c)-a
        else:
            c = int(c)
            cnt = 0
            for bit in bits:
                is_in = bit.sum_(c) - bit.sum_(i-1)
                if is_in:
                    cnt += 1
            print(cnt)
            
            
class BIT:
    __slots__ = ["length", "data"]
    def __init__(self, length):
        self.data = [0]*(length+1)
        self.length = length
    
    def add(self, i, x):
        while i < self.length+1:
            self.data[i] += x
            i += i&-i
    
    def sum_(self, i):
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i&-i
        return x


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    S = input()
    q = int(input())
    for _ in range(q):
        t, i, c = input().split()
        if t == '1':
            S[int(i)-1] = c
        else:
            print(len(set(S[int(i)-1:int(c)])))
        
if __name__ == "__main__":
    main()
Problem p02594 (python)

Fixed submission:
X = int(input())
if X >= 30:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import copy
import math

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

sorted_As = sorted(As,reverse = True)
cut_As = copy.copy(sorted_As)
count_list = [0]*len(sorted_As)

for i in range(K):
    index = cut_As.index(max(cut_As))
    count = count_list[index]
    count_list[index] += 1
    cut_As[index] = sorted_As[index] / (count+2)

'''
for i in range(K):
    count = count_list[0]
    count_list[0] += 1
    cut_As[0] = sorted_As[0] / (count+2)
    cut_As,sorted_As,count_list = (list(x) for x in zip(*sorted(zip(cut_As,sorted_As,count_list),reverse = True)))
'''

print(math.ceil(max(cut_As)))

Buggy submission (verdict: Runtime Error):
import copy
import math

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

sorted_As = sorted(As,reverse = True)
cut_As = copy.copy(sorted_As)
count_list = [0]*len(sorted_As)

for i in range(K):
    index = cut_As.index(max(cut_As))
    count = count_list[index]
    count_list[index] += 1
    cut_As[index] = sorted_As[index] / (count+2)

'''
for i in range(K):
    count = count_list[0]
    count_list[0] += 1
    cut_As[0] = sorted_As[0] / (count+2)
    cut_As,sorted_As,count_list = (list(x) for x in zip(*sorted(zip(cut_As,sorted_As,count_list),reverse = True)))
'''

print(math.ceil(max(cut_As)))
Problem p02661 (python)

Fixed submission:
N = int(input())
array1 = []
array2 = []
for i in range(N):
    a,b = map(int,input().split())
    array1.append(a)
    array2.append(b)

array1.sort()
array2.sort()

if N % 2 == 0:
    min = array1[N//2]+array1[N//2-1]
    max = array2[N//2]+array2[N//2-1]
    print(max-min+1)
else:
    min = array1[N//2]
    max = array2[N//2]
    print(max-min+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
array1 = []
array2 = []
for i in range(N):
    a,b = map(int,input().split())
    array1.append(a)
    array2.append(b)

array1.sort()
array2.sort()

if N % 2 == 0:
    min = array1[N//2]+array1[N//2+1]
    max = array2[N//2]+array2[N//2+1]
    print(max-min+1)
else:
    min = array1[N//2]
    max = array2[N//2]
    print(max-min+1)
Problem p02685 (python)

Fixed submission:
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2,max):
        fac[i] = fac[i-1]*i%mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod

def COM(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k]*finv[n-k]%mod)%mod

mod = 998244353
N,M,K = map(int,input().split())

max = N + M + K
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()
ans = 0
for i in range(K+1):
    c = COM(N-1,i)
    m = pow(M-1,N-i-1,mod)
    ans = (ans + ((c*m%mod)*M%mod))%mod
print(ans)

Buggy submission (verdict: Runtime Error):
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2,max):
        fac[i] = fac[i-1]*i%mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod

def COM(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k]*finv[n-k]%mod)%mod

mod = 998244353
N,M,K = map(int,input().split())

max = N 
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()
ans = 0
for i in range(K+1):
    c = COM(N-1,i)
    m = pow(M-1,N-i-1,mod)
    ans = (ans + ((c*m%mod)*M%mod))%mod
print(ans)

Buggy submission (verdict: Runtime Error):
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2,max):
        fac[i] = fac[i-1]*i%mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod

def COM(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k]*finv[n-k]%mod)%mod

mod = 998244353
N,M,K = map(int,input().split())

max = N
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()
ans = 0
for i in range(K+1):
    c = COM(N-1,i)
    m = pow(M-1,N-i-1,mod)
    ans = (ans + ((c*m%mod)*M%mod))%mod
print(ans)
Problem p02633 (python)

Fixed submission:
X = int(input())
tmp = 360
while True:
    if tmp % X == 0:
        print(tmp//X)
        exit()
    else:
        tmp+= 360

Buggy submission (verdict: Runtime Error):
try:
	n = int(input())
	tmp = 360
	while True:
    	if tmp % n == 0:
        	print(tmp//n)
        	exit(0)
    	else:
        	tmp+= 360
Problem p02598 (python)

Fixed submission:
from math import ceil

n,k = map(int,input().split())
A = list(map(int,input().split()))

def flag(upper):
    c = 0
    for a in A:
        c += ceil(a / upper) - 1
        if c > k:
            return False
    return True

def main():
    A.sort(reverse=True)
    low = 1
    high = A[0]
    while low < high:
        mid = (low + high) // 2
        if flag(mid):
            high = mid
        else:
            low = mid + 1
    print(high)
    return

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from math import ceil

n,k = map(int,input().split())
A = list(map(int,input().split()))

def flag(upper):
    c = 0
    for a in A:
        c += int(a / upper)
        if c > k:
            return False
    return True

def main():
    A.sort(reverse=True)
    low = 0
    high = A[0]
    while low < high:
        mid = (low + high) // 2
        if flag(mid):
            high = mid
        else:
            low = mid + 1
    print(high)
    return

if __name__ == "__main__":
    main()
Problem p02912 (python)

Fixed submission:
def minus(a:str):
    return int(a)*-1

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

import heapq as hq

def main():
    hq.heapify(A)
    for _ in range(M):
        target = hq.heappop(A)
        target = -1*((-1*target) // 2)
        hq.heappush(A,target)
    print(sum(A)*-1)
    return 

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
class Heap:
    
    def maintain_heapify(self,A,i):
        l=2*i+1
        r=2*i+2
        if self.name=='max':
            if l<len(A) and A[l]>A[i]:
                largest=l
            else:
                largest=i
            
            if r<len(A) and A[r]>A[largest]:
                largest=r
            
            if largest!=i:
                A[largest],A[i]=A[i],A[largest]
                self.maintain_heapify(A,largest)

        elif self.name=='min':
            if l<len(A) and A[l]<A[i]:
                smallest=l
            else:
                smallest=i
            if r<len(A) and A[r]<A[smallest]:
                smallest=r
            if smallest!=i:
                A[smallest],A[i]=A[i],A[smallest]
                self.maintain_heapify(A,smallest)

    def build_heap(self,A):
        i=len(A)//2
        while i>=0:
            self.maintain_heapify(A,i)
            i-=1

    def __init__(self,A,name='max'):
        self.name=name
        self.build_heap(A)
        self.heap=A

    def insert(self,v):
        self.heap.append(v)
        self.build_heap(self.heap)

    def deleteroot(self):
        root=self.heap[:1]
        tmp=self.heap[1:len(self.heap)-1]
        self.heap=self.heap[len(self.heap)-1:]+tmp
        self.build_heap(self.heap)
        return root[0]

    def get_root(self):
        return self.heap[0]
    def get_sum(self):
      	for i in range(len(self.heap)):
          self.heap[i] = int(self.heap[i])
        return sum(self.heap)


def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    heap = Heap(A)
    tmp = 0
    for cnt in range(M):
        first = heap.deleteroot()
        plus = first / 2
        heap.insert(plus)
    print(heap.get_sum())
    return
main()