Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())

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

ans = 0
d = {}

for i in range(len(a)):
    if a[i] in d.keys():
        d[a[i]] += 1
    else:
        d[a[i]] = 1
# print(d)

for i in range(len(a)):
    flag = False


    if d[a[i]] > 1:
        continue

    if a[i] != 1 and 1 in d.keys():
        continue
    # print("a: ", a[i])
    j = 2
    while j <= math.sqrt(a[i]):
        if a[i] % j == 0:
            # print(j)
            if a[i] / j == j:
                if j in d.keys():
                    flag = True
                    break
            else:
                if j in d.keys() or (a[i]/j) in d.keys():
                    flag = True
                    break
    
        j += 1
    
    if flag == False:
        ans += 1

print(ans)

Fixed submission:
n = int(input())

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

ans = 0
d = {}


for i in range(len(a)):
    if a[i] in d.keys():
        d[a[i]] += 1
    else:
        d[a[i]] = 1
max_ = max(a)
arr = [True] * (max_+1) 
ans = 0

for i in range(1, max_+1):
    if i in d.keys() and arr[i]:
        temp = i
        # print("i: ", i)
        while (temp + i) <= (max_):
            # print(temp+i)
            arr[(temp+i)] = False

            temp += i

        if d[i] == 1:
            ans += 1
# print(arr)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

ans = 0

for i in range(len(a)):
    flag = False
    for j in range(len(a)):
        if i == j:
            continue

        if a[i] % a[j] == 0:
            flag = True
            break
    
    if flag == False:
        ans += 1

print(ans)

Fixed submission:
n = int(input())

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

ans = 0
d = {}


for i in range(len(a)):
    if a[i] in d.keys():
        d[a[i]] += 1
    else:
        d[a[i]] = 1
max_ = max(a)
arr = [True] * (max_+1) 
ans = 0

for i in range(1, max_+1):
    if i in d.keys() and arr[i]:
        temp = i
        # print("i: ", i)
        while (temp + i) <= (max_):
            # print(temp+i)
            arr[(temp+i)] = False

            temp += i

        if d[i] == 1:
            ans += 1
# print(arr)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x=int(input())
y=list(map(int, input().split()))
z=1
for i in range(x):
  z = z*y[i]
if z > 10**18:
  print(-1)
else:
  print(z)

Fixed submission:
x=int(input())
y=list(map(int, input().split()))
z=1
if 0 in y:
  print(0)
  exit()

for i in range(x):
  z = z*y[i]
  if z > 10**18:
    z=-1
    break
print(z)

Buggy python submission (verdict: Runtime Error):
x=int(input())
y, z=map(int, input().split())
if y*z > 10**18:
  print(-1)
else:
  print(y*z)

Fixed submission:
x=int(input())
y=list(map(int, input().split()))
z=1
if 0 in y:
  print(0)
  exit()

for i in range(x):
  z = z*y[i]
  if z > 10**18:
    z=-1
    break
print(z)
Buggy python submission (verdict: Runtime Error):
A,B,C=map(int, input().split())
print('bust' if A+B+C => 22 else 'win')

Fixed submission:
A,B,C=map(int, input().split())
print('bust' if A+B+C >= 22 else 'win')

Buggy python submission (verdict: Runtime Error):
A,B,C=map(int, input().split())
print('bust' if A+B+C => 22 else 'win')

Fixed submission:
A,B,C=map(int, input().split())
print('bust' if A+B+C >= 22 else 'win')
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int, input().split()))
cnt=0
ans=[]
for i in range(n-1):
  if l[i] >= l[i+1]:
    cnt += 1
    ans.append(cnt)
  else:
    cnt = 0
print(max(ans))


Fixed submission:
n=int(input())
l=list(map(int, input().split()))
cnt=0
ans=[0]
for i in range(n-1):
  if l[i] >= l[i+1]:
    cnt += 1
    ans.append(cnt)
  else:
    cnt = 0
print(max(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
n = 0

while all(i%2==0 for i in A):
  A = [a/2 for a in A] 
  n += 1
print(n)
  

Fixed submission:
n = input()
num_list = list(n)
count = 0

for i in num_list:
  if int(i) == 1:
    count += 1
  else:
    pass

print(count)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import string
 
n = int(input())
a = list(map(int,input().split()))
res = 1
for i in range(n):
    res *= a[i]
    if(res>pow(10,18)):
      	break
 
if(res>pow(10,18)):
    print(-1)
else:
    print(res)

Fixed submission:
# coding: utf-8
import string

n = list(map(int,input().split()))
print(n[0]*n[1])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import string

n = int(input())
a = list(map(int,input().split()))
res = 1
for i in range(n):
    res *= a[i]

if(res>pow(10,18)):
    print(-1)
else:
    print(res)


Fixed submission:
# coding: utf-8
import string

n = int(input())
a = list(map(int,input().split()))
res = 1
for i in range(n):
    res *= a[i]
    if(res>pow(10,18)):
      	break

if(res<=pow(10,18)):
    print(res)
elif(0 in a):
    print(0)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
x=[a+b,a-b,a*b]
print(max(a))


Fixed submission:
a,b=map(int,input().split())
x=[a+b,a-b,a*b]
print(max(x))
Buggy python submission (verdict: Runtime Error):
input = input()
a, b, c = int(input[0]), int(input[1]), int(input[2])
k = int(input[3])
totalnum = 0
#a→b→cの順番で取ればいい。
for aa in range(k):
  if a != 0:
    a-=1
    totalnum+=1
  elif b != 0:
    b-=1
  elif c != 0:
    c-=1
    totalnum-=1
  else:
    break
print(totalnum)

Fixed submission:
input = input().split(" ")
a, b, c = int(input[0]), int(input[1]), int(input[2])
k = int(input[3])
totalnum = 0
for nuum in range(4):
    if a>=k: #もしaの枚数がkを上回っていたら
        totalnum+=k
        k=0
        break
    elif a<k and a!=0: #もしaの枚数がkを下回っていたら
        totalnum+=a #totalnumをa分足して
        k-=a #kからaの枚数分引く
        a=0
    elif b>=k: #もしbの枚数がkを上回っていたら
        k=0
        break
    elif b<k and b!=0: #もしbの枚数がkを下回っていたら
        k-=b #bの枚数分だけkから引く。
        b=0
    elif c>=k: #もしcのところまで来たら
        totalnum-=k
        break
print(totalnum)
Buggy python submission (verdict: Runtime Error):
input = input().split(" ")
if int(input[0]) > 10:
  c = 10 - int(input[0])
  r = 100 * int(c)
  print(r)
else:
  print(input[1]

Fixed submission:
input = input().split(" ")
if int(input[0]) < 10:
  c = 10 - int(input[0])
  r = 100 * int(c)
  res = int(input[1]) + int(r)
  print(res)
elif int(input[0]) >= 10:
  print(input[1])
Buggy python submission (verdict: Runtime Error):
import re
n = input()
s = input()
k = input()
chlist = list(s)
nonreplace = chlist[int(k)]
for num in range(int(n)):
  if chlist[num] == nonreplace:
    pass
  else:
    chlist[num] = "*"
stred = ''.join(chlist)
print(stred)


Fixed submission:
import re
n = input()
s = input()
k = input()
chlist = list(s)
ked = int(k) - 1
nonreplace = chlist[int(ked)]
for num in range(int(n)):
  #numed = num - 1
  if chlist[num] == nonreplace:
    pass
  else:
    chlist[num] = "*"
stred = ''.join(chlist)
print(stred)
Buggy python submission (verdict: Runtime Error):
input = input()
splited = input.splitlines()
fl = splited[0]
sl = splited[1]
red = "R"
blue = "B"
numred = sl.count(red)
numblue = sl.count(blue)
if int(numred) > numblue:
  print("Yes")
else:
  print("No")

Fixed submission:
import time
import sys
import time
fl,sl=[input() for i in range(2)]
red = "R"
blue = "B"
numred = sl.count(red)
numblue = sl.count(blue)
if int(numred) > int(numblue):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
data = input()
capitalized = data.upper()
list = capitalized.split(" ")
for word in list:
  br = str(word)
  result = br[0:1]
  final += result
print(final)

Fixed submission:
data = input()
list = data.split(" ")
final = ""
for word in list:
  result = word[:1]
  result = result.upper()
  final = final + result
print(final)
Buggy python submission (verdict: Runtime Error):
X, Y = [int(x) for x in stdin.readline().rstrip().split()]
if Y % 2 == 0:
    Z = Y / X
    if 2 <= Z <= 4:
        print('Yes')
else:
    print('No')

Fixed submission:
from sys import stdin
X, Y = [int(x) for x in stdin.readline().rstrip().split()]
if Y % 2 == 0:
    Z = Y / X
    if 2 <= Z <= 4:
        print('Yes')
    else:
        print('No')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for _ in range(n)]
from itertools import combinations
s=list(range(n))
ans=10**10
array=[0]*n
res=0
for ii in range(1,n+1):
    for i in combinations(s,ii):
        for j in i:
            res+=ca[j][0]
            for k,l in enumerate(ca[j][1:]):
                array[k]+=l
        if min (array)>=x:
            ans=min(ans,res)
        res=0
        array=[0]*m

if ans==10**10:
    print(-1)
else:
    print(ans)

Fixed submission:
n,m,x=map(int,input().split())
cc=[list(map(int,input().split())) for _ in range(n)]
ans=float('inf')
for b in range(1<<n):
    a=[0]*(m+1)
    for i in range(n):
        if b&(1<<i)==0:
            continue
        for k,l in enumerate(cc[i]):
            a[k]+=l
        if min(a[1:])>=x:
            ans=min(ans,a[0])
    a=[0]*(m+1)
if ans==float('inf'):
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
pp=[0]*n
qq=[True]*n
for i in range(m):
    i,j=input().split()
    i=int(i)
    i-=1
    if qq[i] and j=="AC":
        qq[i]=False
    if qq[i]:
        pp[i]+=1
ans=0
for i in qq:
    if qq[i]==False:
        ans+=1
print(qq.count(False),ans)

Fixed submission:
n,m=map(int,input().split())
pp=[0]*n
res=0

qq=[True]*n
for i in range(m):
    i,j=input().split()
    i=int(i)
    i-=1
    if j=="AC":
        if qq[i]:
            qq[i]=False
            res+=pp[i]
    else:
        pp[i]+=1

print(qq.count(False),res)
Buggy python submission (verdict: Time Limit Exceeded):
n,t=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
ma=AB[-1][0]
dp=[0]*(t+ma)    
for a,b in AB:
    for i in range(t+ma-1,a-1,-1):
        if i-a<t:
            dp[i]=max(dp[i],dp[i-a]+b)

print(max(dp))

Fixed submission:
n,t=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
ma=AB[-1][0]
dp=[0]*(t+ma)    
for a,b in AB:
    for i in range(t+ma-1,a-1,-1):
        if i-a<t:
            dp[i]=max(dp[i],dp[i-a]+b)

print(max(dp))
Buggy python submission (verdict: Runtime Error):

from math import atan,tan,pi
a,b,x = map(int,read().split())

def max_volume(theta):
    
    theta = theta/180*pi
    if theta<atan(b/a):
 
        area = a*b-a*a*tan(theta)/2
    else:
        area = b*(b/tan(theta))/2
    return area*a

left = 0 
right = 90 
while right - left > 1e-7:
    mid = (left+right)/2
    if max_volume(mid) <= x:
        right = mid
    else:
        left = mid

answer = (left+right)/2
print(answer)


Fixed submission:
import math

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

if x/(a**2)/b < 1/2:
    print(180*math.atan((a*b**2)/(2*x))/math.pi)

else:
    print(180*math.atan(2*(a*b-x/a)/(a**2))/math.pi)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())), reverse=True)

ok, ng = a[-1]*f[0], -1
while ok-ng > 1:
	x = (ok+ng)//2
	tmp = 0
	for i in range(n):
		tmp += max(0, a[i] - x//f[i])
	if tmp > k:
		ng = x
	else:
		ok = x
print(ok)


Fixed submission:
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())), reverse=True)

ok, ng = a[-1]*f[0], -1
while ok-ng > 1:
	x = (ok+ng)//2
	tmp = 0
	for i in range(n):
		tmp += max(0, a[i] - x//f[i])
	if tmp > k:
		ng = x
	else:
		ok = x
print(ok)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
k=[]
for _ in range(m):
  a.append(list(map(int,input().split()))[0])
  k.append(sum(2**(int(i)-1)for i in input().split()))
inf=float('inf')
dp=2**n*[inf]
dp[0]=0
for i in range(2**n):
  for j in range(m):
    dp[i|k[j]]=min(dp[i|k[j]],dp[i]+a[j])
print(dp[-1]if inf!=dp[-1]else-1)


Fixed submission:
n,m=map(int,input().split())
a=[]
k=[]
for _ in range(m):
  a.append(list(map(int,input().split()))[0])
  k.append(sum(2**(int(i)-1)for i in input().split()))
inf=float('inf')
dp=2**n*[inf]
dp[0]=0
for i in range(2**n):
  for j in range(m):
    dp[i|k[j]]=min(dp[i|k[j]],dp[i]+a[j])
print(dp[-1]if inf!=dp[-1]else-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
while m:
    a[-1]//=2
    m-=1
    a.sort()

print(sum(a))

Fixed submission:
import heapq as hq

n, m = map(int, input().split())
a = [-int(i) for i in input().split()]
hq.heapify(a)

for _ in range(m):
  hq.heappush(a, -(-hq.heappop(a) // 2))
  
print(sum(a) * -1)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, P = map(int, input().split())
E = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    E[i] = (a - 1, b - 1, P - c)
INF = float("inf")
d = [INF for _ in range(N)]
d[0] = 0
for i in range(2*N):
    for f, t, w in E:
        if d[t] > d[f] + w:
            d[t] = d[f] + w
            if i >= N:
                d[t] = -INF
    if i == N-1:
        dN = d[-1]
if dN != d[-1]:
    print(-1)
elif dN > 0:
    print(0)
else:
    print(-dN)


Fixed submission:
N, M, P = map(int, input().split())
E = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    E[i] = (a - 1, b - 1, P - c)
INF = float("inf")
d = [INF for _ in range(N)]
d[0] = 0
for i in range(2*N):
    for f, t, w in E:
        if d[t] > d[f] + w:
            d[t] = d[f] + w
            if i >= N:
                d[t] = -INF
    if i == N-1:
        dN = d[-1]
if dN != d[-1]:
    print(-1)
elif dN > 0:
    print(0)
else:
    print(-dN)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
l=len(s)

mod=10**9+7

dp=[[0 for j in range(13)] for i in range(l)]

if s[0] =="?":
    dp[0] = [1]*10+[0]*3
else:
    dp[0][int(s[0])] =1

for i in range(1, l):
 if s[i]=='?':
   for j in range(10):
     for k in range(13):
       dp[i][(k*10+j)%13]+=dp[i-1][k]%mod
 else:
   for k in range(13):
     dp[i][(k*10+int(s[i]))%13]+=dp[i-1][k]%mod
print(dp[-1][5]%mod)


Fixed submission:
s=input()
l=len(s)

mod=10**9+7

dp=[[0 for j in range(13)] for i in range(l)]

if s[0] =="?":
    dp[0] = [1]*10+[0]*3
else:
    dp[0][int(s[0])] =1

for i in range(1, l):
 if s[i]=='?':
   for j in range(10):
     for k in range(13):
       dp[i][(k*10+j)%13]+=dp[i-1][k]%mod
 else:
   for k in range(13):
     dp[i][(k*10+int(s[i]))%13]+=dp[i-1][k]%mod
print(dp[-1][5]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for  _ in range(n)]
for i in range(n):
    print(max(a[i+1:]+a[:i]))

Fixed submission:
n=int(input())
a=[int(input()) for  _ in range(n)]
b=sorted(a,reverse=True)
max0=b[0]
max1=b[1]
for i in range(n):
    if a[i]!=max0:
        print(max0)
    else:
        print(max1)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
N, K = map(int, input().split())

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

col = [-1 for i in range(N)]
col[0] = 0
MOD = 10 ** 9 + 7


def dfs(i, ans, depth):
    if depth == 1:
        num = K - 1
    else:
        num = K - 2
    for v in e[i]:
        if col[v] == -1:
            col[v] = 0
            ans = (ans * num) % MOD
            num -= 1
            ans = dfs(v, ans, depth+1)

    return ans


print(dfs(0, K, 1))


Fixed submission:
n,a,b=map(int,input().split())
print(min(b,n*a))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
N, K = map(int, input().split())

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

col = [-1 for i in range(N)]
col[0] = 0
MOD = 10 ** 9 + 7


def dfs(i, ans, depth):
    if depth == 1:
        num = K - 1
    else:
        num = K - 2
    for v in e[i]:
        if col[v] == -1:
            col[v] = 0
            ans = (ans * num) % MOD
            num -= 1
            ans = dfs(v, ans, depth+1)

    return ans


print(dfs(0, K, 1))


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N, K = map(int, input().split())

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

col = [-1 for i in range(N)]
col[0] = 0
MOD = 10 ** 9 + 7


def dfs(i, ans, depth):

    if depth == 1:
        num = K - 1
    else:
        num = K - 2
    for v in e[i]:
        if col[v] == -1:
            col[v] = 0
            ans = (ans * num) % MOD
            num -= 1
            ans = dfs(v, ans, depth+1)

    return ans


print(dfs(0, K, 1))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
d=[1]*(n+1)
for i in range(m):
    d[int(input())]=0
for i in range(n+1):
    if i >1:
        d[i]=(d[i-1]+d[i-2])%(10**9+7)*d[i]
print(d[n+1])

Fixed submission:
n,m=map(int,input().split())
D=[1] * (n + 1)
for _ in range(m):
    D[int(input())] = 0
for i in range(n+1):
    if i > 1:
        D[i] = (D[i-1] + D[i-2]) % 1000000007 * D[i]
print(D[i])

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
d=[1]*(n+1)
for i in range(m):
    d[int(input())]=0
for i in range(n+1):
    if i >1:
        d[i]=(d[i-1]+d[i-2]%(10**9+7))*d[i]
print(d[n+1])

Fixed submission:
n,m=map(int,input().split())
D=[1] * (n + 1)
for _ in range(m):
    D[int(input())] = 0
for i in range(n+1):
    if i > 1:
        D[i] = (D[i-1] + D[i-2]) % 1000000007 * D[i]
print(D[i])
Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]
 
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1
 
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            ans = max(ans,L[h][w]+U[h][w]+R[h][w]+D[h][w]-3)
 
print(ans)

Fixed submission:
H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]
 
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1
 
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            ans = max(ans,L[h][w]+U[h][w]+R[h][w]+D[h][w]-3)
 
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from heapq import heappush, heappop
n,q=map(int,input().split())
a=sorted(((s-x, t-x, x) for _ in range(n) for s, t, x in (map(int, sys.stdin.readline().split()),)), reverse=True)
heap=[]
ans=[]
z=list(map(int,sys.stdin))
for d in z:
  d=int(input())
  while a and a[-1][0]<=d:
    e=a.pop()
    heappush(heap,(e[2],e[1]))
  while heap and heap[0][1]<=d:
    heappop(heap)
  if heap:
    ans.append(heap[0][0])
  else:
    ans.append(-1)

print(*ans, sep='\n')



Fixed submission:
import sys
from heapq import heappush, heappop
n,q=map(int,input().split())
a=sorted(((s-x, t-x, x) for _ in range(n) for s, t, x in (map(int, sys.stdin.readline().split()),)), reverse=True)
heap=[]
ans=[]
for i in range(q):
  d=int(input())
  while a and a[-1][0]<=d:
    e=a.pop()
    heappush(heap,(e[2],e[1]))
  while heap and heap[0][1]<=d:
    heappop(heap)
  if heap:
    ans.append(heap[0][0])
  else:
    ans.append(-1)

print(*ans, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
n,q=map(int,input().split())
a=[]
for i in range(n):
  s,t,x=map(int,input().split())
  s-=x
  t-=x
  a.append([s,t,x])
a=sorted(a,reverse=True)
heap=[]
ans=[]
for i in range(q):
  d=int(input())
  while a and a[-1][0]<=d:
    e=a.pop()
    heappush(heap,(e[2],e[1]))
  while heap and heap[0][1]<=d:
    heappop(heap)
  if heap:
    ans.append(heap[0][0])
  else:
    ans.append(-1)

print(*ans, sep='\n')



Fixed submission:
import sys
from heapq import heappush, heappop
n,q=map(int,input().split())
a=sorted(((s-x, t-x, x) for _ in range(n) for s, t, x in (map(int, sys.stdin.readline().split()),)), reverse=True)
heap=[]
ans=[]
for i in range(q):
  d=int(input())
  while a and a[-1][0]<=d:
    e=a.pop()
    heappush(heap,(e[2],e[1]))
  while heap and heap[0][1]<=d:
    heappop(heap)
  if heap:
    ans.append(heap[0][0])
  else:
    ans.append(-1)

print(*ans, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
n,q=map(int,input().split())
a=[]
for i in range(n):
  s,t,x=map(int,input().split())
  s-=x
  t-=x
  a.append([s,t,x])
a=sorted(a,reverse=True)
heap=[]
ans=[]
for i in range(q):
  d=int(input())
  while a and a[-1][0]<=d:
    e=a.pop()
    heappush(heap,(e[2],e[1]))
  while heap and heap[0][1]<=d:
    heappop(heap)
  if heap:
    ans.append(heap[0][0])
  else:
    ans.append(-1)

for i in ans:
  print(i)


Fixed submission:
import sys
from heapq import heappush, heappop
n,q=map(int,input().split())
a=sorted(((s-x, t-x, x) for _ in range(n) for s, t, x in (map(int, sys.stdin.readline().split()),)), reverse=True)
heap=[]
ans=[]
for i in range(q):
  d=int(input())
  while a and a[-1][0]<=d:
    e=a.pop()
    heappush(heap,(e[2],e[1]))
  while heap and heap[0][1]<=d:
    heappop(heap)
  if heap:
    ans.append(heap[0][0])
  else:
    ans.append(-1)

print(*ans, sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=list(map(int,input().split()))
d=0
for i in range(m):
    b,c=map(int,input().split())
    a+=[c]*b
    d+=b
a.sort()
a=a[d:]
print(sum(a))

Fixed submission:
n,m=map(int,input().split())
*a,=map(int,input().split())
l=[list(map(int,input().split()))[::-1] for _ in range(m)]
a.sort()
d=[]
e=0
for c,b in sorted(l)[::-1]:
	d+=[c]*b
	e+=b
	if e>n:break
for i,(x,y) in enumerate(zip(a,d)):
	if x<y:a[i]=y
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=list(map(int,input().split()))
d=0
for i in range(m):
    b,c=map(int,input().split())
    a+=[c]*b
    d+=b
a.sort()
a=a[d:]
print(sum(a))

Fixed submission:
n,m=map(int,input().split())
*a,=map(int,input().split())
l=[list(map(int,input().split()))[::-1] for _ in range(m)]
a.sort()
d=[]
e=0
for c,b in sorted(l)[::-1]:
	d+=[c]*b
	e+=b
	if e>n:break
for i,(x,y) in enumerate(zip(a,d)):
	if x<y:a[i]=y
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
    b,c=map(int,input().split())
    a+=[c]*b
    a.sort()
    a=a[b:]
print(sum(a))

Fixed submission:
n,m=map(int,input().split())
*a,=map(int,input().split())
l=[list(map(int,input().split()))[::-1] for _ in range(m)]
a.sort()
d=[]
e=0
for c,b in sorted(l)[::-1]:
	d+=[c]*b
	e+=b
	if e>n:break
for i,(x,y) in enumerate(zip(a,d)):
	if x<y:a[i]=y
print(sum(a))