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

Fixed submission:
# input
N = int(input())

if N % 2 == 0:
    print(N)
else:
    print(N * 2)

Buggy submission (verdict: Runtime Error):
import math
# input
N = input()

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm_base(2, N))
Problem p03804 (python)

Fixed submission:
import numpy as np

# input
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

A_arr = np.array(A)
B_arr = np.array(B)

for i in range(N - M + 1):
    for j in range(N - M + 1):
        if np.array_equal(A_arr[i:i + M, j:j + M], B_arr):
            print('Yes')
            exit()

print('No')

Buggy submission (verdict: Runtime Error):
# input
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            for l in range(M):
                if B[k][l] == A[i + k][j + l]:
                    ans += 1
                else:
                    break
            if ans == M * 2:
                print("Yes")
                exit()
            else:
                ans = 0
                break

print('No')
Problem p03805 (python)

Fixed submission:
# input
N, M = map(int, input().split())
G = [list(map(int, input().split())) for _ in range(M)]
edges = [set() for _ in range(N)]

for a, b in G:
    edges[a - 1].add(b - 1)
    edges[b - 1].add(a - 1)

def dfs(start, edges, path):
    path.append(start)
    if len(path) == N:
        path.pop()
        return 1
    ans = 0
    for u in edges[start]:
        if u in path:
            continue
        ans += dfs(u, edges, path)
    path.pop()
    return ans    

print(dfs(0, edges, []))

Buggy submission (verdict: Runtime Error):
# input
N, M = map(int, input().split())
G = [list(map(int, input().split())) for _ in range(M)]
edges = [set() for _ in range(N)]

for a, b in G:
    edges[a - 1].add((b - 1, 1))
    edges[b - 1].add((a - 1, 1))

def dfs(start, edges, path):
    path.append(start)
    if len(path) == n:
        path.pop()
        return 1
    ans = 0
    for u in edges[start]:
        if u in path:
            continue
        ans += dfs(u, path)
    path.pop()
    return ans    

print(dfs(0, []))
Problem p03835 (python)

Fixed submission:
# input
K, S = map(int, input().split())

ans = 0

for i in range(min([S + 1, K + 1])):
    for j in range(min([S -i + 1, K + 1])):
        if S - i - j <= K:
            ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
# input
K, S = map(int, input())

ans = 0

for i in range(K + 1):
    for j in range(S - i + 1):
        for k in range(S - i - j + 1):
            if i + j + k == S:
                ans += 1

print(ans)
Problem p03127 (python)

Fixed submission:
# -*- coding: utf-8 -*-
from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def gcd_list(numbers):
    return reduce(gcd, numbers)

N = int(input())

As = map(int, input().split())

print(gcd_list(As))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())

As = map(int, input().split())

print(gcd_list(As))
Problem p03137 (python)

Fixed submission:
N, M = list(map(int ,input().split()))
X = list(map(int, input().split()))
dis = []
if N >= M:
    print(0)
else:
    X.sort()
    for i in range(M-1):
        dis.append(abs(X[i+1] - X[i]))
    dis.sort(reverse=True)
    ans = max(X) - min(X) - sum(dis[:N-1])
    print(ans)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int ,input().split()))
X = list(map(int, input().split()))
dis = []
if N >= M:
    print(0)
else:
    X.sort()
    for i in range(M):
        dis.append(abs(X[i+1] - X[i]))
    dis.sort()
    print(dis)
    ans = sum(dis[:-(N-1)])
    print(ans)
Problem p03208 (python)

Fixed submission:
n,k=map(int,input().split())
H=[]
for i in range(n):
    H.append(int(input()))
 
H.sort()
 
#print(H)
 
ans=H[n-1]-H[0]
 
for i in range(n-k+1):
    #print(H[i+k-1]-H[i])
    ans=min(ans,H[i+k-1]-H[i])
 
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = []

for i in range(N):
        H.append(int(input()))

H.sort()

ans = []
for i in range(N-K-1):
        # print(i)
        dif = H[i+K-1] - H[i]
        ans.append(dif)

print(min(ans))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = []

for i in range(N):
        h = int(input())
        H.append(int(input()))

H.sort()

ans = []
for i in range(N-K-1):
        # print(i)
        dif = H[i+K-1] - H[i]
        ans.append(dif)

print(min(ans))

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
H = []
for i in range(N):
        h = int(input())
        H.append(h)

H.sort()
ans = []

for i in range(N-K-1):
        # print(i)
        dif = H[i+K-1] - H[i]
        ans.append(dif)

print(min(ans))
Problem p03135 (python)

Fixed submission:
T, X = map(int, input().split())
print(T/X)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M = map(int,input().split())
P = list(map(int,input().split()))
P.sort()
Q = [0] + P[:len(P)-1]
P = np.array(P)
Q = np.array(Q)
R = P-Q
R[0] = 0
for i in range(1,N):
    index = np.argmax(R)
    R[index] = 0
print(sum(R))
Problem p03208 (python)

Fixed submission:
def christmasEve():
    N, K = map(int, input().split())
    h = [int(input()) for i in range(N)]
    strees = sorted(h)
    result=10**9
    for i in range(N-K+1):
        result = min(result, strees[i+K-1] - strees[i])
    print(result)

if __name__ == "__main__":
    christmasEve()

Buggy submission (verdict: Runtime Error):
def christmasEve():
    N, K = map(int, input().split())
    h = [int(input()) for i in range(N)]
    strees = sorted(h)
    result=10**9
    for i in range(len(strees)):
        result = min(result, strees[i+K-1] - strees[i])
    print(result)

if __name__ == "__main__":
    christmasEve()
Problem p03127 (python)

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

n = int(input())
line = list(map(int,input().split()))

ans = line[0]

for i in range(1,n):
    ans = gcd(ans,line[i])

print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = input()
line = list(map(int,input().split()))
ans = gcd_list(line)

print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
line = list(map(int,input().split()))
ans = gcd_list(line)

print(ans)
Problem p03127 (python)

Fixed submission:
from functools import reduce

def gcd(a, b):
    x = max(a, b)
    y = min(a, b)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y 
            y = z
        else:
            return z

def main():
    _ = input()
    monsters = [int(n) for n in input().split(" ")]
    max_gcd = reduce(gcd, monsters)
    print(max_gcd)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from functools import reduce
import math

def main():
    _ = input()
    monsters = [int(n) for n in input().split(" ")]
    max_gcd = reduce(math.gcd, monsters)
    print(max_gcd)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    _ = input()
    monsters = [int(n) for n in input().split(" ")]
    max_gcd = reduce(math.gcd, monsters)
    print(max_gcd)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def decice_winner(a, b):
    if a > b and b != 0:
        return b
    else:
        return a
def calc_min(a, b):
    while True:
        if a <= 1 or b <=1:
            return decice_winner(a, b)
        elif a > b and a / b > 0 :
            a = a % b
        elif b > a and b / a > 0:
            b = b % a
        else:
            return decice_winner(a, b)

def main():
    _ = input()
    monsters = list(set([int(n) for n in input().split(" ")]))
    min1 = min(monsters)
    monsters.remove(min1)
    monsters = list(set([n % min1 for n in monsters]))
    monsters.remove(0)
    if len(monsters) == 0:
        print(min1)
    else:
        min2 = min(monsters)
        print(calc_min(min1, min2))

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

Fixed submission:
def inpul(): return list(map(int, input().split()))

import fractions
from functools import reduce

#最大公約数
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = inpul()
a = inpul()

ans = gcd_list(a)
print(ans)

Buggy submission (verdict: Runtime Error):
def inpul(): return list(map(int, input().split()))

 from fractions import Fraction
from functools import reduce

#最大公約数
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = inpul()
a = inpul()

ans = gcd_list(a)
print(ans)

Buggy submission (verdict: Runtime Error):
def inpul(): return list(map(int, input().split()))

import math
from functools import reduce

#最大公約数
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = inpul()
a = inpul()

ans = gcd_list(a)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
def inpul(): return list(map(int, input().split()))

#最大公約数
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
N = inpul()
a = inpul()

ans = gcd_list(a)
Problem p03137 (python)

Fixed submission:
#python3.4
def inpul(): return list(map(int, input().split()))

N, M = inpul()
X = inpul()
new_list = sorted(X)
diff_list = [new_list[i+1] - new_list[i] for i in range(M-1)]
new_dif_list = sorted(diff_list, reverse = True)

if(N >= M):
    print(0)

else:
  if(N  >= 2):
      for i in range(N-1):
        new_dif_list.pop(0)

  print(sum(new_dif_list))

Buggy submission (verdict: Runtime Error):
#python3.4
def inpul(): return list(map(int, input().split()))

N, M = inpul()
X = inpul()

if(N >= M):
    print(0)
else:
  new_list = sorted(X)
  diff_list = [new_list[i+1] - new_list[i] for i in range(M-1)]
  new_dif_list = sorted(diff_list, reverse = True)

  if(N  >= 2):
    for i in range(N-1):
        new_dif_list.pop(0)

print(sum(new_dif_list))

Buggy submission (verdict: Runtime Error):
#python3.4
def inpul(): return list(map(int, input().split()))

N, M = inpul()
X = inpul()

if(N >= M):
    print(0)

new_list = sorted(X)
diff_list = [new_list[i+1] - new_list[i] for i in range(M-1)]
new_dif_list = sorted(diff_list, reverse = True)
else:
  if(N  >= 2):
      for i in range(N-1):
          new_dif_list.pop(0)

  print(sum(new_dif_list))

Buggy submission (verdict: Runtime Error):
#python3.4
def inpul(): return list(map(int, input().split()))

N, M = inpul()
X = inpul()

if(N >= M):
    print(0)

new_list = sorted(X)
diff_list = [new_list[i+1] - new_list[i] for i in range(M-1)]
new_dif_list = sorted(diff_list, reverse = True)

if(N  >= 2):
    for i in range(N-1):
        new_dif_list.pop(0)

print(sum(new_dif_list))

Buggy submission (verdict: Runtime Error):
#python3.4
def inpul(): return list(map(int, input().split()))

N, M = inpul()
X = inpul()

if(N >= M):
    print(0)

new_list = sorted(X)
diff_list = [new_list[i+1] - new_list[i] for i in range(M-1)]
new_dif_list = sorted(diff_list, reverse = True)

if(N  >= 2):
    for i in range(N-1):
      new_dif_list.pop(0)

print(sum(new_dif_list))
Problem p03127 (python)

Fixed submission:
N = int(input())
L = [int(s) for s in input().split(' ')]

while len(L) > 1:
  L.sort()
  L_new = [L[0]]
  for l in L[1:]:
    v = l % L_new[0]
    if v != 0:
      L_new.append(v)
  L = L_new
print(L[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [int(s) for s in input().split(' ')]

while len(L) > 1:
	L.sort()
    if L[-1] % L[0] == 0:
      L.pop()
    else:
      L[-1] = L[-1] % L[0]
print(L[0])
Problem p03127 (python)

Fixed submission:
n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])
def gcm(a,b):
    if a >= b:
        if a % b == 0:
            return b 
        else:
            return gcm(b,a%b)
    else: return gcm(b,a)
for i in range(1,len(a)):
    a[0] = gcm(a[0],a[i])
print(a[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])
a = sorted(a)
while len(a) > 1:
    for i in range(1,len(a)):
        if a[len(a)-i] % a[0] == 0:
            a.pop(len(a)-i)
        else: a[len(a)-i] %= a[0]
    a = sorted(a)
print(a[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])
a = sorted(a)
while len(a) > 1:
    for i in range(1,len(a)):
        if a[len(a)-1-i] % a[0] == 0:
            a.pop()
        else: a[len(a)-1-i] %= a[0]
    a = sorted(a)
print(a[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])
a = sorted(a)
while len(a) > 1:
    for i in range(1:len(a)):
        if a[len(a)-1-i] % a[0] == 0:
            a.pop()
        else: a[len(a)-1-i] %= a[0]
    a = sorted(a)
print(a[0])
Problem p03127 (python)

Fixed submission:
def gcd(a,b):
    r = a%b
    #print(a,b,r)
    if(r==0): return b
    return gcd(b,r)
n = int(input()) 
#n=4
hps = [int(i) for i in input().split()]
#lst = [2, 2, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [0, 1, 0]
    ##2 4 5 -> 1
    ## minと全ての要素のgcd
hps = sorted(hps)
for i in range(1,n):
    hps[0] = gcd(hps[i], hps[0])
#print(hps)
for i in range(len(hps)):
    if(hps[i]==0): continue
    print(hps[i])
    break

Buggy submission (verdict: Runtime Error):
n = int(input()) 
#n=4
hps = [int(i) for i in input().split()]
#lst = [2, 2, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [0, 1, 0]
    ##2 4 5 -> 1
    ## minと全ての要素のgcd
hps = sorted(hps)
for i in range(1,n):
    hps[0] = gcd(hps[i], hps[0])
#print(hps)
for i in range(len(hps)):
    if(hps[i]==0): continue
    print(hps[i])
    break

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input()) 
#n=3
lst = [int(i) for i in input().split()]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [1000000000, 1000000000, 1000000000]
hps = set(lst)
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[len(hps)-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Buggy submission (verdict: Runtime Error):
n = int(input()) 
#n=3
lst = [int(i) for i in input().split()]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [1000000000, 1000000000, 1000000000]
hps = set(lst)
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[n-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Buggy submission (verdict: Runtime Error):
n = int(input()) 
#n=3
lst = [int(i) for i in input().split()]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [1000000000, 1000000000, 1000000000]
hps = set(lst)
while(1):
    hps = sorted(hps)
    print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[n-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input()) 
#n=4
lst = [int(input()) for i in range(n)]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
hps = np.array(lst)
while(1):
    hps = sorted(hps)
    print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[n-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Buggy submission (verdict: Runtime Error):
n = int(input()) 
lst = [int(i) for i in input().split()]
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Buggy submission (verdict: Runtime Error):
n = int(input()) 
lst = [int(input()) for i in range(n)]
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    hps[1] = hps[1] - hps[0]
print(hps[1])
Problem p03127 (python)

Fixed submission:
n = int(input())
a = [int(k) for k in input().split()]

def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x
ans = gcd(a[0],a[1])
for i in a[2:]:
	ans = gcd(ans,i)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(k) for k in input().split()]
import math
ans = math.gcd(a[0],a[1])
for i in a[2:]:
	ans = math.gcd(ans,i)
print(ans)
Problem p03307 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
def main():
	N = int(input())
	if N % 2 == 0:
		print(int(N))
	else:
		print(int(N*2))
 
if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def main():
	N = input()
	while i % 2 == 0:
      i = N / 2
	print(i*2)

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

Fixed submission:
import fractions
from functools import reduce

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

print(reduce(fractions.gcd, al))

Buggy submission (verdict: Runtime Error):
result = [0 for i in range(0,len(al)**2)]
for i in range(len(al)):
    for j in range(len(al)):
        result = abs(i-j)
print(min(result))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

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



reduce(math.gcd, al)
Problem p03307 (python)

Fixed submission:
N=int(input())
if N %2==0:
    print(N)
else:
    print(N*2)

Buggy submission (verdict: Runtime Error):
n=input()
if n %2==0:
    print(n)
else:
    print(2*n)
Problem p03127 (python)

Fixed submission:
import fileinput


def gcd(a, b):
    if b == 0:
        r = a
    else:
        r = gcd(b, a % b)
    return r


def gcdl(l):
    r = gcd(l[0], l[1])
    for i in range(2, len(l)):
        r = gcd(r, l[i])
    return r


def algorithm(n, a):
    return gcdl(a)


def pass_inputs(input_lines):
    n = input_lines[0][0]
    return algorithm(n, input_lines[1])


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()

Buggy submission (verdict: Runtime Error):
import fileinput


def gcd(a, b):
    if b == 0:
        r = a
    else:
        r = gcd(b, a % b)
    return r


def gcdl(l):
    if len(l) > 1:
        r = gcdl([gcd(l[0], l[1])] + l[2:])
    else:
        r = l
    return r


def algorithm(n, a):
    return gcdl(a)[0]


def pass_inputs(input_lines):
    n = input_lines[0][0]
    return algorithm(n, input_lines[1])


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()
Problem p03127 (python)

Fixed submission:
from fractions import gcd

n = int(input())
a = list(map(int,input().split()))
ans = a[0]

for i,item in enumerate(a):
    if i != 0:
        ans = gcd(ans,item)

print(ans,end='')

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = list(map(int,input().split()))
ans = a[0]

for i,item in enumerate(a):
    if i != 0:
        ans = math.gcd(ans,item)

print(ans,end='')

Buggy submission (verdict: Runtime Error):
n = int(input())
box = list(map(int,input().split()))

while(1):

    for index,item in enumerate(box):
        if index != 0 and item != 0:
            if item % min(box) == 0:
                box[index] = 0
                box.remove(0)
            else:
                box[index] = item % box[0]
        
    #print(box)
    if len(box) == 1:
        break

print(box[0],end='')
Problem p03986 (python)

Fixed submission:
string = input()
stack = []
for s in string:
    if s == "T" and stack and stack[-1] == "S":
        stack.pop()
    else:
        stack.append(s)
print(len("".join(stack)))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]
print(sum([min(a[l:r + 1]) for l in range(N) for r in range(l, N)]))

Buggy submission (verdict: Runtime Error):
X = input()
n = 10 ** 10000
def STring(X, n):
  index = X.find("ST")
  if index == -1 or n == 0:
    return X
  else:
    return STring(X[0:index] + X[index + 2:], n - 1)

print(len(STring(X , n)))

Buggy submission (verdict: Runtime Error):
X = input()

def STring(X):
  index = X.find("ST")
  if index == -1:
    return X
  else:
    return STring(X[0:index] + X[index + 2:])

print(len(STring(X)))
Problem p03127 (python)

Fixed submission:
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())
A = [int(_) for _ in input().split()]

print(gcd_list(A))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
A = [int(_) for _ in input().split()]

print(gcd_list(A))
Problem p03137 (python)

Fixed submission:
import sys

N, M = map(int, input().split())
X = [int(_) for _ in input().split()]

# 座標数よりコマ数が多ければ初期位置で条件を満たす
if N >= M:
    print(0)
    sys.exit()

# ソートする
X.sort()

# 隣り合う数の差を計算する
diff = list()
for m in range(M-1):
    diff.append(X[m+1] - X[m])

diff.sort(reverse=True)
print(sum(diff[N-1:]))

Buggy submission (verdict: Runtime Error):
import sys

N, M = map(int, input().split())
X = [int(_) for _ in input().split()]

# 座標数よりコマ数が多ければ初期位置で条件を満たす
if N >= M:
    print(0)
    sys.exit()

# ソートする
X.sort()

# 隣り合う数の差を計算する
diff = list()
for m in range(M-1):
    diff.append(X[m+1] - X[m])

total = 0
for n in range(N-1):
    max_index = diff.index(max(diff))
    left = 0
    right = 0
    for l in range(len(diff)):
        if l < max_index:
            left += diff[l]
        elif l > max_index:
            right += diff[l]
    if left == right:
        left_list = diff[:max_index]
        left_max = left_list.index(max(left_list))
        right_list = diff[max_index+1:]
        right_max = right_list.index(max(right_list))
        if left_max > right_max:
            diff = diff[:max_index]
            total += right
        else:
            diff = diff[max_index+1:]
            total += left
    elif left > right:
        diff = diff[:max_index]
        total += right
    else:
        diff = diff[max_index+1:]
        total += left

total += sum(diff)
print(total)

Buggy submission (verdict: Runtime Error):
import sys

N, M = map(int, input().split())
X = [int(_) for _ in input().split()]

# 座標数よりコマ数が多ければ初期位置で条件を満たす
if N >= M:
    print(0)
    sys.exit()

# ソートする
X.sort()

# 隣り合う数の差を計算する
diff = list()
for m in range(M-1):
    diff.append(X[m+1] - X[m])

total = 0
for n in range(N-1):
    max_index = diff.index(max(diff))
    left = 0
    right = 0
    for l in range(len(diff)):
        if l < max_index:
            left += diff[l]
        elif l > max_index:
            right += diff[l]
    if left > right:
        diff = diff[:max_index]
        total += right
    else:
        diff = diff[max_index+1:]
        total += left

total += sum(diff)
print(total)

Buggy submission (verdict: Runtime Error):
import sys

N, M = map(int, input().split())
X = [int(_) for _ in input().split()]

# 座標数よりコマ数が多ければ初期位置で条件を満たす
if N > M:
    print(0)
    sys.exit()

# ソートする
X.sort()

# 隣り合う数の差を計算する
diff = list()
for m in range(M-1):
    diff.append(X[m+1] - X[m])

total = 0
for n in range(N-1):
    max_index = diff.index(max(diff))
    left = 0
    right = 0
    for l in range(len(diff)):
        if l < max_index:
            left += diff[l]
        elif l > max_index:
            right += diff[l]
    if left > right:
        diff = diff[:max_index]
        total += right
    else:
        diff = diff[max_index+1:]
        total += left

total += sum(diff)
print(total)