Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

a = input()
q = int(input())

for i in range(q):
    q_list = input().split()
    if q_list[0] == '1':
        a = a[::-1]
    else:
        if q_list[1] == '1':
            a = q_list[2] + a
        else:
            a += q_list[2]
print(a)


Fixed submission:
# coding: utf-8

a = input()
q = int(input())
mode = 1
L = ''
R = ''

for _ in range(q):
    q_list = input().split()

    if q_list[0] == '1':
        mode *= -1
    else:
        if q_list[1] == '1':
            if mode == 1:
                L += q_list[2]
            else:
                R += q_list[2]
        else:
            if mode == -1:
                L += q_list[2]
            else:
                R += q_list[2]
result = L[::-1] + a + R
if mode == -1:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

a = input()
q = int(input())

for i in range(q):
    q_list = input().split()
    if q_list[0] == '1':
        a = a[::-1]
    else:
        if q_list[1] == '1':
            a = q_list[2] + a
        else:
            a += q_list[2]
print(a)


Fixed submission:
# coding: utf-8

a = input()
q = int(input())
mode = 1
L = ''
R = ''

for _ in range(q):
    q_list = input().split()

    if q_list[0] == '1':
        mode *= -1
    else:
        if q_list[1] == '1':
            if mode == 1:
                L += q_list[2]
            else:
                R += q_list[2]
        else:
            if mode == -1:
                L += q_list[2]
            else:
                R += q_list[2]
result = L[::-1] + a + R
if mode == -1:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

a = input()
q = int(input())

for i in range(q):
    q_list = [b for b in input().split()]
    if q_list[0] == '1':
        a = a[::-1]
    else:
        if q_list[1] == '1':
            a = q_list[2] + a
        else:
            a += q_list[2]
print(a)


Fixed submission:
# coding: utf-8

a = input()
q = int(input())
mode = 1
L = ''
R = ''

for _ in range(q):
    q_list = input().split()

    if q_list[0] == '1':
        mode *= -1
    else:
        if q_list[1] == '1':
            if mode == 1:
                L += q_list[2]
            else:
                R += q_list[2]
        else:
            if mode == -1:
                L += q_list[2]
            else:
                R += q_list[2]
result = L[::-1] + a + R
if mode == -1:
    result = result[::-1]
print(result)
Buggy python submission (verdict: Runtime Error):
a = str(input())

if a % 2 == 0:
  print(a % 2)
else:
  print((a+1) % 2)

Fixed submission:
a = int(input())
b = int(a / 2)
c = int((a + 1) / 2)

if a % 2 == 0:
    print(b)
else:
    print(c)
Buggy python submission (verdict: Runtime Error):
x = input()

if x >= 30 :
  print('Yes')
else :
  print('No')

Fixed submission:
x = int(input())

if x >= 30 :
  print('Yes')
else :
  print('No')
Buggy python submission (verdict: Runtime Error):
n,d = map(int,input().split())

ans = 0

for i in input() :
  x,y = map(int,i.split())
  if pow(x,2) + pow(y,2) <= pow(d,2) :
    ans += 1
print(ans)

Fixed submission:
n,d = map(int,input().split())
p = [list(map(int,input().split())) for i in range(n)]
ans = 0

for i in p :
  if i[0]**2 + i[1]**2 <= d**2 :
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
d, t, s = int(input())
a = d / s
print('Yes' if a <= t else 'No')


Fixed submission:
d, t, s = map(int, input().split())
a = d / s
print('Yes' if a <= t else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
total = 0
for i in range(n):
  for j in range(i + 1, n):
    total += l[i] * l[j]
print(total % (10 ** 9 + 7))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = sum(A)
n = 0
for i in range(N-1):
    n += A[i]*(B-A[i])
    B = B-A[i]
print(n%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
import math 

N, K = map(int, input().split())
scores = list(map(int, input().split()))
l = []
for i in range(N - K + 1):
  l += [math.prod(scores[i:i+K])]

for i in range(len(l) - 1):
  if l[i] < l[i + 1]:
    print('Yes')
  else:
    print('No')





Fixed submission:
import math 

N, K = map(int, input().split())
scores = list(map(int, input().split()))
l = []
for i in range(N - K):
  print("Yes") if scores[i] < scores[i + K] else print("No")

for i in l:
  print(i)
Buggy python submission (verdict: Runtime Error):
s = input()
return ' '.join(s.split(','))


Fixed submission:
s = input()
print(' '.join(s.split(',')))

Buggy python submission (verdict: Runtime Error):
return ' '.join(s.split(','))

Fixed submission:
s = input()
print(' '.join(s.split(',')))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
 
# t, s = map(str,input().split())

n = int(input())
str_a = input().split()

a = []
for i in range(len(str_a)):
    a.append(int(str_a[i]))

total = 0
for i in range(n):
    for j in range(i + 1, n):
        total += a[i] * a[j]

print(total % (1000000000 + 7))

Fixed submission:
# -*- coding: utf-8 -*-
 
# t, s = map(str,input().split())

n = int(input())
str_a = input().split()

a = []
for i in range(len(str_a)):
    a.append(int(str_a[i]))

total = 0
c = 0
for i in range(n - 1):
    c += a[-i]
    total += c * a[-(i + 1)]

print(total % (1000000007))
Buggy python submission (verdict: Runtime Error):
x = input(x)

if x  == 0:
    print('1')
if x == 1:
    print('0')

Fixed submission:
x = int(input())

if x  == 0:
    print('1')
if x == 1:
    print('0')
Buggy python submission (verdict: Time Limit Exceeded):
# B

N = int(input())
solve = []

while N > 0:
    solve.append(N % 10)
    N //= 10

ans = 0
for i in range(len(solve)):
    ans += solve[i]

if ans % 9 == 0:
    print('Yes')
if ans % 9 != 0:
    print('No')

Fixed submission:
N = int(input())

k = N % 9

if k == 0:
    print('Yes')
    
if k != 0:
    print('No')
Buggy python submission (verdict: Runtime Error):
from statistics import median

N = int(input())
an = list(map(int,input().split()))

for i in range(N):
    an[i] = an[i] - (i+1)
    
b = int(median(bn))

k = []
for i in range(N):
    y = abs(an[i] - b)
    k.append(y)
ans = sum(k)

print(ans)

Fixed submission:
import numpy as np

N = int(input())
an = list(map(int,input().split()))

for i in range(N):
    an[i] = an[i] - (i+1)
    
b = int(np.median(an))

k = []
for i in range(N):
    y = abs(an[i] - b)
    k.append(y)
ans = sum(k)

print(ans)
Buggy python submission (verdict: Runtime Error):
#  ABC 088 B - Card Game for Two
N = int(input())
an = list(map(int, input().split()))

Alice = []
Bob = []
while len(an) > 0:
    Alice.append(max(an))
    del an[an.index(max(an))]
    Bob.append(max(an))
    del an[an.index(max(an))]

k = 0
j = 0
for i in range(len(Alice)):
    k += Alice[i]
for i in range(len(Bob)):
    j += Bob[i]

print(str(k-j))

Fixed submission:
#  ABC 088 B - Card Game for Two
N = int(input())
an = list(map(int, input().split()))

Alice = []
Bob = []
while len(an) > 0:
    Alice.append(max(an))
    del an[an.index(max(an))]
    if len(an) > 0:
        Bob.append(max(an))
        del an[an.index(max(an))]
    else:
        break

k = 0
j = 0
for i in range(len(Alice)):
    k += Alice[i]
for i in range(len(Bob)):
    j += Bob[i]

print(str(k-j))
Buggy python submission (verdict: Time Limit Exceeded):
# AGC 012 A - AtCoder Group Contest
N = int(input())
an = list(map(int,input().split()))

lists = [[] for _ in range(N)]
for k in range(N):
    lists[k].append(max(an))
    del an[an.index(max(an))]
    lists[k].append(max(an))
    del an[an.index(max(an))]

for k in range(N):
    lists[k].append(max(an))
    del an[an.index(max(an))]
    
sasa = 0
for j in range(N):
    sasa += lists[j][1]
print(sasa)

Fixed submission:
# AGC 012 A - AtCoder Group Contest
N = int(input())
an = list(map(int,input().split()))

lists = [[] for _ in range(N)]
an.sort(reverse=True)

for k in range(N):
    lists[k].append(an[2*k])
    lists[k].append(an[2*k+1])
                    
for i in range(N):
    lists[i].append(an[2*N-1+i])

sasa = 0
for j in range(N):
    sasa += lists[j][1]
print(sasa)
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())

count = 0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            s = x + y + z
            if s == S:
                count = count + 1    
print(str(count))

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

count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if z >=0 and z <= K:
            count +=1
            
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())

count = 0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            s = x + y + z
            if s == S:
                count = count + 1    
print(str(count))

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

count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if z >=0 and z <= K:
            count +=1
            
print(count)
Buggy python submission (verdict: Runtime Error):
a = map(int,input().split())
print(a[0]*a[1])

Fixed submission:
a, b = map(int,input().split())
print(a*b)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
is_zero = False
for i in a:
  if i == 0:
    is_zero = True
    break
if is_zero:
  print(0)
else:
  p = 1
  for i in p:
    p = p*i
    if p > 10**18:
      break
  if p > 10**18:
    p = -1
  print(p)
    

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
is_zero = False
for i in a:
  if i == 0:
    is_zero = True
    break
if is_zero:
  print(0)
else:
  p = 1
  for i in a:
    p = p*i
    if p > 10**18:
      break
  if p > 10**18:
    p = -1
  print(p)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
for i in range(1,n+1):
    print(a.count(i))


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
f = [0]*(n+1)
for i in a:
    f[i] = f[i]+1
for i in range(1,n+1):
    print(f[i])
Buggy python submission (verdict: Runtime Error):
s = input()
t = 753
ans = 1000000
for i in range(len(s)-2):
  ans = min(abs(s[i:i+3]-t))
print(ans)

Fixed submission:
s = input()
t = 753
ans = 1000000
for i in range(len(s)-2):
  ans = min(abs(int(s[i:i+3])-t), ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())

keys = []
for start in range(len(s)):
  for end in range(start+1, len(s)+1):
    key = s[start:end]
    if key in keys:
      continue
    if len(keys) < 5:
      keys.append(key)
      keys.sort()
    elif keys[-1] > key:
      keys.append(key)
      keys.sort()
      keys = keys[:-1]
print(keys[k-1])

Fixed submission:
s = input()
k = int(input())

keys = []
for start in range(len(s)):
  for end in range(start+1, min(start+6, len(s)+1)):
    key = s[start:end]
    if key in keys:
      continue
    if len(keys) < 5:
      keys.append(key)
      keys.sort()
    elif keys[-1] > key:
      keys.append(key)
      keys.sort()
      keys = keys[:-1]
print(keys[k-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
dc = {}
for i in range(n):
  s = input()
  if s in dc:
    dc[s] += 1
  else :
    dc[s] = 1
m = int(input())
for i in range(n):
  t = input()
  if t in dc:
    dc[t] -= 1
  else :
    dc[t] = -1
ans = 0
for i in dc:
  ans = max(ans, dc[i])
print(ans)

Fixed submission:
n = int(input())
dc = {}
for i in range(n):
  s = input()
  if s in dc:
    dc[s] += 1
  else :
    dc[s] = 1
m = int(input())
for i in range(m):
  t = input()
  if t in dc:
    dc[t] -= 1
  else :
    dc[t] = -1
ans = 0
for i in dc:
  ans = max(ans, dc[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

result = ""
for i in s:
  if i == 'B':
    s = s[:-1]
  else
    s = s+i
print(s)

Fixed submission:
s = input()

result = ""
for i in s:
  if i == 'B':
    result = result[:-1]
  else:
    result = result + i
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

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

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

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

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

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def max_group_members(self):
        ret = 1
        for r in self.roots():
            ret = max(len(self.members(r)), ret)
        return ret

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
Groups = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    Groups.union(a-1, b-1)

print(Groups.max_group_members())

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

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

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

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

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


N, M = map(int, input().split())
Groups = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    Groups.union(a-1, b-1)

ans = 0
for i in range(N):
    ans = max(Groups.size(i), ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N, K = map(int,input().split())
A = [int(i) for i in input().split()]

if K == 0:
    print(max(A))
else:
    low = 0
    high = max(A)
    while high - low > 0.5:
        mid = (low + high) / 2
        times = 0
        for a in A:
            times += math.ceil(a / mid) - 1
        if K >= times:
            high = mid
        else:
            low = mid
        #print(mid)

    ans = int(mid)
    times = 0
    for a in A:
        times += math.ceil(a / ans) - 1
    if times <= K:
        print(ans)
    else:
        print(ans+1)


Fixed submission:
import math
N, K = map(int,input().split())
A = [int(i) for i in input().split()]

if K == 0:
    print(max(A))
else:
    low = 0
    high = max(A)
    while high - low > 0.1:
        mid = (low + high) / 2
        times = 0
        for a in A:
            times += math.ceil(a / mid) - 1
        if K >= times:
            high = mid
        else:
            low = mid
        #print(mid)

    ans = int(mid)
    if not ans:
        print(1)
    else:
        times = 0
        for a in A:
            times += math.ceil(a / ans) - 1
        if times <= K:
            print(ans)
        else:
            print(ans+1)
Buggy python submission (verdict: Runtime Error):
S, W = map(int, inpu().split())
if S <= W:
  print("unsafe")
else:
  print("safe")

Fixed submission:
S, W = map(int, input().split())
if S <= W:
  print("unsafe")
else:
  print("safe")
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [int(i) for i in input().split()]
P.sort()
Q.sort()
R.sort()

p, q, r = A - X, B - Y, C - 1
ans = 0

Amin = P[p]
Bmin = Q[q]
Cmax = R[r]
for i in range(C):
    if Cmax <= min(Amin, Bmin):
        break
    else:
        if Amin <= Bmin and p < A:
            ans += Cmax
            r -= 1
            p += 1
            Amin = P[p]
        elif Amin >= Bmin and q < B:
            ans += Cmax
            r -= 1
            q += 1
            Bmin = Q[q]
        Cmax = R[r]
ans += sum(P[p:])+sum(Q[q:])
print(ans)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [int(i) for i in input().split()]
P.sort()
Q.sort()
R.sort()

p, q, r = A - X, B - Y, C - 1
ans = 0

Amin = P[p]
Bmin = Q[q]
Cmax = R[r]
for i in range(C):
    if Cmax <= min(Amin, Bmin):
        break
    else:
        if Amin <= Bmin and p < A:
            ans += Cmax
            r -= 1
            p += 1
            if p < A:
                Amin = P[p]
            else:
                Amin = float("inf")
        elif Amin >= Bmin and q < B:
            ans += Cmax
            r -= 1
            q += 1
            if q < B:
                Bmin = Q[q]
            else:
                Bmin = float("inf")
        Cmax = R[r]
ans += sum(P[p:])+sum(Q[q:])
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
if "A" ib S and "B" in S:
  print("Yes")
else:
  print("No")

Fixed submission:
S = input()
if "A" in S and "B" in S:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
S, T = map(int, input().split())
A, B = map(int, input().split())
if input() == S:
  print(A-1, B)
else:
  print(A, B-1)

Fixed submission:
S, T = input().split()
A, B = map(int, input().split())
if input() == S:
  print(A-1, B)
else:
  print(A, B-1)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
testimony = [[0] * N for i in range(N)]
A = []

for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        x, y = map(int, input().split())
        testimony[i][x-1] = 2 * y - 1

testimony = np.array(testimony)

A = np.array(A)
ans = 0

for i in range(2 ** N):
    honesty = [-1] * N
    h = 0
    for j in range(N):
        if (i >> j) & 1:
            honesty[j] = 1
            h += 1
    honesty = np.array(honesty)
    B = testimony @ honesty - A
    if any(honesty[j] == 1 and B[j] != 0 for j in range(N)):
        continue

    ans = max(ans, h)

print(ans)

Fixed submission:
import numpy as np

N = int(input())
testimony = [[0] * N for i in range(N)]
A = []

for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        x, y = map(int, input().split())
        testimony[i][x-1] = 2 * y - 1

testimony = np.array(testimony)

A = np.array(A)
ans = 0

for i in range(2 ** N):
    honesty = [-1] * N
    h = 0
    for j in range(N):
        if (i >> j) & 1:
            honesty[j] = 1
            h += 1
    honesty = np.array(honesty)
    B = np.dot(testimony,honesty) - A
    if any(honesty[j] == 1 and B[j] != 0 for j in range(N)):
        continue

    ans = max(ans, h)

print(ans)

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

N = int(input())
testimony = [[0] * N for i in range(N)]
A = []

for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        x, y = map(int, input().split())
        testimony[i][x-1] = 2 * y - 1

testimony = np.array(testimony)

A = np.array(A)
ans = 0

for i in range(2 ** N):
    honesty = [-1] * N
    h = 0
    for j in range(N):
        if (i >> j) & 1:
            honesty[j] = 1
            h += 1
    honesty = np.array(honesty)
    B = testimony @ honesty - A
    if any(honesty[j] == 1 and B[j] != 0 for j in range(N)):
        continue

    ans = max(ans, h)

print(ans)

Fixed submission:
import numpy as np

N = int(input())
testimony = [[0] * N for i in range(N)]
A = []

for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        x, y = map(int, input().split())
        testimony[i][x-1] = 2 * y - 1

testimony = np.array(testimony)

A = np.array(A)
ans = 0

for i in range(2 ** N):
    honesty = [-1] * N
    h = 0
    for j in range(N):
        if (i >> j) & 1:
            honesty[j] = 1
            h += 1
    honesty = np.array(honesty)
    B = np.dot(testimony,honesty) - A
    if any(honesty[j] == 1 and B[j] != 0 for j in range(N)):
        continue

    ans = max(ans, h)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
S = input()

l = range(N)
ans = set()

for comb in itertools.combinations(l, 3):
    x, y, z = comb
    s = S[x] + S[y] + S[z]
    ans .add(s)
    
    if len(ans) >= 10 ** 3:
        break
        
print(len(ans))

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    key = str(i)
    key = "0"*(3-len(key)) + key

    cur = 0
    for s in S:
        if s == key[cur]:
            cur += 1
        if cur >= 3:
            ans += 1
            break

print(ans)
Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7


def comb(n, k):
    N = n + k + 1
    fact = [1] * (N + 1)
    rfact = [1] * (N + 1)
    r = 1
    for i in range(1, N + 1):
        fact[i] = r = r * i % MOD

    rfact[N] = r = pow(fact[N], MOD - 2, MOD)
    for i in range(N, 0, -1):
        rfact[i - 1] = r = r * i % MOD
    return fact[n] * rfact[k] * rfact[n - k] % MOD


X, Y = map(int, input().split())
x = 2 * X - Y
y = 2 * Y - X

if x % 3 and y % 3:
    print(0)
else:
    xx = x // 3
    yy = y // 3
    print(comb(xx + yy, xx))

Fixed submission:
MOD = 10 ** 9 + 7


def comb(n, k):
    N = n + k + 1
    fact = [1] * (N + 1)
    rfact = [1] * (N + 1)
    r = 1
    for i in range(1, N + 1):
        fact[i] = r = r * i % MOD

    rfact[N] = r = pow(fact[N], MOD - 2, MOD)
    for i in range(N, 0, -1):
        rfact[i - 1] = r = r * i % MOD
    return fact[n] * rfact[k] * rfact[n - k] % MOD


X, Y = map(int, input().split())
x = 2 * X - Y
y = 2 * Y - X

if (x % 3 and y % 3) or x < 0 or y < 0:
    print(0)
else:
    xx = x // 3
    yy = y // 3
    print(comb(xx + yy, xx))
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input())
print(max(A - 2 * B, 0))

Fixed submission:
A, B = map(int, input().split())
print(max(A - 2 * B, 0))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()



for i in range(M):
  A[N-1] = A[N-1] // 2
  if A[N-1] < A[N-2]:
    A.sort()
    
print(sum(A))

Fixed submission:
import heapq

N, M = map(int, input().split())
A = [int(i) * (-1) for i in input().split()]
heapq.heapify(A)
h = heapq.heappop(A)

for i in range(M):
  h = heapq.heappushpop(A, (h*(-1))//2*(-1))
    
print((sum(A)+h) * (-1))