Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#始めの2匹が決まるとあとは自動的に決まるので矛盾していないかどうか判定

def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    s = list(input())
    s += s[0]

    def check(p):
        for i in range(1, N):
            if s[i]=='o' and p[i]=='S':
                p += p[i-1]
            elif s[i]=='o' and p[i]=='W':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            elif s[i]=='x' and p[i]=='S':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            else:
                p += p[i-1]
        if p[0]==p[N] and p[1]==p[N+1]:
            print(p[:-2])
            exit()

    for i in ['SS', 'SW', 'WS', 'WW']:
        check(i)
    print(-1)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    s = list(input())

    def check(p):
        for i in range(1, N):
            if s[i]=='o' and p[i]=='S':
                p += p[i-1]
            elif s[i]=='o' and p[i]=='W':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            elif s[i]=='x' and p[i]=='S':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            else:
                p += p[i-1]
        if p[0]==p[N]:
            if s[0]=='o' and p[0]=='S':
                if p[N-1]==p[1]:
                    print(p[:N])
                    exit()
            elif s[0]=='x' and p[0]=='S':
                if p[N-1]!=p[1]:
                    print(p[:N])
                    exit()
            elif s[0]=='o' and p[0]=='W':
                if p[N-1]!=p[1]:
                    print(p[:N])
                    exit()
            else:
                if p[N-1]==p[1]:
                    print(p[:N])
                    exit()

    for i in ['SS', 'SW', 'WS', 'WW']:
        check(i)
    print(-1)
    


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
res = 0
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007


    N,M = map(int, input().split())
    g = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int, input().split())
        g[a-1].append(b-1)
        g[b-1].append(a-1)

    visited = [0]*N

    def dfs(node):
      	global res
        visited[node]=1
        if all(visited):
            res += 1
            return
        for n_node in g[node]:
                if not visited[n_node]:
                    dfs(n_node)
                    visited[n_node] = 0
    dfs(0)
    print(res)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

    n,m = map(int, input().split())
    edge = [list(map(int, input().split())) for _ in range(m)]
    res = []
    visited = [0]*n

    def dfs(node):
        visited[node-1]=1
        if sum(visited)==n:
            res.append(1)
            return
        for x,y in edge:
            if x == node:
                if not visited[y-1]:
                    dfs(y)
                    visited[y-1] = 0
            if y == node:
                if not visited[x-1]:
                    dfs(x)
                    visited[x-1] = 0

    for a,b in edge:
        if a==1:
            dfs(a)
            print(len(res))
            exit()

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
for i in range(1, n+1):
    num = 2
    while i != 1:
        if i % num==0:
            i //= num
            l.append(num)
        else:
            num += 1
ans = 1
for i in set(l):
    ans *= (l.count(i) + 1) % (10**9+7)
print(ans)

Fixed submission:
n = int(input())
s, ans, num = 1, 1, 2
for i in range(2, n+1):
  s *= i
l = []
while s != 1:
  if not s % num:
    l.append(num)
    s //= num
  else:
    num += 1
for i in set(l):
  ans *= l.count(i)+1
print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):
k, s = list(map(int, input().split()))
cnt = 0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            total = i+j+k
            if total==s:
                cnt += 1
print(cnt)

Fixed submission:
s = input()
print(s.replace(',', ' '))
Buggy python submission (verdict: Time Limit Exceeded):
k, s = list(map(int, input().split()))
cnt = 0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            total = i+j+k
            if total==s:
                cnt += 1
print(cnt)

Fixed submission:
k, s = list(map(int, input().split()))
cnt = 0
for i in range(k+1):
    if i>s:
        break
    for j in range(k+1):
        if i+j>s:
            break
        if i+j+k>=s:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
print('vowel') if input() in ['a', 'i', 'u', 'e', 'o'] print('consonant')

Fixed submission:
print('vowel') if input() in ['a', 'i', 'u', 'e', 'o'] else print('consonant')
Buggy python submission (verdict: Time Limit Exceeded):
def div_count(N):
    divs = 0
    for i in range(1, int(N**0.5) + 1):
        if not N % i:
            divs += 1
            if i != N // i:
                divs += 1
    return divs

def solve():
    ret = 0
    for k in range(1, N + 1):
        ret += k * div_count(k)
    print(ret)

if __name__ == "__main__":
    N = int(input())
    solve()

Fixed submission:
def solve():
    ret = 0
    for k in range(1, N + 1):
        y = N // k
        ret += k * y * (y + 1) // 2
    print(ret)

if __name__ == "__main__":
    N = int(input())
    solve()
Buggy python submission (verdict: Runtime Error):
import numpy as np

if __name__ == "__main__":
    N = int(input())
    A = np.array(list(map(int, input().split())))
    ret = A.prod()
    print(ret if ret < pow(10, 18) else -1)

Fixed submission:
def solve(N, A):
    ret = 1
    upper = 10**18
    if 0 in A:
      return 0
    for a in A:
        ret *= a
        if upper < ret:
          return -1
    return ret
 
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, A):
    ret = 1
    upper = 10**18
    for a in A:
        ret *= a
    return ret if ret <= upper else -1

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))

Fixed submission:
def solve(N, A):
    ret = 1
    upper = 10**18
    if 0 in A:
      return 0
    for a in A:
        ret *= a
        if upper < ret:
          return -1
    return ret
 
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque, defaultdict

def solve(N, M, paths):
    used = [False for _ in range(M)]
    stack = deque([1])
    ret = [[float("inf"), -1] for _ in range(N + 1)]
    ret[1] = [0, 1]

    while stack:
        cur = stack.popleft()
        nexts = paths[cur]
        for n in nexts:
            if used[n[0]]:
                continue
            used[n[0]] = True
            stack.append(n[1])
            if ret[cur][0] + 1 < ret[n[1]][0]:
                ret[n[1]] = [ret[cur][0] + 1, cur]

    print("Yes")
    for r in ret[2:]:
        print(r[1])

if __name__ == "__main__":
    N, M = map(int, input().split())
    paths = defaultdict(list)
    for idx in range(M):
        a, b = map(int, input().split())
        paths[a].append([idx, b])
        paths[b].append([idx, a])

    solve(N, M, paths)

Fixed submission:
from collections import deque, defaultdict

def solve(N, M, paths):
    used = [False for _ in range(M)]
    stack = deque([1])
    ret = [[float("inf"), -1] for _ in range(N + 1)]
    ret[1] = [0, 1]

    while stack:
        cur = stack.popleft()
        nexts = paths[cur]
        for n in nexts:
            if used[n[0]]:
                continue
            used[n[0]] = True
            if ret[cur][0] + 1 < ret[n[1]][0]:
                ret[n[1]] = [ret[cur][0] + 1, cur]
                stack.append(n[1])

    print("Yes")
    for r in ret[2:]:
        print(r[1])

if __name__ == "__main__":
    N, M = map(int, input().split())
    paths = defaultdict(list)
    for idx in range(M):
        a, b = map(int, input().split())
        paths[a].append([idx, b])
        paths[b].append([idx, a])

    solve(N, M, paths)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = set()
for _ in range(K):
  d = int(input())
  A.add(list(input().split()))
print(N - len(A))


Fixed submission:
N, K = map(int, input().split())
A = set()
for _ in range(K):
  d = int(input())
  A.update(list(map(int, input().split())))
print(N - len(A))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = set()
for _ in rnage(K):
  d = int(input())
  A.add(list(input().split()))
print(N - len(A))

Fixed submission:
N, K = map(int, input().split())
A = set()
for _ in range(K):
  d = int(input())
  A.update(list(map(int, input().split())))
print(N - len(A))
Buggy python submission (verdict: Time Limit Exceeded):
def solve(S):
    ref = {}
    ret = 0
    for i in range(len(S) + 1):
        t = int(S[i:]) % 2019 if i < len(S) else 0
        ret += ref.get(t, 0)
        ref[t] = ref.get(t, 0) + 1
    return ret

if __name__ == "__main__":
    S = input()
    print(solve(S))

Fixed submission:
MOD = 2019

def solve(S):
    N = len(S)
    dp = [0 for _ in range(MOD)]
    tmp = 0
    ret = 0
    for i in range(N):
        m = (tmp + int(S[i]) * pow(10, N - i - 1, MOD)) % MOD
        ret += dp[m]
        dp[m] += 1
        tmp = m
    ret += dp[0]
    return ret

if __name__ == "__main__":
    S = input()
    print(solve(S))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(S):
    T = []
    for i in range(len(S)):
        T.append(int(S[i:]) % 2019)
    T.append(0)

    ref = {}
    ret = 0
    for t in T:
        ret += ref.get(t, 0)
        ref[t] = ref.get(t, 0) + 1
    return ret

if __name__ == "__main__":
    S = input()
    print(solve(S))

Fixed submission:
MOD = 2019

def solve(S):
    N = len(S)
    dp = [0 for _ in range(MOD)]
    tmp = 0
    ret = 0
    for i in range(N):
        m = (tmp + int(S[i]) * pow(10, N - i - 1, MOD)) % MOD
        ret += dp[m]
        dp[m] += 1
        tmp = m
    ret += dp[0]
    return ret

if __name__ == "__main__":
    S = input()
    print(solve(S))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(S):
    ret = 0
    for i in range(len(S)):
        for j in range(i, len(S)):
           ret += 1 if not int(S[i: j + 1]) % 2019 else 0
    return ret

if __name__ == "__main__":
    S = input()
    print(solve(S))

Fixed submission:
MOD = 2019

def solve(S):
    N = len(S)
    dp = [0 for _ in range(MOD)]
    tmp = 0
    ret = 0
    for i in range(N):
        m = (tmp + int(S[i]) * pow(10, N - i - 1, MOD)) % MOD
        ret += dp[m]
        dp[m] += 1
        tmp = m
    ret += dp[0]
    return ret

if __name__ == "__main__":
    S = input()
    print(solve(S))
Buggy python submission (verdict: Runtime Error):
def solve(X, Y, C, p, q, r):
    red_apples = sorted(p, reverse=True)[: X]
    green_apples = sorted(q, reverse=True)[: Y]
    white_apples = sorted(r)

    ret = 0
    while white_apples:
        if white_apples[-1] <= red_apples[-1] and white_apples[-1] <= green_apples[-1]:
            break

        ret += white_apples.pop(-1)
        if red_apples[-1] < green_apples[-1]:
            red_apples.pop(-1)
        else:
            green_apples.pop(-1)
    return ret + sum(red_apples) + sum(green_apples)

if __name__ == '__main__':
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    print(solve(X, Y, C, p, q, r))

Fixed submission:
def solve(X, Y, p, q, r):
    red_apples = sorted(p, reverse=True)[: X]
    green_apples = sorted(q, reverse=True)[: Y]
    white_apples = sorted(r)

    ret = 0
    while red_apples and green_apples:
        if not white_apples or (white_apples[-1] < red_apples[-1] and white_apples[-1] < green_apples[-1]):
            return ret + sum(red_apples) + sum(green_apples)

        ret += white_apples.pop(-1)
        if red_apples[-1] < green_apples[-1]:
            red_apples.pop(-1)
        else:
            green_apples.pop(-1)


    if not red_apples:
        while green_apples and white_apples and (green_apples[-1] < white_apples[-1]):
            ret += white_apples.pop(-1)
            green_apples.pop(-1)
        return ret + sum(green_apples)

    else:
        while red_apples and white_apples and (red_apples[-1] < white_apples[-1]):
            ret += white_apples.pop(-1)
            red_apples.pop(-1)
        return ret + sum(red_apples)

if __name__ == '__main__':
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    print(solve(X, Y, p, q, r))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def solve(H, W, s):
    scores = [[float('inf') for _ in range(W)] for _ in range(H)]
    stack = deque()
    if s[0][0] == '.':
        scores[0][0] = 0
        stack.append([(0, 0), [(0, 0)]])
    else:
        scores[0][0] = 1
        stack.append([(0, 0), [(1, 0), (0, 1)]])

    while stack:
        (x, y), diff = stack.popleft()
        for next_x, next_y in [(x + 1, y), (x, y + 1)]:
            if not (next_x < H and next_y < W):
                continue
            if s[next_x][next_y] == '.':
                scores[next_x][next_y] = min(scores[next_x][next_y], scores[x][y])
                stack.append([(next_x, next_y), [(0, 0)]])
            elif (next_x - x, next_y - y) in diff:
                scores[next_x][next_y] = min(scores[next_x][next_y], scores[x][y])
                stack.append([(next_x, next_y), [(next_x - x, next_y - y)]])
            else:
                scores[next_x][next_y] = min(scores[next_x][next_y], scores[x][y] + 1)
                stack.append([(next_x, next_y), [(next_x - x, next_y - y)]])

    return scores[H - 1][W - 1]

if __name__ == '__main__':
    H, W = map(int, input().split())
    s = []
    for _ in range(H):
        s.append(list(input()))

    print(solve(H, W, s))


Fixed submission:
def solve(H, W, s):
    scores = [[float('inf') for _ in range(W)] for _ in range(H)]
    scores[0][0] = 0 if s[0][0] == '.' else 1

    for i in range(H):
        for j in range(W):
            for x, y in [(i - 1, j), (i, j - 1)]:
                if x < 0 or y < 0:
                    continue
                if s[i][j] == '.' or s[x][y] == '#':
                    scores[i][j] = min(scores[i][j], scores[x][y])
                else:
                    scores[i][j] = min(scores[i][j], scores[x][y] + 1)

    return scores[H - 1][W - 1]

if __name__ == '__main__':
    H, W = map(int, input().split())
    s = []
    for _ in range(H):
        s.append(list(input()))

    print(solve(H, W, s))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

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

cur_lcm = lcm(A[0], A[1])

for a in A[1:]:
    cur_lcm = lcm(cur_lcm, a)

if M < cur_lcm / 2:
    print(0)
else:
    print(M // cur_lcm + 1)

Fixed submission:
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

def solve(N, M, A):
    while A[0] % 2 == 0:
        for idx, a in enumerate(A):
            if a % 2 != 0:
                return 0
            A[idx] //= 2
        M //= 2

    for a in A:
        if a % 2 == 0:
            return 0

    cur_lcm = 1
    for a in A:
        cur_lcm = lcm(cur_lcm, a)
        if M < cur_lcm:
            return 0
    return (M // cur_lcm + 1) // 2

if __name__ == '__main__':
    N, M = map(int, input().split())
    A = list((map(int, input().split())))
    A = [a // 2 for a in A]
    print(solve(N, M, A))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

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

if len(A) == 1:
    if M < A[0] // 2 or A[0] % 2 != 0:
        print(0)
    else:
        print(M // A[0] + 1)
    exit()

cur_lcm = lcm(A[0], A[1])

for a in A[1:]:
    cur_lcm = lcm(cur_lcm, a)

if M < cur_lcm / 2 or cur_lcm % 2 != 0:
    print(0)
else:
    print(M // cur_lcm + 1)

Fixed submission:
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

def solve(N, M, A):
    while A[0] % 2 == 0:
        for idx, a in enumerate(A):
            if a % 2 != 0:
                return 0
            A[idx] //= 2
        M //= 2

    for a in A:
        if a % 2 == 0:
            return 0

    cur_lcm = 1
    for a in A:
        cur_lcm = lcm(cur_lcm, a)
        if M < cur_lcm:
            return 0
    return (M // cur_lcm + 1) // 2

if __name__ == '__main__':
    N, M = map(int, input().split())
    A = list((map(int, input().split())))
    A = [a // 2 for a in A]
    print(solve(N, M, A))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

N, M = map(int, input().split())
A = list(set(map(int, input().split())))
cur_lcm = lcm(A[0], A[1])

for a in A[1:]:
    cur_lcm = lcm(cur_lcm, a)

if M < cur_lcm / 2:
    print(0)
else:
    print(M // cur_lcm + 1)

Fixed submission:
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

def solve(N, M, A):
    while A[0] % 2 == 0:
        for idx, a in enumerate(A):
            if a % 2 != 0:
                return 0
            A[idx] //= 2
        M //= 2

    for a in A:
        if a % 2 == 0:
            return 0

    cur_lcm = 1
    for a in A:
        cur_lcm = lcm(cur_lcm, a)
        if M < cur_lcm:
            return 0
    return (M // cur_lcm + 1) // 2

if __name__ == '__main__':
    N, M = map(int, input().split())
    A = list((map(int, input().split())))
    A = [a // 2 for a in A]
    print(solve(N, M, A))
Buggy python submission (verdict: Runtime Error):
import numpy as np

def solve():
    ret = np.array([[1 for _ in range(W)] for _ in range(H)])
    row_groups = np.array([0 for _ in range(H)])
    row_group_set = set()
    prev_row = 0
    for row in range(H):
        if '#' in s[row]:
            row_groups[prev_row: row + 1] = row
            row_group_set.add(row)
            prev_row = row + 1
    row_groups[prev_row: ] = prev_row - 1

    cur_group_num = 1
    for row in row_group_set:
        prev_col = 0
        for col in range(W):
            if s[row][col] == '#':
                ret[row][prev_col: col + 1] = cur_group_num
                cur_group_num += 1
                prev_col = col + 1
            ret[row][prev_col: ] = cur_group_num - 1

    for row, row_group_num in enumerate(row_groups):
        if row in row_group_set:
            continue
        for col in range(W):
            ret[row][col] = ret[row_group_num][col]

    for row in ret:
        print(' '.join(map(str, row.tolist())))

if __name__ == "__main__":
    H, W, K = map(int, input().split())
    s = []
    for row in range(H):
        s.append(list(input()))
    solve()

Fixed submission:
import numpy as np

def solve():
    ret = np.array([[1 for _ in range(W)] for _ in range(H)])
    row_groups = np.array([0 for _ in range(H)])
    row_group_set = set()
    prev_row = 0
    for row in range(H):
        if '#' in s[row]:
            row_groups[prev_row: row + 1] = row
            row_group_set.add(row)
            prev_row = row + 1
    row_groups[prev_row: ] = prev_row - 1

    cur_group_num = 1
    for row in row_group_set:
        prev_col = 0
        for col in range(W):
            if s[row][col] == '#':
                ret[row][prev_col: col + 1] = cur_group_num
                cur_group_num += 1
                prev_col = col + 1
            ret[row][prev_col: ] = cur_group_num - 1

    for row, row_group_num in enumerate(row_groups):
        if row in row_group_set:
            continue
        for col in range(W):
            ret[row][col] = ret[row_group_num][col]

    for row in ret:
        print(' '.join(map(str, row.tolist())))

if __name__ == "__main__":
    H, W, K = map(int, input().split())
    s = []
    for row in range(H):
        s.append(list(input()))
    solve()
Buggy python submission (verdict: Runtime Error):
N = int(input())
ret = 1 - 1 + N - 1
for div in range(2, int(N ** 0.5) + 1):
    if N % div != 0: continue
    ret = min(ret, div - 1 + N // div - 1)
print(ret)

Fixed submission:
import math

a, b, x = map(int, input().split())
ret = (b - x / a**2) * 2 / a if a**2 * b <= 2 * x else  a * b**2 / (2 * x)
print(math.degrees(math.atan(ret)))
Buggy python submission (verdict: Runtime Error):
from bisect import *
if __name__ == '__main__':
    N = int(input())
    L = sorted(map(int, input().split()))
    print(sum(jdx - bisect(L, a - L[jdx], 0, jdx) for idx, a in enumerate(L) for jdx in range(idx)))

Fixed submission:
if __name__ == '__main__':
    A, B = map(int, input().split())
    if A <= 2 * B:
        print(0)
    else:
        print(A - 2 * B)

Buggy python submission (verdict: Runtime Error):
def lowerBound(nums, target):
    if nums[-1] < target: return -1
    lp = 0
    rp = len(nums) - 1
    mp = lp + rp >> 1
    while lp <= rp:
        mp = lp + rp >> 1
        if nums[mp] == target:
            return mp
        if nums[mp] < target:
            lp = mp + 1
        else:
            rp = mp - 1
    return mp if target < nums[mp] else -1

if __name__ == '__main__':
    N = int(input())
    L = [int(l) for l in input().split()]
    L.sort()
    ret = 0
    for idx in range(len(L) - 1, 1, -1):
        for jdx in range(idx - 1, 0, -1):
            c = L[idx] - L[jdx] + 1
            ldx = lowerBound(L[:jdx], c)
            if ldx == -1: continue
            ret += jdx - ldx
    print(ret)


Fixed submission:
if __name__ == '__main__':
    A, B = map(int, input().split())
    if A <= 2 * B:
        print(0)
    else:
        print(A - 2 * B)
Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    N, M = map(int, input().split())
    A = sorted(map(int, input().split()), reverse=True)
    p = 0
    while 0 < M:
        if N == 1:
            p = 0
        elif N == 2:
            p = A.index(max(A[0], A[1]))
        else:
            p = A.index(max(A[p - 1], A[p], A[p + 1])) if p != 0 else A.index(max(A[p], A[p + 1], A[p + 2]))

        A[p] //= 2
        M -= 1

    ret = 0
    for a in A:
        ret += a
    print(ret)

Fixed submission:
import heapq
if __name__ == '__main__':
    N, M = map(int, input().split())
    A = list(map(lambda x: int(x) * (-1), input().split()))
    heapq.heapify(A)
    for _ in range(M):
        tmp = heapq.heappop(A)
        heapq.heappush(A, -(-tmp // 2))
    print(-sum(A))