Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,M,X,Y = inpl()
X = max(inpl(),X)
Y = min(inpl(),Y)
if X < Y:
    print("No War")
else:
    print("War")


Fixed submission:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,M,X,Y = inpl()
X = max(max(inpl()),X)
Y = min(min(inpl()),Y)
if X < Y:
    print("No War")
else:
    print("War")

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,M,X,Y = inpl()
X = max(inpl(),X)
Y = mrin(inpl(),Y)
if X < Y:
    print("No War")
else:
    print("War")


Fixed submission:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,M,X,Y = inpl()
X = max(max(inpl()),X)
Y = min(min(inpl()),Y)
if X < Y:
    print("No War")
else:
    print("War")
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 998244353
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

K,N = inpl()

MAX = 20000
fac = [1]*(MAX+1)
for i in range(1,MAX+1):
	fac[i] = (fac[i-1]*i)%mod

gyakugen = [1]*(MAX+1)
gyakugen[MAX] = pow(fac[MAX],mod-2,mod)
for i in range(MAX,0,-1):
	gyakugen[i-1] = (gyakugen[i]*i)%mod

def Comb(n,k):#nCk
	return (fac[n]*gyakugen[k]*gyakugen[n-k])%mod

#K=k,N=n,0pair = 0
def calc(k,n,i):
	x = (i-2)//2
	k -= x
	n -= x
	if k == 1:
		if n <= 1:
			return n
		else:
			return 0
	elif k < 1:
		return 0
	tmp = 0
	for j in range(2):
		zb = n-j
		zm = k-2
		tmp += Comb(zb+zm,min(zb,zm))%mod
	tmp %= mod
	tmp *= pow(2,x,mod)
	return tmp

ans = []
for i in range(2,K+2):
	if i%2 == 0:
		pairs = (i-2)//2
		tmp = 0
		for p0 in range(pairs+1):
			tmp += calc(K-p0*2,N,i-p0*2)*Comb(pairs,p0)%mod
			tmp %= mod
	ans.append(tmp)
	print(tmp)

ans = ans[::-1]

for i in range(1,K):
	print(ans[i])


Fixed submission:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,K = inpl()

if K%2 == 1:
	print((N//K)**3)
else:
	ans = (N//K)**3
	tmp = N//K
	if N%K >= K//2:
		tmp += 1
	ans += tmp**3
	print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()

def calc(x):
	aa_dush = [-1]*N
	for i in range(N):
		if aa[i] >= x:
			aa_dush[i] = 1
	#aa_dush = [1, 1, 1, 1, 1, 1, -1, 1, -1, -1]

	S = [0] #S_0 = 0を忘れずにつける
	tmp = 0
	MIN = MAX = 0
	for i in range(N):
		tmp += aa_dush[i]
		MIN = min(tmp,MIN)
		MAX = max(tmp,MAX)
		S.append(tmp)
	#S = [0, 1, 2, 3, 4, 5, 6, 5, 6, 5, 4]
	#MIN = 0 , MAX = 6

	L = (MAX-MIN+1) #BITのサイズ L=6
	bit = [0]*(L+1) #1indexで扱うのでL+1の長さで取る
	ans = 0
	for S_i in S:
		S_i -= (MIN-1) #S_iの最小値が1となるように調整

		#BITで既出の要素のうちS_i以下の要素数をカウント
		tmp = 0
		x = S_i
		while x > 0:
			tmp += bit[x]
			x -= x & -x
		ans += tmp

		#BITのS_iに1を加算して更新
		x = S_i
		while x <= L:
			bit[x] += 1
			x += x & -x

	return ans #中央値がx以上となる(l,r)の組の数

border = ( (N+1)*N//2 +1 )//2
OK = 0
NG = 10**9+3

while NG - OK > 1:
	mid = (OK+NG)//2
	if calc(mid) >= border:
		OK = mid
	else:
		NG = mid

print(OK)


Fixed submission:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()

def calc(x):
	aa_dush = [-1]*N
	for i in range(N):
		if aa[i] >= x:
			aa_dush[i] = 1
	#aa_dush = [1, 1, 1, 1, 1, 1, -1, 1, -1, -1]

	S = [0] #S_0 = 0を忘れずにつける
	tmp = 0
	MIN = MAX = 0
	for i in range(N):
		tmp += aa_dush[i]
		MIN = min(tmp,MIN)
		MAX = max(tmp,MAX)
		S.append(tmp)
	#S = [0, 1, 2, 3, 4, 5, 6, 5, 6, 5, 4]
	#MIN = 0 , MAX = 6

	L = (MAX-MIN+1) #BITのサイズ L=6
	bit = [0]*(L+1) #1indexで扱うのでL+1の長さで取る
	ans = 0
	for S_i in S:
		S_i -= (MIN-1) #S_iの最小値が1となるように調整

		#BITで既出の要素のうちS_i以下の要素数をカウント
		tmp = 0
		x = S_i
		while x > 0:
			tmp += bit[x]
			x -= x & -x
		ans += tmp

		#BITのS_iに1を加算して更新
		x = S_i
		while x <= L:
			bit[x] += 1
			x += x & -x

	return ans #中央値がx以上となる(l,r)の組の数

border = ( (N+1)*N//2 +1 )//2
OK = 0
NG = 10**9+3

while NG - OK > 1:
	mid = (OK+NG)//2
	if calc(mid) >= border:
		OK = mid
	else:
		NG = mid

print(OK)
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(sum(map(int,input.split()))-N)

Fixed submission:
#a = int(input())
#b,c = map(int,input().split())
#s = input()
#list_s = list(input())
#list_int = list(map(int,input().split()))

#list = [0 for i in range(n)]
#dp = [[0 for i in range(A)] for j in range(B)]

#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

# aa=[int(input()) for i in range(n)]

#for i,name in enumerate(list)

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7

#最大公約数
def gcd(a,b):
	while b:
		a,b = b, a%b
	return a

#最小公倍数
def lcm(a,b):
	return a*b // gcd(a,b)

N = int(input())
aa = list_int = list(map(int,input().split()))

mod = 1

for i in range(N):
	mod = lcm(aa[i],mod)

mod -= 1
ans = 0
for i in range(N):
	ans += mod%aa[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import bisect

sys.setrecursionlimit(10**8)

N = int(input())
A = list(map(int,input().split()))
Asum = [0]
aa = 0

#Asum[i] = A[0]+A[1]+ … +A[i-1]
for i in range(N):
	aa += A[i]
	Asum.append(aa)


ans = 10**20
	
	
for c in range(2,N-1):
	AL = A[:c]
	AR = A[c:]
	
	AsumL = Asum[c]
	AsumR = Asum[-1] - AsumL
	
	Lh = AsumL/2
	Rh = AsumR/2
		
	Lh_i = bisect.bisect_left(Asum,Lh)
	L1 = abs(Asum[Lh_i] - Lh)
	L2 = abs(Asum[Lh_i-1] - Lh)
	if L1 <= L2:
		B = Asum[Lh_i]
	else:
		B = Asum[Lh_i-1]
	
	C = AsumL - B

	Rh_i = bisect.bisect_left(Asum,Rh+AsumL)
	R1 = abs(Asum[Rh_i] - AsumL - Rh)
	R2 = abs(Asum[Rh_i-1] - AsumL - Rh)
	if R1 <= R2:
		D = Asum[Rh_i] - AsumL
	else:
		D = Asum[Rh_i-1] - AsumL
	
	E = AsumR - D
	
	dist = max(B,C,D,E) - min(B,C,D,E)	
	ans = min(ans,dist)
	
print(ans)

Fixed submission:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
SUM = sum(aa)
SUMaa_L = [0]
SUMaa_R = [SUM]

tmp = 0
for a in aa:
	tmp += a
	SUMaa_L.append(tmp)
	SUMaa_R.append(SUM-tmp)

cutL = []
l = 1
SUML = SUMaa_L[l]
for cutM in range(2,N-1):
	SUM = SUMaa_L[cutM]
	while SUML < SUM/2:
		l += 1
		SUML = SUMaa_L[l]
	l1,l2 = SUMaa_L[l-1], SUMaa_L[l]
	r1,r2 = SUM-l1, SUM-l2
	if abs(l1-r1) > abs(l2-r2):
		cutL.append([l2,r2])
	else:
		cutL.append([l1,r1])

cutR = []
r = N-1
SUMR = SUMaa_R[r]
for cutM in reversed(range(2,N-1)):
	SUM = SUMaa_R[cutM]
	while SUMR < SUM/2:
		r -= 1
		SUMR = SUMaa_R[r]
	l1,l2 = SUMaa_R[r+1], SUMaa_R[r]
	r1,r2 = SUM-l1, SUM-l2
	if abs(l1-r1) > abs(l2-r2):
		cutR.append([l2,r2])
	else:
		cutR.append([l1,r1])

ans = INF
for i in range(N-3):
	a,b = cutL[i]
	c,d = cutR[N-4-i]
	ans = min(ans,max(a,b,c,d)-min(a,b,c,d))

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

N,K = map(int,input().split())

N -= K

ans = math.ceil(N / (K-1)) + 1

print (ans)

Fixed submission:
li = list(input())

ans = 0

for i in range(4) :
	if li[i] == '+' : 
		ans += 1
	else:
		ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
AA = inpl()

ans = 0
R = 0
for L in range(N):
    xorsum = AA[L]
    plussum = AA[L]
    R = L
    while xorsum == plussum:
        R += 1
        if R >= N:
            break
        xorsum ^= AA[R]
        plussum += AA[R]
    #print(L,R)
    ans += (R-L)

print(ans)


Fixed submission:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
atoz = [chr(i) for i in range(97,97+26)]

N = inp()
aa = inpl()
xorSUM = SUM = 0
r = 0
ans = 0
for l in range(N):
	while xorSUM == SUM:
		ans += r-l
		r += 1
		if r > N:
			break
		xorSUM ^= aa[r-1]
		SUM += aa[r-1]
	else:
		SUM -= aa[l]
		xorSUM ^= aa[l]
		continue
	break
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True
	

N = int(input())
count = 0
a_list = []

for i in range(5550):
	a = 10 * i + 1
	if is_prime(a):
		a_list.append(a)
		count += 1
		if count == N:
			break

print (' '.join(map(str, a_list)))

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

if b >= a:
	print (a)
else:
	print (a-1)
Buggy python submission (verdict: Runtime Error):

H,W = map(int, input().split())

table = []

for i in range(H):
	table.append(list(input()))


def check(x,y):
	if table[y-1][x]=='#' or table[y+1][x]=='#' or table[y][x-1]=='#' or table[y][x+1]=='#' :
		return
	else:
		print ('No')
		quit()
		

for y in range(H):
	for x in range(W):
		check(x,y)

print ('Yes')		

Fixed submission:
H,W = map(int, input().split())

table = []

for i in range(H):
	table.append(list(input()))

counter = 0
	
def check(x,y):
	counter = 0
			
	if x > 0:
		if table[y][x-1] == '#':
			counter += 1
			
	if x < W-1:
		if table[y][x+1] == '#':
			counter += 1
	
	if y > 0:
		if table[y-1][x] == '#':
			counter += 1
	
	if y < H-1:
		if table[y+1][x] == '#':
			counter += 1
	
	if counter == 0:
		print('No')
		quit()
			
	

for y in range(H):
	for x in range(W):
		if table[y][x] == '#':
			check(x,y)

print ('Yes')
Buggy python submission (verdict: Runtime Error):
def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True
	

N = int(input())
count = 0
a_list = []

for i in range(5550):
	a = 10 * i + 1
	if is_prime(a):
		a_list.append(a)
		count += 1
		if count == N:
			break

print (' '.join(map(str, a_list)))

Fixed submission:
import math

def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True
	

N = int(input())
count = 0
a_list = []

for i in range(5550):
	a = 10 * i + 1
	if is_prime(a):
		a_list.append(a)
		count += 1
		if count == N:
			break

print (' '.join(map(str, a_list)))
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**8)

def find(x):	#xの根を返す
	global table
	global diff_weight
	
	if table[x] == x:
		return x
	else:
		diff_weight[x] += diff_weight[table[x]] #親の更新に伴う 重みの更新
		table[x] = find(table[x])	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def union(x,y,w):	#xとyを diff(x,y)=w で繋げる
	w = w - weight(y) + weight(x) 
	x = find(x)	
	y = find(y)
	
	if x == y:
		return
	
	if rank[x] < rank[y]:
		x,y = y,x
		w = -w
	
	table[y] = x
	diff_weight[y] = w
	
	if rank[x] == rank[y]:
			rank[y] += 1

def check(x,y): #xとyか繋がっているか -> return bool
	if find(x) == find(y):
		return True
	else:
		return False

def weight(x):
	find(x)	#経路圧縮
	return diff_weight[x]
		
def diff(x,y): # weight(y)-weight(x)  (繋がってる前提)
	return (weight(y) - weight(x))

		
N,M = map(int,input().split())

table = [i for i in range(N)]	#木の親 table[x] == x なら根	
rank  = [1 for i in range(N)]	#木の長さ
diff_weight = [0 for i in range(N)]


for i in range(M):
	a,b,D = (map(int,input().split()))
	a -= 1
	b -= 1
	if check(a,b):
		if diff(a,b) != D:
			print ('table',table)
			print ('weight',diff_weight)
			print('No')
			sys.exit()
	else:
		union(a,b,D)
	print ('table',table)
	print ('weight',diff_weight)
	
	
print ('Yes')

Fixed submission:
import sys

sys.setrecursionlimit(10**8)

def find(x):	#xの根を返す
	global table
	global diff_weight
	
	if table[x] == x:
		return x
	else:
		root = find(table[x])
		diff_weight[x] += diff_weight[table[x]] #親の更新に伴う 重みの更新
		table[x] = root	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def union(x,y,w):	#xとyを diff(x,y)=w で繋げる
	w = w - weight(y) + weight(x) 
	x = find(x)	
	y = find(y)
	
	if x == y:
		return
	
	if rank[x] < rank[y]:
		x,y = y,x
		w = -w
	
	table[y] = x
	diff_weight[y] = w
	
	if rank[x] == rank[y]:
			rank[y] += 1

def check(x,y): #xとyか繋がっているか -> return bool
	if find(x) == find(y):
		return True
	else:
		return False

def weight(x):
	find(x)	#経路圧縮
	return diff_weight[x]
		
def diff(x,y): # weight(y)-weight(x)  (繋がってる前提)
	return (weight(y) - weight(x))

		
N,M = map(int,input().split())

table = [i for i in range(N)]	#木の親 table[x] == x なら根	
rank  = [1 for i in range(N)]	#木の長さ
diff_weight = [0 for i in range(N)]


for i in range(M):
	a,b,D = (map(int,input().split()))
	a -= 1
	b -= 1
	if check(a,b):
		if diff(a,b) != D:
			print('No')
			sys.exit()
	else:
		union(a,b,D)
	
	
print ('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = list(input())
D_li = list(map(int,input().split()))
M = list(input())
T_li = list(map(int,input().split()))

for i in T_li:
	if i in D_li:
		D_li.remove(i)
	else:
		print('NO')
		sys.exit()

print('YES')

Fixed submission:
import sys
from collections import defaultdict

dict = defaultdict(int) #lamda:0

N = list(input())
D_li = list(map(int,input().split()))

for key in D_li:
	dict[key] += 1
	
M = list(input())
T_li = list(map(int,input().split()))

for key in T_li:
	dict[key] -= 1
	if dict[key] < 0:
		print('NO')
		sys.exit()

print('YES')
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict 

N,M = map(int,input().split())
dict = defaultdict(set)

for i in range(M):
	a,b = list(map(int,input().split()))
	dict[a].add(b)
	dict[b].add(a)


color = [0 for i in range(N+1)]
nibu = True

def dfs(v,c):
	u'''
	v : 現在のグラフの頂点
	c : vのグラフのcolor
	queue : 探索済みのグラフの頂点
	res   : 二部グラフの判定 bool
	'''

	global color
	global nibu 

	for i in list(dict[v]):
		if color[i] == c:#隣の頂点が同じ値を与えられている際Falseを返す
			nibu = False
			break
		elif color[i] == 0:	#探索済みでなければ再帰する
			color[i] = c*-1		#0ならcとは異なる値を格納
			dfs(i,-c)		#引数に-cとすることで,cが1=>-1=>1を繰り返す


color[1] = 1  #始点色分けする

dfs(1,1)

if nibu:
	b = color.count(1)
	w = color.count(-1)
	ans = b * w - M
else:
	ans = N * (N-1)//2 - M
	
print(ans)

Fixed submission:
from collections import defaultdict 
import sys

sys.setrecursionlimit(10**8)


N,M = map(int,input().split())
dict = defaultdict(set)

for i in range(M):
	a,b = list(map(int,input().split()))
	dict[a].add(b)
	dict[b].add(a)


color = [0 for i in range(N+1)]
nibu = True

def dfs(v,c):
	u'''
	v : 現在のグラフの頂点
	c : vのグラフのcolor
	queue : 探索済みのグラフの頂点
	res   : 二部グラフの判定 bool
	'''

	global color
	global nibu 

	for i in list(dict[v]):
		if color[i] == c:#隣の頂点が同じ値を与えられている際Falseを返す
			nibu = False
			break
		elif color[i] == 0:	#探索済みでなければ再帰する
			color[i] = c*-1		#0ならcとは異なる値を格納
			dfs(i,-c)		#引数に-cとすることで,cが1=>-1=>1を繰り返す


color[1] = 1  #始点色分けする

dfs(1,1)

if nibu:
	b = color.count(1)
	w = color.count(-1)
	ans = b * w - M
else:
	ans = N * (N-1)//2 - M
	
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())


N = int(input())
lines = []

for i in range(N):
	lines.append(inpl())

ans = 0
for s in range(N):
	for t in range(s+1,N):
		c = lines[s][t]
		ans += c
		for mid in range(N):
			if mid == s or mid == t:
				continue
			a = lines[s][mid]
			b = lines[mid][t]
			if a+b < c:
				print(-1)
				sys.exit()
			elif a+b == c:
				ans -= c
				break
print(ans)

Fixed submission:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())


N = int(input())
lines = []

for i in range(N):
	lines.append(inpl())

ans = 0
for s in range(N):
	for t in range(s+1,N):
		c = lines[s][t]
		ans += c
		for mid in range(N):
			if mid == s or mid == t:
				continue
			a = lines[s][mid]
			b = lines[mid][t]
			if a+b < c:
				print(-1)
				sys.exit()
			elif a+b == c:
				ans -= c
				break
print(ans)
Buggy python submission (verdict: Runtime Error):
X,t = map(int,input().split())
print(max(X-t),0)

Fixed submission:
X,t = map(int,input().split())
print(max(X-t,0))
Buggy python submission (verdict: Runtime Error):
a,b,c,d = inpl()
print(max(0,(min(b,d)-max(a,c))))

Fixed submission:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

a,b,c,d = inpl()
print(max(0,(min(b,d)-max(a,c))))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())

lines = defaultdict(set)

for i in range(N-1):
	a,b,c = inpl() #a -> b コスト:c の経路
	lines[a].add((b,c))
	lines[b].add((a,c))

Q,s = inpl()

weight = [-1]*(N+1)
weight[s] = 0

q = [[0,s]]
heapq.heapify(q)

while q:
	w0,s = heapq.heappop(q)
	for line in list(lines[s]):
		t = line[0]
		w = w0 + line[1]
		if weight[t] == -1 or weight[t] > w: #未探索orより小さい
			heapq.heappush(q, [w,t])
			weight[t] = w

for i in range(Q):
	x,y = inpl()
	print(weight[x]+weight[y])


Fixed submission:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())

lines = defaultdict(set)
for i in range(N-1):
	a,b,c = inpl()
	a -= 1
	b -= 1
	lines[a].add((b,c))
	lines[b].add((a,c))

Q,s = inpl()
s -= 1
ss = [-1]*N
ss[s] = 0

def check(a,w):
	global ss
	for b,c in lines[a]:
		if ss[b] == -1:
			ss[b] = w + c
			check(b,w+c)

check(s,0)

for i in range(Q):
	x,y = inpl()
	print(ss[x-1]+ss[y-1])
Buggy python submission (verdict: Runtime Error):
a,b,c = inpl_int()
print(a+b+c-max(a,b,c))


Fixed submission:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl_int(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

a,b,c = inpl_int()
print(a+b+c-max(a,b,c))