Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, Q = list(map(int, input().split(" ")))
A_list = list(map(int, input().split(" ")))

def game(A_list, X, N):
    aoki_A_list = sorted(A_list, key=lambda val: abs(val-X))

    count = 0
    aoki_last_plus = None 
    aoki_minus_plus = None
    aoki_last_minus = None
    while True:
        taka_val = A_list[-count-1]
        aoki_val = aoki_A_list[count]
        aoki_view_val = aoki_val - X

        if aoki_view_val >= 0:
            aoki_last_plus = aoki_val
            now_plus = True
        else:
            now_plus = False

        #print(taka_val, aoki_val, aoki_last_plus, aoki_view_val)

        if aoki_last_plus is not None and aoki_last_plus >= taka_val:
            if not now_plus:
                aoki_fail = False
            if now_plus:
                if aoki_last_plus == taka_val:
                    aoki_fail = True
                else:
                    aoki_fail = False

            break

        if aoki_view_val < 0:
            aoki_last_minus = aoki_val
        
        count += 1

    conflict_count = count

    first_sum = sum(aoki_A_list[:conflict_count])
    if aoki_last_minus is not None:
        aoki_minus_last_i = A_list.index(aoki_last_minus)
    else:
        if conflict_count >= 1:
            aoki_minus_last_i = A_list.index(aoki_A_list[0])
        else:
            aoki_minus_last_i = None

    last_i = aoki_minus_last_i
    if last_i is not None:
        if aoki_fail:
            if last_i >= 1:
                if last_i % 2 == 1:
                    nokori_sum = sum(A_list[0:last_i:2])
                else:
                    nokori_sum = sum(A_list[1:last_i:2])
                
            else:
                nokori_sum = 0
        else:
            if last_i >= 2:
                nokori_sum = sum(A_list[(last_i%2):last_i-1:2])
            else:
                nokori_sum = 0

        out = sum(A_list) - (first_sum + nokori_sum)
    else:
        if N % 2 == 1:
            out = sum(A_list[0::2])
        else:
            out = sum(A_list[1::2])

    return out
        
for i in range(Q):
    X = int(input())
    out = game(A_list, X, N)
    print(out)


Fixed submission:
N, H, W = [int(input()) for i in range(3)]

print((N - H + 1) * (N - W + 1))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = len(S)

count = 0
while True:
    S = S.replace("BW", "#")
    tmp_count = S.count("#")
    count += tmp_count
    S = S.replace("#", "WB")

    if tmp_count == 0:
        break

print(count)

Fixed submission:
S = input()

count = 0
out = 0
for cur_i, s in enumerate(S):
    if s == "W":
        out += (cur_i - count)
        count += 1

print(out)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
n = len(S)

count = 0
while True:
    DID = False
    for i in range(n-1):
        if S[i] == "B" and S[i+1] == "W":
            S[i] = "W"
            S[i+1] = "B"
            count += 1
            DID = True

    if not DID:
        break

print(count)

Fixed submission:
S = input()

count = 0
out = 0
for cur_i, s in enumerate(S):
    if s == "W":
        out += (cur_i - count)
        count += 1

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

N = int(raw_input().replace("\n", ""))

a_list = []

for i in xrange(N):
    a = int(raw_input().replace("\n", ""))
    a_list.append(a)

input_list = a_list

a_array = np.asarray(a_list)
sum_diffs = []
for start_elm in input_list:
    a_list = copy.deepcopy(input_list)
    target_elm = start_elm
    
    sum_diff = 0
    while len(a_list) >= 1:
        a_list.remove(target_elm)
        if len(a_list) >= 1:
            a_array = np.abs(np.asarray(a_list) - target_elm)
            target_elm_index = np.argmax(a_array)
            target_elm = a_list[target_elm_index]
            sum_diff += a_array[target_elm_index]
        else:
            #sum_diff += np.abs(a_list[0] - target_elm)
            break
    
    sum_diffs.append(sum_diff)

print max(sum_diffs)

Fixed submission:
str1 = raw_input().replace("\n", "")

if len(str1) == 2:
    print str1
else:
    print str1[::-1]
Buggy python submission (verdict: Runtime Error):
import numpy as np

H, W = map(int, input().split(" "))

lines = np.asarray([list(input().replace("\n", "")) for h in range(H)])

h_indexs, w_indexs = map(set, np.where(lines == "#"))

outlines = lines[list(h_indexs), :][:, list(w_indexs)]
for outline in outlines:
    print("".join(outline))

Fixed submission:
inputs = raw_input().replace("\n", "")
N, i = map(int, inputs.split(" "))
print N + 1 - i
Buggy python submission (verdict: Runtime Error):
import numpy as np

H, W = map(int, input().split(" "))

lines = np.asarray([list(input().replace("\n", "")) for h in range(H)])

h_indexs, w_indexs = map(set, np.where(lines == "#"))

outlines = lines[list(h_indexs), :][:, list(w_indexs)]
for outline in outlines:
    print("".join(outline))

Fixed submission:
import numpy as np

inputs = raw_input().replace("\n", "")
H, W = map(int, inputs.split(" "))

lines = np.asarray([list(raw_input().replace("\n", "")) for h in xrange(H)])

h_indexs, w_indexs = map(set, np.where(lines == "#"))

outlines = lines[list(h_indexs), :][:, list(w_indexs)]
for outline in outlines:
    print "".join(outline)
Buggy python submission (verdict: Time Limit Exceeded):

code = """

# distutils: language=c++
# distutils: include_dirs=[/home/USERNAME/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False


cdef extern from "<atcoder/math>" namespace "atcoder":
    long long floor_sum(long long n, long long m, long long a, long long b)

cpdef long long FloorSum(long long n, long long m, long long a, long long b):
    return FloorSum(n, m, a, b)
"""


import os, sys, getpass

if sys.argv[-1] == 'ONLINE_JUDGE':
    code.replace("USERNAME", getpass.getuser())
    open('atcoder.pyx','w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')
    sys.exit(0)


from atcoder import FloorSum

def main():
    T = int(input())
    for i in range(T):
        n,m,a,b = list(map(int,input().split()))
        print(FloorSum(n, m, a, b))

main()

Fixed submission:
def FloorSum(n,m,a,b):
    ret = 0
    while True:
        if a>=m:
            ret += (n-1)*n*(a//m)//2
            a%=m

        if b>=m:
            ret += n*(b//m)
            b%=m

        y = (a*n+b)//m
        x = y*m-b

        if y==0:
            return ret

        ret += (n-(x+a-1)//a)*y
        n = y
        b = (a-x%a)%a
        m,a = a,m

T = int(input())

for i in range(T):
    n,m,a,b = list(map(int,input().split()))
    print(FloorSum(n,m,a,b))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

ud = [0]

if A[1] > A[0]:
    trend = 1
elif A[1] == A[0]:
    trend = 0
else:
    trend = -1

if trend != 0:
    first_trend = trend

for i in range(1,N):
    if A[i] > A[i-1]:
        if first_trend==0:
            first_trend = 1
        if trend==-1:
            ud.append(i-1)
        trend = 1
    elif A[i] < A[i-1]:
        if first_trend==0:
            first_trend = -1
        if trend==1:
            ud.append(i-1)
        trend = -1

ud.append(N-1)

M = 1000

for i in range(len(ud)):
    if first_trend == 1:
        if i%2==0 and i!=len(ud)-1:
            stock = M // A[ud[i]]
            M = stock*A[ud[i+1]] + M % A[ud[i]]
    else:
        if i%2==1 and i!=len(ud)-1:
            stock = M // A[ud[i]]
            M = stock*A[ud[i+1]] + M % A[ud[i]]


print(M)

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

ud = [0]

if A[1] > A[0]:
    trend = 1
elif A[1] == A[0]:
    trend = 0
else:
    trend = -1

if trend != 0:
    first_trend = trend
else:
    first_trend = 0
for i in range(1,N):
    if A[i] > A[i-1]:
        if first_trend==0:
            first_trend = 1
        if trend==-1:
            ud.append(i-1)
        trend = 1
    elif A[i] < A[i-1]:
        if first_trend==0:
            first_trend = -1
        if trend==1:
            ud.append(i-1)
        trend = -1

ud.append(N-1)

M = 1000

for i in range(len(ud)):
    if first_trend == 1:
        if i%2==0 and i!=len(ud)-1:
            stock = M // A[ud[i]]
            M = stock*A[ud[i+1]] + M % A[ud[i]]
    else:
        if i%2==1 and i!=len(ud)-1:
            stock = M // A[ud[i]]
            M = stock*A[ud[i+1]] + M % A[ud[i]]


print(M)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
 
def gcd(a,b):
    a,b = max(a,b),min(a,b)
    while a%b!=0:
        a,b = b,a%b
    return b

mod = 10**9 + 7

l = A[0]
for i in range(1,N):
    l = (A[i]//gcd(A[i],l))*l


ans = 0
for i in range(N):
    ans+=l//A[i]
    ans%=mod
    
print(ans)

Fixed submission:

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

mod = 10**9 + 7

from collections import defaultdict

B = [defaultdict(int) for i in range(N)]
C = defaultdict(int)

for x in range(N):
    a = A[x]
    for i in range(2,int(a**0.5)+1):
        while a%i==0 and a>0:
            B[x][i]+=1
            a//=i
            #print(a)
            C[i]=max(C[i],B[x][i])
    #print(a)
    if a>1:
        B[x][a]+=1
        C[a] = max(C[a],B[x][a])
#print(B,C)
l = 1
for key in C:
    l*=pow(key,C[key],mod)
    l%=mod

ans = 0
for i in range(N):
    b = l
    for key in B[i]:
        c = pow(key,B[i][key],mod)
        b *= pow(c,mod-2,mod)
    ans+=b
    ans%=mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
 
def gcd(a,b):
    a,b = max(a,b),min(a,b)
    while a%b!=0:
        a,b = b,a%b
    return b

mod = 10**9 + 7

l = A[0]
for i in range(1,N):
    l = (A[i]//gcd(A[i],l))*l


ans = 0
for i in range(N):
    ans+=l//A[i]
    ans%=mod
    
print(ans)

Fixed submission:

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

mod = 10**9 + 7

from collections import defaultdict

B = [defaultdict(int) for i in range(N)]
C = defaultdict(int)

for x in range(N):
    a = A[x]
    for i in range(2,int(a**0.5)+1):
        while a%i==0 and a>0:
            B[x][i]+=1
            a//=i
            #print(a)
            C[i]=max(C[i],B[x][i])
    #print(a)
    if a>1:
        B[x][a]+=1
        C[a] = max(C[a],B[x][a])
#print(B,C)
l = 1
for key in C:
    l*=pow(key,C[key],mod)
    l%=mod

ans = 0
for i in range(N):
    b = l
    for key in B[i]:
        c = pow(key,B[i][key],mod)
        b *= pow(c,mod-2,mod)
    ans+=b
    ans%=mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
 
def gcd(a,b):
    a,b = max(a,b),min(a,b)
    while a%b!=0:
        a,b = b,a%b
    return b

mod = 10**9 + 7

l = A[0]
for i in range(1,N):
    l = A[i]*l//gcd(A[i],l)


ans = 0
for i in range(N):
    ans+=l//A[i]
    ans%=mod
    
print(ans)

Fixed submission:

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

mod = 10**9 + 7

from collections import defaultdict

B = [defaultdict(int) for i in range(N)]
C = defaultdict(int)

for x in range(N):
    a = A[x]
    for i in range(2,int(a**0.5)+1):
        while a%i==0 and a>0:
            B[x][i]+=1
            a//=i
            #print(a)
            C[i]=max(C[i],B[x][i])
    #print(a)
    if a>1:
        B[x][a]+=1
        C[a] = max(C[a],B[x][a])
#print(B,C)
l = 1
for key in C:
    l*=pow(key,C[key],mod)
    l%=mod

ans = 0
for i in range(N):
    b = l
    for key in B[i]:
        c = pow(key,B[i][key],mod)
        b *= pow(c,mod-2,mod)
    ans+=b
    ans%=mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort()
F.sort(reverse = True)

M = 0
for i in range(N):
    M=max(F[i]*A[i],M)

def judge(n):
    score = 0
    for i in range(N):
        score += max(A[i] - n//F[i],0)
    return score<=K

def bisect(l,r):
    while r-l>1:
        if judge((l+r)//2):
            r = (l+r)//2
        else:
            l = (l+r)//2
    return r

if judge(0):
    print(0)
else:
    print(bisect(0,M))


Fixed submission:
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort()
F.sort(reverse = True)

M = 0
for i in range(N):
    M=max(F[i]*A[i],M)

def judge(n):
    score = 0
    for i in range(N):
        score += max(A[i] - n//F[i],0)
    return score<=K

def bisect(l,r):
    while r-l>1:
        if judge((l+r)//2):
            r = (l+r)//2
        else:
            l = (l+r)//2
    return r

if judge(0):
    print(0)
else:
    print(bisect(0,M))
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right

s = input()
t = input()

char_list = [[] for i in range(26)]

for i in range(2*len(s)):
        if i<len(s):
                char_list[ord(s[i])-97].append(i)
        else:
                char_list[ord(s[i-len(s)])-97].append(i)

INF = 10**27

for i in range(26):
        char_list[i].append(INF)

next_list = [[char_list[j][bisect_right(char_list[j],i)] for j in range(26)] for i in range(len(s))]

flag = False
for i in range(len(s)):
        if t[0]==s[i]:
                flag=True
                x = i
                y = i
                break
if flag:
        flag2 = True
        for i ina range(1,len(t)):
                n = next_list[x][ord(t[i])-97]
                y += n - x
                x = n%(len(s))
                if y >= INF:
                        flag2=False
                        break
        if flag2:
                print(y+1)
        else:
                print(-1)
else:
        print(-1)

Fixed submission:
from bisect import bisect_right

s = input()
t = input()

char_list = [[] for i in range(26)]

for i in range(2*len(s)):
        if i<len(s):
                char_list[ord(s[i])-97].append(i)
        else:
                char_list[ord(s[i-len(s)])-97].append(i)

INF = 10**27

for i in range(26):
        char_list[i].append(INF)

next_list = [[char_list[j][bisect_right(char_list[j],i)] for j in range(26)] for i in range(len(s))]

flag = False
for i in range(len(s)):
        if t[0]==s[i]:
                flag=True
                x = i
                y = i
                break
if flag:
        flag2 = True
        for i in range(1,len(t)):
                n = next_list[x][ord(t[i])-97]
                y += n - x
                x = n%(len(s))
                if y >= INF:
                        flag2=False
                        break
        if flag2:
                print(y+1)
        else:
                print(-1)
else:
        print(-1)
Buggy python submission (verdict: Time Limit Exceeded):

def bisect(a,B,lo,hi):
    if hi-lo<=1:
        return hi
    elif B[(hi+lo)//2]>=a:
        return bisect(a,B,(hi+lo)//2,hi)
    else:
        return bisect(a,B,lo,(hi+lo)//2)

N = int(input())

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

B = [A[0]]

for i in range(1,N):
    if B[-1]>=A[i]:
        B.append(A[i])
    else:
        if B[0]<A[i]:
            B[0]=A[i]
        else: 
            B[bisect(A[i],B,0,len(B)-1)]=A[i]
print(len(B))

Fixed submission:

def bisect(a,B,lo,hi):
    if hi-lo<=1:
        return hi
    elif B[(hi+lo)//2]>=a:
        return bisect(a,B,(hi+lo)//2,hi)
    else:
        return bisect(a,B,lo,(hi+lo)//2)

N = int(input())

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

B = [A[0]]

for i in range(1,N):
    if B[-1]>=A[i]:
        B.append(A[i])
    else:
        if B[0]<A[i]:
            B[0]=A[i]
        else: 
            B[bisect(A[i],B,0,len(B)-1)]=A[i]
print(len(B))

Buggy python submission (verdict: Time Limit Exceeded):

def bisect(a,B,lo,hi):
    if hi-lo==1:
        return hi
    elif B[(hi+lo)//2]>=a:
        return bisect(a,B,(hi+lo)//2,hi)
    else:
        return bisect(a,B,lo,(hi+lo)//2)

N = int(input())

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

B = [A[0]]

for i in range(1,N):
    if B[-1]>=A[i]:
        B.append(A[i])
    else:
        if B[0]<A[i]:
            B[0]=A[i]
        else: 
            B[bisect(A[i],B,0,len(B))]=A[i]
print(len(B))

Fixed submission:

def bisect(a,B,lo,hi):
    if hi-lo<=1:
        return hi
    elif B[(hi+lo)//2]>=a:
        return bisect(a,B,(hi+lo)//2,hi)
    else:
        return bisect(a,B,lo,(hi+lo)//2)

N = int(input())

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

B = [A[0]]

for i in range(1,N):
    if B[-1]>=A[i]:
        B.append(A[i])
    else:
        if B[0]<A[i]:
            B[0]=A[i]
        else: 
            B[bisect(A[i],B,0,len(B)-1)]=A[i]
print(len(B))

Buggy python submission (verdict: Time Limit Exceeded):

def bisect(a,A,lo,hi):
    if hi-lo==1:
        return hi
    if A[(hi+lo)//2]>=a:
        return bisect(a,A,(hi+lo)//2,hi)
    else:
        return bisect(a,A,lo,(hi+lo)//2)

N = int(input())

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

B = [A[0]]

for i in range(1,N):
    if B[-1]>=A[i]:
        B.append(A[i])
    else:
        if B[0]<A[i]:
            B[0]=A[i]
        else:
            B[bisect(A[i],B,0,len(B)-1)]=A[i]

print(len(B))

Fixed submission:

def bisect(a,B,lo,hi):
    if hi-lo<=1:
        return hi
    elif B[(hi+lo)//2]>=a:
        return bisect(a,B,(hi+lo)//2,hi)
    else:
        return bisect(a,B,lo,(hi+lo)//2)

N = int(input())

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

B = [A[0]]

for i in range(1,N):
    if B[-1]>=A[i]:
        B.append(A[i])
    else:
        if B[0]<A[i]:
            B[0]=A[i]
        else: 
            B[bisect(A[i],B,0,len(B)-1)]=A[i]
print(len(B))
Buggy python submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))

e_list = [[] for i in range(N)]

for i in range(N-1):
    a,b = list(map(int,input().split()))
    a,b = a-1,b-1
    e_list[a].append(b)
    e_list[b].append(a)

if K==1:
    print(1)
else:
    mod=10**9+7
    combA = [1]
    ca = 1
    for i in range(K-1):
        ca = (ca*(K-1-i))%mod
        combA.append(ca)
    combB = [1]
    cb = 1
    for i in range(K-2):
        cb = (cb*(K-2-i))%mod
        combB.append(cb)

    #print(combA)
    #print(combB)
    ans = K
    mod=10**9+7
    vi = 0 #時と場合によってここを変える
    from collections import deque
    Q = deque([vi])
    checked_list = [False for i in range(N)]
    checked_list[vi]=True
    while len(Q)>0:
        v = Q.pop()
        count=0
        for v1 in e_list[v]:
            if not checked_list[v1]:
                checked_list[v1]=True
                Q.appendleft(v1)
                count+=1
        
        if v==0:
            ans= (ans*combA[count])%mod
        else:
            ans= (ans*combB[count])%mod
            #print(count)

    print(ans)

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

e_list = [[] for i in range(N)]

for i in range(N-1):
    a,b = list(map(int,input().split()))
    a,b = a-1,b-1
    e_list[a].append(b)
    e_list[b].append(a)

if K==1:
    if N==1:
        print(1)
    else:
        print(0)
else:
    mod=10**9+7
    combA = [1]
    ca = 1
    for i in range(K-1):
        ca = (ca*(K-1-i))%mod
        combA.append(ca)
    combB = [1]
    cb = 1
    for i in range(K-2):
        cb = (cb*(K-2-i))%mod
        combB.append(cb)
    flag=True
    #print(combA)
    #print(combB)
    ans = K
    mod=10**9+7
    vi = 0 #時と場合によってここを変える
    from collections import deque
    Q = deque([vi])
    checked_list = [False for i in range(N)]
    checked_list[vi]=True
    while len(Q)>0:
        v = Q.pop()
        count=0
        for v1 in e_list[v]:
            if not checked_list[v1]:
                checked_list[v1]=True
                Q.appendleft(v1)
                count+=1
        
        if v==0:
            if count<=K-1:
                ans= (ans*combA[count])%mod
            else:
                flag=False
                break
        else:
            if count<=K-2:
                ans= (ans*combB[count])%mod
                #print(count)
            else:
                flag=False
                break
    if flag:
        print(ans)
    else:
        print(0)
Buggy python submission (verdict: Runtime Error):
S=input()

from collections import Counter

c=Counter([S[0],S[1],S[2],S[3]])

if len(list(c.keys()))==2:
    flag=True
    for key in c.keys():
        if c[key]!=2:
            flag=False:
            break

    if flag:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Fixed submission:
S=input()

from collections import Counter

c=Counter([S[0],S[1],S[2],S[3]])

if len(list(c.keys()))==2:
    flag=True
    for key in c.keys():
        if c[key]!=2:
            flag=False
            break

    if flag:
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
parseInt(x) = parse(Int,x)

parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    X, A = readline() |> split |> parseMap
    if X<A
        println(0)
    else
        println(10)
    end
end

main()

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

if X<A:
    print(0)
else:
    print(10)
Buggy python submission (verdict: Runtime Error):



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

for i in range(N-1):
    a,b=list(map(int,input().split()))
    a=a-1
    b=b-1
    road_list[a].append(b)
    road_list[b].append(a)
c = list(map(int,input().split()))
from collections import deque
Q = deque([[0,0]])
ans = []
checked_list = [False for i in range(N)]
checked_list[0]=True
count_list = [10**9 for i in range(N)]
count_list[0] = 0

while len(Q)>0:
    v,count = Q.pop()
    count+=1
    for v1 in road_list[v]:        
        if not checked_list[v1]:
            checked_list[v1]=True
            Q.append([v1,count])
            count_list[v1]=count

c.sort()

count_list = [[i,count_list[i]] for i in range(N)]
count_list = sorted(count_list, key=lambda x:x[1],reverse=True)
d = [[count_list[i][0],c[i]] for i in range(N)]
d = sorted(d, key=lambda x:x[0])
d = [d[i][1] for i in range(N)]
print(sum(c[:-1]))
print(*d)


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

Fixed submission:

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

for i in range(N-1):
    a,b=list(map(int,input().split()))
    a=a-1
    b=b-1
    road_list[a].append(b)
    road_list[b].append(a)
c = list(map(int,input().split()))
from collections import deque
Q = deque([[0,0]])
ans = []
checked_list = [False for i in range(N)]
checked_list[0]=True
count_list = [10**9 for i in range(N)]
count_list[0] = 0

while len(Q)>0:
    v,count = Q.pop()
    count+=1
    for v1 in road_list[v]:        
        if not checked_list[v1]:
            checked_list[v1]=True
            Q.append([v1,count])
            count_list[v1]=count

c.sort()

count_list = [[i,count_list[i]] for i in range(N)]
count_list = sorted(count_list, key=lambda x:x[1],reverse=True)
d = [[count_list[i][0],c[i]] for i in range(N)]
d = sorted(d, key=lambda x:x[0])
d = [d[i][1] for i in range(N)]
print(sum(c[:-1]))
print(*d)
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

def main():
    N,Q = list(map(int,input().split()))

    road = []
    x_list = []

    for i in range(N):
        s,t,x = list(map(int,input().split()))
        road.append([0,s-x,x])
        road.append([1,t-x,x])

    for i in range(Q):
        road.append([2,int(input()),i])

    from collections import defaultdict

    counter = defaultdict(int)
    counter[10**27] = 1
    ans = [0]*Q

    road.sort(key=lambda x:x[0])
    road.sort(key=lambda x:x[1])

    q = [10**27]

    from heapq import heappop,heappush

    for id,_,x in road:
        if id==0:
            heappush(q,x)
            counter[x]+=1
        elif id==1:
            counter[x]-=1
        else:
            while counter[q[0]]==0:
                heappop(q)
            #print(q)
            if q[0]<10**27:
                ans[x] = q[0]
            else:
                ans[x] = -1
    print("\n".join(map(str,ans)))

if __name__ == '__main__':
    main()



Fixed submission:

A,P=list(map(int,input().split()))

P+=A*3

print(P//2)