Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
o,f,i=998244353,[1],1
while i<o/399:f+=[f[-1]*i%o];i+=1
c=lambda n,k:f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o)
n,m=map(int,input().split())
w,u=3*m,n-1
a=c(w+u,u)-n*c(n+m-2,u)
while-~m<min(w,n):m+=2;a-=c(n,m)*c((w-m)//2+u,u)
print(a%o)

Fixed submission:
n=int(input())
a = n//(10**9)+1
b = 10**9-(n%(10**9))
if n%(10**9) == 0:
  print(0,0,10**9,0,1,a-1)
else:
  print(0,0,10**9,b,1,a)

Buggy python submission (verdict: Runtime Error):
o,f,i=998244353,[1],1
while i<o/399:f+=f[-1]*i%o;i+=1
c=lambda n,k:f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o)
n,m=map(int,input().split())
w,u=3*m,n-1
a=c(w+u,u)-n*c(n+m-2,u)
if u>m:
 for i in range(m+1,min(w,n)+1):
  if w-i+1&1:a-=c(n,i)*c((w-i)//2+u,u) 
print(a%o)

Fixed submission:
n=int(input())
a = n//(10**9)+1
b = 10**9-(n%(10**9))
if n%(10**9) == 0:
  print(0,0,10**9,0,1,a-1)
else:
  print(0,0,10**9,b,1,a)

Buggy python submission (verdict: Runtime Error):
o=998244353
f=[1]
for i in range(1,2500100):f.append(f[-1]*i%o)
def c(n,k):return f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o)
n,m=map(int,input().split())
w=3*m
u=n-1
a=c(w+u,u)-n*c(n+m-2,u)
if u>m:
 for i in range(m+1,min(w,n)+1):
  if w-i+1&1:a-=c(n,i)*c((w-i)//2+u,u)
print(a%o)

Fixed submission:
n=int(input())
a = n//(10**9)+1
b = 10**9-(n%(10**9))
if n%(10**9) == 0:
  print(0,0,10**9,0,1,a-1)
else:
  print(0,0,10**9,b,1,a)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n-1,-1,-1):
  x=(sum(ans[i-1::i]))%2
  if x!=a[i]:
    ans[i]=1
print(sum(ans))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n-1,-1,-1):
  x=(sum(ans[i::i+1]))%2
  if x!=a[i]:
    ans[i]=1
print(sum(ans))
for i in range(n):
  if ans[i]==1:
    print(str(i+1)+" ",end="")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
x = list(set(a))
if len(x) >= 4:
  print("No")
  exit()
if len(x) == 3:
  if x[0]^x[1] == x[2] and 3*a.count[x[0]] == 3*a.count[x[1]] == 3*a.count[x[2]] == n:
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 2:
  if x[0] == 0 or x[1] == 0 and 2*a.count[x[0]] == 2*a.count[x[1]] == n:
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 1:
  if x[0] == 0:
    print("Yes")
  else:
    print("No")

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
x = list(set(a))
x.sort()
if len(x) >= 4:
  print("No")
  exit()
if len(x) == 3:
  if x[0]^x[1] == x[2] and 3*a.count(x[0]) == 3*a.count(x[1]) == 3*a.count(x[2]) == n:
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 2:
  if x[0] == 0 and (2*a.count(x[0]) == 2*a.count(x[1]) == n or 6*a.count(x[0]) == 3*a.count(x[1]) == 2*n):
    print("Yes")
  else:
    print("No")
  exit()
if len(x) == 1:
  if x[0] == 0:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
a.sort()
else:
  print(a[n//2]-a[n//2-1])

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort()
print(a[n//2]-a[n//2-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
a.sort()
print(a[n//2+1]-a[n//2])

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort()
print(a[n//2]-a[n//2-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
s,t = map(int,input().split())
visited = [[-1,-1,-1] for i in range(n+1)]
que = deque([(s,0,0)])
while que:
  x,mod,cnt = que.popleft()
  visited[x][mod] = cnt
  if x == t and mod == 0:
    break
  for y in graph[x]:
    if visited[y][(mod+1)%3] == -1:
      que.append((y,(mod+1)%3,cnt+1))
      visited[y][(mod+1)%3] == cnt+1
print(visited[t][0]//3)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
s,t = map(int,input().split())
visited = [[-1,-1,-1] for i in range(n+1)]
que = deque([(s,0,0)])
while que:
  x,mod,cnt = que.popleft()
  visited[x][mod] = cnt
  if x == t and mod == 0:
    break
  for y in graph[x]:
    if visited[y][(mod+1)%3] == -1:
      que.append((y,(mod+1)%3,cnt+1))
      visited[y][(mod+1)%3] = cnt+1
print(visited[t][0]//3)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
s,t = map(int,input().split())
visited = [[-1,-1,-1] for i in range(n+1)]
que = deque([(s,0,0)])
while que:
  x,mod,cnt = que.popleft()
  visited[x][mod] = cnt
  if x == t and mod == 0:
    break
  for y in graph[x]:
    if visited[y][(mod+1)%3] == -1:
      que.append((y,(mod+1)%3,cnt+1))
print(visited[t][0]//3)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
s,t = map(int,input().split())
visited = [[-1,-1,-1] for i in range(n+1)]
que = deque([(s,0,0)])
while que:
  x,mod,cnt = que.popleft()
  visited[x][mod] = cnt
  if x == t and mod == 0:
    break
  for y in graph[x]:
    if visited[y][(mod+1)%3] == -1:
      que.append((y,(mod+1)%3,cnt+1))
      visited[y][(mod+1)%3] = cnt+1
print(visited[t][0]//3)
Buggy python submission (verdict: Runtime Error):
import sys
readline=sys.stdin.buffer.readline
n=int(input())
a=[list(map(int, readline().split())) for _ in range(n)]
a.sort(key=lambda x: x[1])
t=0
for i in range(n):
  t+=a[i][0]
  if t>a[i][1]:
    print("No")
    break
  elif i==n-1:
    print("Yes")


Fixed submission:
s=input()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")
Buggy python submission (verdict: Runtime Error):
import math
import sys

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

A = num[0]
B = num[1]
C = num[2]
D = num[3]

def ans_mthd(i, j, k):
    return i - i // j - i // k + i * math.gcd(j, k) / j // k 

ans = ans_mthd(B, C, D)-ans_mthd(A-1, C, D)
# print(math.gcd(C, D))
# print(C * D)
# print(ans_mthd(B, C, D) // 1)
print(ans)

Fixed submission:
import fractions
A,B,C,D=map(int, input().split())
def ans_mthd(i, j, k):
    return (i - i // j - i // k + i * fractions.gcd(j, k) // j // k )
ans = ans_mthd(B, C, D)-ans_mthd(A-1, C, D)
print(ans)

Buggy python submission (verdict: Runtime Error):
from decimal import *
import math
import sys

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

A = num[0]
B = num[1]
C = num[2]
D = num[3]

def ans_mthd(i, j, k):
    return Decimal((i - i // j - i // k + i * math.gcd(j, k) / j // k ))

ans = ans_mthd(B, C, D)-ans_mthd(A-1, C, D)
# print(math.gcd(C, D))
# print(C * D)
# print(ans_mthd(B, C, D) // 1)
print(ans)

Fixed submission:
import fractions
A,B,C,D=map(int, input().split())
def ans_mthd(i, j, k):
    return (i - i // j - i // k + i * fractions.gcd(j, k) // j // k )
ans = ans_mthd(B, C, D)-ans_mthd(A-1, C, D)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
readline=sys.stdin.buffer.readline
n=int(input())
a=[list(map(int, readline().split())) for _ in range(n)]
a.sort(key=lambda x: x[1])
t=0
for i in range(n):
  t+=a[i][0]
  if t>a[i][1]:
    print("No")
    break
  elif i==n-1:
    print("Yes")


Fixed submission:
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
a.sort(key=lambda x: x[1])
t=0
for i in range(n):
  t+=a[i][0]
  if t>a[i][1]:
    print("No")
    break
  elif i==n-1:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
import sys
readline=sys.stdin.buffer.redline
n=int(input())
a=[list(map(int, readline().split())) for _ in range(n)]
a.sort(key=lambda x: x[1])
t=0
for i in range(n):
  t+=a[i][0]
  if t>a[i][1]:
    print("No")
    break
  elif i==n-1:
    print("Yes")


Fixed submission:
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
a.sort(key=lambda x: x[1])
t=0
for i in range(n):
  t+=a[i][0]
  if t>a[i][1]:
    print("No")
    break
  elif i==n-1:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
a.sort(key=lambda x: x[1])
t=0
for i in range(n):
  t+=a[0]
  if t>a[1]:
    print("No")
    break
  elif i==n-1:
    print("Yes")

Fixed submission:
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
a.sort(key=lambda x: x[1])
t=0
for i in range(n):
  t+=a[i][0]
  if t>a[i][1]:
    print("No")
    break
  elif i==n-1:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=list(map(int,input().split()))
a=0
for i in range(n):
  a+=l(i)
  if a>x:
    print(i+1)
    break

Fixed submission:
n,x=map(int,input().split())
l=list(map(int,input().split()))
a=0
for i in range(n):
  a+=l[i]
  if a>x:
    print(i+1)
    break
else:
  print(1+n)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import defaultdict
  import bisect
  n,m = map(int,input().split())
  s = list(map(int,input().split()))
  t = list(map(int,input().split()))
  mod = 10**9+7
  p = max(n,m)
  if n>m:
    t.extend((0,)*(n-m))
  else:
    s.extend((0,)*(m-n))
  dcs = defaultdict(list)
  dct = defaultdict(list)
  dp = [[1 for i in range(p+1)] for j in range(p+1)]
  for i in range(p):
    if s[i] != 0:
      dcs[s[i]].append(i)
    if t[i] != 0:
      dct[t[i]].append(i)
  def update(i,j):
    val = dp[i-1][j-1]
    x = s[i-1]
    y = t[j-1]
    if dct[x]:
      k = bisect.bisect_left(dct[x],j-1)
      if k != 0:
        val += dp[i][dct[x][k-1]+1]-dp[i-1][dct[x][k-1]+1]
    if dcs[y]:
      l = bisect.bisect_left(dcs[y],i-1)
      if l != 0:
        val += dp[dcs[y][l-1]+1][j]-dp[dcs[y][l-1]+1][j-1]
    if x == y:
      val += dp[i-1][j-1]
    dp[i][j] = val%mod

  for i in range(1,p+1):
    for j in range(1,p+1):
      update(i,j)
  print(dp[-1][-1])
main()

Fixed submission:
from collections import defaultdict
import bisect
n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
mod = 10**9+7
p = max(n,m)
if n>m:
  t.extend((0,)*(n-m))
else:
  s.extend((0,)*(m-n))
dp = [[1 for i in range(p+1)] for j in range(p+1)]
for i in range(1,p+1):
  for j in range(1,p+1):
    x = s[i-1]
    y = t[j-1]
    if x == y:
      dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod
    else:
      dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import bisect
n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
mod = 10**9+7
p = max(n,m)
if n>m:
  t.extend((0,)*(n-m))
else:
  s.extend((0,)*(m-n))
dcs = defaultdict(list)
dct = defaultdict(list)
dp = [[1 for i in range(p+1)] for j in range(p+1)]
for i in range(p):
  if s[i] != 0:
    dcs[s[i]].append(i)
  if t[i] != 0:
    dct[t[i]].append(i)
for i in range(1,p+1):
  for j in range(1,p+1):
    val = dp[i-1][j-1]
    x = s[i-1]
    y = t[j-1]
    if dct[x]:
      k = bisect.bisect_left(dct[x],j-1)
      if k != 0:
        val += dp[i][dct[x][k-1]+1]-dp[i-1][dct[x][k-1]+1]
    if dcs[y]:
      l = bisect.bisect_left(dcs[y],i-1)
      if l != 0:
        val += dp[dcs[y][l-1]+1][j]-dp[dcs[y][l-1]+1][j-1]
    if x == y:
      val += dp[i-1][j-1]
    dp[i][j] = val%mod
print(dp[-1][-1])

Fixed submission:
from collections import defaultdict
import bisect
n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
mod = 10**9+7
p = max(n,m)
if n>m:
  t.extend((0,)*(n-m))
else:
  s.extend((0,)*(m-n))
dp = [[1 for i in range(p+1)] for j in range(p+1)]
for i in range(1,p+1):
  for j in range(1,p+1):
    x = s[i-1]
    y = t[j-1]
    if x == y:
      dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod
    else:
      dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod
print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
gsb1 = list(map(int,input().split()))
gsb2 = list(map(int,input().split()))
def trade(n,g1,s1,b1,g2,s2,b2):
  tradelist = []
  for x,y in (g1,g2),(s1,s2),(b1,b2):
    if x < y:
      tradelist.append((x,y))
  if not tradelist:
    return n
  dp = [0]*(n+1)
  for w,v in tradelist:
    for i in range(n+1-w):
      dp[i+w] = max(dp[i+w],dp[i]+v)
  return dp[n]

ans1 = trade(n,*gsb1,*gsb2)
ans2 = trade(ans1,*gsb2,*gsb1)
print(ans2)

Fixed submission:
n = int(input())
g1,s1,b1 = map(int,input().split())
g2,s2,b2 = map(int,input().split())
def trade(n,g1,s1,b1,g2,s2,b2):
  tradelist = []
  for x,y in (g1,g2),(s1,s2),(b1,b2):
    if x < y:
      tradelist.append((x,y))
  if not tradelist:
    return n
  dp = [0]*(n+1)
  for w,v in tradelist:
    for i in range(n+1-w):
      dp[i+w] = max(dp[i+w],dp[i]+v)
  ptr = n
  ret = dp[n]
  while ptr and dp[ptr-1] == dp[n]:
    ret += 1
    ptr -= 1
  return ret

ans1 = trade(n,g1,s1,b1,g2,s2,b2)
ans2 = trade(ans1,g2,s2,b2,g1,s1,b1)
print(ans2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 10000
for i in range(1,N):
  ans = min(ans, abs(sum(A[:i]-A[i+1:]))
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
ans = 10000
for i in range(1,N):
  ans = min(ans, abs(sum(A[:i])-sum(A[i:])))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
N = input()
k = len(N)
mod = 10**9+7
def mthd(n):
    x = format(n,"b")
    ln = len(x)
    if x == "1":
        return 3
    elif x == "0":
        return 1
    elif n == 2**(ln)-1:
        return pow(3,ln,mod)
    else:
        l = 2**(ln-1)
        s = n % l
        return (mthd(s)*2+mthd(l-1)) % mod
print(mthd(int(N,2)))

Fixed submission:
N = input()
k = len(N)
mod = 10**9+7
DP = [[0,0] for i in range(k+1)]
DP[0][0] = 1
DP[0][1] = 0
for i in range(1,k+1):
    if N[i-1] == "1":
        DP[i][0] = (DP[i-1][0]*2)%mod
        DP[i][1] = (DP[i-1][1]*3+DP[i-1][0])%mod
    if N[i-1] == "0":
        DP[i][0] = DP[i-1][0]
        DP[i][1] = (DP[i-1][1]*3)%mod
print((DP[k][0]+DP[k][1])%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
N = input()
k = len(N)
mod = 10**9+7
def mthd(n):
    x = format(n,"b")
    ln = len(x)
    if x == "1":
        return 3
    elif x == "0":
        return 1
    elif n == 2**(ln)-1:
        return pow(3,ln,mod)
    else:
        l = 2**(ln-1)
        s = n % l
        return (mthd(s)*2+mthd(l-1)) % mod
print(mthd(int(N,2)))

Fixed submission:
N = input()
k = len(N)
mod = 10**9+7
DP = [[0,0] for i in range(k+1)]
DP[0][0] = 1
DP[0][1] = 0
for i in range(1,k+1):
    if N[i-1] == "1":
        DP[i][0] = (DP[i-1][0]*2)%mod
        DP[i][1] = (DP[i-1][1]*3+DP[i-1][0])%mod
    if N[i-1] == "0":
        DP[i][0] = DP[i-1][0]
        DP[i][1] = (DP[i-1][1]*3)%mod
print((DP[k][0]+DP[k][1])%mod)

Buggy python submission (verdict: Runtime Error):
N = input()
k = len(N)
mod = 10**9+7
def mthd(n):
    x = format(n,"b")
    ln = len(x)
    if x == "1":
        return 3
    elif x == "0":
        return 1
    elif n == 2**(ln)-1:
        return pow(3,ln,mod)
    else:
        l = 2**(ln-1)
        s = n % l
        return (mthd(s)*2+mthd(l-1)) % mod
print(mthd(int(N,2)))

Fixed submission:
N = input()
k = len(N)
mod = 10**9+7
DP = [[0,0] for i in range(k+1)]
DP[0][0] = 1
DP[0][1] = 0
for i in range(1,k+1):
    if N[i-1] == "1":
        DP[i][0] = (DP[i-1][0]*2)%mod
        DP[i][1] = (DP[i-1][1]*3+DP[i-1][0])%mod
    if N[i-1] == "0":
        DP[i][0] = DP[i-1][0]
        DP[i][1] = (DP[i-1][1]*3)%mod
print((DP[k][0]+DP[k][1])%mod)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
n,x = map(int,input().split())
blr = [list(map(int,input().split())) for i in range(n)]
tad = []
for i in range(n):
  b,l,r = blr[i]
  tad.append(((x-b)*r+b*l,-b*l,(x-b)*r,i))
tad.sort(reverse=True)
t = list(zip(*tad))[2]
a = list(zip(*tad))[1]
a = [a[i]*(-1) for i in range(n)]
tacc = list(accumulate(t))
aacc = list(accumulate(a))
for i in range(n):
  if tacc[i]>=aacc[n-1]-aacc[i]:
    p = i
    break
if p == 0:
  tsum = 0
  asum = aacc[n-1]
else:
  tsum = tacc[p-1]
  asum = aacc[n-1]-aacc[p-1]
vis = [0]*n
for i in range(p):
  if tad[i][0] == tad[p][0]:
    continue
  v = tad[i][3]
  vis[v] = 1
ans = 10**18
for i in range(n):
  if vis[i]:
    continue
  b,l,r = blr[i]
  asumd = asum-b*l
  dif = tsum-asumd
  anstmp = p*x
  if dif >= 0:
    anstmp += b-dif//l
    print(2/0)
  else:
    anstmp += (-dif+r-1)//r+b
  if anstmp > (p+1)*x:
    continue
  ans = min(ans,anstmp)
print(ans)

Fixed submission:
import sys
N,A,B,C,D = map(int, input().split())
S = input()
for i in range(N-1):
  if S[i] == S[i+1] == '#':
    if A < i+1 < C or B < i+1 < D:
      print("No")
      sys.exit()
if C>D:
  for i in range(N-2):
    if S[i] == S[i+1] == S[i+2] == '.':
      if B <= i+2 <= D:
        break
    if i == N-3:
      print("No")
      sys.exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
import bisect
n,K = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
ans = [0]
if K>2*n:
    K = 2*n
if K == 1:
    print(max(a[0],a[n-1],0))
    exit()
for k in range((K+1)//2,K+1):
    r = K-k
    for i in range(k+1):
        ls = a[:i]+a[n-k+i:]
        ls.sort()
        if r == 0:
            ans.append(sum(ls))
        elif ls[r-1]<0:
            ans.append(sum(ls[r:]))
        else:
            x = bisect.bisect_left(ls,0)
            ans.append(sum(ls[x:]))
print(max(ans))

Fixed submission:
import bisect
n,K = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
ans = [0]
if K>2*n:
    K = 2*n
if K == 1:
    print(max(a[0],a[n-1],0))
    exit()
for k in range((K+1)//2,min(K+1,n+1)):
    r = K-k
    for i in range(k+1):
        ls = a[:i]+a[n-k+i:]
        ls.sort()
        if r == 0:
            ans.append(sum(ls))
        elif ls[r-1]<0:
            ans.append(sum(ls[r:]))
        else:
            x = bisect.bisect_left(ls,0)
            ans.append(sum(ls[x:]))
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import heappop,heappush
input = sys.stdin.readline
n,Q = map(int,input().split())
stx = [list(map(int,input().split())) for i in range(n)]
dls = [int(input()) for i in range(Q)]
event = []
for i in range(n):
  s,t,x = stx[i]
  event.append((s-x,1,x))
  event.append((t-x,-1,x))
for i in range(Q):
  d = dls[i]
  event.append((d,2,i))
event.sort()
ans = [-1]*Q
s = set()
hq = []
for t,q,x in event:
  if q == 1:
    s.add(x)
    heappush(hq,x)
  elif q == -1:
    s.remove(x)
  elif q == 2:
    while hq and hq[0] not in s:
      heappop(hq)
    if hq:
      ans[x] = hq[0]
    else:
      ans[x] = -1
print(*ans,sep="\n")

Fixed submission:
import sys
from heapq import heappop,heappush
input = sys.stdin.readline
n,Q = map(int,input().split())
stx = [list(map(int,input().split())) for i in range(n)]
dls = [int(input()) for i in range(Q)]
event = []
for i in range(n):
  s,t,x = stx[i]
  event.append((s-x,1,x))
  event.append((t-x,-1,x))
for i in range(Q):
  d = dls[i]
  event.append((d,2,i))
event.sort()
ans = [-1]*Q
s = set()
hq = []
for t,q,x in event:
  if q == 1:
    s.add(x)
    heappush(hq,x)
  elif q == -1:
    s.remove(x)
  elif q == 2:
    while hq and hq[0] not in s:
      heappop(hq)
    if hq:
      ans[x] = hq[0]
    else:
      ans[x] = -1
print(*ans,sep="\n")
Buggy python submission (verdict: Runtime Error):
import bisect
import sys
input=sys.stdin.readline
from operator import itemgetter
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=itemgetter(1),reverse=True)
s=0
ans=0
for i in range(m):
  if a[s]<bc[i][1]:
    t=bisect.bisect_left(a,bc[i][1],s,n)
    cvt=min(t-s,bc[i][0])
    ans+=bc[i][1]*cvt
    s+=cvt
    if s>=n:
      break
  else:
    break
print(ans+sum(a[s:]))


Fixed submission:
a,b=map(int,input().split())
if a>=13:
  print(b)
elif a>=6:
  print(b//2)
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
s=0
for i in range(m):
  if a[s]<bc[i][1]:
    t=bisect.bisect_left(a,bc[i][1],s,n)
    for j in range(s,min(t,s+bc[i][0])):
      a[j]=bc[i][1]
    s=min(t,s+bc[i][0])
    if s>=n:
      break
  else:
    break
print(sum(ans))


Fixed submission:
a,b=map(int,input().split())
if a>=13:
  print(b)
elif a>=6:
  print(b//2)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
s=0
for i in range(m):
  if a[s]<bc[i][1]:
    t=bisect.bisect_left(a,bc[i][1],s,n)
    for j in range(s,min(t,s+bc[i][0])):
      a[j]=bc[i][1]
    s=min(t,s+bc[i][0])
    if s>=n:
      break
  else:
    break
print(sum(ans))


Fixed submission:
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
s=0
for i in range(m):
  if a[s]<bc[i][1]:
    t=bisect.bisect_left(a,bc[i][1],s,n)
    for j in range(s,min(t,s+bc[i][0])):
      a[j]=bc[i][1]
    s=min(t,s+bc[i][0])
    if s>=n:
      break
  else:
    break
print(sum(a))

Buggy python submission (verdict: Runtime Error):
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
s=0
for i in range(m):
  if a[s]<bc[i][1]:
    t=bisect.bisect_left(a,bc[i][1],s,n)
    for j in range(s,min(t,s+bc[i][0])):
      a[j]=bc[i][1]
    s=min(t,s+bc[i][0])
  else:
    break
print(sum(ans))

Fixed submission:
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
s=0
for i in range(m):
  if a[s]<bc[i][1]:
    t=bisect.bisect_left(a,bc[i][1],s,n)
    for j in range(s,min(t,s+bc[i][0])):
      a[j]=bc[i][1]
    s=min(t,s+bc[i][0])
    if s>=n:
      break
  else:
    break
print(sum(a))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()
s[k-1]=s[k-1].lower()
print(*s,sep="")

Fixed submission:
n,k=map(int,input().split())
s=list(input())
s[k-1]=s[k-1].lower()
print(*s,sep="")

Buggy python submission (verdict: Runtime Error):
n,k=int(input())
s=input()
s[k-1]=s[k-1].lower()
print(*s,sep="")

Fixed submission:
n,k=map(int,input().split())
s=list(input())
s[k-1]=s[k-1].lower()
print(*s,sep="")

Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())
s[k-1]=s[k-1].lower()
print(*s,sep="")

Fixed submission:
n,k=map(int,input().split())
s=list(input())
s[k-1]=s[k-1].lower()
print(*s,sep="")

Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())
x=s[k-1]
y=x.lower()
print(s.replace(x,y))

Fixed submission:
n,k=map(int,input().split())
s=list(input())
s[k-1]=s[k-1].lower()
print(*s,sep="")