Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,K,L=map(int,input().split())

gK=[set([x]) for x in range(N)]
gL=[set([x]) for x in range(N)]

class UnionFind(object):
  def __init__(self,n):
    self.table=[-1]*n
 
  def find(self,x):
    parent=self.table[x]
    if parent<0:
      return x
    else:
      root=self.find(parent)
      self.table[x]=root
      return root
 
  def union(self,a,b,li):
    root1=self.find(a)
    root2=self.find(b)
    if root1 != root2:
      if self.table[root1] != self.table[root2]:
        if self.table[root1] < self.table[root2]:
          self.table[root2]=root1
          li[root1]=(li[root1] | li[root2])
        else:
          self.table[root1]=root2
          li[root2]=(li[root1] | li[root2])
      else:
        self.table[root1]+=(-1)
        self.table[root2]=root1
        li[root1]=(li[root1] | li[root2])
      
ufK=UnionFind(N)
for i in range(K):
  p,q=map(int,input().split())
  gK[p-1].add(q-1)
  gK[q-1].add(p-1)
  ufK.union(p-1,q-1,gK)

ufL=UnionFind(N)
for i in range(L):
  p,q=map(int,input().split())
  gL[p-1].add(q-1)
  gL[q-1].add(p-1)
  ufL.union(p-1,q-1,gL)

ans=[]
for i in range(N):
  a=ufK.find(i)
  b=ufL.find(i)
  ab= (gK[a] & gL[b])
  ans.append(len(ab))

print(*ans)


Fixed submission:
from collections import defaultdict

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

class UnionFind(object):
  def __init__(self,n):
    self.table=[-1]*n
 
  def find(self,x):
    parent=self.table[x]
    if parent<0:
      return x
    else:
      root=self.find(parent)
      self.table[x]=root
      return root
 
  def union(self,a,b):
    root1=self.find(a)
    root2=self.find(b)
    if root1 != root2:
      if self.table[root1] != self.table[root2]:
        if self.table[root1] < self.table[root2]:
          self.table[root2]=root1
        else:
          self.table[root1]=root2
      else:
        self.table[root1]+=(-1)
        self.table[root2]=root1
      
ufK=UnionFind(N)
for i in range(K):
  p,q=map(int,input().split())
  ufK.union(p-1,q-1)

ufL=UnionFind(N)
for i in range(L):
  p,q=map(int,input().split())
  ufL.union(p-1,q-1)

KL=defaultdict(int)
ans=[]
for i in range(N):
  a=ufK.find(i)
  b=ufL.find(i)
  KL[(a,b)]+=1
for i in range(N):
  a=ufK.find(i)
  b=ufL.find(i)
  ans.append(KL[(a,b)])
  
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import math

def culcD(a,b):
  x1,y1,r1=a
  x2,y2,r2=b
  return max(0,math.sqrt((x1-x2)**2+(y1-y2)**2)-(r1+r2))

A=[]

xs,ys,xg,yg=map(int,input().split())
A.append((xs,ys,0))
A.append((xg,yg,0))

V=defaultdict(int)
V[(0,1)]=(culcD(A[0],A[1]))
V[(1,0)]=(culcD(A[0],A[1]))

N=int(input())
for i in range(N):
  x,y,r=map(int,input().split())
  A.append((x,y,r))
  for j in range(len(A)-1):
    dist = culcD(A[j],A[-1])
    V[(i+2,j)]=dist
    V[(j,i+2)]=dist

def dijkstra(n):
  d=[float('inf')]*(n+2)
  d[0]=0
  used=[False]*(n+2)
  
  while True:
    v=-1
    for i in range(n+2):
      if used[i]==False and (v==-1 or d[i] < d[v]):
        v=i
    if v==-1:
      break
    used[v]=True
    for j in range(n+2):
      d[j]=min(d[j],d[v]+V[(j,v)])

  return d[1]

print(dijkstra(N))

Fixed submission:
from collections import defaultdict
import math

def culcD(a,b):
  x1,y1,r1=a
  x2,y2,r2=b
  return max(0,math.sqrt((x1-x2)**2+(y1-y2)**2)-(r1+r2))

A=[]

xs,ys,xg,yg=map(int,input().split())
A.append((xs,ys,0))
A.append((xg,yg,0))

V=defaultdict(int)
V[(0,1)]=(culcD(A[0],A[1]))
V[(1,0)]=(culcD(A[0],A[1]))

N=int(input())
for i in range(N):
  x,y,r=map(int,input().split())
  A.append((x,y,r))
  for j in range(len(A)-1):
    dist = culcD(A[j],A[-1])
    V[(i+2,j)]=dist
    V[(j,i+2)]=dist

def dijkstra(n):
  d=[float('inf')]*(n+2)
  d[0]=0
  used=[False]*(n+2)
  
  while True:
    v=-1
    for i in range(n+2):
      if used[i]==False and (v==-1 or d[i] < d[v]):
        v=i
    if v==-1:
      break
    used[v]=True
    for j in range(n+2):
      d[j]=min(d[j],d[v]+V[(j,v)])

  return d[1]

print(dijkstra(N))
Buggy python submission (verdict: Runtime Error):
N,K=int(input().split())
ans=K
for i in range(N-1):
  ans*=(K-1)
print(ans)

Fixed submission:
N,K=map(int,input().split())
ans=K
for i in range(N-1):
  ans*=(K-1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a_min=1
b_min=1
for i in range(N):
  a,b=map(int,input().split())
  cnt=1
  while True:
    if a_min<=a*cnt and b_min<=b*cnt:
      break
    cnt+=1
  a_min=a*cnt
  b_min=b*cnt
print(a_min+b_min)

Fixed submission:
import math
N=int(input())
min_a=1
min_b=1
for i in range(N):
  a,b=map(int,input().split())
  at=min_a//a
  if min_a%a!=0:
    at+=1
  bt=min_b//b
  if min_b%b!=0:
    bt+=1
  n=max(at,bt)
  min_a=a*n
  min_b=b*n
print(min_a+min_b)
Buggy python submission (verdict: Runtime Error):
a=int(input().split())
b=int(input().split())
c=int(input().split())

print(int((a+b)*c/2))

Fixed submission:
a=int(input())
b=int(input())
c=int(input())

print(int((a+b)*c/2))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

XY=[]
ND=[[-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,1]]

M=defaultdict(int)
for i in range(N):
  a,b=map(int,input().split())
  XY.append([a-1,b-1])
  for c,d in ND:
    if 1 <= a-1+c < H-1 and 1 <= b-1+d < W-1:
      M[(a-1+c,b-1+d)]+=1

dict={1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}
cnt=0
for a,b in XY:
  for c,d in ND:
    if 1 <= a+c < H-1 and 1 <= b+d < W-1 and M[(a+c,b+d)]>=0:
      dict[M[(a+c,b+d)]]+=1
      M[(a+c,b+d)]=-1
      cnt+=1
ans=(H-2)*(W-2)-cnt
print(ans)
for i in range(1,10):
  print(dict[i])

Fixed submission:
from collections import defaultdict

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

XY=[]
ND=[[-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,1]]

M=defaultdict(int)
for i in range(N):
  a,b=map(int,input().split())
  XY.append([a-1,b-1])
  for c,d in ND:
    if 1 <= a-1+c < H-1 and 1 <= b-1+d < W-1:
      M[(a-1+c,b-1+d)]+=1

dict={1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}
cnt=0
for a,b in M.items():
  dict[b]+=1
  cnt+=1
ans=(H-2)*(W-2)-cnt
print(ans)
for i in range(1,10):
  print(dict[i])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[]
for i in range(N):
  a=int(input())
  A.append(a)
res=sorted(A)

ans=0
for j,k in enumerate(res):
  cnt=A.index(k)
  if abs(j-cnt)%2==1:
    ans+=1

print(ans//2)

Fixed submission:
N=int(input())
A=[]
for i in range(N):
  a=int(input())
  A.append(a)
res=sorted(A)

def binary_search(x):
  l=0
  r=N-1

  while True:
    mid=(l+r)//2
    if res[mid]==x:
      return mid
    elif res[mid]>x:
      r=mid-1
    elif res[mid]<x:
      l=mid+1

ans=0
for j,k in enumerate(A):
  cnt=binary_search(k)
  if abs(j-cnt)%2==1:
    ans+=1

print(ans//2)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split());
xList =list(map(int, input().split()))
xList.sort();

if M == 1:
  print(0);
else:
  diff = xList[M - 1] - xList[1];

  diffList = [];
  prevX = xList[0];
  for i in range(1, M):
      x = xList[i];
      diffList.append(x - prevX);
      prevX = x;
  diffList.sort();

  for i in range(N - 1):
      diffList.pop();

  length = len(diffList);
  result = 0;
  for i in range(length):
      result += diffList[i];

  print(result);

Fixed submission:
N, M = map(int, input().split());
xList =list(map(int, input().split()))
xList.sort();

if N >= M:
  print(0);
else:
  diff = xList[M - 1] - xList[1];

  diffList = [];
  prevX = xList[0];
  for i in range(1, M):
      x = xList[i];
      diffList.append(x - prevX);
      prevX = x;
  diffList.sort();

  for i in range(N - 1):
      diffList.pop();

  length = len(diffList);
  result = 0;
  for i in range(length):
      result += diffList[i];

  print(result);
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input())

if (a < 10 or b < 10):
  print(a*b)
else:
  print(-1)

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

if (a < 10 and b < 10):
  print(a*b)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input()) 
	t = [int(input()) for i in range(n)] 
    print(t[1]*2 - t[0])

Fixed submission:
import sys

a = []
for line in sys.stdin:
    a.append(int(line))
print(a[1] * 2 - a[0])

Buggy python submission (verdict: Runtime Error):
def main:
  print(1000)

Fixed submission:
import sys

a = []
for line in sys.stdin:
    a.append(int(line))
print(a[1] * 2 - a[0])
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
min_num = MAX(l) +1
ans = 0
for i in l:
  if min_num >= i:
    min_num = i
    ans += 1
print(ans)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
min_num = max(l) +1
ans = 0
for i in l:
  if min_num >= i:
    min_num = i
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
l,r = map(int,input().split())
mod = 2019
arr = np.array(list(set([i%mod for i in range(l,r+1)])))
ans = 10**9

for left in range(len(arr)-1):
    ans = min(min(arr[left]*arr[left+1:]%mod),ans)
    left +=1
print(ans)

Fixed submission:
import numpy as np
l,r = map(int,input().split())
mod = 2019
arr = np.array(list(set([i%mod for i in range(l,min(r+1,l+2019))])))
ans = 2019

for left in range(len(arr)-1):
    ans = min(min(arr[left]*arr[left+1:]%mod),ans)
    if ans == 0:
        print(ans)
        exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
l,r = map(int,input().split())
mod = 2019
li = list(set([i%mod for i in range(l,r+1)]))
li.sort()
ans = 10**9

for left in range(len(li)-1):
    ans = min(min(list(map(lambda x: li[left]*x%mod, li[left+1:]))),ans)
    left +=1
print(ans)

Fixed submission:
import numpy as np
l,r = map(int,input().split())
mod = 2019
arr = np.array(list(set([i%mod for i in range(l,min(r+1,l+2019))])))
ans = 2019

for left in range(len(arr)-1):
    ans = min(min(arr[left]*arr[left+1:]%mod),ans)
    if ans == 0:
        print(ans)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
mod = 10**9+7
red = n-k

def combination(n,r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)

for i in range(1,k+1):
    print(combination(red+1,i)*combination(k-1, i-1)%mod)

Fixed submission:
import math
n,k = map(int,input().split())
mod = 10**9+7
red = n-k
def combination(n,r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)

for i in range(1,k+1):
    print(combination(red+1,i)*combination(k-1, i-1)%mod if red+1>=i else 0)
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
cd = c*d//math.gcd(c,d)
e = a-1
f = (b//c + b//d - b//(cd)) - (e//c + e//d - e//(cd))
print(b-e-f)

Fixed submission:
import fractions
a,b,c,d = map(int,input().split())
cd = c*d//fractions.gcd(c,d)
e = a-1
f = (b//c + b//d - b//(cd)) - (e//c + e//d - e//(cd))
print(b-e-f)
Buggy python submission (verdict: Runtime Error):
import fractions
a,b,c,d = map(int,input().split())
cd = c*d//fractions.gcd(c,d)
e = a-1
f = (b//c + b//d - b//(cd)) - (e//c + e//d - e//(cd))
print(b-e-f)

Fixed submission:
n = int(input())
l = []
for i in range(n):
    l += [list(map(int,input().split()))]
l = sorted(l,key=lambda x:x[1])
t = 0
for i in range(n):
    t += l[i][0]
    if t > l[i][1]:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
import pandas as pd
n = int(input())
shops = [0]*n
points = [0]*n
nums = [i for i in range(1,n+1)]
for i in range(n):
    shops[i],points[i] = input().split()
d = pd.DataFrame({'shops':shops,'points':points,'nums':nums})    
l = d.sort_values('shops').sort_values('points', ascending=False)['nums'].tolist()
for i in range(len(l)):
    print(l[i])

Fixed submission:
n = int(input())
l = []
for i in range(1,n+1):
    a, b = input().split()
    l += [[a,int(b),i]]
l = sorted(sorted(l, key=lambda x:x[1], reverse=True), key=lambda x:x[0])
for i in range(len(l)):
    print(l[i][2])
Buggy python submission (verdict: Time Limit Exceeded):
n,m= map(int,input().split())
for i in range(m):
    a,b = map(int,input().split())
    if i == 0:
        l = [a+j for j in range(b-a+1)]
    l = list(set([a+j for j in range(b-a+1)]) & set(l))
print(len(set(l)))

Fixed submission:
n,m = map(int, input().split())
left = 0
right = 10**5
for _ in range(m):
    l,r = map(int,input().split())
    left = max(left, l)
    right = min(right,r)
print(max(0,right-left+1))

Buggy python submission (verdict: Time Limit Exceeded):
n,m= map(int,input().split())
a = [0]*m
b = [0]*m
for i in range(m):
    a,b = map(int,input().split())
    if i == 0:
        l = [a+j for j in range(b-a+1)]
    l = list(set([a+j for j in range(b-a+1)]) & set(l))
print(len(set(l)))

Fixed submission:
n,m = map(int, input().split())
left = 0
right = 10**5
for _ in range(m):
    l,r = map(int,input().split())
    left = max(left, l)
    right = min(right,r)
print(max(0,right-left+1))
Buggy python submission (verdict: Runtime Error):
N, K = map(input().split())
print(N-K+1)

Fixed submission:
N, K = map(int, input().split())
print(N-K+1)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
cnt = 0
for i in range(1, int(np.ceil(np.sqrt(N)))):
    if (N-i)%i ==0:
        cnt += int((N-i)/i)
print(cnt)

Fixed submission:
import numpy as np
N = int(input())
cnt = 0
for i in range(1, int(np.ceil(np.sqrt(N)))):
    if (N-i)%i ==0 and (N-i)/i >i:
        cnt += int((N-i)/i)
print(cnt)

Buggy python submission (verdict: Runtime Error):
N = int(input())
cnt = 0
for i in range(1, int(np.sqrt(N))+1):
    cnt += (N-i)//i
print(cnt)    

Fixed submission:
import numpy as np
N = int(input())
cnt = 0
for i in range(1, int(np.ceil(np.sqrt(N)))):
    if (N-i)%i ==0 and (N-i)/i >i:
        cnt += int((N-i)/i)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
cnt = 0
for i in range(2, N+1):
    m = N//i
    e = N%i
    if m==e:
        cnt +=i
print(cnt)        

Fixed submission:
import numpy as np
N = int(input())
cnt = 0
for i in range(1, int(np.ceil(np.sqrt(N)))):
    if (N-i)%i ==0 and (N-i)/i >i:
        cnt += int((N-i)/i)
print(cnt)

Buggy python submission (verdict: Runtime Error):
N = map(int,input())
cnt = 0
for i in range(2, N+1):
    m = N//i
    e = N%i
    if m==e:
        cnt +=i
print(cnt)        

Fixed submission:
import numpy as np
N = int(input())
cnt = 0
for i in range(1, int(np.ceil(np.sqrt(N)))):
    if (N-i)%i ==0 and (N-i)/i >i:
        cnt += int((N-i)/i)
print(cnt)

Buggy python submission (verdict: Runtime Error):
N = map(int,input())
cnt = 0
for i in range(2, len(N)+1):
    m = N//i
    e = N%i
    if m==e:
        cnt +=i
print(cnt)       

Fixed submission:
import numpy as np
N = int(input())
cnt = 0
for i in range(1, int(np.ceil(np.sqrt(N)))):
    if (N-i)%i ==0 and (N-i)/i >i:
        cnt += int((N-i)/i)
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
vl = list(map(int, input().split()))
cl = list(map(int, input().split()))
ans = 0
for i in range(n):
    if vl[i] > cl[i]:
        ans += v[i]-c[i]
print(ans)

Fixed submission:
n = int(input())
vl = list(map(int, input().split()))
cl = list(map(int, input().split()))
ans = 0
for i in range(n):
    if vl[i] > cl[i]:
        ans += vl[i]-cl[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
vl = [int(input()) for _ in range(n)]
cl = [int(input()) for _ in range(n)]
ans = 0
for i in range(n):
    if vl[i] > cl[i]:
        ans += v[i]-c[i]
print(ans)

Fixed submission:
n = int(input())
vl = list(map(int, input().split()))
cl = list(map(int, input().split()))
ans = 0
for i in range(n):
    if vl[i] > cl[i]:
        ans += vl[i]-cl[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()
l = list(input.split())

cnt = 0
max_height = 0
for i in range(len(l)):
  if l[i] > max_height:
    cnt +=1
    max_height = l[i]
    
print(cnt)   
  

Fixed submission:
n = input()
l = list(input().split())
 
cnt = 0
max_height = 0
for i in range(len(l)):
  if int(l[i]) >= int(max_height):
    cnt +=1
    max_height = l[i]
    
print(cnt)
Buggy python submission (verdict: Runtime Error):
l = [int(input()) for i in range(5)]
l.sort()
print(max(l[0]-40, l[1]-30, [2]-20, l[3]-10, l[4]))

Fixed submission:
import math
l = [int(input()) for i in range(5)]
e = 10
for i in l:
    re = i%10
    if re !=0:
        e = min(e, re)
l = [math.ceil(i/10)*10 for i in l]
print(sum(l)-(10-e))
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
l = [input() for _ in range(5)]
print(math.ceil(n/min(l)+4))

Fixed submission:
import math
n = int(input())
l = [int(input()) for _ in range(5)]
print(math.ceil(n/min(l))+4)
Buggy python submission (verdict: Runtime Error):
s = input()
cnt = 0
cnt_list = [0]*len(s)
for i in s:
    if s in 'ACTG ':
        cnt +=1
    else:
        cnt = 0
    cnt_list[i] = cnt
print(max(cnt_list))

Fixed submission:
s = input()
cnt = 0
cnt_list = [0]*len(s)
for idx,i in enumerate(s):
    if i in 'ACTG ':
        cnt +=1
    else:
        cnt = 0
    cnt_list[idx] = cnt
print(max(cnt_list))
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()

for i in range(q):
    l, r = map(int, input().split())
    print(s[l-1:r].count('AC'))

Fixed submission:
n,q = map(int, input().split())
s = input()
cum_list = [0]*(n+1)
a_flag = 0

for idx,i in enumerate(s,1):
    cum_list[idx] = cum_list[idx-1]
    if a_flag == 1 and i =='C':
        cum_list[idx] +=1
    if i == 'A':
        a_flag = 1
    else:
        a_flag = 0

for i in range(q):
    l, r = map(int, input().split())
    print(cum_list[r]-cum_list[l])
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
l = [list(map(int,input().split)) for _ in range(n)]
cnt = 0
ans = 0
l.sort(key=lambda x:x[0])
for i in range(n):
    cnt += l[i][1]
    ans += l[i][0] * l[i][1]
    if cnt > m:
        ans -= l[i][0] * l[i][1]
        ans += l[i][0]*(m-(cnt-l[i][1]))
print(ans)

Fixed submission:
n,m = map(int, input().split())
l = [list(map(int,input().split())) for _ in range(n)]
cnt = 0
ans = 0
l.sort(key=lambda x:x[0])
for i in range(n):
    cnt += l[i][1]
    ans += l[i][0] * l[i][1]
    if cnt > m:
        ans -= l[i][0] * l[i][1]
        ans += l[i][0]*(m-(cnt-l[i][1]))
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input().split())
cnt = 0
for i in range(1,100):
  if a%i ==0 and b%i==0:
    cnt +=1
    if cnt = k:
      print(i)
  

Fixed submission:
a,b,k = map(int,input().split())
cnt = 0
for i in range(100,0,-1):
  if a%i ==0 and b%i==0:
    cnt +=1
    if cnt == k:
      print(i)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
origin = len(s)
le = 0
while len(s) != le:
    le = len(s)
    s = s.replace('10','').replace('01','')
    
print(origin-len(s))

Fixed submission:
s = input()
cnt_one = s.count('1')
cnt_zero = len(s) - cnt_one
print(min(cnt_zero, cnt_one)*2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for _ in range(n):
  x,u = input().split()
  if u == 'BTC':
    x *= 380000
  ans += x

print(ans)

Fixed submission:
n = int(input())
ans = 0
for _ in range(n):
  x,u = input().split()
  x = float(x)
  if u == 'BTC':
    x *= 380000
  ans += x

print(ans)
Buggy python submission (verdict: Runtime Error):
a.b = map(int, input().split())
if b%a == 0:
  print(a+b)
else:
  print(b-a)

Fixed submission:
a,b = map(int, input().split())
if b%a == 0:
  print(a+b)
else:
  print(b-a)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
x = list(map(int,input().split()))
if m =< n:
    print(0)
    quit()

x.sort()
dist_l = [0] * (m-1)

for i in range(m-1):
    dist_l[i] = x[i+1] - x[i]

dist_l.sort()
print(sum(dist_l[:-(n-1)]))

Fixed submission:
n,m = map(int,input().split())
x = list(map(int,input().split()))

x.sort()
dist_l = [0] * (m-1)

for i in range(m-1):
    dist_l[i] = x[i+1] - x[i]

dist_l.sort()
print(sum(dist_l[:-(n-1)]) if n !=1 else sum(dist_l))
Buggy python submission (verdict: Runtime Error):
n,T = map(int,input().split())
ct = [[map(int,input().split())] for _ in range(n)]
cost = 9999
for i in range(n):
    c,t = ct[i][0],ct[i][1]
    if t<=T:
        cost = min(cost,c)
print(cost if cost != 9999 else 'TLE')

Fixed submission:
n,T = map(int,input().split())
ct = [list(map(int,input().split())) for _ in range(n)]
cost = 9999
for i in range(n):
    c,t = ct[i][0],ct[i][1]
    if t<=T:
        cost = min(cost,c)
print(cost if cost != 9999 else 'TLE')

Buggy python submission (verdict: Runtime Error):
n,T = map(int,input().split())
ct = [[map(int,input().split())] for _ in range(n)]
cost = 9999
for i in range(n):
  c,t = ct[i][0],ct[i][1]
  if t<=T:
    cost = min(cost,c)
print(cost if cost != 9999 else 'TLE')

Fixed submission:
n,T = map(int,input().split())
ct = [list(map(int,input().split())) for _ in range(n)]
cost = 9999
for i in range(n):
    c,t = ct[i][0],ct[i][1]
    if t<=T:
        cost = min(cost,c)
print(cost if cost != 9999 else 'TLE')
Buggy python submission (verdict: Runtime Error):
r = int(input())
ans = ''
if r < 1200:
  print('ABC')
elfi r < 2800:
  print('ARC')
else:
  print('AGC')

Fixed submission:
r = int(input())
if r < 1200:
  print('ABC')
elif r < 2800:
  print('ARC')
else:
  print('AGC')
Buggy python submission (verdict: Runtime Error):
n = input()
l = map(int,[*n])
if int(n)%sum(l) == 0:
  print('Yes')
else:
  print('No')

Fixed submission:
n = input()
l = map(int,list(n))
if int(n)%sum(l) == 0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
l = [0]*n
for i in range(n):
    l[i] = s[0:i].count('W') + s[i+1:].count('E')
print(min(l))    

Fixed submission:
n = int(input())
s = input()
es = s.count('E')
e_cnt = 0
l = [0]*n
for i in range(n):
    left = i-e_cnt
    if s[i] == 'E':
        e_cnt +=1
    right = es - e_cnt
    l[i] = right+left

print(min(l))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
l = [0]*n
for i in range(n):
    l[i] = s[0:i].count('W') + s[i+1:]count('E')
print(min(l))    

Fixed submission:
n = int(input())
s = input()
es = s.count('E')
e_cnt = 0
l = [0]*n
for i in range(n):
    left = i-e_cnt
    if s[i] == 'E':
        e_cnt +=1
    right = es - e_cnt
    l[i] = right+left

print(min(l))
Buggy python submission (verdict: Runtime Error):
n = int(input)
l = []
for i in range(n):
    l.append(i)
print(len(set(l)))

Fixed submission:
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
print(len(set(l)))
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if a ==b:
    print(c)
elif a==c:
    print(b)
else print(a)

Fixed submission:
a,b,c = map(int,input().split())
if a ==b:
    print(c)
elif a==c:
    print(b)
else: 
    print(a)
Buggy python submission (verdict: Runtime Error):
n,k = input().split()
print(k*(k-1)**(n-1))

Fixed submission:
n,k = map(int,input().split())
print(k*(k-1)**(n-1))