Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03776 (python)

Fixed submission:
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v = sorted(v,reverse=True)

# (合計, 個数)
max_avg = (sum(v[:A]), A)

t = v[A-1]
num1 = v[:A].count(t)
num2 = v[A:].count(t)

fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=170141183460469231731687303715884105727

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k):
    if k<0 or k>n or n<0:
        return 0
    return (fact[n]*ifact[k]*ifact[n-k])%p

combination(N,fact,ifact)

res = int(op(num1+num2, num1))
if v[0]==v[-1]:
    res = 0
    for i in range(A,B+1):
        res += int(op(N, i))
elif v[0] == v[B-1]:
    res = 0
    for i in range(A, B+1):
        res += int(op(num1+num2,i))
elif v[0] == v[A-1]:
    res = 0
    for i in range(A, min(B, A+num2)+1):
        res += int(op(num1+num2, i))
print(max_avg[0]/max_avg[1])
print(res)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v = sorted(v,reverse=True)

# (合計, 個数)
max_avg = (sum(v[:A]), A)

t = v[A-1]
num1 = v[:A].count(t)
num2 = v[A:].count(t)

fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=170141183460469231731687303715884105727

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k):
    if k<0 or k>n or n<0:
        return 0
    return (fact[n]*ifact[k]*ifact[n-k])%p

combination(N,fact,ifact)


res = int(comb(num1+num2, num1))
if v[0]==v[-1]:
    res = 0
    for i in range(A,B+1):
        res += int(op(N, i))

print(max_avg[0]/max_avg[1])
print(res)
Problem p02623 (python)

Fixed submission:
def strToList(str,offset=0):
    res = [];
    for el in str.split(" "):
        if el!='':
            res.append(int(el)+offset)
    return res


[N,M,K] = strToList(input())
A = strToList(input())
B = strToList(input())

current_time = 0
current_value = 0
iA = 0
iB = 0

while iA<N:
    if current_time+A[iA]<=K:
        current_time+=A[iA]
        current_value+=1
        iA+=1
    else:
        break

max_value = current_value
iA-=1

while iA>-2 and iB<M:
    if current_time+B[iB]<=K:
        current_time+=B[iB]
        iB+=1
        current_value+=1
        if current_value>max_value:
            max_value=current_value
    else:
        current_time-=A[iA]
        iA-=1
        current_value-=1

print(max_value)

Buggy submission (verdict: Runtime Error):
def strToList(str,offset=0):
    res = [];
    for el in str.split(" "):
        if el!='':
            res.append(int(el)+offset)
    return res


[N,M,K] = strToList(input())
A = strToList(input())
B = strToList(input())

current_time = 0
current_value = 0
iA = 0
iB = 0

while iA<N:
    if current_time+A[iA]<=K:
        current_time+=A[iA]
        current_value+=1
        iA+=1
    else:
        break

max_value = current_value

while iA>=0 and iB<M:
    if current_time+B[iB]<=K:
        current_time+=B[iB]
        iB+=1
        current_value+=1
        if current_value>max_value:
            max_value=current_value
    else:
        current_time-=A[iA]
        iA-=1
        current_value-=1

print(max_value)
Problem p02659 (python)

Fixed submission:
a, b = input().split()
a = int(a)
b = int(b.replace(".",""))

c = a * b
ans = c//100
print(ans)

Buggy submission (verdict: Runtime Error):
n , m = map(float ,input().split())
n = int(n)
ans = str(n * (m * 100)) // 100

print(ans[:ans.find('.')])

Buggy submission (verdict: Runtime Error):
n , m = map(float ,input().split())
n = int(n)
ans = str(n * (m * 100)) / 100

print(ans[:ans.find('.')])
Problem p03011 (python)

Fixed submission:
A = list(map(int,input().split()))
print(sum(A)-max(A))

Buggy submission (verdict: Runtime Error):
A = list(map(int,input().split()))
print(SUM(A) - MAX(A))
Problem p03426 (python)

Fixed submission:
H,W,D=list(map(int,input().split()))
map_=[[0,0] for _ in range(H*W+1)]
for y in range(H):
    for x,A in enumerate(map(int,input().split())):
        map_[A]=[x+1,y+1]

cost=[0 for _ in range(H*W+1)]
for i in range(D+1,H*W+1):
    cost[i]+=abs(map_[i][0]-map_[i-D][0])+abs(map_[i][1]-map_[i-D][1])+cost[i-D]
Q=int(input())
for i in range(Q):
    L,R=list(map(int,input().split()))
    print(cost[R]-cost[L])

Buggy submission (verdict: Runtime Error):
H,W,D=list(map(int,input().split()))
arr=[0 for i in range(H*W+1)]
for y in range(H):
    for x,n in enumerate(map(int,input().split())):
        arr[n]=[x,y]

dic={}

Q=int(input())
for i in range(Q):
    ans=0
    now,goal= list(map(int,input().split()))
    nx=arr[now][0]
    ny=arr[now][1]
    tmp=now
    for j in range((goal-now)//D):
        if dic.get(tmp*H*W+goal,0)!=0:
            dic[now*H*W+goal]=ans+dic[tmp*H*W+goal]
            break
        tmp+=D
        x=arr[tmp][0]
        y=arr[tmp][1]
        ans+=abs(x-nx)+abs(y-ny)
        nx=x
        ny=y
        dic[now*H*W+tmp]=ans
    print(dic[now*H*W+goal])
Problem p02688 (python)

Fixed submission:
N,K=map(int,input().split())
l=[x for x in range(1,N+1)]
for i in range(K):
	d=int(input())
	A=list(map(int,input().strip().split()))
	for j in range(len(A)):
		if A[j] in l:
			l.remove(A[j])
print(len(l))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
l=[x for x in range(1,N+1)]
S=set(l)
m=int(input())
B=set((map(int,input().strip().split())))
se=list(S-B)
for i in range(1,K):
	d=int(input())
	A=list(map(int,input().strip().split()))
	for j in range(len(A)):
		if A[j] in se:
			del se[A[j]]
print(len(se))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
l=[x for x in range(1,N+1)]
S=set(l)
m=int(input())
B=set((map(int,input().strip().split())))
se=list(S-B)
for i in range(1,K):
	d=int(input())
	A=list(map(int,input().strip().split()))
	for i in range(len(A)):
		if A[i] in se:
			del se[A[i]]
print(len(se))
Problem p02659 (python)

Fixed submission:
import decimal
a, b = map(decimal.Decimal, input().split())
print(a * b // 1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print((int)(a*b))
Problem p02629 (python)

Fixed submission:
n = int(input())
n -= 1
ans = []
for i in range(100):
  if n >= 26:
    n -= 26
    ans.append(chr(n%26+97))
    n //= 26
ans.append(chr(n+97))
ans = ans[::-1]
print(*ans,sep="")

Buggy submission (verdict: Runtime Error):
n = int(input())n = int(input())
n -= 1
ans = []
for i in range(100):
  if n >= 26:
    n -= 26
    ans.append(chr(n%26+97))
    n //= 26
ans.append(chr(n+97))
print(*ans[::-1],sep="")
Problem p02659 (python)

Fixed submission:
a,b = input().split()
a = int(a)
c = b.replace(".","")
c = int(c)
print(a*c//100)

Buggy submission (verdict: Runtime Error):
a,b = input()
a = int(a)
b.replace(".","")
b = int(b)
print(a*b//100)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
b *= 100
print(a*b//100)
Problem p02679 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
mod = 10**9+7
def p2(x):
  return pow(2,x,mod)
dc = defaultdict(int)
st = set()
from math import gcd
n00 = 0
n0x = 0
nx0 = 0
nxy = 0
ls = []
for i in range(n):
  if a[i][0] == a[i][1] == 0:
    n00 += 1
  elif a[i][0] == 0:
    n0x += 1
  elif a[i][1] == 0:
    nx0 += 1
  else:
    nxy += 1
    if a[i][0] < 0 and a[i][1] < 0:
      a[i][0] *= -1
      a[i][1] *= -1
    elif a[i][0] < 0:
      a[i][0] *= -1
      a[i][1] *= -1
    ls.append(a[i])
if len(ls) == 0:
  print((p2(n0x)+p2(nx0)-1+n00-1)%mod)
  exit()
def part(x,y):
  g = gcd(x,y)
  return (x//g,y//g)
for i in range(nxy):
  p = part(*ls[i])
  st.add(p)
  dc[p] += 1
banned = []
for i,j in dc:
  if i*j > 0 and (j,-i) in st:
    banned.append((dc[(i,j)],dc[(j,-i)]))
sm = sum([banned[i][0]+banned[i][1] for i in range(len(banned))])
ans = p2(nxy-sm)
for i,j in banned:
  ans = (ans*(p2(i)+p2(j)-1))%mod
k = p2(n0x)+p2(nx0)-1
ans *= k
ans += n00-1
print(ans%mod)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from functools import cmp_to_key
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
mod = 10**9+7
n00 = 0
n0x = 0
nx0 = 0
nxy = 0
ls = []
for i in range(n):
  if a[i][0] == a[i][1] == 0:
    n00 += 1
  elif a[i][0] == 0:
    n0x += 1
  elif a[i][1] == 0:
    nx0 += 1
  else:
    nxy += 1
    if a[i][0] < 0 and a[i][1] < 0:
      a[i][0] *= -1
      a[i][1] *= -1
    elif a[i][0] < 0:
      a[i][0] *= -1
      a[i][1] *= -1
    ls.append(a[i])
def sorting(x,y):
  if x[0]*y[1]-x[1]*y[0] == 0:
    return 0
  if x[0]*y[1]-x[1]*y[0] > 0:
    return 1
  else:
    return -1
ls.sort(key = cmp_to_key(sorting))
tls = []
t = 1
for i in range(1,n):
  if sorting(ls[i],ls[i-1]) == 0:
    t += 1
  else:
    tls.append([t,*ls[i-1]])
    t = 1
tls.append([t,*ls[n-1]])
for i in range(len(tls)):
  if tls[i][2] < 0:
    tls = tls[:i]+tls[len(tls)-1:i-1:-1]
    break

l = 0
r = len(tls)-1
banned = []
while l < r:
  la,lb = tls[l][1:]
  ra,rb = tls[r][1:]
  if la*ra + lb*rb == 0:
    banned.append((tls[l][0],tls[r][0]))
    l += 1
    r -= 1
  elif la*ra + lb*rb > 0:
    r -= 1
  else:
    l += 1
sm = sum([banned[i][0]+banned[i][1] for i in range(len(banned))])
def p2(x):
  return pow(2,x,mod)
ans = p2(n-sm)
for i,j in banned:
  ans = (ans*(p2(i)+p2(j)-1))%mod
k = p2(n0x)+p2(nx0)-1
ans *= k
ans += n00-1
print(ans%mod)
Problem p02711 (python)

Fixed submission:
if input().count("7"):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
dp = [[0 for i in range(3)] for j in range(n+1)]
for i in range(1,n+1):
  ai = a[i-1]
  dp[i] = dp[i-1][:]
  if i%2:
    dp[i][0] += +ai
    dp[i][1] = max(dp[i-1][0],dp[i-1][1])
  if i%2 == 0:
    dp[i][1] += ai
    dp[i][2] = max(dp[i-1][1],dp[i-1][2])
  if i >= 3 and i%2:
    dp[i][2] += ai
if n%2 == 0:
  print(max(dp[-1][0],dp[-1][1]))
else:
  print(max(dp[-1][1],dp[-1][2]))
Problem p02757 (python)

Fixed submission:
from collections import Counter
from itertools import accumulate
import sys
input = sys.stdin.readline
n,p = map(int,input().split())
s = input().rstrip()
if p == 2:
  ans = 0
  for i in range(n):
    if int(s[i])%2 == 0:
      ans += i+1
  print(ans)
elif p == 5:
  ans = 0
  for i in range(n):
    if int(s[i])%5 == 0:
      ans += i+1
  print(ans)
else:
  ls = [0]
  prev = 0
  for i in range(n):
    x = int(s[n-i-1])
    y = (prev+x*pow(10,i,p))%p
    ls.append(y)
    prev = y
  c = Counter(ls)
  ans = 0
  for x in c.values():
    ans += x*(x-1)//2
  print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
from itertools import accumulate
import sys
input = sys.stdin.readline
n,p = map(int,input().split())
s = input().rstrip()
if p == 2:
  ans = 0
  for i in range(n):
    if int(s[i])%2 == 0:
      ans += i+1
  print(ans)
elif p == 5:
  for i in range(n):
    if int(s[i])%5 == 0:
      ans += i+1
  print(ans)
else:
  ls = [0]
  prev = 0
  for i in range(n):
    x = int(s[n-i-1])
    y = (prev+x*pow(10,i,p))%p
    ls.append(y)
    prev = y
  c = Counter(ls)
  ans = 0
  for x in c.values():
    ans += x*(x-1)//2
  print(ans)
Problem p02777 (python)

Fixed submission:
s,t = input().split()
n,m = map(int,input().split())
x = input()
if x == s:
  print(n-1,m)
else:
  print(n,m-1)

Buggy submission (verdict: Runtime Error):
mod = 10**9+7
rng = 2000100
fctr = [1]+[0]*(rng-1)
finv = [1]+[0]*(rng-1)
for i in range(1,rng):
  fctr[i] = fctr[i-1]*i%mod
for i in range(1,rng):
  finv[i] = pow(fctr[i],mod-2,mod)
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod

x1,y1,x2,y2 = map(int,input().split())
print((cmb(x2+y2+2,x2+1)-cmb(x2+y1+1,y1)-cmb(x1+y2+1,x1)+cmb(x1+y1,x1))%mod)
Problem p02815 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
mod = 10**9+7
a = list(map(int,input().split()))
a.sort()
ans = 0
const = pow(2,n,mod)
if n == 1:
  print(a[0]*2%mod)
  exit()
for i in range(n):
  ans = (ans + a[i]*const*(pow(2,n-1,mod)+pow(2,n-2,mod)*(n-i-1))%mod)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
mod = 10**9+7
a = list(map(int,input().split()))
a.sort()
ans = 0
const = pow(2,n,mod)
for i in range(n):
  ans = (ans + a[i]*const*(pow(2,n-1,mod)+pow(2,n-2,mod)*(n-i-1))%mod)%mod
print(ans)
Problem p02819 (python)

Fixed submission:
def prm(x):
  if x == 1 or x == 4:
    return False
  for i in range(2,int(x**0.5+1)):
    if x%i == 0:
      return False
  return True
X=int(input())
for i in range(X,X**2):
  if prm(i):
    print(i)
    break

Buggy submission (verdict: Runtime Error):
def prm(x):
  if x == 1 or x == 4:
    return False
  for i in range(1,int(x**0.5+1)):
    if x%i == 0:
      return False
  return True
for i in range(X,X**2):
  if prm(i):
    print(i)
    break

Buggy submission (verdict: Runtime Error):
def prm(x):
  if x == 1 or x == 4:
    return False
  for i in range(1,int(i**0.5+1)):
    if x%i == 0:
      return False
  return True
for i in range(X,X**2):
  if prm(i):
    print(i)
    break
Problem p02835 (python)

Fixed submission:
a,b,c=map(int,input().split())
if a+b+c>21:
  print("bust")
else:
  print("win")

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
h,w = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]
grid = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    grid[i][j] = abs(a[i][j]-b[i][j])
dp = [[[False for i in range(80*(h+w+1)+1)] for j in range(w)] for k in range(h)]
dp[0][0][grid[i][j]] = True
for j in range(1,w):
  for k in range(80*j+1):
    t = grid[0][j]
    dp[0][j][k] = dp[0][j][k] or dp[0][j-1][k+t] or dp[0][j-1][abs(k-t)]
for i in range(1,h):
  for k in range(80*i+1):
    t = grid[i][0]
    dp[i][0][k] = dp[i][0][k] or dp[i-1][0][k+t] or dp[i-1][0][abs(k-t)]
for i in range(1,h):
  for j in range(1,w):
    for k in range(80*(i+j)+1):
      t = grid[i][j]
      dp[i][j][k] = dp[i][j][k] or dp[i][j-1][k+t] or dp[i][j-1][abs(k-t)] or dp[i-1][j][k+t] or dp[i-1][j][abs(k-t)]
for i in range(12801):
  if dp[h-1][w-1][i]:
    print(i)
    break

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
h,w = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]
grid = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    grid[i][j] = abs(a[i][j]-b[i][j])
dp = [[[False for i in range(12881)] for j in range(w)] for k in range(h)]
dp[0][0][grid[i][j]] = True
for j in range(1,w):
  for k in range(80*j+1):
    t = grid[0][j]
    dp[0][j][k] = dp[0][j][k] or dp[0][j-1][k+t] or dp[0][j-1][abs(k-t)]
for i in range(1,h):
  for k in range(80*i+1):
    t = grid[i][0]
    dp[i][0][k] = dp[i][0][k] or dp[i-1][0][k+t] or dp[i-1][0][abs(k-t)]
for i in range(1,h):
  for j in range(1,w):
    for k in range(80*(i+j)+1):
      t = grid[i][j]
      dp[i][j][k] = dp[i][j][k] or dp[i][j-1][k+t] or dp[i][j-1][abs(k-t)] or dp[i-1][j][k+t] or dp[i-1][j][abs(k-t)]
for i in range(12801):
  if dp[h-1][w-1][i]:
    print(i)
    break
Problem p02836 (python)

Fixed submission:
S = input()
ans = 0
for i in range(len(S)//2):
  if S[i] != S[-i-1]:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
ans = 0
for i in range(len(S)//2):
  if S[i] != S[-i-1]:
    ans+=1
print(ans)
Problem p02847 (python)

Fixed submission:
N = input()
if N == "SUN":
    print(7)
elif N == "SAT":
    print(1)
elif N == "FRI":
    print(2)
elif N == "MON":
    print(6)
elif N == "THU":
    print(3)
elif N == "WED":
    print(4)
elif N == "TUE":
    print(5)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from math import factorial as fc

def cmb_2(n):
    return n*(n-1)//2

N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A = [i-1 for i in A]

sumA = list(accumulate(A))
sumA = [0]+[i % K for i in sumA]
x = sumA[:K]
modmap = [0]*K
for i in x:
    modmap[i] += 1

ans = 0
for i in range(K):
    ans += cmb_2(modmap[i],2)

for i in range(N-K+1):
    modmap[sumA[K+i]] += 1
    modmap[sumA[i]] -= 1
    ans += modmap[sumA[K+i]]-1

print(ans)
Problem p02879 (python)

Fixed submission:
x,y=map(int,input().split())
if x<=9 and y<=9:
  print(x*y)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
import sys

def jeat(a, f, x, K):
    N = 0
    for i in range(len(a)):
        if a[i]*f[i] > x:
            N += a[i] - x // f[i]
    if N > K:
        return False
    if N <= K:
        return True

N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
F = list(map(int, input().split(' ')))
if K >= sum(A):
    print(0)
    sys.exit()
A.sort()
F.sort(reverse = True)
a = 0
b = 10**13
while (True):
    z = (a+b)//2
    if jeat(A,F,z,K) == True:
        if jeat(A,F,z-1,K) == False:
            break
        b = z-1
    else:
        if jeat(A,F,z+1,K) == True:
            z += 1
            break
        a = z+1

print(z)

Buggy submission (verdict: Runtime Error):
import sys

def jeat(a, f, x, K):
    N = 0
    for i in range(len(a)):
        if a[i]*f[i] > x:
            N += a[i] - x // f[i]
    if N > K:
        return False
    if N <= K:
        return True

N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
F = list(map(int, input().split(' ')))
if K >= sum(A):
    print(0)
    sys.exit()
A.sort()
F.sort(reverse = True)
a = 0
b = 10**18
while (a<b):
    z = (a+b)//2
    if jeat(A,F,z,K) == True:
        if jeat(A,F,z-1,K) == False:
            break
        b = z-1
    else:
        if jeat(A,F,z+1,K) == True:
            z -= 1
            break
        a = z+1

print(z)
Problem p02881 (python)

Fixed submission:
N = int(input())
for i in range(1,int(N**0.5+1)):
  if N % i == 0:
    ans = i + N // i - 2
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
for i in range(int(N**0.5+1)):
  if N % i == 0:
    ans = i + N // i - 2
print(ans)
Problem p02915 (python)

Fixed submission:
print(int(input())**3)

Buggy submission (verdict: Runtime Error):
import math
def cmb(n,r):
  return math.factorial(n)//(math.factorial(r)*math.factorial(n-r))
n=int(input())
a=list(map(int,input().split()))
a.sort()
ls=[0]
cnt=0
for i in range(1,2**n):
  if a[i]>a[i-1]:
    cnt+=1
  ls.append(cnt)
lmt = []
for i in range(n+1):
  lmt.extend([i]*cmb(n,i))
bias = ls[-1]-lmt[-1]
jdg = 0
ulmt = 0
for i in range(n):
  jdg += ls.count(i)
  ulmt += 2**(n-i-1)
  if jdg > ulmt:
    print("No")
    exit()
for x,l in zip(ls,lmt):
  if x-l > bias:
    print("No")
    break
else:
  print("Yes")
Problem p02948 (python)

Fixed submission:
from itertools import accumulate
import heapq as hq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab.sort()
ls = []
hq.heapify(ls)
k = max([a[0] for a in ab]+[m])
daylist = [0]*(k+1)
for i in range(n):
  daylist[ab[i][0]] += 1
daylistsum = list(accumulate(daylist))
ans = 0
for i in range(1,m+1):
  for j in range(daylistsum[i-1],daylistsum[i]):
    hq.heappush(ls,-ab[j][1])
  if ls:
    ans -= hq.heappop(ls)
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
import heapq as hq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab.sort()
ls = []
hq.heapify(ls)
k = max([a[0] for a in ab])
daylist = [0]*(k+1)
for i in range(n):
  daylist[ab[i][0]] += 1
daylistsum = list(accumulate(daylist))
ans = 0
for i in range(1,m+1):
  for j in range(daylistsum[i-1],daylistsum[i]):
    hq.heappush(ls,-ab[j][1])
  if ls:
    ans -= hq.heappop(ls)
print(ans)
Problem p02989 (python)

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

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

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

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 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)
Problem p03015 (python)

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 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)))
Problem p03017 (python)

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 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)
Problem p03038 (python)

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 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))

Buggy 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))