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

Fixed submission:
cards = [int(i) for i in input().split()]

if sum(cards) >= 22:
    print('bust')
else :
    print('win')

Buggy submission (verdict: Runtime Error):
from itertools import product

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

for i in range(N):
    ai = int(input())
    for j in range(ai): 
        x, y = map(int, input().split())
        x = x - 1
        A[i].append([x, y])
        
# ここから判定
ans = 0
for pattern in product([0, 1], repeat=N):
    num = pattern.count(1)
    contradictions = False
    for i, testimony in enumerate(A):
        if pattern[i] == 0:
            continue
        for t in testimony:
            x, y = t
            if pattern[x] != Y ^ (1- pattern[i]):
                contradictions  = True
                break
        if contradictions:
            break
    if contradictions:
        continue
    ans = max(ans, num)
print(ans)
Problem p02954 (python)

Fixed submission:
S = input()

counter = []
cnt_dict = {'R':0, 'L':0}
for i in range(len(S)):
    l = S[i]
    if l == 'R':
        if cnt_dict['L'] == 0:
            cnt_dict[l] += 1
        else :
            counter.append(cnt_dict)
            cnt_dict = {'R':0, 'L':0}
            cnt_dict[l] += 1
    else :
        cnt_dict[l] += 1
counter.append(cnt_dict)
        
output = []
for c in counter:
    block_R = [0 for _ in range(c['R'])]
    block_L = [0 for _ in range(c['L'])]
    q, r = divmod((c['R'] + c['L']), 2)
    if r == 0:
        block_R[-1] = q
        block_L[0] = q
    else :
        if c['R'] % 2 == 0:
            block_R[-1] = q
            block_L[0] = q + r
        else :
            block_R[-1] = q + r
            block_L[0] = q
    
    
    output += block_R
    output += block_L
    
print(' '.join(map(str,output)))

Buggy submission (verdict: Runtime Error):
S = input()

counter = []
cnt_dict = {'R':0, 'L':0}
for i in range(len(S)):
    l = S[i]
    if l == 'R':
        if cnt_dict['L'] == 0:
            cnt_dict[l] += 1
        else :
            counter.append(cnt_dict)
            cnt_dict = {'R':0, 'L':0}
            cnt_dict[l] += 1
    else :
        cnt_dict[l] += 1
counter.append(cnt_dict)
        
output = []
for c in counter:
    block_R = [0 for _ in range(c['R'])]
    block_L = [0 for _ in range(c['L'])]
    q, r = divmod((c['R'] + c['L']), 2)
    if r == 0:
        block_R[-1] = q
        block_L[0] = q
    else :
        if c['R'] % 2 == 0:
            block_R[-1] = q
            blcok_L[0] = q + r
        else :
            block_R[-1] = q + r
            block_L[0] = q
    
    
    output += block_R
    output += block_L
    
print(' '.join(map(str,output)))
Problem p03104 (python)

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

if A % 2 == 0 and B % 2 == 0:
    diff = (B - A + 1) // 2
    if diff % 2 == 1:
         print(1 ^ B)
    else :
        print(0 ^ B)
elif A % 2 == 0 and B % 2 == 1:
    diff = (B - A + 1) // 2
    if diff % 2 == 1:
        print(1)
    else :
        print(0)
elif A % 2 == 1 and B % 2 == 0:
    diff = (B - A) // 2
    if diff % 2 == 1:
        print(A ^ 1 ^ B)
    else :
        print(A ^ 0 ^ B)
else :
    diff = (B - A) // 2
    if diff % 2 == 1:
        print(A ^ 1)
    else :
        print(A ^ 0)

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

diff = (B - A) // 2

if A % 2 == 0 and B % 2 == 0:
    if num_of_ones % 2 == 1:
         print(1 ^ B)
    else :
        print(0 ^ B)
elif A % 2 == 0 and B % 2 == 1:
    if num_of_ones % 2 == 1:
        print(1)
    else :
        print(0)
elif A % 2 == 1 and B % 2 == 0:
    if num_of_ones % 2 == 1:
        print(A ^ 1 ^ B)
    else :
        print(A ^ 0 ^ B)
else :
    if num_of_ones % 2 == 1:
        print(A ^ 1)
    else :
        print(A ^ 0)

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

diff = (B - A) // 2

if A % 2 == 0 and B % 2 == 0:
    if num_of_ones % 2 == 1:
         print(1 ^ B)
    else :
        print(0 ^ B)
elif A % 2 == 0 and B % 2 == 1:
    if num_of_ones % 2 == 1:
        print(1)
    else :
        print(0)
elif A % 2 == 1 and B % 2 == 0:
    if num_of_ones % 2 == 1:
        print(A ^ 1 ^ B)
    else :
        print(A ^ 0 ^ B)
else :
    if num_of_ones % 2 == 1:
        print(A ^ 1)
    else :
        print(A ^ 0)
Problem p03221 (python)

Fixed submission:
from collections import defaultdict
import bisect

N, M = [int(i) for i in input().split()]

PY = []
PYd = defaultdict(list)

for i in range(M):
    x, y = [int(i) for i in input().split()]
    PYd[x].append(y)
    PY.append((x,y))
    
for i in PYd.keys():
    PYd[i].sort()
    
for p,y in PY:
    str_p = str(p).zfill(6)
    index = str(bisect.bisect(PYd[p], y)).zfill(6)
    print(str_p+index)

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]

PY = []
PYd = {i:[] for i in range(1, N+1)}

for i in range(M):
    x, y = [int(i) for i in input().split()]
    PYd[x].append(y)
    PY.append((x,y))
    
for i in PYd.keys():
    PYd[i].sort()
    
for p,y in PY:
    str_p = str(p).zfill(6)
    index = str(bisect.bisect(PYd[p], y)).zfill(6)
    print(str_p+index)
Problem p02570 (python)

Fixed submission:
import sys
si = sys.stdin.readline


def main():
    [d, t, s] = [int(e) for e in si().split()]
    if d <= t*s:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# union find, bfs

import sys
from collections import deque
si = sys.stdin.readline


def main():
    [n, m] = [int(e) for e in si().split()]
    if not m:
        print(1)
        return

    visited = [False]*(n+1)
    fm = [set() for _ in range(n+1)]
    mx, comp = 0, 0

    while m:
        m -= 1
        [a, b] = [int(e) for e in si().split()]
        fm[a].add(b)
        fm[b].add(a)

    for i in range(1, n+1):
        if visited[i]:
            continue
        visited[i] = True
        comp += 1
        q = deque()
        q.append(i)
        cnt = 1
        while q:
            curr = q.popleft()
            for e in fm[curr]:
                if not visited[e]:
                    visited[e] = True
                    q.append(e)
                    cnt += 1
        mx = max(mx, cnt)
    print(mx)

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

Fixed submission:
# atCoder Beginner Contest 147 a

import sys


def main():
    l = list(sys.stdin.readline().split())
    l = [int(e) for e in l]
    if sum(l) <= 21:
        print('win')
    else:
        print('bust')


main()

Buggy submission (verdict: Runtime Error):
# atCoder Beginner Contest 147 a

import sys


def main():
    l = list(sys.stdin.readline().split())
    [int(e) for e in l]
    if sum(l) <= 21:
        print('win')
    else:
        print('bust')


main()

Buggy submission (verdict: Runtime Error):
# atCoder Beginner Contest 147 a

import sys


def main():
    l = list(sys.stdin.readline().split())
    if sum(l) <= 21:
        print('win')
    else:
        print('bust')


main()
Problem p02836 (python)

Fixed submission:
def main():
    l = input()
    givenLen = len(l)
    if l==l[::-1]:
        return 0

    count=0
    for i in range(len(l)//2):
        if l[i]!=l[len(l)-1-i]:
            count+=1
    return count

print(main())

Buggy submission (verdict: Runtime Error):
import sys


def main():
    n = input()
    n = int(n)
    l = {}
    lR = {}
    l = list(sys.stdin.readline().split())
    lR = l[::-1]
    givenLen = len(l)
    if l == lR:
        return 0

    temp = {}
    temp[0] = 0
    for i, e in enumerate(l):
        temp[i+1] = e
    l = dict(temp)
    temp = {}
    temp[0] = 0
    for i, e in enumerate(lR):
        temp[i+1] = e
    lR = dict(temp)

    LCStable = [[0 for _ in range(givenLen+1)]]*(givenLen+1)

    for i in l:
        for j in lR:
            if i==0 or j==0:
                LCStable[i][j]=0
            elif l[i]==lR[j]:
                LCStable[i][j]=LCStable[i-1][j-1]+1
            else:
                LCStable[i][j]=max(LCStable[i][j-1],LCStable[i-1][j])
    # print(LCStable)
    return givenLen-LCStable[-1][-1]


# if __name__ == '__main__':
#     print(main())

print(main())
Problem p02597 (python)

Fixed submission:
n = int(input())
s = input()
l = []
for i in range(len(s)):
  if s[i] == "R":
    l.append(i)
if l ==[]:
  print(0)
elif l[0] < len(l):
  ans = 0
  for i in l:
    if i >len(l)-1:
      ans += 1
  print(ans)
else:
  print(len(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
l = []
for i in range(len(s)):
  if s[i] == "R":
    l.append(i)
if l[0] < len(l):
  ans = 0
  for i in l:
    if i >len(l)-1:
      ans += 1
  print(ans)
else:
  print(len(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
l = []
for i in range(len(s)):
  if s[i] == "R":
    l.append(i)
if l[0] < len(l):
  ans = 0
  for i in l:
    if i >len(l):
      ans += 1
  print(ans)
	
else:
  print(len(l))
Problem p02712 (python)

Fixed submission:
a = int(input())
lists = [i+1 for i in range(a) if (i+1)%5!=0 and (i+1)%3!=0]

print(sum(lists))

Buggy submission (verdict: Runtime Error):
a = input()
lists = [i+1 for i in range(a)]
for t in lists:
  if t % 5 == 0:
    lists.remove(t)
  elif t % 3 ==0:
    lists.remove(t)
    
print(sum(lists))
Problem p02571 (python)

Fixed submission:
S = input()
T = input()
lS = len(S)
lT = len(T)
C = []
for i in range(lS-lT+1):
    count = 0
    for j in range(lT):
        if S[i+j]!=T[j]:
            count += 1
    C.append(count)
print(min(C))

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
lS = len(S)
lT = len(T)
C = []
for i in range(lS-lT):
    count = 0
    for j in range(lT):
        if S[i+j]!=T[j]:
            count += 1
    C.append(count)
print(min(C))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
p,S = 0,0
for i in range(N-1):
    ap = A.pop(0)
    AA = sum(A)
    aa = ap*AA
    a = aa%1000000007
    S += a
p = S%1000000007
print(p)
Problem p02571 (python)

Fixed submission:
import numpy as np

S=input()
T=input()

length = len(list(T))
S_length = len(list(S))

max_score = 0
for i in range(len(list(S))-len(list(T))):
    tmp_T = np.array(list(T))
    tmp_S = np.array(list(S))[i:i+len(tmp_T)]
    score = np.zeros(len(tmp_T))
    score[tmp_T==tmp_S]=1
    score = np.sum(score)
    if max_score < score:
        max_score=score

if S_length==length:
    tmp_T = np.array(list(T))
    tmp_S = np.array(list(S))
    score = np.zeros(len(tmp_T))
    score[tmp_T==tmp_S]=1
    max_score = np.sum(score)
print(int(length-max_score))

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

S=input()
T=input()

max_score = 0
for i in range(len(list(S))-len(list(T))):
    tmp_T = np.array(list(T))
    tmp_S = np.array(list(S))[i:i+len(tmp_T)]
    score = np.zeros(len(tmp_T))
    score[tmp_T==tmp_S]=1
    score = np.sum(score)
    if max_score < score:
        max_score=score
print(int(len(tmp_T)-max_score))
Problem p02572 (python)

Fixed submission:
N = int(input())
As = list(map(int, input().split()))

result = 0
before_sum = sum(As)
for i in range(N-1):
    before_sum-=As[i]
    result+=As[i]*(before_sum)
print(result%(1*10**9+7))

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

result = 0
for i in range(N-1):
    result+=As[i]*sum(As[i+1:])
print(result%(1*10**9+7))
Problem p02689 (python)

Fixed submission:
import numpy as np

N,M = map(int, input().split())
score = list(map(int, input().split()))
adj_list = [[] for _ in range(N)]

for _ in range(M):
    A,B = map(int, input().split())
    adj_list[A-1].append(B-1)
    adj_list[B-1].append(A-1)

score_ = 0
for i, adjs in enumerate(adj_list):
    is_max = True
    for adj in adjs:
        if score[i] <= score[adj]:
            is_max = False
    if is_max:
        score_+=1
print(score_)

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

N,M = map(int, input().split())
score = list(map(int, input().split()))
adj_mat = np.zeros((N,N))

for _ in range(M):
    A,B = map(int, input().split())
    adj_mat[A-1, B-1] = 1
    adj_mat[B-1, A-1] = 1

score_ = 0
for i, adjs in enumerate(adj_mat):
    is_max = True
    for adj in np.where(adjs==1)[0]:
        if score[i] <= score[adj]:
            is_max = False
    if is_max:
        score_+=1
print(score_)
Problem p02685 (python)

Fixed submission:
# coding: utf-8


def bpow(x, y, z):
    a = 1
    for b in format(y, 'b'):
        a = (a*a) % z
        if b == '1':
            a = (a*x) % z
    return a


def solve(*args: str) -> str:
    n, m, k = map(int, args[0].split())
    mod = 998244353

    if m == 1 and n-1 == k:
        return str(1)

    ncr = 1
    p = m*bpow(m-1, n-1, mod) % mod
    ret = p
    inv = bpow(m-1, mod-2, mod)
    for i in range(1, k+1):
        ncr = (ncr * (n-i)*bpow(i, mod-2, mod)) % mod
        p = (p*inv) % mod
        ret += p*ncr % mod

    return str(ret % mod)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Buggy submission (verdict: Runtime Error):
# coding: utf-8


def solve(*args: str) -> str:
    n, m, k = map(int, args[0].split())
    mod = 998244353

    P = [1]*(k+1)
    p = pow(m-1, n-2-k, mod)
    for i in range(k+1):
        p = p*(m-1) % mod
        P[-1-i] = p

    ret = m*P[0] % mod
    ncr = 1
    for i in range(1, k+1):
        ncr = ncr*(n-i)//i
        ret += m*P[i]*ncr % mod

    return str(ret % mod)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
Problem p02695 (python)

Fixed submission:
# coding: utf-8


def solve(*args: str) -> str:
    n, m, q = map(int, args[0].split())
    ABCD = [tuple(map(int, abcd.split())) for abcd in args[1:]]

    ret = 0
    stack = [(i, '') for i in range(10)]
    while stack:
        t, s = stack.pop()
        S = s+str(t)
        if len(S) == n:
            ret = max(
                ret,
                sum([d for a, b, c, d in ABCD if int(S[b-1])-int(S[a-1]) == c])
            )
            continue

        for i in range(t, m):
            stack.append((i, S))

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Buggy submission (verdict: Runtime Error):
# coding: utf-8


def solve(*args: str) -> str:
    n, m, q = map(int, args[0].split())
    ABCD = [tuple(map(int, abcd.split())) for abcd in args[1:]]

    ret = 0
    stack = [(0, '')]
    while stack:
        d, s = stack.pop()
        S = s+str(d)
        if len(S) == m:
            ret = max(
                ret,
                sum([d for a, b, c, d in ABCD if int(S[b-1])-int(S[a-1]) == c])
            )
            continue

        for i in range(d, 10):
            stack.append((i, S))

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
Problem p02762 (python)

Fixed submission:
# coding: utf-8
from sys import setrecursionlimit


def dfs(node: int):
    if checked[node]:
        return

    checked[node] = True
    chain.add(node)
    for n in friends[node]:
        dfs(n)


def solve(*args: str) -> str:
    setrecursionlimit(2 * 10 ** 9)
    n, m, k = map(int, args[0].split())

    global friends
    friends = {i: set() for i in range(n+1)}
    blocked = {i: set() for i in range(n+1)}

    for a, b in map(str.split, args[1:1+m]):
        friends[int(a)].add(int(b))
        friends[int(b)].add(int(a))

    for c, d in map(str.split, args[1+m:1+m+k]):
        blocked[int(c)].add(int(d))
        blocked[int(d)].add(int(c))

    global checked
    checked = [False]*(n+1)

    ret = [0]*(n+1)
    for a in range(1, n+1):
        if checked[a]:
            continue

        global chain
        chain = set()
        dfs(a)
        count = len(chain) - 1
        for i in chain:
            ret[i] += count - len(chain & (friends[i] | blocked[i]))

    return ' '.join(map(str, ret[1:]))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Buggy submission (verdict: Runtime Error):
# coding: utf-8


def dfs(node: int):
    if node in checked:
        return

    checked.add(node)
    chain.add(node)
    for n in friends[node]-checked:
        dfs(n)


def solve(*args: str) -> str:
    n, m, k = map(int, args[0].split())
    AB = [tuple(map(int, ab)) for ab in map(str.split, args[1:1+m])]
    CD = [tuple(map(int, cd)) for cd in map(str.split, args[1+m:1+m+k])]

    global checked
    checked = set()

    global friends
    friends = [set() for _ in range(n+1)]
    blocked = [set() for _ in range(n+1)]

    for a, b in AB:
        friends[a].add(b)
        friends[b].add(a)

    for c, d in CD:
        blocked[c].add(d)
        blocked[d].add(c)

    ret = [0]*(n+1)
    for a in range(1, n+1):
        if a in checked:
            continue

        global chain
        chain = set()
        dfs(a)
        for i in chain:
            ret[i] += len(chain-friends[i]-blocked[i]) - 1

    return ' '.join(map(str, ret[1:]))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
Problem p02897 (python)

Fixed submission:
# coding: utf-8


def solve(arg: str) -> str:
    N = int(arg)
    return str(int((N+1) / 2) / N)


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

Buggy submission (verdict: Runtime Error):
# coding: utf-8


def solve(arg: str) -> str:
    a, b = map(int, arg.split())
    div = [1]
    for n in range(2, min(a, b) + 1):
        if a % n == 0 and b % n == 0:
            if(all([n % m != 0 for m in div if m != 1])):
                div.append(n)

    return str(len(div))


if __name__ == "__main__":
    print(solve(input()))
Problem p02914 (python)

Fixed submission:
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    A = np.array(args[1].split(), dtype=np.int64)

    n_bit = len(np.binary_repr(max(A)))

    xor = np.bitwise_xor.reduce(A)
    A &= ~xor

    for b in reversed(range(n_bit)):
        b_set = A & 1 << b != 0
        msb_args = np.where(b_set & (A < 1 << b+1))[0]
        if len(msb_args):
            b_set[msb_args[0]] = False
            A[b_set] ^= A[msb_args[0]]

    ret = 2*np.bitwise_xor.reduce(A) + xor

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Buggy submission (verdict: Runtime Error):
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = tuple(map(int, args[1].split()))

    ret = 0

    xor = [0]*(2**n)
    xor[1] = A[0]

    for i in range(1, n):
        for j in range(2**i):
            xor[2**i+j] = A[i] ^ xor[j]

    for i in range(1, 2**(n-1)):
        ret = max(ret, xor[i] + xor[-1-i])

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
Problem p02623 (python)

Fixed submission:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

# もしすべてaから選んだ場合
time = k
aOnly = 0
for i in range(len(a)):
    time -= a[i]
    if time < 0:
        time += a[i]
        i -= 1
        break
    aOnly += 1
a_idx = i
b_idx = -1

for i in range(len(b)):
    time -= b[i]
    if time < 0:
        time += b[i]
        i -= 1
        break
    aOnly += 1
b_idx = i
ans = aOnly

ans_kari = ans
for i in range(a_idx, -1, -1):
    time += a[i]
    ans_kari -= 1
    for j in range(b_idx+1, len(b)):
        time -= b[j]
        if time < 0:
            time += b[j]
            b_idx = j-1
            break
        ans_kari += 1
    ans = max(ans, ans_kari)
    
print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

# もしすべてaから選んだ場合
time = k
aOnly = 0
for i in range(len(a)):
    time -= a[i]
    if time < 0:
        time += a[i]
        i -= 1
        break
    aOnly += 1
a_idx = i
b_idx = -1

for i in range(len(b)):
    time -= b[i]
    if time < 0:
        time += b[i]
        i -= 1
        break
    aOnly += 1
b_idx = i
ans = aOnly

ans_kari = ans
for i in range(a_idx, -1, -1):
    time += a[i]
    ans_kari -= 1
    for j in range(b_idx+1, len(b)):
        time -= b[i]
        if time < 0:
            time += b[i]
            b_idx = i-1
            break
        ans_kari += 1
    ans = max(ans, ans_kari)
    
print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

# もしすべてaから選んだ場合
time = k
aOnly = 0
for i in range(len(a)):
    time -= a[i]
    if time < 0:
        time += a[i]
        break
    aOnly += 1
a_idx = i-1
b_idx = -1
if time > 0:
    for i in range(len(b)):
        time -= b[i]
        if time < 0:
            break
        aOnly += 1
    b_idx = i-1
    ans = aOnly
    time += b[i]

else:
    ans = aOnly
    time += a[i]

ans_kari = ans
for i in range(a_idx, -1, -1):
    time += a[i]
    ans_kari -= 1
    for j in range(b_idx+1, len(b)):
        time -= b[i]
        if time < 0:
            time += b[i]
            b_idx = i-1
            break
        ans_kari += 1
    ans = max(ans, ans_kari)
    
print(ans)
Problem p02912 (python)

Fixed submission:
import heapq
import math
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), a))
ticket_num = m
heapq.heapify(a)

if n > 1:
    for i in range(m):
        MAX = heapq.heappop(a)
        MAX = math.ceil(MAX / 2)
        heapq.heappush(a,MAX)
        
else:
    MAX = heapq.heappop(a)
    MAX = math.ceil(MAX / (2**m))
    heapq.heappush(a,MAX)

print(sum(a)*(-1))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
ticket_num = m
a_sorted = sorted(a, reverse=True)

if n > 1:
    while ticket_num > 0:
        first = a_sorted[0]
        second = a_sorted[1]
        fi_bin = bin(first)
        se_bin = bin(second)
        sa = len(fi_bin)-len(se_bin)
        if sa == 0:
            sa = 1
        first = first >> sa
        ticket_num -= sa
        if first == second:
            first = first >> 1
            ticket_num -= 1
        index = 1
        while index < n or a_sorted[index] > first:
            index += 1
        a_sorted[:index-1] = a_sorted[1:index]
        a_sorted[index-1] = first
else:
    a_sorted[0] = a_sorted[0]>>m

print(sum(a_sorted))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
ticket_num = m
a_sorted = sorted(a, reverse=True)

if n > 1:
    while ticket_num > 0:
        first = a_sorted[0]
        second = a_sorted[1]
        fi_bin = bin(first)
        se_bin = bin(second)
        sa = len(fi_bin)-len(se_bin)
        if sa == 0:
            sa = 1
        first = first >> sa
        ticket_num -= sa
        if first == second:
            first = first >> 1
            ticket_num -= 1
        index = 1
        while a_sorted[index] > first:
            index += 1
        a_sorted[:index-1] = a_sorted[1:index]
        a_sorted[index-1] = first
else:
    a_sorted[0] = a_sorted[0]>>m

print(sum(a_sorted))