Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np

def knapsack2(N,W,weight,value,WW):
  #初期化
  inf=float("inf")
  dp=[[-inf for i in range(WW)] for j in range(N+1)]
  for i in range(WW):
      dp[0][i]=0

  #DP
  for i in range(N):
    for w in range(WW):
      if weight[i]<=w:
        if w-weight[i]>=W: #時間切れ
          dp[i+1][w]=dp[i][w]
        else: #注文可能
          dp[i+1][w]=max(dp[i][w-weight[i]]+value[i], dp[i][w])
      else: #NG
        dp[i+1][w]=dp[i][w]
  return np.max(np.array(dp))
  #return dp[N][2*W]

N, T = map(int,input().split())
WW = T+3000
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))

weight = [elem[0] for elem in ab]
value = [elem[1] for elem in ab]
res = knapsack2(N,T,weight,value,WW)
print(res)


Fixed submission:
#import numpy as np

def knapsack2(N,W,weight,value,WW):
  #初期化
  inf=float("inf")
  dp=[[-inf for i in range(WW)] for j in range(N+1)]
  for i in range(WW):
      dp[0][i]=0
  maxval = 0
  #DP
  for i in range(N):
    for w in range(WW):
      if weight[i]<=w:
        if w-weight[i]>=W: #時間切れ
          dp[i+1][w]=dp[i][w]
        else: #注文可能
          dp[i+1][w]=max(dp[i][w-weight[i]]+value[i], dp[i][w])
      else: #NG
        dp[i+1][w]=dp[i][w]
    maxval = max([maxval, max(dp[i+1])])
#  for elem in dp:
#    print(elem[:2*W])
  return maxval
  #return np.max(np.array(dp))
  #return dp[N][2*W]

N, T = map(int,input().split())
WW = T+3000
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))

ab =  sorted(ab,key=lambda x:x[0])

weight = [elem[0] for elem in ab]
value = [elem[1] for elem in ab]
res = knapsack2(N,T,weight,value,WW)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j] - 0.1
        res += bisect.bisect_right(L, tgt)-(j+1)
print(res)


Fixed submission:
import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j]
        res += bisect.bisect_left(L, tgt)-(j+1)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j] - 0.1
        res += bisect.bisect_right(L[j+1:], tgt)
print(res)


Fixed submission:
import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j]
        res += bisect.bisect_left(L, tgt)-(j+1)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
c = 0
for i in range(N):
    for j in range(i+1,N):
        tmp = N-j-1
        for k in range(N-1, j, -1):
            if L[k] < L[i]+L[j]:
                break
            tmp -= 1
        c += tmp
print(c)


Fixed submission:
import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j]
        res += bisect.bisect_left(L, tgt)-(j+1)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, M = map(int,input().split())
ab = []
c = []
def bit(st):
    ls = list(st)
    res = 0
    for elem in ls:
        res += 2**(elem-1)
    return res

for i in range(M):
    ab.append(list(map(int,input().split())))
    c.append(set(map(int,input().split())))
dp = [10**6]*(2**N)
dp[0] = 0
for i in range(M):
    for j in range(2**N):
        dp[bit(c[i]) | j] = min(dp[bit(c[i]) | j], dp[j]+ab[i][0])
if dp[2**N-1] == 10**6:
    print(-1)
else:
    print(dp[2**N-1])


Fixed submission:
import sys
input = sys.stdin.readline
N, M = map(int,input().split())
ab = []
c = []
def bit(ls):
    res = 0
    for elem in ls:
        res += 2**(elem-1)
    return res

for i in range(M):
    ab.append(list(map(int,input().split())))
    l = list(map(int,input().split()))
    val = bit(l)
    c.append(val)
dp = [10**6]*(2**N)
dp[0] = 0
for i in range(M):
    for j in range(2**N):
        dp[c[i] | j] = min(dp[c[i] | j], dp[j]+ab[i][0])
if dp[2**N-1] == 10**6:
    print(-1)
else:
    print(dp[2**N-1])
Buggy python submission (verdict: Runtime Error):
print(int(input) ** 3)

Fixed submission:
print(int(input()) ** 3)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(N):
    if i==0:
        sum += b[0]
    elif i==N-1:
        sum += b[N-1]
    else:
        sum += min(b[i], b[i+1])
print(sum)


Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(N):
    if i==0:
        sum += b[0]
    elif i==N-1:
        sum += b[N-2]
    else:
        sum += min([b[i-1], b[i]])
print(sum)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
S = input()
out = ['0'] * len(S)
for i in range(K):
    if i!=0:
        S = ''.join(out)
    idx = 0
    maxidx = 0
    length = 1
    maxlen = 10000
    back = S[0]
    for j in range(len(S)):
        if back == S[j]:
            length += 1
        else:
            if length <= maxlen:
                #print(length)
                maxlen = length
                maxidx = j
                length = 1
            else:
                length = 1
                idx = j
        if length == j+2 and S[0] == 'L':
            length -= 1
        if j == len(S)-1 and S[j] == 'R':
            length -= 1
        back = S[j]
    temp = ['0'] * maxlen
    for j in range(maxlen):
        #print([maxidx,maxlen])
        if maxlen == 1:
            if S[maxidx + maxlen - j - 2] == 'L':
                temp[j] = 'R'
            else:
                temp[j] = 'L'
        else:
            if S[maxidx + maxlen - j - 1] == 'L':
                temp[j] = 'R'
            else:
                temp[j] = 'L'
    for j in range(len(S)):
        out[j] = S[j]
    for j in range(maxlen):
        if maxlen == 1:
            out[maxidx + j - 1] = temp[j]
        else:
            out[maxidx + j] = temp[j]
#print(''.join(out))
count=0
#right
for i in range(len(S)):
    if i==0 and out[i]=='L':
        continue
    elif i==N-1 and out[i]=='R':
        break
    if out[i]=='R' and out[i+1]=='R':
        count += 1
    if out[i]=='L' and out[i-1]=='L':
        count += 1
print(count)


Fixed submission:
import bisect
import heapq
import numpy as np
N, K = map(int,input().split())
s = input()
res = 0
if s[0] == 'R' and s[1] == 'R':
    res += 1
for i in range(1,N-1):
    if s[i-1] == 'R' and s[i] == 'L':
        continue
    elif s[i+1] == 'L' and s[i] == 'R':
        continue
    res += 1
if s[N-1] == 'L' and s[N-2] == 'L':
    res += 1
res = min([N-1, res+2*K])
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ab = [list(map(int,input().split())) for i in range(N)]
ab = sorted(ab, key = lambda x:x[0])
tgt = []
count = 0
profit = 0
for m in range(M-1,-1,-1):
    for i in range(count, len(ab)):
        if ab[i][0] == M-m:
            tgt.append(ab[i][1])
            count += 1
        else:
            break
    if tgt != []:
        profit += max(tgt)
        tgt.remove(max(tgt))
print(profit)


Fixed submission:
import heapq
N, M = map(int, input().split())
ab = [list(map(int,input().split())) for i in range(N)]
ab = sorted(ab, key = lambda x:x[0])
tgt = []
heapq.heapify(tgt)
count = 0
profit = 0
for m in range(M-1,-1,-1):
    for i in range(count, len(ab)):
        if ab[i][0] == M-m:
            heapq.heappush(tgt, -ab[i][1])
            count += 1
        else:
            break
    if len(tgt) != 0:
        getval = -heapq.heappop(tgt)
        profit += getval
print(profit)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=[int(input()) for i in range(N)]
ls=[]
mi=10**10
for elem in a:
  upd_flg=0
  if elem <= mi:
    ls.append(elem)
    mi=elem
    continue
  for i in range(len(ls)):
    if elem > ls[i]:
      ls[i]=elem
      upd_flg=1
      break
  if upd_flg==0:
    ls.append(elem)
    mi=elem
print(len(ls))

Fixed submission:
import sys
input = sys.stdin.readline
import bisect
N = int(input())
a = [-int(input()) for i in range(N)]
ls = []
res = 0
for elem in a:
    idx = bisect.bisect_right(ls,elem)
    if idx == res:
        ls.append(elem)
        res += 1
    else:
        ls[idx] = elem
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from scipy.special import comb

N, K = map(int,input().split())
MOD = 10**9+7
for i in range(1,K+1):
    val1 = comb(K-1, i-1, exact=True)%MOD
    val2 = comb(N-K-1, i, exact=True)%MOD
    val3 = comb(N-K-1, i-1, exact=True)%MOD
    val4 = comb(N-K-1, i-2, exact=True)%MOD
    print((val1*(val2+2*val3+val4))%MOD)


Fixed submission:
import sys
input = sys.stdin.readline
from scipy.misc import comb

N, K = map(int,input().split())
MOD = 10**9+7
for i in range(1,K+1):
    if i==1 and N==K:
        print(1)
        continue
    val1 = comb(K-1, i-1, exact=True)%MOD
    val2 = comb(N-K-1, i, exact=True)%MOD
    val3 = comb(N-K-1, i-1, exact=True)%MOD
    val4 = comb(N-K-1, i-2, exact=True)%MOD
    res = (val1*(val2+2*val3+val4))%MOD
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [ list(map(int,input().split())) for i in range(M) ]
for i in range(M):
    for j in range(BC[i][0]):
        A.append(BC[i][1])
A = sorted(A, reverse=True)
print(sum(A[0:N]))


Fixed submission:
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) ]
BC = sorted(BC, key=itemgetter(1), reverse=True)
sumval=0
idx=0
for i in range(len(BC)):
    sumval += BC[i][0]
    idx += 1
    if sumval >= N:
        break
BC = BC[0:idx]
for i in range(len(BC)):
    for j in range(BC[i][0]):
        A.append(BC[i][1])
A = sorted(A, reverse=True)
print(sum(A[0:N]))
Buggy python submission (verdict: Runtime Error):
import numpy as np
import copy
N, A, B, C = map(int,input().split())
t = sorted([A,B,C])
A = t[0]
B = t[1]
C = t[2]
l = []
for i in range(N):
    l.append(int(input()))
dic = {}

def calc(ls):
    dic[tuple(ls)] = 0
    #print([np.abs(i-A) for i in ls])
    Asublist = [np.abs(i-A) for i in ls]
    #Asublist = list(sorted([np.abs(i-A) for i in ls]))[0:2]
    Bsublist = list(sorted([np.abs(i-B) for i in ls]))[0:2]
    Csublist = list(sorted([np.abs(i-C) for i in ls]))[0:2]
    res = min(Asublist)
    idx = Asublist.index(res)
    ls.remove(ls[idx])

    Bsublist = [np.abs(i-B) for i in ls]
    tmp = min(Bsublist)
    res += tmp
    idx = Bsublist.index(tmp)
    ls.remove(ls[idx])

    Csublist = [np.abs(i-C) for i in ls]
    tmp = min(Csublist)
    res += tmp
    idx = Csublist.index(tmp)
    ls.remove(ls[idx])

    #dic[tuple(ls)] = res
    return res + 10*(N - (len(ls)+3))

def rec(ls, num, maxcomb, minval):
    if num == 1:
        minval = calc(copy.deepcopy(ls))
    count = 0
    for i in range(0, len(ls)-1):
        for j in range(i+1, len(ls)):
            tmp = [ls[i]+ls[j]]
            tmp = tmp + [ls[k] for k in range(len(ls)) if k!=i and k!=j]
            #print(tmp)
            if tuple(tmp) in dic.keys():
                continue
            tmp2 = calc(copy.deepcopy(tmp))
            #print([minval, tmp2])
            if minval > tmp2:
                minval = tmp2
            if num < maxcomb:
                #print([i,j,num])
                #print(tmp)
                tmp3 = rec(copy.deepcopy(tmp), num+1, maxcomb, minval)
                if minval > tmp3:
                    minval = tmp3
    return minval
minval = rec(l, 1, N-3, np.inf)
print(minval)


Fixed submission:
import numpy as np
import copy
N, A, B, C = map(int,input().split())
t = sorted([A,B,C])
A = t[0]
B = t[1]
C = t[2]
l = []
for i in range(N):
    l.append(int(input()))
dic = {}

def calc(ls):
    dic[tuple(ls)] = 0
    Asublist = [np.abs(i-A) for i in ls]
    res = min(Asublist)
    idx = Asublist.index(res)
    ls.remove(ls[idx])

    Bsublist = [np.abs(i-B) for i in ls]
    tmp = min(Bsublist)
    res += tmp
    idx = Bsublist.index(tmp)
    ls.remove(ls[idx])

    Csublist = [np.abs(i-C) for i in ls]
    tmp = min(Csublist)
    res += tmp
    idx = Csublist.index(tmp)
    ls.remove(ls[idx])

    return res + 10*(N - (len(ls)+3))

def rec(ls, num, maxcomb, minval):
    if num > maxcomb:
        return minval
    for i in range(0, len(ls)-1):
        for j in range(i+1, len(ls)):
            tmp = [ls[i]+ls[j]]
            tmp = tmp + [ls[k] for k in range(len(ls)) if k!=i and k!=j]
            if tuple(tmp) in dic.keys():
                continue
            tmp2 = calc(copy.deepcopy(tmp))
            if minval > tmp2:
                minval = tmp2
            if num < maxcomb:
                tmp3 = rec(copy.deepcopy(tmp), num+1, maxcomb, minval)
                if minval > tmp3:
                    minval = tmp3
    return minval
minval = rec(l, 1, N-3, calc(copy.deepcopy(l)))
print(minval)
Buggy python submission (verdict: Time Limit Exceeded):

if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    
    N, K = map(int,input().split())
    WD = [list(map(int,input().split())) for _ in range(N)]
    #W = [elem[0] for elem in WD]
    #D = [elem[1] for elem in WD]

    def solve(tgt):
        res = 0
        for w,d in WD:
            res += max(0, (tgt-w)//d+1)
        if res >= K:
            return True
        else:
            return False

    ok = 4*(10 ** 18)  # exist
    ng = 0  # not exist
    while abs(ok - ng) > 1:
        cnt = (ok + ng) // 2
        if solve(cnt):
            ok = cnt
        else:
            ng = cnt
    print(ok)
    

Fixed submission:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    
    N, K = map(int,input().split())
    WD = [tuple(map(int,input().split())) for _ in range(N)]

    def solve(tgt):
        res = 0
        for w,d in WD:
            res += max(0, (tgt-w)//d+1)
        if res >= K:
            return True
        else:
            return False

    ok = 2*(10 ** 18)  # exist
    ng = 0  # not exist
    while abs(ok - ng) > 1:
        cnt = (ok + ng) // 2
        if solve(cnt):
            ok = cnt
        else:
            ng = cnt
    print(ok)
Buggy python submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
e=abs(b-a)
if c+d+e==0:
    print("YES")
    exit()
upper=(e+(n-1)*d)//(c+d)
lower=(e+(n-1)*c)//(c+d)
if upper==lower:
    if (e+(n-1)*c) % (c+d) == 0 and 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
        print("YES")
        print(2//0)
    else:
        print("NO")
else:
    if 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
	    print("YES")
    else:
        print("NO")


Fixed submission:
n,a,b,c,d=map(int,input().split())
e=abs(b-a)
if c+d+e==0:
    print("YES")
    exit()
upper=(e+(n-1)*d)//(c+d)
lower=(e+(n-1)*c)//(c+d)
if upper==lower:
    if (e+(n-1)*c) % (c+d) == 0 and 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
        print("YES")
    else:
        print("NO")
else:
  if 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
	    print("YES")
  else:
        print("NO")

Buggy python submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
e=abs(b-a)
if c+d+e==0:
    print("YES")
    exit()
upper=(e+(n-1)*d)//(c+d)
lower=(e+(n-1)*c)//(c+d)
if upper==lower:
    if (e+(n-1)*c) % (c+d) == 0 and 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
        print("YES")
        print(2//0)
    else:
        print("NO")
else:
    print("YES")


Fixed submission:
n,a,b,c,d=map(int,input().split())
e=abs(b-a)
if c+d+e==0:
    print("YES")
    exit()
upper=(e+(n-1)*d)//(c+d)
lower=(e+(n-1)*c)//(c+d)
if upper==lower:
    if (e+(n-1)*c) % (c+d) == 0 and 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
        print("YES")
    else:
        print("NO")
else:
  if 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
	    print("YES")
  else:
        print("NO")
Buggy python 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)




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 python submission (verdict: Runtime Error):
x,y=map(int,input().split())
res = []
if x>0 and y>0:
    res.append(abs(y-x))
elif x*y<0:
    res.append(1+abs(y+x))
elif x<0 and y<0:
    res.append(2+abs(y-x))
print(min(res))


Fixed submission:
x,y=map(int,input().split())
res = 0
if 0<=x<=y:
    res = y-x
elif 0<y<x:
    res = x-y+2
elif y==0 and x>0:
    res = x+1
elif y==0 and x<0:
    res = abs(x)
elif x==0 and y>0:
    res = y
elif x==0 and y<0:
    res = abs(y)+1
elif x<0<y:
    res = abs(x+y)+1
elif y<0<x:
    res = abs(x+y)+1
elif x<=y<=0:
    res = y-x
elif y<x<=0:
    res = x-y+2
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict as dd
H,W,N=map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
tpl = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)]
edge_WtoB = dd(list)
edge_BtoB = dd(list)
node_B = set(ab)
node_W = set()
res = dd(int)
# 今見てるマスが黒
for a,b in ab:
    for s,t in tpl:
        tgt = (a+s,b+t)
        # 隣接マスも黒
        if tgt in node_B:
            if not (1 < a < H and 1 < b < W):
                continue
            edge_BtoB[(a,b)].append(tgt)
        # 隣接マスは白
        else:
            if not (1 < a + s < H and 1 < b + t < W):
                continue
            edge_WtoB[tgt].append((a,b))
            node_W.add(tgt)
for tgt in node_W:
    res[len(edge_WtoB[tgt])] += 1
for tgt in node_B:
    res[len(edge_BtoB[tgt])] += 1
zero = (H-2)*(W-2)
for j in range(1,10):
    zero -= res[j]
res[0] = zero
for j in range(10):
    print(res[j])

Fixed submission:
from collections import defaultdict as dd
H,W,N=map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
tpl = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)]
edge_WtoB = dd(int)
edge_BtoB = dd(int)
node_B = set(ab)
# node_W = set()
res = dd(int)
# 今見てるマスが黒
for a,b in ab:
    for s,t in tpl:
        tgt = (a+s,b+t)
        # 隣接マスも黒
        if tgt in node_B:
            if not (1 < a < H and 1 < b < W):
                continue
            edge_BtoB[(a,b)] += 1
        # 隣接マスは白
        else:
            if not (1 < a + s < H and 1 < b + t < W):
                continue
            edge_WtoB[tgt] += 1
            # node_W.add(tgt)
for val in edge_WtoB.values():
    res[val] += 1
for val in edge_BtoB.values():
    res[val] += 1
zero = (H-2)*(W-2)
for j in range(1,10):
    zero -= res[j]
res[0] = zero
for j in range(10):
    print(res[j])
Buggy python submission (verdict: Time Limit Exceeded):
class Segtree(object):
    import math
    def __init__(self, init_val, N, func_type):
        self.func = self.segfunc_min
        self.ide_ele = 10**9 # min
        if func_type == 'max':
            self.func = self.segfunc_max
            self.ide_ele = -10**9 # max
        elif func_type == 'gcd':
            self.func = self.segfunc_gcd
            self.ide_ele = 0 # gcd
        elif func_type == 'lcm':
            self.func = self.segfunc_lcm
            self.ide_ele = 1 # lcm
        elif func_type == 'add':
            self.func = self.segfunc_add
            self.ide_ele = 0 # add

        self.num = 2**(N-1).bit_length()
        self.seg = [self.ide_ele]*2*self.num
        self.init_val = init_val

        n = len(self.init_val)
        self.seg[self.num-1:n+self.num-1] = self.init_val[:n]
        #built
        for i in range(self.num-2,-1,-1) :
            self.seg[i] = self.func(self.seg[2*i+1], self.seg[2*i+2])

    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.func(self.seg[k*2+1], self.seg[k*2+2])

    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.func(res,self.seg[p])
            if q&1 == 1:
                res = self.func(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.func(res,self.seg[p])
        else:
            res = self.func(self.func(res,self.seg[p]),self.seg[q])
        return res

    def segfunc_min(self, a, b):
        if a > b:
            return b
        return a

    def segfunc_max(self, a, b):
        if a >= b:
            return a
        return b

    def segfunc_gcd(self, a, b):
        return math.gcd(a,b)

    def segfunc_lcm(self, a, b):
        return a*b//math.gcd(a,b)

    def segfunc_add(self, a, b):
        return a+b
N,x = map(int,input().split())
a = list(map(int,input().split()))
res = 10**18
seg = Segtree(a+a, 2*N, 'min')
# print(seg.seg)
for k in range(N-1,-1,-1):
    tmp = k*x
    tmp += sum([seg.query(N+i-k,N+i+1) for i in range(N)])
    res = min(res,tmp)
print(res)

Fixed submission:
N,x = map(int,input().split())
a = list(map(int,input().split()))
res = 10**18
d = [[0]*N for _ in range(N)]
for i in range(N):
    d[i][0] = a[i]
    for k in range(1,N):
        d[i][k] = min(d[i][k-1], a[i-k])

for k in range(N-1,-1,-1):
    tmp = k*x
    tmp += sum([d[i][k] for i in range(N)])
    res = min(res,tmp)
print(res)
Buggy python submission (verdict: Runtime Error):
import sys

a, v = map(int, inpu().split())
b, w = map(int, inpu().split())
t = int(input())
if (a == b):
  print('YES')
  sys.exit(0)
if (v <= w):
  print('NO')
  sys.exit(0)
res = abs(a - b) / (v - w)
if (res > t):
  print('NO')
else:
  print('YES')
sys.exit(0)
  

Fixed submission:
import sys

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if (a == b):
    print('YES')
    sys.exit(0)
if (v <= w):
    print('NO')
    sys.exit(0)
res = abs(a - b) / (v - w)
if (res > t):
    print('NO')
else:
    print('YES')
sys.exit(0)