Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m,v,p = inpl()
a = inpl()
c = Counter(a)
a.sort()
b_num = a[n-p]
d_cnt = 0
b_cnt = 0
u_cnt = 0
for i in a:
    if i < b_num: d_cnt += 1
    elif i == b_num: b_cnt += 1
    else: u_cnt += 1

def f(x,i):
    if x >= b_num:
        return True
    if x + m < b_num:
        return False
    if i + u_cnt >= v-1:
        return True
    cnt = 0
    for ind,item in enumerate(a):
        if item > b_num or item <= x:
            cnt += m
        else:
            cnt += x + m - item
    if cnt >= m*v:
        return True
    else:
        return False

ok = n-1
ng = 0
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if f(a[mid],mid):
        ok = mid
    else:
        ng = mid
print(n-mid)


Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m,v,p = inpl()
a = inpl()
c = Counter(a)
a.sort()
b_num = a[n-p]
d_cnt = 0
b_cnt = 0
u_cnt = 0
for i in a:
    if i < b_num: d_cnt += 1
    elif i == b_num: b_cnt += 1
    else: u_cnt += 1

def f(x,i):
    if x >= b_num:
        return True
    if x + m < b_num:
        return False
    if i + 1 + u_cnt >= v:
        return True
    cnt = 0
    for item in a:
        if item > b_num or item <= x:
            cnt += m
        else:
            cnt += x + m - item
    # print(cnt)
    if cnt >= m*v:
        return True
    else:
        return False
# print(f(a[2],2))
ok = n
ng = -1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if f(a[mid],mid):
        ok = mid
    else:
        ng = mid
print(n-ng-1)
Buggy python submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

t = inpl()
a = inpl()
b = inpl()
if (a[0] > b[0] and a[1] > b[1]) or (a[0] < b[0] and a[1] < b[1]):
    print(0)
    quit()
c = [0,0]
for i in range(2):
    c[i] = abs(a[i]-b[i]) * t[i]
if c[0] == c[1]:
    print('infinity')
    quit()
if c[0] > c[1]:
    print(0)
else:
    sa = c[1]-c[0]
    if c[1]%sa:
        tmp = 1
    print((c[1]-1)//(c[1]-c[0])*2 - tmp)


Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

t = inpl()
a = inpl()
b = inpl()
if (a[0] > b[0] and a[1] > b[1]) or (a[0] < b[0] and a[1] < b[1]):
    print(0)
    quit()
c = [0,0]
for i in range(2):
    c[i] = abs(a[i]-b[i]) * t[i]
if c[0] == c[1]:
    print('infinity')
    quit()
if c[0] > c[1]:
    print(0)
else:
    sa = c[1]-c[0]
    tmp = 0
    if c[1]%sa:
        tmp = 1
    print((c[1]-1)//(c[1]-c[0])*2 - tmp)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d
n,m = inpl()
a = [inpl() for i in range(m)]
cost = [[float('inf')] * n for i in range(n)]
for i in range(n-1):
    cost[i+1][i] = 0
for i in a:
    cost[i[0]-1][i[1]-1] = i[2]
res = dijkstra(0,n,m+n-1,cost)
if res[n-1] == float('inf'):
    print(-1)
else:
    print(res[n-1])

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heappush(edgelist,e)
    while len(edgelist):
        minedge = heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heappush(edgelist,[e[0]+d[v],e[1]])
    return d

################################
n,w = map(int,input().split()) #n:頂点数　w:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1])
for i in range(n-1):
    edge[i+1].append([0,i])
res = dijkstra_heap(0)
if res[-1] == float('inf'):
    print(-1)
else:
    print(res[-1])
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().sprit())
if a < 10 and b< 10:
  print(a*b)
else:
  print(-1)

Fixed submission:
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b = inpl()
if a < 10 and b < 10:
    print(a*b)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = float('inf')
for i in range(1,math.sqrt(n)):
    if n%i == 0:
        res = min(res, i + n/i)
print(int(res-2))


Fixed submission:
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = 10**13+4
for i in range(1,2*10**6):
    if (n/i).is_integer():
        res = min(res, i + n/i)
print(int(res-2))
Buggy python submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,x = inpl()


if x/(a**2*b) <= 0.5:
    tmp = ((2*x)/(a*b)) / b
    atan1 = math.degrees(math.atan(tmp))
    print(90-atan1)
else:
    c = 2*(b-x/(a*a))
    tmp = a/c
    atan1 = math.degrees(math.atan(tmp))
    print(90-atan1)


Fixed submission:
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,x = inpl()

if a*a*b == x:
    print(0)
    quit()
if x/(a**2*b) <= 0.5:
    tmp = ((2*x)/(a*b)) / b
    atan1 = math.degrees(math.atan(tmp))
    print(90-atan1)
else:
    c = 2*(b-x/(a*a))
    tmp = a/c
    atan1 = math.degrees(math.atan(tmp))
    print(90-atan1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))


n = inp()
a = inpl()
ans = 0
a.sort()
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if a[k] < a[j] + a[i]:
                ans += 1

print(ans)


Fixed submission:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
ans = 0
a.sort()
for i in range(n-2):
    for j in range(i+1,n-1):
        b = a[j+1:]
        tmp = a[i] + a[j] - 1
        tt = bisect.bisect_right(b,tmp)
        if tt > 0 :
            ans += tt
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
ans = 0
a.sort()
for i in range(n-2):
    for j in range(i+1,n-1):
        b = a[j+1:]
        tmp = a[i] + a[j] - 1
        tt = bisect.bisect_right(b,tmp)
        # print(i,j,tmp,tt,b)
        if tmp >= a[-1]:
            ans += tt
        elif tt > 0 :
            ans += tt
        
print(ans)

Fixed submission:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
ans = 0
a.sort()
for i in range(n-2):
    for j in range(i+1,n-1):
        b = a[j+1:]
        tmp = a[i] + a[j] - 1
        tt = bisect.bisect_right(b,tmp)
        if tt > 0 :
            ans += tt
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,l = inpl()
d = [[INF]*n for _ in range(n)]
for _ in range(m):
    a,b,c = inpl()
    d[a-1][b-1] = c
    d[b-1][a-1] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])
e = [[INF]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            e[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k]+e[k][j])
q = inp()
for _ in range(q):
    a,b = inpl()
    ans = e[a-1][b-1]
    print(-1 if ans == INF else ans-1)


Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,l = inpl()
d = [[INF]*n for _ in range(n)]
for _ in range(m):
    a,b,c = inpl()
    d[a-1][b-1] = c
    d[b-1][a-1] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])
e = [[INF]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            e[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k]+e[k][j])
q = inp()
for _ in range(q):
    a,b = inpl()
    ans = e[a-1][b-1]
    print(-1 if ans == INF else ans-1)
Buggy python submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
dp = [INF]*(n**2)
dp[0] = 0
for i in range(m):
    val,b = inpl()
    c = inpl()
    key = 0
    for j in c:
        key += 2**(j-1)
    for _ in range(n**2):
        dp[_|key] = min(dp[_|key], dp[_]+val)
        
res = dp[-1]
print(res if res != INF else -1)
# pprint.pprint(dp)

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
dp = [INF]*(2**n)
dp[0] = 0
for i in range(m):
    val,b = inpl()
    c = inpl()
    key = 0
    for j in c:
        key += 2**(j-1)
    for _ in range(2**n):
        dp[_|key] = min(dp[_|key], dp[_]+val)
        
res = dp[-1]
print(res if res != INF else -1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
a = inpl()
a.sort()
for i in range(m):
    a[-1] /= 2
    a.sort()
for i in range(n):
    a[i] = math.floor(a[i])
print(sum(a))

Fixed submission:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
a = inpl()
hq = []
heapq.heapify(hq)
ans = 0
for i in range(n):
    tt = a[i]
    heapq.heappush(hq,-tt)
for i in range(m):
    tmp = heapq.heappop(hq)
    tmp /= 2
    heapq.heappush(hq,tmp)
    # print(hq)
for i in range(n):
    tttt = heapq.heappop(hq)
    ans -= math.ceil(tttt)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys,math
# k,x = map(int,input().split())
N = int(input())
s = []
ans = [0] * N
for i in range(N):
    tmp = input()
    li_tmp = list(tmp)
    s_tmp = sorted(li_tmp)
    st = "".join(s_tmp)
    s.append(st)

a = []
a.append(s[N-1])
for i in range(N-2,-1,-1):
    for j in range(i+1,N):
        if s[i] == s[j]:
            ans[i] += ans[j] + 1
            break
print(sum(ans))

Fixed submission:
import sys,math,itertools
def r(x):
    sum = 0
    for i in range(1,x+1):
        sum += i
    return sum

N = int(input())
s = []
ans = [0] * N
for i in range(N):
    tmp = input()
    li_tmp = list(tmp)
    s_tmp = sorted(li_tmp)
    st = "".join(s_tmp)
    s.append(st)

data = {}
a = set()
a.add(s[N-1])
for i in range(N-2,-1,-1):
    if s[i] in a:
        if s[i] in data:
            data[s[i]] += 1
        else:
            data[s[i]] = 1 
    else:
        a.add(s[i])
for i in data:
    data[i] = r(data[i])
print(sum(data.values()))

Buggy python submission (verdict: Time Limit Exceeded):
import sys,math
N = int(input())
s = []
ans = 0
for i in range(N):
    tmp = input()
    li_tmp = list(tmp)
    s_tmp = sorted(li_tmp)
    st = "".join(s_tmp)
    s.append(st)

a = []
a.append(s[N-1])
for i in range(N-2,-1,-1):
    ans += a.count(s[i])
    a.append(s[i])
print(ans)

Fixed submission:
import sys,math,itertools
def r(x):
    sum = 0
    for i in range(1,x+1):
        sum += i
    return sum

N = int(input())
s = []
ans = [0] * N
for i in range(N):
    tmp = input()
    li_tmp = list(tmp)
    s_tmp = sorted(li_tmp)
    st = "".join(s_tmp)
    s.append(st)

data = {}
a = set()
a.add(s[N-1])
for i in range(N-2,-1,-1):
    if s[i] in a:
        if s[i] in data:
            data[s[i]] += 1
        else:
            data[s[i]] = 1 
    else:
        a.add(s[i])
for i in data:
    data[i] = r(data[i])
print(sum(data.values()))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,m = inpl()
aa = [[] for i in range(m)]
ans = 0
max_b = [0] * m
for i in range(n):
    a,b = inpl()
    if a <= m:
        aa[a-1].append(b)
for i in range(m):
    if aa[i]:
        max_b[i] = max(aa[i])

for i in range(m):
    mmm = 0
    max_i = -1
    for j in range(i+1):
        if max_b[j] > mmm:
            mmm = max_b[j]
            max_i = j
    ans += mmm
    if len(aa[max_i]) and max_i != -1:
        aa[max_i].remove(mmm)
        if aa[max_i]:
            max_b[max_i] = max(aa[max_i])
        else :
            max_b[max_i] = 0
print(ans)




Fixed submission:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
hq = []
n,m = inpl()
ab = [[] for i in range(m)]
for i in range(n):
    a,b = inpl()
    if a <= m:
        ab[a-1].append(b)

heapq.heapify(hq)
for i in range(m):
    for j in ab[i]:
        heapq.heappush(hq,-j)
    if hq:
        ans -= heapq.heappop(hq)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,m = inpl()
aa = [[] for i in range(m)]
ans = 0
for i in range(n):
    a,b = inpl()
    if a <= m:
        aa[a-1].append(b)
for i in range(m):
    if aa[i]:
        aa[i].sort()
        ans += aa[i].pop()
        if i < m-1:
            for j in aa[i]:
                aa[i+1].append(j)
print(ans)




Fixed submission:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
hq = []
n,m = inpl()
ab = [[] for i in range(m)]
for i in range(n):
    a,b = inpl()
    if a <= m:
        ab[a-1].append(b)

heapq.heapify(hq)
for i in range(m):
    for j in ab[i]:
        heapq.heappush(hq,-j)
    if hq:
        ans -= heapq.heappop(hq)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
A = input()
N = len(A)
B = [0] * len(A)
k = 0
tmp= 0
for i in range(len(A)):
    if A[i] == 'R':
        tmp += 1
        for j in range(i+1,N):
            if A[j] == 'R':
                tmp += 1
            else:
                k = j
                break
        if tmp % 2 ==0:
            B[k] += 1
        else:
            B[k-1] += 1
        tmp = 0
    else:
        tmp += 1
        for j in range(1,i)[::-1]:
            if A[j] == 'L':
                tmp += 1
            else:
                k = j
                break
        if tmp % 2 ==0:
            B[k] += 1
        else:            
            B[k+1] += 1
        tmp = 0
L = [str(i) for i in B]
print(" ".join(L))


Fixed submission:
import sys,fractions
a = input()
n = len(a)
t = []
ans = [0] * n
cnt = 0
tmp = a[0]
for i in range(n):
    if a[i] == tmp:
       cnt += 1 
    else:
        t.append(cnt)
        tmp = a[i]
        cnt = 1
t.append(cnt)
N = len(t)
len = 0
for i in range(N)[::2]:
    tmp_len = t[i] + t[i+1]
    #R
    ans[len + t[i] - 1] += int((t[i]+1)/2)
    ans[len + t[i]] += int(t[i]/2)
    #L
    ans[len + t[i] - 1] += int(t[i+1]/2)
    ans[len + t[i]] += int((t[i+1]+1)/2)
    len += tmp_len
L = [str(i) for i in ans]
print(" ".join(L))

Buggy python submission (verdict: Runtime Error):
import sys
A = input()
N = len(A)
B = [0] * len(A)
k = 0
tmp= 0
for i in range(len(A)):
    if A[i] == 'R':
        tmp += 1
        for j in range(i+1,N):
            if A[j] == 'R':
                tmp += 1
            else:
                k = j
                break
        if tmp % 2 ==0:
            B[k] += 1
        else:
            B[k-1] += 1
        tmp = 0
    else:
        tmp += 1
        for j in range(1,i)[::-1]:
            if A[j] == 'L':
                tmp += 1
            else:
                k = j
                break
        if tmp % 2 ==0:
            B[k] += 1
        else:            
            B[k+1] += 1
        tmp = 0
L = [str(i) for i in B]
L = " ".join(L)
print(L)

Fixed submission:
import sys,fractions
a = input()
n = len(a)
t = []
ans = [0] * n
cnt = 0
tmp = a[0]
for i in range(n):
    if a[i] == tmp:
       cnt += 1 
    else:
        t.append(cnt)
        tmp = a[i]
        cnt = 1
t.append(cnt)
N = len(t)
len = 0
for i in range(N)[::2]:
    tmp_len = t[i] + t[i+1]
    #R
    ans[len + t[i] - 1] += int((t[i]+1)/2)
    ans[len + t[i]] += int(t[i]/2)
    #L
    ans[len + t[i] - 1] += int(t[i+1]/2)
    ans[len + t[i]] += int((t[i+1]+1)/2)
    len += tmp_len
L = [str(i) for i in ans]
print(" ".join(L))