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

Fixed submission:

def solve_commentary():
    N, K = map(int, input().split())
    R = N - K  # 赤玉の数
    MOD = 10 ** 9 + 7
    for i in range(1, K + 1):
        if N - K + 1 >= i:
            print((combinations_count(N - K + 1, i) * combinations_count(K - 1, i - 1)) % (MOD))
        else:
            print(0)
        pass
    pass


def combinations_count(n, r):
    import math
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def ppprint(itr_obj):
    for ite in itr_obj:
        print(ite)


if __name__ == '__main__':
    # solve()
    solve_commentary()

Buggy submission (verdict: Runtime Error):
def solve_commentary():
    N, K = map(int, input().split())
    R = N - K  # 赤玉の数
    MOD = 10 ** 9 + 7
    for i in range(1, K + 1):
        print((combinations_count(N - K + 1, i) * combinations_count(K - 1, i - 1)) % (MOD))
        pass
    pass


def combinations_count(n, r):
    import math
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def ppprint(itr_obj):
    for ite in itr_obj:
        print(ite)


if __name__ == '__main__':
    # solve()
    solve_commentary()
Problem p03013 (python)

Fixed submission:
def solve():
    N, M = map(int, input().split())
    A = []
    if M != 0:
        A = [int(input()) for _ in range(M)]
    A.sort(reverse=True)
    mm = 10 ** 9 + 7
    dp = [0] * (N + 1)
    dp[0] = 1  # 0段目に行くパターンは1とする
    tag = -1
    if len(A) != 0:
        tag = A.pop()
    # 1段目のパターンを設定
    if tag == 1:
        dp[1] = 0
        if len(A) == 0:
            tag = -1
        else:
            tag = A.pop()
    else:
        dp[1] = 1
    for i in range(2, N + 1):
        if i == tag:
            if len(A) == 0:
                tag = -1
            else:
                tag = A.pop()
            continue
        dp[i] = (dp[i - 1] + dp[i - 2]) % mm
    print(dp[N])


if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
def solve():
    N, M = map(int, input().split())
    A = []
    if M != 0:
        A = [int(input()) for _ in range(M)]
    A.sort(reverse=True)
    mm = 10 ** 9 + 7
    dp = [0] * (N + 1)
    dp[0] = 1  # 0段目に行くパターンは1とする
    tag = -1
    if len(A) != 0:
        tag = A.pop()
    # 1段目のパターンを設定
    if tag == 1:
        dp[1] = 0
        tag = A.pop()
    else:
        dp[1] = 1
    for i in range(2, N + 1):
        if i == tag:
            if len(A) == 0:
                tag = -1
            else:
                tag = A.pop()
            continue
        dp[i] = (dp[i - 1] + dp[i - 2]) % mm
    print(dp[N])


if __name__ == '__main__':
    solve()
Problem p03038 (python)

Fixed submission:
"""
解説を参考に作成 その3
"""


def solve():
    N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    A.sort()
    CB = [list(reversed([int(i) for i in input().split()])) for _ in range(M)]
    CB = list(sorted(CB, reverse=True))

    count = 0
    flag = False
    for cb in CB:
        for b in range(cb[1]):
            if A[count] < cb[0]:
                A[count] = cb[0]
            else:
                flag = True
                break
            count += 1
            if count >= N:
                flag = True
                break

        if flag:
            break
    print(sum(A))


if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
"""
解説を参考に作成 その3
"""


def solve():
    N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    A.sort()
    CB = [list(reversed([int(i) for i in input().split()])) for _ in range(M)]
    CB = list(sorted(CB, reverse=True))

    count = 0
    flag = False
    for cb in CB:
        for b in range(cb[1]):
            if A[count] < cb[0]:
                A[count] = cb[0]
            else:
                flag = True
                break
            count += 1
        if flag:
            break
    print(sum(A))


if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
"""
解説を参考に作成 その2
"""


def solve():
    N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    A.sort()
    CB = [list(reversed([int(i) for i in input().split()])) for _ in range(M)]
    CB = list(sorted(CB, reverse=True))

    count = 0
    for cb in CB:
        for b in range(cb[1]):
            if A[count] < cb[0]:
                A[count] = cb[0]
            else:
                break
            count += 1
        else:
            continue
        break
    print(sum(A))


if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
def solve():
    N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    A.sort()
    CB = [list(reversed([int(i) for i in input().split()])) for _ in range(M)]
    CB = list(sorted(CB, reverse=True))

    change_list = []  # 値を変更した数の変更後の値を入れる

    for CiBi in CB:
        for i in range(CiBi[1]):
            if A[0] < CiBi[0]:
                change_list.append(CiBi[0])
                A.pop(0)  # 変更した値は以後変更対象となることはないのでリストから出す
            else:
                break
        # A.sort()

    print(sum(A) + sum(change_list))


if __name__ == '__main__':
    solve()
Problem p02676 (python)

Fixed submission:
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı
# memnün oldum

K = int(input())
S = input()



if(len(S) <= K):
    print(S)
else:
    print(S[:K] + '.' * 3)
    #for i in range(3):
    #    change = change.replace(change[i], '.')
    #print(S[:K] + change[:3])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı
# memnün oldum

K = int(input())
S = input()
slen = len(S)



if(slen <= K):
    print(S)
else:
    change = S[K:]
    for i in range(3):
        change = change.replace(change[i], '.')
    print(S[:K] + change[:3])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı
# memnün oldum

K = int(input())
S = input()
slen = len(S)



if(slen < K):
    print(S)
else:
    change = S[K:]
    for i in range(3):
        change = change.replace(change[i], '.')
    print(S[:K] + change[:3])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı
# memnün oldum

K = int(input())
S = input()
slen = len(S)



if(slen < K):
    print(S)
else: 
    change = S[K:]
    for i in range(3):
        change = change.replace(change[i], ".")
    print(S[:K] + change[:3])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı
# memnün oldum

K = int(input())
S = input()
slen = len(S)

if(slen >= 100):
    S = S[:99]


if(slen < K):
    print(S)
else: 
    pr = S[:K]
    #
    change = S[K:]
    #print(change)
    for i in range(3):
        change = change.replace(change[i], ".")
    print(pr + change[:3])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı
# memnün oldum

K = int(input())
S = input()


slen = len(S)
if(slen < K):
    print(S)
else: 
    pr = S[:K]
    #
    change = S[K:]
    #print(change)
    for i in range(3):
        change = change.replace(change[i], ".")
    print(pr + change[:3])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı
# memnün oldum

K = int(input())
S = input()


slen = len(S)
if(slen < K):
    print(S)
else: 
    pr = S[:K]
    change = S[K:K+3]
    #print(change)
    for i in range(3):
        change = change.replace(change[i], ".")
    print(pr + change)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı
# memnün oldum

K = int(input())
S = input()


slen = len(S)
if(slen < K):
    print(S)
else: 
    pr = S[:K]
    change = S[K:K+3]
    for i in range(3):
        change = change.replace(change[i], ".")
    print(pr + change)
Problem p02592 (python)

Fixed submission:
a,b,c=0,1,2
one,zero=3,4
x,y=5,6
pi,pj=7,8
z=9
def p(i,j,k):print("+",i,j,k)
def l(i,j,k):print("<",i,j,k)
def s(i,j):
    for k in range(j):p(i,i,i)
print(60452)
p(a,b,one);l(zero,one,one)
for i in range(29,-1,-1):
    p(one,zero,pi);s(pi,i)
    p(x,pi,pi);l(a,pi,pi);l(pi,one,pi)
    p(zero,zero,y)
    for j in range(29,-1,-1):
        p(one,zero,pj);s(pj,j)
        p(y,pj,pj);l(b,pj,pj);l(pj,one,pj)
        l(pi,pj,z);l(z,pj,z);s(z,i+j);p(c,z,c)
        s(pj,j);p(y,pj,y)
    s(pi,i);p(x,pi,x)

Buggy submission (verdict: Runtime Error):
a,l="+<"
f,r=print,range(29,-1,-1)
f(60451,l,4,0,3)
s,t=[a,7,7,7],[a,8,8,8]
for i in r:f(a,3,4,7,*s*i,a,5,7,7,l,0,7,7,l,7,3,7,a,4,4,6,*[*[a,3,4,8,*t*j,a,6,8,8,l,1,8,8,l,8,3,8,l,8,7,9,*t*j,a,8,6,6,l,9,7,8,*t*(i+j),a,8,2,2]for j in r],*s*i,a,7,5,5)

Buggy submission (verdict: Runtime Error):
a,b,c=0,1,2
one,zero=1,0
x,y=5,6
pi,pj=7,8
z=9
p(a,b,one);l(zero,one,one)
def p(i,j,k):print("+",i,j,k)
def l(i,j,k):print("<",i,j,k)
def s(i,j):
    for k in range(j):p(i,i,i)
for i in range(29,0,-1):
    p(one,zero,pi);s(pi,i)
    p(x,pi,pi);l(a,pi,pi);l(pi,one,pi)
    p(one,zero,y)
    for j in range(29,0,-1):
        p(one,zero,pj);s(pj,j)
        p(y,pj,pi);l(b,pj,pj);l(pj,one,pj)
        l(pi,pj,z);l(z,pj,z);s(z,i+j);p(c,z,c)
        s(pj,j);p(y,pj,y)
    s(pi,i);p(x,pi,x)
Problem p03431 (python)

Fixed submission:
n,k=map(int,input().split())
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
a=0
for i in r(n-1,k):a+=f[k-1]*pow(f[i]*f[k-1-i],-1,p)
print(a%p)

Buggy submission (verdict: Runtime Error):
n,k,p=map(int,input().split()),998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]]
print(sum(f[-1]*pow(f[i]*f[-1-i],-1,p)for i in r(n-1,k))%p)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
a=1<<~-k
for i in r(min(n-1,k)):a-=f[k-1]*pow(f[i]*f[k-1-i],-1,p)
print(a%p)
Problem p02552 (python)

Fixed submission:
x=int(input())
if x==0:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
a,b,c,d=list(map(int,input().split()))
if a>=0 and c>=0:
    one=b
    two=d

elif a<0 and c<0:
    one=a
    two=c

elif a>=0 and c<0:
    one=a
    two=d
else:
    one=b
    two=c


print(one*two)

Buggy submission (verdict: Runtime Error):
x=int(input())
if x=0:
    print(1)
else:
    print(0)
Problem p02793 (python)

Fixed submission:
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0

def gcd(a, b):
    # 大きい方を被除数、小さい方を除数とする
    dividend = max(a, b)
    divider = min(a, b)

    if divider == 0:
        return dividend

    # 最大公約数を見つけるまで繰り返す
    while dividend % divider != 0:
        # 除算を行い、その除数を次回の被除数、剰余を次回の除数として処理を繰り返す
        r = dividend % divider
        dividend = divider
        divider = r

    # 一方がもう一方を割り切れた時点で、その除数を最大公約数とみなせる
    return divider


def lcm(a, b):
    return (a * b) // gcd(a, b)

def modinv(x):
    return pow(x, mod-2, mod)

b = list(set(a))
# for i in range(n):

# L = reduce(lcm, a)
L = reduce(lcm, b)

# print(L)

for i in range(n):
    # ans += (L // a[i])
    ans += L * modinv(a[i])

print(ans % mod)

Buggy submission (verdict: Runtime Error):
# import numpy as np
from fractions import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0



def lcm(a, b):
    # return (a * b) // np.gcd(a, b)
    return (a * b) // math.gcd(a, b)

L = reduce(lcm, a)

# print(L)

for i in range(n):
    ans += (L // a[i])
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

from functools import reduce

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0

def gcd(a, b):
    # 大きい方を被除数、小さい方を除数とする
    dividend = max(a, b)
    divider = min(a, b)

    if divider == 0:
        return dividend

    # 最大公約数を見つけるまで繰り返す
    while dividend % divider != 0:
        # 除算を行い、その除数を次回の被除数、剰余を次回の除数として処理を繰り返す
        r = dividend % divider
        dividend = divider
        divider = r

    # 一方がもう一方を割り切れた時点で、その除数を最大公約数とみなせる
    return divider


def lcm(a, b):
    return (a * b) // gcd(a, b)

a.sort(reverse=True)
v1, v2 = None, None
L = None

# if len(a) > 1:
#     v1 = a[0]
#     v2 = a[1]
#     L = lcm(v1, v2)
#     # print(L)
# else:
#     L = reduce(lcm, a)

L = reduce(lcm, a)

# print(L)

for i in range(n):
    ans += (L // a[i])
    # ans %= mod

print(ans % mod)

Buggy submission (verdict: Runtime Error):
# import numpy as np
from fractions import math

from functools import reduce

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0



def lcm(a, b):
    # return (a * b) // np.gcd(a, b)
    return (a * b) // math.gcd(a, b)

L = reduce(lcm, a)

# print(L)

for i in range(n):
    ans += (L // a[i])
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

from functools import reduce

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0

def lcm(a, b):
    return (a * b) // np.gcd(a, b)

L = reduce(lcm, a)

# print(L)

for i in range(n):
    ans += (L // a[i])
    ans %= mod

print(ans)
Problem p02862 (python)

Fixed submission:
import math
import sys
sys.setrecursionlimit(10**5)
x, y = map(int, input().split())
mod = 10**9+7

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if (x + y) % 3 != 0:
    print(0)
    sys.exit()

if y > 2 * x or y < x / 2:
    print(0)
    sys.exit()

cnt = (x + y) // 3
# p = cnt // 2
p = (2 * x - y) // 3
#print(cnt, p)

# Calclate cntCp
comb = Combination(1000000)
ans = comb(cnt, p)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
x, y = map(int, input().split())
#dp = [[0] * (y+1) for _ in range(x+1)]
#dp = [[0] * (x*2+1) for _ in range(x+1)]
dp = [[0] * (y+1) for _ in range(x+1)]
div = 10**9+7

if (x + y) % 3 != 0:
    print(0)
    sys.exit()

if y > 2 * x or y < x / 2:
    print(0)
    sys.exit()

dp[0][0] = 1
dp[2][1] = 1
dp[1][2] = 1

#print(dp)

for i in range(2, x+1):
    #for j in range(i // 2, 2 * i + 1):
    for j in range(i // 2, y+1):
        #print(i, j)
        # if j > y:
        #     break
        if (i + j) % 3 != 0:
            continue
        if y == x / 2:
            dp[i][j] = dp[i-2][j-1] % div
        elif y == 2 * x:
            dp[i][j] = dp[i-1][j-2] % div
        else:
            #print('merge!', dp[i-1][j-2], dp[i-2][j-1])
            dp[i][j] = (dp[i-1][j-2] + dp[i-2][j-1]) % div

#print(dp)
print(dp[x][y])
Problem p02951 (python)

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

print(max(0, c - (a - b)))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

print(max(0, c - (a - b)))
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
a = []
# dp = [0]*(n+1)
dp = [None]*(10**5+1)
mod = 10**9+7
dp[0] = 0

for i in range(m):
    ng = int(input())
    a.append(ng)
    dp[ng] = 0

if 1 in a and 2 in a:
    print(0)
    exit()
elif 1 in a and 2 not in a:
    dp[1] = 0
    dp[2] = 1
elif 1 not in a and 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3, n+1):
    if dp[i] is None:
        dp[i] = (dp[i-1] + dp[i-2]) % mod

print(dp[n])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = []
dp = [0]*(n+1)
mod = 10**9+7

for i in range(m):
    a.append(int(input()))

if 1 in a and 2 in a:
    print(0)
    exit()
elif 1 in a and 2 not in a:
    dp[1] = 0
    dp[2] = 1
elif 1 not in a and 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3, n+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod

print(dp[n])
Problem p03072 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
ans = 1
maxH = h[0]

for i in range(1, n):
    if h[i] >= maxH:
        ans += 1
        maxH = h[i]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
ans = 1
maxH = h[0]

for i in range(1, n):
    if h[i] >= maxH:
	ans += 1
	maxH = h[i]

print(ans)
Problem p03073 (python)

Fixed submission:
s = input()
oddone = ''
evenone = ''

for i in range(len(s)):
    if i % 2 == 1:
        oddone += '1'
        evenone += '0'
    else:
        oddone += '0'
        evenone += '1'

def diffCount(s1, s2):
    count = 0
    if len(s1) != len(s2):
        print('error')
        return

    for i in range(len(s1)):
        if s1[i] != s2[i]:
            count += 1

    return count

print(min(diffCount(s, oddone), diffCount(s, evenone)))

Buggy submission (verdict: Runtime Error):
s = input()
oddone = ''
evenone = ''

for i in range(len(s)):
    if i % 2 == 1:
        oddone += '1'
        evenone += '0'
    else:
        oddone += '0'
        evenone += '1'

def diffCount(s1, s2):
    count = 0
    if len(s1) != len(s2):
        print('error')
        return

    for i in range(len(s1)):
        if s1[i] != s2[i]:
            count += 1

    return count

print(min(diffCount(s, oddone), diffCount(s, evenone)))

Buggy submission (verdict: Runtime Error):
s = input()
oddone = ''
evenone = ''

for i in range(len(s)):
    if i % 2 ==	1:
        oddone += '1'
        evenone += '0'
    else:
	oddone += '0'
	evenone += '1'

def diffCount(s1, s2):
    count = 0
    if len(s1) != len(s2):
	print('error')
	return

    for i in range(len(s1)):
        if s1[i] != s2[i]:
	    count += 1

    return count

print(min(diffCount(s, oddone), diffCount(s, evenone)))
Problem p03127 (python)

Fixed submission:
import fractions
from functools import reduce

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

#print(reduce((lambda x, y: math.gcd(x, y)), a))
print(reduce((lambda x, y: fractions.gcd(x, y)), a))

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

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

print(reduce((lambda x, y: math.gcd(x, y)), a))

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

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

print(reduce((lambda x, y: math.gcd(x, y)), a))

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

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

print(reduce(lambda x, y: math.gcd(x, y), a))

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

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

print(reduce(lambda x, y: math.gcd(x, y), a))

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

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

print(reduce(lambda x, y: math.gcd(x, y), a))
Problem p03137 (python)

Fixed submission:
import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

#list.sort(a, reverse=True)
a.sort()
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
        break
    a.pop()
#    count -= a[i]

#print(count)
print(sum(a))

Buggy submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

list.sort(a, reverse=True)
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
        break
    count -= a[i]

print(count)

Buggy submission (verdict: Runtime Error):
Import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

list.sort(a, reverse=True)
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
        break
    count -= a[i]

print(count)

Buggy submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

list.sort(a, reverse=True)
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
	    break
    count -= a[i]

print(count)

Buggy submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

list.sort(a, reverse=True)
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    count -= a[i]

print(count)