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

Fixed submission:
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
p_flg = [[0]*W for _ in range(H)]
dyx = [(-1,0),(1,0),(0,-1),(0,1)]

def bfn(y,x,cnt):
    stack = [(y,x,cnt)]
    p_flg[y][x] = cnt
    while stack:
        sy, sx, cnt= stack.pop(0)
        cnt += 1
        for dy, dx in dyx:
            ny, nx = sy+dy, sx+dx
            if ny == H-1 and nx == W-1:
                return cnt
            elif 0<=ny<H and 0<=nx<W:
                if maze[ny][nx] !="#" and not p_flg[ny][nx]:
                    p_flg[ny][nx] = cnt
                    stack.append((ny,nx,cnt))
    return 0

def main():
    n_obs = 0
    for h in range(H):
        for w in range(W):
            if maze[h][w] == "#":
                n_obs += 1
    n_path = bfn(0,0,1) -1
    if n_path == -1:
        print(-1)
        return
    else:
        ans = H*W - n_obs - n_path -1
        print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
p_flg = [[0]*W for _ in range(H)]
dyx = [(-1,0),(1,0),(0,-1),(0,1)]

def bfn(y,x,cnt):
    stack = [(y,x,cnt)]
    p_flg[y][x] = cnt
    while stack:
        sy, sx, cnt= stack.pop(0)
        cnt += 1
        for dy, dx in dyx:
            ny, nx = sy+dy, sx+dx
            if ny == H-1 and nx == W-1:
                return cnt
            elif 0<=ny<H and 0<=nx<W:
                if maze[ny][nx] !="#" and not p_flg[ny][nx]:
                    p_flg[ny][nx] = cnt
                    stack.append((ny,nx,cnt))

def main():
    n_obs = 0
    for h in range(H):
        for w in range(W):
            if maze[h][w] == "#":
                n_obs += 1
    n_path = bfn(0,0,1) -1
    ans = H*W - n_obs - n_path -1
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
p_flg = [[0]*W for _ in range(H)]
dyx = [(-1,0),(1,0),(0,-1),(0,1)]

def bfn(y,x,cnt):
    stack = [(y,x,cnt)]
    p_flg[y][x] = cnt
    while stack:
        sy, sx, cnt= stack.pop(0)
        cnt += 1
        for dy, dx in dyx:
            ny, nx = sy+dy, sx+dx
            if ny == H-1 and nx == W-1:
                return cnt
            if 0<=ny<H and 0<=nx<W:
                if maze[ny][nx] !="#" and not p_flg[ny][nx]:
                    p_flg[ny][nx] = cnt
                    stack.append((ny,nx,cnt))

def main():
    n_obs = 0
    for h in range(H):
        for w in range(W):
            if maze[h][w] == "#":
                n_obs += 1
    n_path = bfn(0,0,1) -1
    ans = H*W - n_obs - n_path -1
    print(ans)

if __name__ == "__main__":
    main()
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a, b = input().split()
c = int(a+b)
d = math.sqrt(c)
if d%1 == 0:
  print("Yes"):
  else:
    print("No"):

Buggy submission (verdict: Runtime Error):
a, b = map(int, input.split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")
Problem p03456 (python)

Fixed submission:
import math
a, b = input().split()
c = a+b
c = int(c)
d = math.sqrt(c)
if d%1 == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a, b = input().split()
c = int(a+b)
d = math.sqrt(c)
if d%1 == 0:
  print("Yes")
else:
  print("No")
Problem p03493 (python)

Fixed submission:
a = input()
a=a.replace("0","" )
print(len(a))

Buggy submission (verdict: Runtime Error):
n = input()
a = list(map(int, input().split()))
# n = 3
# a = [10, 11, 12]
ans =0
product =1
for i in a:
    product = product *i
while product%2 ==0:
        product = product/2
        ans = ans + 1
print(ans)
Problem p03854 (python)

Fixed submission:
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
    print("NO")
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
s = input()
wordList =[ "eraser", "erase","dreamer", "dream"]
ansList = []
def ansFunc(s1, ansList):
    #ansCount = 0
    for w in wordList:
        #print(s1, w)
        if s1.startswith(w):
            s2 = s1.replace(w, "",1)
            if s2 == '':
                print("YES")
                ansList.append(1)
            else:
                ansFunc(s2, ansList)
ansFunc(s, ansList)
if len(ansList) ==0:
    print("NO")

Buggy submission (verdict: Runtime Error):
s = input()
wordList =[ "eraser", "erase","dreamer", "dream"]
ansList = []
def ansFunc(s1, ansList):
    #ansCount = 0
    for w in wordList:
        #print(s1, w)
        if s1.startswith(w):
            s2 = s1.replace(w, "",1)
            if s2 == '':
                print("YES")
                ansList.append(1)
            else:
                ansFunc(s2, ansList)
ansFunc(s, ansList)
if len(ansList) ==0:
    print("NO")

Buggy submission (verdict: Runtime Error):
s = input()
wordList = ['dream', 'dreamer', 'erase', 'eraser']
ansCount = 0
def ansFunc(s1, ansCount):
    for w in wordList:
        #print(s1, w)
        if s1.startswith(w):
            s2 = s1.replace(w, "")
            if s2 == '':
                print("YES")
                ansCount += 1
                return ansCount
            else:
                ansCount = ansFunc(s2, ansCount)
ansCount=ansFunc(s, ansCount)
#print("NO")

Buggy submission (verdict: Runtime Error):
s = input()
wordList = ['dream', 'dreamer', 'erase', 'eraser']
ansCount = 0
def ansFunc(s1):
    for w in wordList:
        if s1.startswith(w):
            s1 = s1.replace(w, "")
            print(s1)
            if s1 == '':
                print("seikou")
                ansCount += 1
            else:
                ansFunc(s1)
ansFlg = ansFunc(s)
if ansFlg != 0:
    print("YES")
else:
    print("NO")
Problem p02999 (python)

Fixed submission:
a,b = (int(x) for x in input().split())
if a < b:
  print(0)
else: print(10)

Buggy submission (verdict: Runtime Error):
n,x = (int(x) for x in input().split())
l=list(map(int,input().split()))
k=0
d=0

while d<=x:
   if len(l)<=k:
    break
   else:
    d=d+l[k]
    k=k+1
if d<x:
  print(k+1)
else:print(k)
Problem p03000 (python)

Fixed submission:
n,x = (int(x) for x in input().split())
l=list(map(int,input().split()))
k=0
d=0

while d<=x:
   if len(l)<=k:
    break
   else:
    d=d+l[k]
    k=k+1
if d<=x:
  print(k+1)
else:print(k)

Buggy submission (verdict: Runtime Error):
n,x = (int(x) for x in input().split())
l=list(map(int,input().split()))
k=0
d=0

while d<=x:
  d=d+l[k]
  k=k+1

if n+1<k:
  print(n+1)
else:print(k)
Problem p02677 (python)

Fixed submission:
import math


def main():
    a, b, h, m = map(int, input().split())
    th = (h * 60 + m) / 720 * 2 * math.pi
    tm = m / 60 * 2 * math.pi
    xh = a * math.cos(th)
    yh = a * math.sin(th)
    xm = b * math.cos(tm)
    ym = b * math.sin(tm)
    dx = xh - xm
    dy = yh - ym
    ans = math.sqrt(dx ** 2 + dy ** 2)
    print("%.10f" % ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math


def main():
    a, b, h, m = map(int, input().split())
    if h == 0 and m == 0:
        print(abs(b - a))
        exit()

    h_basho = h * 60 + m
    m_basho = m * 12
    h_m_basho = h_basho - m_basho

    if h_m_basho == 360:
        print(a + b)
        exit()
    elif h_m_basho < 360:
        kakudo = 90 * h_m_basho / 180
    else:
        kakudo = 90 * (720 - h_m_basho) / 180

    ab2 = a ** 2 + b ** 2
    cos = 2 * a * b * (round(math.cos(round(math.radians(kakudo)), 20), 20))

    if kakudo <= 90:
        ac = ab2 - cos
        print("%.20f" % math.sqrt(ac))
    else:
        ac = ab2 + cos
        print("%.20f" % math.sqrt(ac))


if __name__ == '__main__':
    main()
Problem p03244 (python)

Fixed submission:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    # a = [v[i] for i in range(n) if i % 2 == 0]
    # b = [v[i] for i in range(n) if i % 2 == 1]

    # a_count = Counter.most_common(Counter(a))
    # b_count = Counter.most_common(Counter(b))

    # half_n = n // 2
    ac = Counter(v[::2]).most_common(2)
    bc = Counter(v[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        print(n - ac[0][1] - bc[0][1])
    else:
        if len(bc) == 1 or len(ac) == 1:
            print(n // 2)
        else:
            print(n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1]))

    # ans = 0

    # half_n = n // 2
    # eq = a_count[0][0] == b_count[0][0]
    # h_ac0 = half_n - a_count[0][1]
    # h_bc0 = half_n - b_count[0][1]

    # if len(a_count) == 1 and len(b_count) == 1:
    #     if eq:
    #         print(half_n)
    #         exit()
    #     else:
    #         print(ans)
    #         exit()

    # if a_count[0][1] > b_count[0][1]:
    #     ans += h_ac0
    #     if eq:
    #         ans += half_n - b_count[1][1]
    #     else:
    #         ans += h_bc0
    # elif a_count[0][1] < b_count[0][1]:
    #     ans += h_bc0
    #     if eq:
    #         ans += half_n - a_count[1][1]
    #     else:
    #         ans += h_ac0
    # else:
    #     if eq:
    #         ans += h_ac0
    #         ans += half_n - b_count[1][1]
    #     else:
    #         ans += h_ac0
    #         ans += h_bc0
    # print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    a = [v[i] for i in range(n) if i % 2 == 0]
    b = [v[i] for i in range(n) if i % 2 == 1]
    half_n = n // 2
    a_count = Counter.most_common(Counter(a))
    b_count = Counter.most_common(Counter(b))
    ans = 0
    if a_count[0][1] > b_count[0][1]:
        ans += half_n - a_count[0][1]
        if a_count[0][0] == b_count[0][0]:
            ans += half_n - b_count[1][1]
        else:
            ans += half_n - b_count[0][1]
    elif a_count[0][1] < b_count[0][1]:
        ans += half_n - b_count[0][1]
        if a_count[0][0] == b_count[0][0]:
            ans += half_n - a_count[1][1]
        else:
            ans += half_n - a_count[0][1]
    else:
        if a_count[0][0] == b_count[0][0]:
            ans += half_n - a_count[0][1]
            ans += half_n - b_count[1][1]
        else:
            ans += half_n - a_count[0][1]
            ans += half_n - b_count[0][1]
    print(ans)


if __name__ == '__main__':
    main()
Problem p02727 (python)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
p = p[-X:]
q = q[-Y:]
r.extend(p)
r.extend(q)
r.sort()
print(sum(r[-(X + Y):]))

Buggy submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split())) + [-1]
q = list(map(int, input().split())) + [-1]
r = list(map(int, input().split())) + [-1]
p.sort()
q.sort()
r.sort()

summ = 0
Z = 0
while X + Y - Z:
    if r[-1] * (C - Z > 0) < p[-1] * (X > 0) > q[-1] * (Y > 0):
        summ += p.pop()
        X -= 1
    elif p[-1] * (X > 0) < q[-1] * (Y > 0) > r[-1] * (C - Z > 0):
        summ += q.pop()
        Y -= 1
    else:
        summ += r.pop()
        Z += 1

print(summ)
Problem p02899 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
s = sorted([i for i in range(N)], key=lambda i: A[i])
s = [i + 1 for i in s]
print(*s)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
s = sorted([*range(N)], key=lambda i: A[i])
s = [i + 1 for i in s]
print(*s)
Problem p02921 (python)

Fixed submission:
s,t=open(0).read().split();print(sum([j==i for i,j in zip(s,t)]))

Buggy submission (verdict: Runtime Error):
s,t=map(int,open(0).read().split());print(sum([j==i for i in s for j in t]))
Problem p03030 (python)

Fixed submission:
_,*l=open(0).read().split()
[print(i + 1)for i in sorted(range(len(l)//2),key=lambda i:(l[i*2],-int(l[i*2+1])))]

Buggy submission (verdict: Runtime Error):
_,*l=open(0).read().split()
[print(i + 1)for i in sorted([*range(len(l)//2)],key=lambda i:(l[i*2],-int(l[i*2+1])))]
Problem p03559 (python)

Fixed submission:
import bisect


I = lambda: map(int, input().split())
N = int(input())
A = list(I())
B = list(I())
C = list(I())
B.sort()
C.sort()

s = [0] * (N + 1)
for i, bi in enumerate(B):
    s[i + 1] = s[i] + N - bisect.bisect_right(C, bi)

print(sum(s[N] - s[bisect.bisect_right(B, ai)] for ai in A))

Buggy submission (verdict: Runtime Error):

import bisect


I = lambda: list(map(int, input().split()))
N = I()
A = I()
B = I()
C = I()
A.sort()
B.sort()
C.sort()

summ = 0
for ai in A:
    r = bisect.bisect_right(B, ai)
    for bi in B[r:]:
        rr = bisect.bisect_right(C, bi)
        summ += (N - r) * (N - rr)

print(summ)
Problem p02782 (python)

Fixed submission:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1, c1, r2, c2 = map(int, input().split())

def g(r, c):
  return cmb(r+c+2,c+1,mod)-1

ans = g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1)
print(ans%mod)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1,c1,r2,c2 = map(int, input().split())
ans = cmb(r2+c2+2,c2+1,mod)-cmb(r2+c1+1,c1,mod)-cmb(r1+c2+1,c2+1,mod)+cmb(r1+c1,c1,mod)
print(ans)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1,c1,r2,c2 = map(int, input().split())
ans = cmb(r2+c2+2,c2+1,mod)-cmb(r2+c1+1,c1,mod)-cmb(r1+c2+1,c2+1,mod)+cmb(r1+c1,c1,mod)
print(ans)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1, c1, r2, c2 = map(int, input().split())

def g(r, c):
  return cmb(r+c+2,c+1,mod)-1

ans = g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1)
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1, c1, r2, c2 = map(int, input().split())

def g(r, c):
  return cmb(r+c+2,c+1,mod)-1

ans = g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1)
print(ans)
Problem p02804 (python)

Fixed submission:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, K = map(int, input().split())
a = [int(c) for c in input().split()]
a.sort()
M = 0
m = 0
for i in range(N-1, 0, -1):
  M += cmb(i,K-1, mod)*a[i]
  M %= mod
for i in range(N-1):
  m += cmb(N-1-i, K-1, mod)*a[i]
  m %= mod
print((M-m)%mod)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, K = map(int, input().split())
a = [int(c) for c in input().split()]
a.sort()
M = 0
m = 0
for i in range(N-1, 0, -1):
  M += cmb(i,K-1, mod)*a[i]
  M %= mod
for i in range(N-1):
  m += cmb(N-1-i, K-1, mod)*a[i]
  m %= mod
print((M-m)%mod)
Problem p02814 (python)

Fixed submission:
from fractions import gcd
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

N, M = map(int, input().split())
a = [int(c) for c in input().split()]
b = [c//2 for c in a]
g = reduce(lcm_base, b, 1)
G = reduce(lcm_base, a, 1)
if M<g:
  print(0)
  import sys
  sys.exit()
m = a[0]&-a[0]
for i in range(N):
  if m != a[i]&(-a[i]):
    print(0)
    break
else:
  n = (M-g)//G
  print(n+1)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
N, M = map(int, input().split())
a = [int(c) for c in input().split()]
G = a[0]*a[1]//gcd(a[0], a[1])
g = (a[0]//2)*(a[1]//2)//gcd(a[0]//2, a[1]//2)
for i in range(2,N):
  G = G*a[i]//gcd(G, a[i])
  g = g*(a[i]//2)//gcd(g, a[i]//2)
if M<g:
  print(0)
elif g%2==0:
  print(0)
else:
  n = (M-g)//G
  print(n+1)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
N, M = map(int, input().split())
a = [int(c) for c in input().split()]
b = [c//2 for c in a]
g = b[0]*b[1]//gcd(b[0], b[1])
for i in range(2,N):
  g = g*b[i]//gcd(g, b[i])

G = a[0]*a[1]//gcd(a[0], a[1])
for i in range(2,N):
  G = G*a[i]//gcd(G, a[i])

if M<g:
  print(0)
else:
  n = (M-g)//G
  print(n+1)
Problem p02821 (python)

Fixed submission:
N, M = map(int, input().split())
A = [int(c) for c in input().split()]
A.sort(reverse=True)
B = A[::-1]
l = 0
r = 10**6
def f(m):
  cnt = 0
  j = 0
  for i in range(N):
    while j<N:
      if A[i]+B[j]>=m:
        cnt += N-j
        break
      j += 1
  return cnt>=M
while l+1<r:
  n = (l+r)//2
  if f(n):
    l = n
  else:
    r = n
C = [0]
for i in range(N):
  C += [C[-1]+B[i]]
ans = 0
j = 0
m = 0
flag = False
for i in range(N):
  while j<N:
    if A[i]+B[j]>l:
      ans += C[-1]-C[j]+A[i]*(N-j)
      m += N-j
      break
    j += 1
ans += (M-m)*l
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,M,*A = map(int, open('0').read().split())
A = np.sort(A)
B = np.cumsum(np.concatenate([[0],A[::-1]]))
l = -1
r = 10**6
while l+1<r:
  s = (l+r)//2
  cnt = np.sum(N-np.searchsorted(A,s-A))
  if cnt>=M:
    l = s
  else:
    r = s
ind = np.searchsorted(A,r-A)
M -= np.sum(N-ind)
ans = np.sum(B[N-ind]+A*(N-ind))+M*l
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
from itertools import accumulate
N,M,*A = map(int, open('0').read().split())
A.sort()
B = list(accumulate(A[::-1]))
l = -1
r = 10**9
while l+1<r:
  s = (l+r)//2
  cnt = 0
  for c in A:
    i = bisect_left(A,s-c)
    cnt += N-i
  if cnt>=M:
    l = s
  else:
    r = s
ans = 0
for c in A:
  i = bisect_left(A,r-c)
  M -= N-i
  if i<N:
    ans += B[N-1-i]+c*(N-i)
ans += M*l
print(ans)
Problem p02839 (python)

Fixed submission:
import numpy as np
H,W = map(int,input().split())
A = [[0]*W for i in range(H)]
B = [[0]*W for i in range(H)]
for i in range(H):
  inf = [int(c) for c in input().split()]
  for j in range(W):
    A[i][j] = inf[j]
    
for i in range(H):
  inf = [int(c) for c in input().split()]
  for j in range(W):
    B[i][j] = inf[j]

X = (H + W) * 80
L = X + X + 1
# X点持った状態から始める
dp = [[0] * W for _ in range(H)]
d = abs(A[0][0] - B[0][0])
dp[0][0] = np.zeros(L,np.bool)
dp[0][0][X+d] = 1
for h in range(H):
    for w,(a,b) in enumerate(zip(A[h],B[h])):
        if h == w == 0:
            continue
        d = abs(a - b)
        x = np.zeros(L,np.bool)
        if h != 0:
            x[d:] |= dp[h-1][w][:L-d]
            x[:L-d] |= dp[h-1][w][d:]
        if w != 0:
            x[d:] |= dp[h][w-1][:L-d]
            x[:L-d] |= dp[h][w-1][d:]
        dp[h][w] = x

dp2 = dp[-1][-1]
can_make = np.where(dp2)[0] - X

answer = np.abs(can_make).min()
print(answer)

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W = map(int,input().split())
A = [[0]*W for i in range(H)]
B = [[0]*W for i in range(W)]
for i in range(H):
  inf = [int(c) for c in input().split()]
  for j in range(W):
    A[i][j] = inf[j]
    
for i in range(H):
  inf = [int(c) for c in input().split()]
  for j in range(W):
    B[i][j] = inf[j]

X = (H + W) * 80
L = X + X + 1
# X点持った状態から始める
dp = [[0] * W for _ in range(H)]
d = abs(A[0][0] - B[0][0])
dp[0][0] = np.zeros(L,np.bool)
dp[0][0][X+d] = 1
for h in range(H):
    for w,(a,b) in enumerate(zip(A[h],B[h])):
        if h == w == 0:
            continue
        d = abs(a - b)
        x = np.zeros(L,np.bool)
        if h != 0:
            x[d:] |= dp[h-1][w][:L-d]
            x[:L-d] |= dp[h-1][w][d:]
        if w != 0:
            x[d:] |= dp[h][w-1][:L-d]
            x[:L-d] |= dp[h][w-1][d:]
        dp[h][w] = x

dp2 = dp[-1][-1]
can_make = np.where(dp2)[0] - X

answer = np.abs(can_make).min()
print(answer)
Problem p02882 (python)

Fixed submission:
from math import atan, degrees
a, b, x = map(int, input().split())
if x<=a*a*b//2:
  tan = (2*x)/(a*b*b)
  print(90-degrees(atan(tan)))
else:
  m = a*b*a-x
  if m==0:
    print(0)
  else:
    tan = a*a*a/(2*m)
    print(90-degrees(atan(tan)))

Buggy submission (verdict: Runtime Error):
from math import atan, degrees
a, b, x = map(int, input().split())
if x<=a*a*b//2:
  tan = (2*x)/(a*b*b)
  print(90-degrees(atan(tan)))
else:
  m = a*b*a-x
  tan = a*a*a/(2*m)
  print(90-degrees(atan(tan)))
Problem p02900 (python)

Fixed submission:
from collections import defaultdict
A, B = map(int, input().split())
ls = defaultdict(int)
ans = 0
for i in range(1, max(int(A**0.5)+1, int(B**0.5)+1)):
  if A%i==0 and B%i==0:
    if ls[i]==0:
      ls[i]=1
      for n in range(2,int(i**0.5)+1):
        if i%n==0:
          break
      else:
        ans += 1
  if A%i==0:
    j = A//i
    if B%j!=0:
      continue
  elif B%i==0:
    j = B//i
    if A%j!=0:
      continue
  else:
    continue
  if ls[j]==0:
    ls[j] = 1
  else:
    continue
  for n in range(2,int(j**0.5)+1):
    if j%n==0:
      break
  else:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
ls = [0]*(max(int(A**0.5)+1, int(B**0.5)+1)+1)
ans = 0
for i in range(1, max(int(A**0.5)+1, int(B**0.5)+1)):
  if A%i==0 and B%i==0:
    if ls[i]==0:
      ls[i]=1
    else:
      continue
    for n in range(2,int(i**0.5)+1):
      if i%n==0:
        break
    else:
      ans += 1
    j = A//i
    if B%j!=0:
      continue
    if ls[j]==0:
      ls[j] = 1
    else:
      continue
    for n in range(2,int(j**0.5)+1):
      if j%n==0:
        break
    else:
      ans += 1
print(ans)