Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys


def solve(K: int):

    ct = 0
    q = [1,2,3,4,5,6,7,8,9]
    while(len(q)>0):
        a = q.pop(0)
        al = a % 10
        ct += 1 
        if ct == K:
            print(a)
            break

        if al != 0:
            q += [a*10+al - 1]
        q += [a*10+al]
        if al != 9:
            q += [a*10+al + 1]

        # print(q)


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from collections import deque

def solve(K: int):

    ct = 0
    q = deque([1,2,3,4,5,6,7,8,9])
    while(len(q)>0):
        a = q.popleft()
        al = a % 10
        ct += 1 
        if ct == K:
            print(a)
            break

        if al != 0:
            q.append(a*10+al - 1)
        q.append(a*10+al)
        if al != 9:
            q.append(a*10+al + 1)

        # print(q)


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
 
 
def solve(N: int, X: int, Y: int):
    cst = [0 for _ in range(N)]
    nodes = [Node(i, N, X, Y) for i in range(N)]
    for i in range(N):
        for n in nodes:
            n.done = False
            n.cost = -1
        # nodes = []
        # for j in range(N):
        #     nodes.append(Node(j, N, X, Y))
        # nodes = [Node(i, N, X, Y) for i in range(N)]
        nodes[i].cost = 0
        while True:
            doneNode = Node(N, N, X, Y)
            for n in nodes:
                if n.done or n.cost < 0:
                    pass
                elif doneNode.num == N or n.cost < doneNode.cost:
                    doneNode = n
            if doneNode.num == N:
                break
            
            doneNode.done = True
            for i in doneNode.edges:
                if nodes[i].cost < 0 or doneNode.cost + 1 < nodes[i].cost:
                    nodes[i].cost = doneNode.cost + 1
        
        for n in nodes:
            cst[n.cost] += 1
    
    for i in range(1, len(cst)):
        print(int(cst[i] / 2))
        
 
 
 
class Node:
    def __init__(self, i, N, X, Y):
        self.num = i
        self.edges = set()
        if i == 0:
            self.edges.add(i+1)
        elif i == N - 1:
            self.edges.add(i-1)
        else:
            self.edges.add(i+1)
            self.edges.add(i-1)
        if i == X - 1:
            self.edges.add(Y - 1)
        elif i == Y - 1:
            self.edges.add(X - 1)
        self.done = False
        self.cost = -1
 
            
            
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(N, X, Y)
 
if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python3
import sys
# from functools import total_ordering
import heapq

from collections import Counter as cl

def solve(N: int, X: int, Y: int):

    def dis(a,b):
        fw = abs(a-b)
        bw1 = abs(X-a)+abs(Y-b)+1
        bw2 = abs(X-b)+abs(Y-a)+1
        bw = min(bw1,bw2)
        return min(fw, bw)
    
    dist_l = [0]*(N-1)
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            dist_l[dis(i,j)-1] += 1


    print("\n".join(map(str, dist_l)))




def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(N, X, Y)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
 
 
def solve(N: int, A: int, B: int):
 
    # if A+B < N : N = A+B
    if N <= A : print(N)
    else : 
        k = N // (A+B)
        rem = N - (A+B)*k
        b_ = A - rem
        if  b_ >= 0: print(k*A+rem+1)
        else : print(k*A)
 
 
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)
 
if __name__ == 

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):

    if N <= A : print(N)    
    else :
        k = N // (A+B)
        rem = N - (A+B)*k
        if  rem >= A:
            print(k*A+A)
        elif rem >= 0:
            print(k*A+rem)
        else : print(k*A)


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
def solve(S, Q, query):
    st = S
    for qq in query:
        if qq[0] == "1":
            st = st[::-1]
        else :
            if qq[1] == "1": st = qq[2] + st
            elif qq[1] == "2": st = st + qq[2]

    print(st)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            # for word in line.split():
            yield line
    tokens = iterate_tokens()
    S = str(next(tokens)).replace('\n', '')  # type: str
    Q = str(next(tokens)).replace('\n', '')  # type: str
    query = []
    for x in tokens:
        sp = x.split()
        # print(sp)
        if sp[0] == "1": query.append(sp[0])
        else :
            query.append((sp[0], sp[1], sp[2]))
    # print(query)

    solve(S, Q, query)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from collections import deque


def solve(S, Q, query):

    state = 1 # forward
    head = deque([])
    tail = deque([])

    for qq in query:
        if qq[0] == "1":
            state *= -1
        else:
            if qq[1] == "1":
                is_head = (state==1)
            elif qq[1] == "2":
                is_head = (state==-1)
            
            if is_head:
                head.append(qq[2])
            else:
                tail.append(qq[2])
    
    head = "".join([head.pop() for _ in range(len(head))])
    tail = "".join([tail.popleft() for _ in range(len(tail))])

    print((head + S + tail)[::state])

    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            # for word in line.split():
            yield line
    tokens = iterate_tokens()
    S = str(next(tokens)).replace('\n', '')  # type: str
    Q = str(next(tokens)).replace('\n', '')  # type: str
    query = []
    for x in tokens:
        sp = x.split()
        # print(sp)
        if sp[0] == "1": query.append(sp[0])
        else :
            query.append((sp[0], sp[1], sp[2]))
    # print(query)

    solve(S, Q, query)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from math import factorial

MOD = 1000000007  # type: int
from numba import jit

# @jit
def combination(n: int, r:int, mod=MOD):
    n1 = n+1
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

def solve(X: int, Y: int):

    u = (2*Y - X)//3
    r = (X- u)//2

    if ((2*Y - X)%3!=0) or (r*u <0):
        print(0)
        return

    a = combination(u+r, u)
    print(a)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
MOD = 1000000007  # type: int

def combination(n: int, r:int, mod=MOD):
    n1 = n+1
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

def solve(X: int, Y: int):

    u = (2*Y - X)//3
    r = (X- u)//2

    if ((2*Y - X)%3!=0) or (r*u <0):
        print(0)
        return

    a = combination(u+r, u)
    print(a)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a = [int(i) for i in input().split()] 

return np.array([a[0]+a[1],a[0]^a[1],a[0]*a[1]]).max()



Fixed submission:
import numpy as np
a = [int(i) for i in input().split()] 

print(np.array([a[0]+a[1],a[0]-a[1],a[0]*a[1]]).max())
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%9==o:
  print('Yes')
else:
  print('No')

Fixed submission:
n=int(input())
if n%9==0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())

a=list(map(int,input().split()))
  
b=[]
if n>1:
  for j in range (n-1):
    c=a[j]-a[j+1]
    if c>-1:
      b.append(c)
      a[j+1]=a[j+1]+c
      
   
  if max(b)>-1:
    print(sum(b))
  else:
    print(0)
    
else:
  print(0)


Fixed submission:
n=int(input())

a=list(map(int,input().split()))
  
b=[]
if n>1:
  for j in range (n-1):
    c=a[j]-a[j+1]
    if c>-1:
      b.append(c)
      a[j+1]=a[j+1]+c
    else:
      b.append(0)
      
   
  if max(b)>-1:
    print(sum(b))
  else:
    print(0)
    
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
n=int(input())

a=list(map(int,input().split()))
  
b=[]
for j in range (n-1):
  c=a[j+1]-a[j]
  b.append(c)

if max(b)>-1:
  print(max(b))
else:
  print(0)
  

Fixed submission:
n=int(input())

a=list(map(int,input().split()))
  
b=[]
if n>1:
  for j in range (n-1):
    c=a[j]-a[j+1]
    if c>-1:
      b.append(c)
      a[j+1]=a[j+1]+c
    else:
      b.append(0)
      
   
  if max(b)>-1:
    print(sum(b))
  else:
    print(0)
    
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
n=int(input())

a=list(map(int,input().split()))
  
b=[]
for j in range (n-1):
  c=a[j+1]-a[j]
  b.append(c)
  
print(max(b))


Fixed submission:
n=int(input())

a=list(map(int,input().split()))
  
b=[]
if n>1:
  for j in range (n-1):
    c=a[j]-a[j+1]
    if c>-1:
      b.append(c)
      a[j+1]=a[j+1]+c
    else:
      b.append(0)
      
   
  if max(b)>-1:
    print(sum(b))
  else:
    print(0)
    
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
import math
n, x, t = map(int, input().split())

print(t * math(n/x))

Fixed submission:
import math
n, x, t = map(int, input().split())
 
print(t * math.ceil(n/x))
Buggy python submission (verdict: Runtime Error):
import math, heapq
N, K = map(int, input().split())

a = list(map(int, input().split()))
a.sort(reverse=True)
lst = []
for i in a:
    lst.append([-i, 0])

heapq.heapify(lst)

i = 0
while i < K:
    p1 = heapq.heappop(lst)
    p2 = heapq.heappop(lst)
    k = int(p1[0]*p1[1]/p2[0] - p1[1] + 1)
    if i + k <= K:
        p1[0] = p1[0] * (p1[1] + 1) / (p1[1] + 1 + k)
        p1[1] += k
        i += k
    else:
        p1[0] = p1[0] * (p1[1] + 1) / (p1[1] + 1 + K - i)
        p1[1] += K - i
        i = K
        
    heapq.heappush(lst, p1)
    heapq.heappush(lst, p2)

p = heapq.heappop(lst)
print(math.ceil(-p[0]))

Fixed submission:
import math
N, K = map(int, input().split())

a = list(map(int, input().split()))

def cal(x):
    s = 0
    for aa in a:
        s += math.ceil(aa / x) - 1
    if s <= K: return True
    else: return False

l = 0
r = max(a)
while abs(r - l) > 1:
    mid = (l + r) // 2
    if cal(mid):
        r = mid
    else:
        l = mid
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
import math, heapq
N, K = map(int, input().split())

a = list(map(int, input().split()))
a.sort(reverse=True)
lst = []
for i in a:
    lst.append([-i, 0])

heapq.heapify(lst)

for i in range(K):
    p = heapq.heappop(lst)
    p[1] += 1
    p[0] = p[0] * p[1] / (p[1] + 1)
    heapq.heappush(lst, p)
p = heapq.heappop(lst)
print(math.ceil(-p[0]))

Fixed submission:
import math
N, K = map(int, input().split())

a = list(map(int, input().split()))

def cal(x):
    s = 0
    for aa in a:
        s += math.ceil(aa / x) - 1
    if s <= K: return True
    else: return False

l = 0
r = max(a)
while abs(r - l) > 1:
    mid = (l + r) // 2
    if cal(mid):
        r = mid
    else:
        l = mid
print(r)
Buggy python submission (verdict: Runtime Error):
ans = [0]*(N+1)

for i in range(1, int(N**0.5)+1):
    for j in range(1, int(N**0.5)+2):
       for k in range(1, int(N**0.5)+2):
            f = i*i + j*j + k*k +i*j + j*k + k*i
            if f <= N:
                ans[f] += 1
print(*ans[1:], sep='\n')


Fixed submission:
N = int(input())

ans = [0]*(N+1)

for i in range(1, int(N**0.5)+1):
    for j in range(1, int(N**0.5)+2):
       for k in range(1, int(N**0.5)+2):
            f = i*i + j*j + k*k +i*j + j*k + k*i
            if f <= N:
                ans[f] += 1
print(*ans[1:], sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        ans = -1       
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        ans = 10**18 + 1
        
print(ans if ans <= 10**18 else -1)
Buggy python submission (verdict: Runtime Error):
X= int(input())

for b in range(-100, 100):
    for a in range(100):
        if a**5 == X + b**5:
            ans =(a, b)
            break
print(*ans)

Fixed submission:
X= int(input())

for b in range(-200, 200):
    for a in range(200):
        if a**5 == X + b**5:
            ans =(a, b)
            break
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = list(input())
S.reverse()
MOD = 2019

t = [0]
for i in range(len(S)):
    q = (t[-1] + int(S[i]) * ((10**i) % MOD)) % MOD
    t.append(q)

cnt = Counter(t)
cnt_mc = cnt.most_common()

ans = 0
for _, j in cnt_mc:
    if j >= 2:
        ans += j * (j - 1) // 2
        
print(ans)

Fixed submission:
from collections import Counter
S = list(input())
S.reverse()
MOD = 2019

t = [0]
r = 1
for i in range(len(S)):
    q = (t[-1] + (int(S[i]) * r) % MOD) % MOD
    t.append(q)
    r *= 10
    r %= MOD

cnt = Counter(t)
cnt_mc = cnt.most_common()

ans = 0
for _, j in cnt_mc:
    if j >= 2:
        ans += j * (j - 1) // 2
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = list(input())
S.reverse()
MOD = 2019

t = [0]
for i in range(len(S)):
    q = (t[-1] + int(S[i]) * (10**i)) % MOD
    t.append(q)

cnt = Counter(t)
cnt_mc = cnt.most_common()

ans = 0
for _, j in cnt_mc:
    if j >= 2:
        ans += j * (j - 1) // 2
        
print(ans)

Fixed submission:
from collections import Counter
S = list(input())
S.reverse()
MOD = 2019

t = [0]
r = 1
for i in range(len(S)):
    q = (t[-1] + (int(S[i]) * r) % MOD) % MOD
    t.append(q)
    r *= 10
    r %= MOD

cnt = Counter(t)
cnt_mc = cnt.most_common()

ans = 0
for _, j in cnt_mc:
    if j >= 2:
        ans += j * (j - 1) // 2
        
print(ans)
Buggy python submission (verdict: Runtime Error):
r = int(input())
 
print(math.pi * r * 2)

Fixed submission:
import math

r = int(input())

print(math.pi * r * 2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

rlst, glst, blst = [], [], []

for i, s in enumerate(S):
    if s=='R':rlst.append(i)
    elif s=='G':glst.append(i)
    else: blst.append(i)
rlst.sort()
glst.sort()
blst.sort()
      
ans = 0

for r in rlst:
    for g in glst:
        rg = abs(r - g)
        if min(r, g) - rg in blst: ans += 1
        if max(r, g) + rg in blst: ans += 1
        if rg % 2 == 0 and (r + g) // 2 in blst: ans += 1
print(len(rlst) * len(glst) * len(blst) - ans)
        

Fixed submission:
import numpy as np
from itertools import combinations_with_replacement

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

rgb = 'RGB'

nr = S.count(rgb[0])
ng = S.count(rgb[1])
nb = N - nr - ng
nlst = np.array([nr, ng, nb])

nmax = np.argmax(nlst)
nmin = np.argmin(nlst)
if nmax == nmin:nmin = 2

minlst, midlst = [], []
maxlst = [0]*N

for i, s in enumerate(S):
    if s==rgb[nmax]:maxlst[i] = 1
    elif s==rgb[nmin]:minlst.append(i)
    else: midlst.append(i)
minlst.sort()
midlst.sort()
      
ans = 0

for midl in midlst:
    for minl in minlst:
        mm = abs(midl - minl)
        mmin = min(minl, midl) - mm
        mmax = max(minl, midl) + mm
        if mmin >= 0:
            if maxlst[mmin]: ans += 1
        if mmax <= N-1:
            if maxlst[mmax]: ans += 1
        if mm % 2 == 0 and maxlst[(minl + midl) // 2]: ans += 1
print(nr * ng * nb - ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, X, Y = map(int, input().split())

graph = []
graph.append([1])
for i in range(1, N-1):
    graph.append([i-1, i+1])
graph.append([N-2])

graph[X-1].append(Y-1)
graph[Y-1].append(X-1)

cnt = [0]*N

def bfs(num):
    dq = deque()
    dq.append((num,0))
    visited = [-1]*N
    visited[num] = 0
    while dq:
        a, b = dq.popleft()
        for i in graph[a]:
            if visited[i] == -1:
                visited[i] = b+1
                dq.append((i, b+1))

    for i in visited:
        if i > 0:
            cnt[i] += 1
    return cnt
for i in range(N): bfs(i)
for i in cnt[1:]:
    print(i//2)


Fixed submission:
from collections import deque
N, X, Y = map(int, input().split())

graph = []
graph.append([1])
for i in range(1, N-1):
    graph.append([i-1, i+1])
graph.append([N-2])

graph[X-1].append(Y-1)
graph[Y-1].append(X-1)

cnt = [0]*N

def bfs(num):
    dq = deque()
    dq.append((num,0))
    visited = [-1]*N
    visited[num] = 0
    while dq:
        a, b = dq.popleft()
        for i in graph[a]:
            if visited[i] == -1:
                visited[i] = b+1
                dq.append((i, b+1))
    return visited

vx = bfs(X-1)
vy = bfs(Y-1)

for i in range(0,N-1):
    for j in range(i+1, N):
        if abs(X-1-i) <= abs(Y-1-i):
            idx = min(j-i, abs(X-1-i) + vx[j])
        else:
            idx = min(j-i, abs(Y-1-i) + vy[j])
        cnt[idx] += 1
    
for i in cnt[1:]:print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
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()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort()

p = p[:X]
q = q[:Y]
heapq.heapify(p)
heapq.heapify(q)

jdgp = True
jdgq = True

while r and (jdgp or jdgq):
    if jdgp:hp = heapq.heappop(p)
    if jdgq:hq = heapq.heappop(q)
    rr = r.pop()
    if hp > hq:
        if jdgp:heapq.heappush(p, hp)
        if rr > hq:
            heapq.heappush(q, rr)
            hq = rr
        else:
            if jdgq:heapq.heappush(q, hq)
            r.append(rr)
            jdgq = False
    else:
        if jdgq:heapq.heappush(q, hq)
        if rr > hp:
            heapq.heappush(p, rr)
            hp = rr
        else:
            if jdgp:heapq.heappush(p, hp)
            r.append(rr)
            jdgp = False

print(sum(p) + sum(q))

Fixed submission:
import heapq
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()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort()

p = p[:X]
q = q[:Y]
heapq.heapify(p)
heapq.heapify(q)

jdg = True

while r and jdg:
    hp = heapq.heappop(p)
    hq = heapq.heappop(q)
    rr = r.pop()
    if hp > hq:
        heapq.heappush(p, hp)
        if rr > hq:
            heapq.heappush(q, rr)
        else:
            heapq.heappush(q, hq)
            r.append(rr)
            jdg = False            
    else:
        heapq.heappush(q, hq)
        if rr > hp:
            heapq.heappush(p, rr)
        else:
            heapq.heappush(p, hp)
            r.append(rr)
            jdg = False
print(sum(p) + sum(q))