Buggy python submission (verdict: Runtime Error):
M,N=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if M > N:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(M-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)

Fixed submission:
N,M=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if N < M:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(N-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
M,N=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()
#print(xdelta)

if M == 1:
	print(0)
elif N == 1:
	print(sum(xdelta))
elif M <= N:
	print(0)
else:
	for i in range(M-1):
		xdelta.pop(-1)
	print(sum(xdelta))

Fixed submission:
N,M=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if N < M:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(N-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
M,N=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()
#print(xdelta)

if M == 1:
	print(0)
elif N == 1:
	print(sum(xdelta))
else:
	for i in range(M-1):
		xdelta.pop(-1)
	print(sum(xdelta))

Fixed submission:
N,M=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if N < M:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(N-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
M,N=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()
#print(xdelta)

if xdelta == [] or N == 1:
	print(int(sum(map(abs,X))))
else:
	for i in range(M-1):
		xdelta.pop(-1)
	print(sum(xdelta))

Fixed submission:
N,M=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if N < M:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(N-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
M,N=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()
#print(xdelta)

if xdelta == []:
	print(int(sum(map(abs,X))))
else:
	for i in range(M-1):
		xdelta.pop(-1)
	print(sum(xdelta))

Fixed submission:
N,M=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if N < M:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(N-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
M,N=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

if xdelta == []:
	print(int(sum(map(abs,X))))
else:
	for i in range(M-1):
		xdelta.pop(-1)
	print(sum(xdelta))

Fixed submission:
N,M=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if N < M:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(N-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
M,N=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(X[i+1]-X[i])

xdelta.sort()

if xdelta == []:
	print(int(sum(map(abs,X))))
else:
	for i in range(M-1):
		xdelta.pop(-1)
	print(sum(xdelta))

Fixed submission:
N,M=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if N < M:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(N-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
M,N=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(X[i+1]-X[i])

xdelta.sort()

for i in range(M-1):
	xdelta.pop(-1)
	
print(sum(xdelta))

Fixed submission:
N,M=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if N < M:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(N-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)