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

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**9)
    from collections import deque
    mod = 10**9+7
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        x, y = map(int, input().split())
        G[x-1].append(y-1)
        G[y-1].append(x-1)
    que = deque([0])
    children = [[] for _ in range(N)]
    while que:
        v = que.pop()
        for nv in G[v]:
            if children[nv]:
                continue
            children[v].append(nv)
            que.append(nv)   
    memo = [[-1]*2 for _ in range(N)]
    def dp(i, c):
        if memo[i][c] >=0:
            return memo[i][c]
        if c == 1:
            res = 1
            for j in children[i]:
                res*=dp(j, 0)
                res%=mod
            memo[i][c] = res
        else:
            res = 1
            for j in children[i]:
                res*=(dp(j, 0)+dp(j, 1))
                res%=mod
            memo[i][c]= res
        return memo[i][c]
    print((dp(0, 0)+dp(0, 1))%mod)
main()

Buggy submission (verdict: Runtime Error):
def main():
    input = sys.stdin.readline
    import sys
    sys.setrecursionlimit(10**9)
    from collections import deque
    mod = 10**9+7
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        x, y = map(int, input().split())
        G[x-1].append(y-1)
        G[y-1].append(x-1)
    que = deque([0])
    children = [[] for _ in range(N)]
    while que:
        v = que.pop()
        for nv in G[v]:
            if children[nv]:
                continue
            children[v].append(nv)
            que.append(nv)   
    memo = [[-1]*2 for _ in range(N)]
    def dp(i, c):
        if memo[i][c] >=0:
            return memo[i][c]
        if c == 1:
            res = 1
            for j in children[i]:
                res*=dp(j, 0)
                res%=mod
            memo[i][c] = res
        else:
            res = 1
            for j in children[i]:
                res*=(dp(j, 0)+dp(j, 1))
                res%=mod
            memo[i][c]= res
        return memo[i][c]
    print((dp(0, 0)+dp(0, 1))%mod)
main()

Buggy submission (verdict: Runtime Error):
def main():
    from collections import deque
    mod = 10**9+7
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        x, y = map(int, input().split())
        G[x-1].append(y-1)
        G[y-1].append(x-1)
    que = deque([0])
    children = [[] for _ in range(N)]
    while que:
        v = que.pop()
        for nv in G[v]:
            if children[nv]:
                continue
            children[v].append(nv)
            que.append(nv)   
    memo = [[-1]*2 for _ in range(N)]
    def dp(i, c):
        if memo[i][c] >=0:
            return memo[i][c]
        if not children[i]:
            return 1
        if c == 1:
            memo[i][c] = sum(dp(j, 0) for j in children[i])%mod
        else:
            memo[i][c] = sum(dp(j, 0) for j in children[i])%mod+sum(dp(j, 1) for j in children[i])%mod
            memo[i][c]%=mod
        return memo[i][c]
    print(dp(0, 0)+dp(0, 1))
main()
Problem p03178 (python)

Fixed submission:
mod = 10**9+7
K = input()
n = len(K)
D = int(input())
dp = [[[0]*2 for i in range(D)] for _ in range(n)]
for i in range(int(K[0])):
    dp[0][i%D][0] += 1
dp[0][int(K[0])%D][1] += 1
for i in range(n-1):
    for j in range(D):
        for d in range(10):
            dp[i+1][(j+d)%D][0]+=dp[i][j][0]
            dp[i+1][(j+d)%D][0]%=mod
        for d in range(int(K[i+1])):
            dp[i+1][(j+d)%D][0]+=dp[i][j][1]
            dp[i+1][(j+d)%D][0]%=mod
        dp[i+1][(j+int(K[i+1]))%D][1] += dp[i][j][1]
        dp[i+1][(j+int(K[i+1]))%D][1]%=mod
print((dp[-1][0][0]+dp[-1][0][1]-1)%mod)

Buggy submission (verdict: Runtime Error):
K = input()
n = len(K)
D = int(input())
dp = [[[0]*2 for i in range(D)] for _ in range(n)]
for i in range(int(K[0])):
    dp[0][i%D][0] += 1
dp[0][int(K[0])%D][1] += 1
for i in range(n-1):
    for j in range(D):
        for d in range(10):
            dp[i+1][(j+d)%D][0]+=dp[i][j][0]
            dp[i+1][(j+d)%D][0]%=mod
        for d in range(int(K[i+1])):
            dp[i+1][(j+d)%D][0]+=dp[i][j][1]
            dp[i+1][(j+d)%D][0]%=mod
        dp[i+1][(j+int(K[i+1]))%D][1] += dp[i][j][1]
        dp[i+1][(j+int(K[i+1]))%D][1]%=mod


print(dp[-1][0][0]+dp[-1][0][1]-1)
Problem p03179 (python)

Fixed submission:
mod = 10**9+7
N = int(input())
s = input()
dp = [[0]*N for _ in range(N)]
for i in range(N):
    dp[0][i] = 1
for i in range(1, N):
    if s[i-1] == '>':
        dp[i][0] = dp[i-1][0]
        for j in range(1, N-i):
            dp[i][j] = (dp[i][j-1] + dp[i-1][j])%mod
    else:
        for j in range(N-1)[::-1]:
            dp[i][j] = (dp[i][j+1]+dp[i-1][j+1])%mod
print(sum(dp[-1])%mod)

Buggy submission (verdict: Runtime Error):
import numpy as np
mod = 10**9+7
N = int(input())
s = input()
dp = [[0]*N for _ in range(N)]
for i in range(N):
    dp[0][i] = 1
for i in range(1, N):
    if s[i-1] == '>':
        dp[i][0] = dp[i-1][0]
        for j in range(1, N-i):
            dp[i][j] = (dp[i][j-1] + dp[i-1][j])%mod
    else:
        for j in range(N-1)[::-1]:
            dp[i][j] = (dp[i][j+1]+dp[i-1][j+1])%mod
print(sum(dp[-1])%mod)
Problem p03183 (python)

Fixed submission:
from functools import cmp_to_key
def cmp(a, b):
    w1, s1, v1 = a
    w2, s2, v2 = b
    if min(s1, s2-w1)>min(s2, s1-w2):
        return 1
    else:
        return -1
N = int(input())
dp = [[0]*10001 for _ in range(N)]
wsv = []
for _ in range(N):
    w, s, v = map(int, input().split())
    wsv.append((w, s, v))
wsv.sort(key = lambda x:-(x[0]+x[1]))
w, s, v = wsv[0]
dp[0][s] = v
for i in range(N-1):
    w, s, v = wsv[i+1]
    for j in range(10001):
        if j>=w:
            dp[i+1][min(s, j-w)] = max(dp[i][j]+v, dp[i+1][min(s, j-w)])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    dp[i+1][s] = max(dp[i+1][s], v)
print(max(dp[-1]))

Buggy submission (verdict: Runtime Error):
from functools import cmp_to_key
def cmp(a, b):
    w1, s1, v1 = a
    w2, s2, v2 = b
    if min(s1, s2-w1)>min(s2, s1-w2):
        return 1
    else:
        return -1
N = int(input())
dp = [[0]*1001 for _ in range(N)]
wsv = []
for _ in range(N):
    w, s, v = map(int, input().split())
    wsv.append((w, s, v))
wsv.sort(key = cmp_to_key(cmp))
w, s, v = wsv[0]
dp[0][s] = v
for i in range(N-1):
    w, s, v = wsv[i+1]
    for j in range(1001):
        if j>=w:
            dp[i+1][min(s, j-w)] = max(dp[i][j]+v, dp[i+1][min(s, j-w)])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
print(max(dp[-1]))
Problem p03239 (python)

Fixed submission:
n,t = map(int, input().split())
ct = [list(map(int, input().split())) for i in range(n)]
ct=sorted(ct, key=lambda cti : cti[0])
for i in range(n):
    if ct[i][1]<=t:
        print(ct[i][0])
        exit()
print('TLE')

Buggy submission (verdict: Runtime Error):
a,b,k=map(int, input().split())
cnt=0
for i in range(min(a,b)+1,0,-1):
    if a%i==0 and b%i==0:
        cnt+=1
        if cnt==k:
            print(i)
Problem p03263 (python)

Fixed submission:
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
ans = []
for i in range(H-1):
    for j in range(W):
        if a[i][j] % 2 == 1:
            ans.append((i+1, j+1, i+2, j+1))
            a[i+1][j]+=1
for i in range(W-1):
    if a[H-1][i] % 2 == 1:
        ans.append((H, i+1, H, i+2))
        a[H-1][i+1] +=1
print(len(ans))
for a in ans:
    print(*a)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a=[list(map(int, input().split())) for i in range(h)]
l=[]
for i in range(h):
    for j in range(w):
        if a[i][j]%2==1:
            l.append((i,j))
def move(y1,x1, y2,x2):
    if y1<y2:
        for i in range(y1,y2):
            print(i+1, x1+1, i+2, x1+1)
    elif y1>y2:
        for i in range(y1,y2, -1):
            print(i+1, x1+1, i, x1+1)
    if x1<x2:
        for i in range(x1,x2):
            print(y2+1, i+1, y2+1, i+2)
    elif x1>x2:
        for i in range(x1,x2, -1):
            print(y2+1, i+1, y2+1, i)
ans=0
for i in range(0,len(l),2):
    ans+=abs(l[i][0]-l[i+1][0])+abs(l[i][1]-l[i+1][1])
print(ans)
for i in range(0,len(l),2):
    move(l[i][0],l[i][1],l[i+1][0],l[i+1][1])
Problem p03281 (python)

Fixed submission:
n = int(input())
yaku=[]
ans=0
for j in range(1, n+1)[::2]:
    yaku=[]
    for i in range(1, j+1):
        if j%i==0:
            yaku.append(i)
    if len(yaku)==8:
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
yaku=[]
ans=0
for j in range(1, n+1)[::2]:
    for i in range(1, i+1):
        if j%i==0:
            yaku.append(i)
    if len(yaku)==8:
        ans+=1
print(ans)
Problem p03287 (python)

Fixed submission:
def main():
    n, m = map(int, input().split())
    a=list(map(int, input().split()))
    s=[0]*(n+1)
    for i in range(1, n+1):
        s[i]=s[i-1]+a[i-1]
    dic={}
    for i in range(n+1):
        tmp=s[i]%m
        if tmp in dic.keys():
            dic[tmp]+=1
        else:
            dic[tmp]=1
    ans=0
    for i in dic.values():
        ans+=i*(i-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a=list(map(int, input().split()))
s=[0]*(n+1)
for i in range(1, n+1):
    s[i]=s[i-1]+a[i-1]
dic={}
for i in range(n+1):
    tmp=s[i]%m
    if tmp in dic.keys():
        dic[tmp]+=1
    else:
        dic[tmp]=1
ans=0
for i in dic.values():
    ans+=i*(i-1)//2
print(ans)
n, m = map(int, input().split())
a=list(map(int, input().split()))
s=[0]*(n+1)
for i in range(1, n+1):
    s[i]=s[i-1]+a[i-1]
dic={}
for i in range(n+1):
    tmp=s[i]%m
    if tmp in dic.keys():
        dic[tmp]+=1
    else:
        dic[tmp]=1
ans=0
for i in dic.values():
    ans+=i*(i-1)//2
print(ans)
Problem p03353 (python)

Fixed submission:
s=input()
k=int(input())
substrings=set()
for i in range(len(s)):
    for j in range(5):
        if i+j<len(s):
            substrings.add(s[i:i+j+1])
substrings=sorted(list(substrings))
print(substrings[k-1])

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
a=[]
for i in range(len(s)):
    for j in range(i+1, min(i+k, len(s)+1)):
        a.append(s[i:j])
b=list(set(a))
b.sort()
print(b[k-1])
Problem p03448 (python)

Fixed submission:
a=int(input())
b=int(input())
c=int(input())
x=int(input())
t=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i+100*j+50*k==x:
        t+=1
print(t)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
c=input()
x=input()
t=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i+100*j+50*k==x:
        t+=1
print(t)
Problem p03455 (python)

Fixed submission:
a,b=[int(i) for i in input().split()]
if a*b%2==1:
  print('Odd')
else:
  print('Even')

Buggy submission (verdict: Runtime Error):
def travel(x,y,t):
    for i in range(t):
        if x+y==t-2*i:
            return True
    return False
n=int(input())
for i in range(n):
    t, x, y = [int(j) for j in input().split() ]
    if not travel(x,y,t):
        print("No")
        exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
i=input()
j=input()
int(i)
int(j)
if i*j%2==1:
  print('Odd')
else:
  print('Even')
Problem p03493 (python)

Fixed submission:
a=input()
print(a.count('1'))

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
a=[int(i) for i in input().split()]
t=0
while True:
  for i in range(N):
    if a[i]%2==0:
      a[i]//=2
    else:
      print(t)
      sys.exit()
  t+=1

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
a=[int(i) for i in input().split()]
t=0
while True:
  for i in range(N):
    if a[i]%2==0:
      a[i]//=2
    else:
      print(t)
      sys.exit()
  t+=1

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
a=[int(i) for i in input().split()]
t=0
while True:
  for i in range(N):
    if a[i]%2==0:
      a[i]//=2
    else:
      print(t)
      sys.exit()
	t+=1

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
a=[int(i) for i in input().split()]
t=0
while True:
  for i in range(N):
    if a[i]%2==0:
      a[i]//=2
      t+=1
    else:
      print(t)
      sys.exit()

Buggy submission (verdict: Runtime Error):
a=input()
c=0
for i in range(2):
  if a>=10**(2-i):
    a-10**(2-i)
    c+=1
print(c)
Problem p03494 (python)

Fixed submission:
import sys
N=int(input())
a=[int(i) for i in input().split()]
t=0
while True:
  for i in range(N):
    if a[i]%2==0:
      a[i]//=2
    else:
      print(t)
      sys.exit()
  t+=1

Buggy submission (verdict: Runtime Error):
import sys
N=input()
a=[int(i) for i in input().split()]
t=0
while True:
  for i in range(N):
    if a[i]%2==0:
      a[i]//=2
      t+=1
    else:
      print(t)
      sys.exit()
Problem p03504 (python)

Fixed submission:
T_max = 10**5
N, C = map(int, input().split())
channel = [[] for _ in range(C)]
time = [0]*(T_max+2)
for i in range(N):
    s, t, c = map(int, input().split())
    channel[c-1].append((s, t))
for c in channel:
    c.sort()
    if len(c)==0:
        continue
    time[c[0][0]]+=1
    for i in range(1, len(c)):
        if c[i-1] [1] != c[i][0]:
            time[c[i-1][1]+1] -= 1
            time[c[i][0]]+=1
    time[c[-1][1]+1]-=1
for i in range(1, T_max+1):
    time[i] = time[i-1]+time[i]
print(max(time))

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
num = 10#**5+1
count = [0]*(num)
channel = [0]*num
for i in range(N):
    s, t, c = map(int, input().split())
    print(count)
    if channel[s]==c and channel[t-1]==c:
        count[s]+=1
        count[t-1]-=1
    elif channel[s]==c:#はじめ＝終わり
        count[s]+=1
        count[t]-=1
    elif channel[t-1]==c:
        count[t-1]-=1
        count[s-1]+=1
    else:
        count[s-1]+=1
        count[t]-=1
    channel[s-1]=c
    channel[t]=c
print(count)
for i in range(1, num):
    count[i]+=count[i-1]
print(max(count))

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
num = 10*5+1
count = [0]*(num)
for i in range(N):
    s, t, c = map(int, input().split())
    count[s-1]+=1
    count[t]-=1
for i in range(1, num):
    count[i]+=count[i-1]
print(max(count))
Problem p03545 (python)

Fixed submission:
a, b, c, d = map(int, list(input()))
if a+b+c+d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if a+b+c+d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
Problem p03575 (python)

Fixed submission:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]


    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])


    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
def C(x):
    U=UnionFind(n)
    for i in range(m):
        if i==x :
            continue
        U.unite(ab[i][0]-1, ab[i][1]-1)
    for i in range(n):
        for j in range(n):
            if not U.same(i, j):
                return False
    return True
ans=0
for y in range(m):
    if not C(y):
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]


    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])


    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
def C(x):
    U=UnionFind(n)
    for i in range(m):
        if i==x:
            continue
        U.unite(ab[i][0]-1, ab[i][1]-1)
    for i in range(n):
        for j in range(m):
            if not U.same(i, j):
                return False
    return True
ans=0
for x in range(m):
    if not C(x):
        ans+=1
print(ans)
Problem p03576 (python)

Fixed submission:
import bisect
def count_generate(h,w,a):
    count = [[0]*w for j in range(h)]
    count[0][0] = a[0][0]
    for i in range(1,w):
        count[0][i] = count[0][i-1]+a[0][i]
    for i in range(1,h):
        cnt_w = 0
        for j in range(w):
            cnt_w += a[i][j]
            count[i][j] = count[i-1][j]+cnt_w
    return count

def da_calc(p,q,x,y, da):
    if p > x or q > y:
        return 0
    if p == 0 and q == 0:
        return da[x][y]
    if p == 0:
        return da[x][y]-da[x][q-1]
    if q == 0:
        return da[x][y]-da[p-1][y]
    return da[x][y]-da[p-1][y]-da[x][q-1]+da[p-1][q-1]

N, K = map(int, input().split())
a = []
b = []
for i in range(N):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
    
a_sorted = sorted(set(a))
b_sorted = sorted(set(b))
h = len(a_sorted)
w = len(b_sorted)

Map = [[0]*w for _ in range(h)]

for i in range(N):
    ai = bisect.bisect_left(a_sorted, a[i])
    bi = bisect.bisect_left(b_sorted, b[i])
    Map[ai][bi]+=1

count = count_generate(h, w, Map)
ans = float('inf')
for i in range(h):
    for j in range(i+1, h):
        for k in range(w):
            for l in range(k+1, w):
                #print(i, j, k, l, da_calc(i, k, j, l, count))
                if da_calc(i, k, j, l, count)>=K:
                    #print(i, j, k, l)
                    ans = min(ans, (a_sorted[j]-a_sorted[i])
                              *(b_sorted[l]-b_sorted[k]))
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
def count_generate(h,w,a):
    count = [[0]*w for j in range(h)]
    count[0][0] = a[0][0]
    for i in range(1,w):
        count[0][i] = count[0][i-1]+a[0][i]
    for i in range(1,h):
        cnt_w = 0
        for j in range(w):
            cnt_w += a[i][j]
            count[i][j] = count[i-1][j]+cnt_w
    return count

def da_calc(p,q,x,y, da):
    if p > x or q > y:
        return 0
    if p == 0 and q == 0:
        return da[x][y]
    if p == 0:
        return da[x][y]-da[x][q-1]
    if q == 0:
        return da[x][y]-da[p-1][y]
    return da[x][y]-da[p-1][y]-da[x][q-1]+da[p-1][q-1]

N, K = map(int, input().split())
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
    
a_sorted = sorted(set(a))
b_sorted = sorted(set(b))
h = len(a_sorted)
w = len(b_sorted)

Map = [[0]*w for _ in range(h)]

for i in range(N):
    ai = bisect.bisect_left(a_sorted, a[i])
    bi = bisect.bisect_left(b_sorted, b[i])
    Map[ai][bi]+=1

count = count_generate(h, w, Map)
ans = float('inf')
for i in range(h):
    for j in range(i+1, h):
        for k in range(w):
            for l in range(k+1, w):
                #print(i, j, k, l, da_calc(i, k, j, l, count))
                if da_calc(i, k, j, l, count)>=K:
                    #print(i, j, k, l)
                    ans = min(ans, (a_sorted[j]-a_sorted[i])
                              *(b_sorted[l]-b_sorted[k]))
print(ans)
Problem p03579 (python)

Fixed submission:
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
def is_bipartite(G):
    n = len(G)
    color = [-1]*n
    que = deque([0])
    color[0] = 0
    while que:
        v = que.pop()
        c = color[v]
        for nv in G[v]:
            if color[nv]<0:
                color[nv] = 1-c
                que.append(nv)
            elif color[nv] == c:
                return False
    return color
color = is_bipartite(G)
if color:
    a = color.count(0)
    b = N-a
    print(a*b-M)
else:
    print(N*(N-1)//2-M)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
def is_bipartite(G):
    n = len(G)
    color = [-1]*n
    que = deque([0])
    color[0] = 0
    while que:
        v = que.pop()
        c = color[v]
        for nv in G[v]:
            if color[nv]<0:
                color[nv] = 1-c
                que.append(nv)
            elif color[nv] == c:
                return False
    return color
color = is_bipartite(G)
if color:
    a = color.count(0)
    b = N-a
    print(a*b-M)
else:
    print(N*(N-1)//2-M)
Problem p03600 (python)

Fixed submission:
import sys
inf = float('inf')
N = int(input())
d = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
    d[i][i] = 0
ans=0
for a in range(N):
    for b in range(N):
        flag = True
        for i in range(N):
            if i == a or i == b:
                continue
            if d[a][i]+d[i][b]<d[a][b]:
                print(-1)
                sys.exit()
            if d[a][i]+d[i][b]==d[a][b]:
                flag = False
                break
        if flag:
            ans+=d[a][b]
            
print(ans//2)

Buggy submission (verdict: Runtime Error):
import sys
inf = float('inf')
N = int(input())
d = [list(map(int, input().split())) for _ in range(N)]
edges = []
for i in range(N):
    for j in range(i+1, N):
        edges.append((A[i][j], i, j))
edges.sort()
for i in range(N):
    d[i][i] = 0
ans=0
for a in range(N):
    for b in range(N):
        flag = True
        for i in range(N):
            if i == a or i == b:
                continue
            if d[a][i]+d[i][b]<d[a][b]:
                print(-1)
                sys.exit()
            if d[a][i]+d[i][b]==d[a][b]:
                flag = False
                break
        if flag:
            ans+=d[a][b]
            
print(ans//2)