Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
hlist = list(map(int,input().split()))
hp_list = sorted(hlist)
if k <len(hlist):
  for i in range(k):
    del hp_list[-i-1]
  print(sum(hp_list))
else:
  print(0)



Fixed submission:
import heapq
n,k = map(int,input().split())
hlist = list(map(lambda x: int(x)*(-1),input().split()))

heapq.heapify(hlist)
if k < n:
  for i in range(k):
    heapq.heappop(hlist)
  print(-sum(hlist))
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
input = stdin.readline
n = int(input())
pn = list(map(int, input().split()))
ans = 1
for i in range(n-1):
  if min(pn[:i+1]) >= pn[i+1]:
    ans +=1
print(ans)


Fixed submission:
n = int(input())
plist = list(map(int,input().split()))
min = n + 1
count = 0
for i in range(n):
  if plist[i] <= min:
    min = plist[i]
    count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
pn = list(map(int, input().split()))
ans = 1
for i in range(n-1):
  if min(pn[:i+1]) >= pn[i+1]:
    ans +=1
print(ans)

Fixed submission:
n = int(input())
plist = list(map(int,input().split()))
min = n + 1
count = 0
for i in range(n):
  if plist[i] <= min:
    min = plist[i]
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
ansl = []
for i in range(1,min(a,b)//2+1):
  if a%i == 0 and b%i == 0:
    ansl.append(i)
print(int(a*b/max(ansl)))

Fixed submission:
a,b = map(int,input().split())
ansl = []
if min(a,b) == 1:
  print(max(a,b))
else:
  for i in range(1,min(a,b)+1):
    if a%i == 0 and b%i == 0:
      ansl.append(i)
  if not ansl:
    print(a*b)
  else:
    print(int(a*b/max(ansl)))
Buggy python submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())
l = 2/a**2*(a**2*b-x)
if x >= a**2*b/2:
  print(90-math.degrees(math.atan(a/l)))
else:
  k = 2*x/(b*a)
  print(90-math.degrees(math.atan(k/b)))


Fixed submission:
import math
a,b,x = map(int,input().split())
l = 2/a**2*(a**2*b-x)
if x >= a**2*b/2:
  if l != 0:
    print(90-math.degrees(math.atan(a/l)))
  else:
    print(0)
else:
  k = 2*x/(b*a)
  print(90-math.degrees(math.atan(k/b)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(map(int,input().split()))
for i in range(1,n+1):
  print(alist.index(i)+1,end = " ")


Fixed submission:
n = int(input())
alist = list(map(int,input().split()))
anslist = [0]*n
for i in range(n):
  anslist[alist[i]-1] = i+1
for i in anslist:
  print(i,end = " ")
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int,input().split())
plist = [k]*n
for j in range(q):
  s = int(input())
  for i in range(n):
    plist[i] -= 1
  plist[s-1] += 1
  
for i in plist:
  if i <= 0:
    print('No')
  else:print('Yes')


Fixed submission:
n,k,q = map(int,input().split())
plist = [k-q]*n
for i in range(q):
  s = int(input())
  plist[s-1] += 1
for i in plist:
  if i <= 0:
    print('No')
  else:print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
alist = list(map(int,input().split()))
for i in range(m):
  alist[alist.index(max(alist))] //= 2
print(sum(alist))

Fixed submission:
import sys
input = sys.stdin.buffer.readline
from math import log

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

table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]

for i in range(n):
    for y in range(int(log(a[-1],2))+2):
        table[i][y] = a[i]//pow(2,y)
        if a[i]//pow(2,y) == 0:
            break

s_table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]
for i in range(n):
    s_table[i][0] = table[i][0]

import heapq
hq = []
heapq.heapify(hq)
h_push = heapq.heappush
h_pop = heapq.heappop

for i in range(n):
    for y in range(1,int(log(a[-1],2))+2):
        s_table[i][y] = table[i][y]-table[i][y-1]
        h_push(hq,table[i][y]-table[i][y-1])
        if table[i][y]-table[i][y-1] == -1:
            break


ans = sum(a)

for i in range(m):
    if not hq:
        print(0)
        exit()
    ans += h_pop(hq)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
alist = list(map(int,input().split()))
for i in range(m):
  alist.sort()
  alist[-1] //= 2
print(sum(alist))

Fixed submission:
import sys
input = sys.stdin.buffer.readline
from math import log

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

table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]

for i in range(n):
    for y in range(int(log(a[-1],2))+2):
        table[i][y] = a[i]//pow(2,y)
        if a[i]//pow(2,y) == 0:
            break

s_table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]
for i in range(n):
    s_table[i][0] = table[i][0]

import heapq
hq = []
heapq.heapify(hq)
h_push = heapq.heappush
h_pop = heapq.heappop

for i in range(n):
    for y in range(1,int(log(a[-1],2))+2):
        s_table[i][y] = table[i][y]-table[i][y-1]
        h_push(hq,table[i][y]-table[i][y-1])
        if table[i][y]-table[i][y-1] == -1:
            break


ans = sum(a)

for i in range(m):
    if not hq:
        print(0)
        exit()
    ans += h_pop(hq)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n,q = map(int,input().split())
ab = [list(map(int,input().split()))for i in range(n-1)]
px = [list(map(int,input().split()))for i in range(q)]

def dfs(m):
    if m in vdic:
        for i in range(len(vdic[m])):
            point[vdic[m][i]] += point[m]
            dfs(vdic[m][i])

point = [0]*(n+1)

vdic = {}
for i in range(n-1):
    if ab[i][0] not in vdic:
        vdic[ab[i][0]] = []
    vdic[ab[i][0]].append(ab[i][1])

for i in range(q):
    point[px[i][0]] += px[i][1]
'''
for v in vdic:
    for c in vdic[v]:
        point[c] += point[v]
'''
dfs(1)

for i in range(1,len(point)):
    print(point[i],end = ' ')



Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

n,q = map(int,input().split())
ab = [list(map(int,input().split()))for i in range(n-1)]
px = [list(map(int,input().split()))for i in range(q)]

def dfs(m):
    for i in range(len(adj[m])):
        if depth[adj[m][i]] == float('inf'):
            depth[adj[m][i]] = depth[m] + 1
            point[adj[m][i]] += point[m]
            dfs(adj[m][i])


point = [0]*(n+1)
depth = [float('inf')]*(n+1)
adj = [[]for _ in range(n+1)]

for i in range(n-1):
    adj[ab[i][0]].append(ab[i][1])
    adj[ab[i][1]].append(ab[i][0])

for i in range(q):
    point[px[i][0]] += px[i][1]

depth[1] = 1
dfs(1)

for i in range(1,n+1):
    print(point[i],end = ' ')










'''
n,q = map(int,input().split())
ab = [list(map(int,input().split()))for i in range(n-1)]
px = [list(map(int,input().split()))for i in range(q)]

def dfs(m):
    if m in vdic:
        for i in range(len(vdic[m])):
            point[vdic[m][i]] += point[m]
            dfs(vdic[m][i])

point = [0]*(n+1)

vdic = {}
for i in range(n-1):
    if ab[i][0] not in vdic:
        vdic[ab[i][0]] = []
    vdic[ab[i][0]].append(ab[i][1])

for i in range(q):
    point[px[i][0]] += px[i][1]

dfs(1)

for i in range(1,len(point)):
    print(point[i],end = ' ')

'''
Buggy python submission (verdict: Time Limit Exceeded):
l,r = map(int,input().split())
min = 2019
for i in range(l,r):
  for j in range(i+1,r+1):
    if min > (i*j)%2019:
      min = (i*j)%2019
print(min)


Fixed submission:
L,R = map(int,input().split())
mn = 2018
if R - L >= 2018:
  print(0)
else:
  for i in range(L,R):
    for j in range(i+1,R+1):
      if (i*j)%2019 < mn:
        mn = (i*j)%2019
  print(mn)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
all_val = b-a+1
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
if a%c == 0:
  c_val = b//c-a//c+1
else:
  c_val = b//c-a//c
if a%d == 0:
  d_val = b//d-a//d+1
else:
  d_val = b//d-a//d
if a%lcm(c,d) == 0:
  lcm_val = b//lcm(d,c)-a//lcm(d,c)+1
else:
  lcm_val = b//lcm(d,c)-a//lcm(d,c)
print(all_val-c_val-d_val+lcm_val)

Fixed submission:
a,b,c,d = map(int,input().split())
all_val = b-a+1
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
if a%c == 0:
  c_val = b//c-a//c+1
else:
  c_val = b//c-a//c
if a%d == 0:
  d_val = b//d-a//d+1
else:
  d_val = b//d-a//d
if a%lcm(c,d) == 0:
  lcm_val = b//lcm(d,c)-a//lcm(d,c)+1
else:
  lcm_val = b//lcm(d,c)-a//lcm(d,c)
print(all_val-c_val-d_val+lcm_val)
Buggy python submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
sumlist = []
for i in range(1,n+1):
  point = i
  if point <= k-1:
    s = math.log2(k/i)
    if s == int(s):
      sumlist.append((1/2)**(int(s)))
    else:
      sumlist.append((1/2)**(int(s)+1))
  else:sumlist.append(1)
print(round(sum(sumlist)/n,10)-10**(-10))

Fixed submission:
import math
n,k = map(int,input().split())
sumlist = []
for i in range(1,n+1):
  point = i
  if point <= k-1:
    s = math.log(k/i,2)
    if s == int(s):
      sumlist.append((1/2)**(int(s)))
    else:
      sumlist.append((1/2)**(int(s)+1))
  else:sumlist.append(1)
print(round(sum(sumlist)/n,10)-10**(-10))

Buggy python submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
sum = 0
for i in range(1,n+1):
  point = i
  if point <= k-1:
    s = math.log2(k/i)
    if s == int(s):
      sum += (1/2)**(int(s))
    else:
      sum += (1/2)**(int(s)+1)
  else:sum += 1
print(round(sum/n,10)-10**(-10))

Fixed submission:
import math
n,k = map(int,input().split())
sumlist = []
for i in range(1,n+1):
  point = i
  if point <= k-1:
    s = math.log(k/i,2)
    if s == int(s):
      sumlist.append((1/2)**(int(s)))
    else:
      sumlist.append((1/2)**(int(s)+1))
  else:sumlist.append(1)
print(round(sum(sumlist)/n,10)-10**(-10))

Buggy python submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
sum = 0
for i in range(1,n+1):
  point = i
  if point <= k-1:
    s = math.log2(k/i)
    if s == int(s):
      sum += (1/2)**(int(s))
    else:
      sum += (1/2)**(int(s)+1)
  else:sum += 1
print(round(sum/n,10))

Fixed submission:
import math
n,k = map(int,input().split())
sumlist = []
for i in range(1,n+1):
  point = i
  if point <= k-1:
    s = math.log(k/i,2)
    if s == int(s):
      sumlist.append((1/2)**(int(s)))
    else:
      sumlist.append((1/2)**(int(s)+1))
  else:sumlist.append(1)
print(round(sum(sumlist)/n,10)-10**(-10))
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
alist = list(map(int,input().split()))
aalist = alist[:]
mx = 0
for i in range(n):
    alist.pop(i)
    for j in range(1,n-1):
            alist[j] = math.gcd(alist[j], alist[j-1])
    mx = max(mx,alist[n-2])
    alist = aalist[:]
print(mx)

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

from fractions import gcd
left = [a[0]]
right = [0]*n
right[-1] = a[-1]

for i in range(1,n):
    left.append(gcd(left[-1], a[i]))

for i in range(n-2,-1,-1):
    right[i] = gcd(a[i], right[i+1])

ans = 0
for i in range(n):
    if i == 0:
        ans = max(ans,right[i+1])
    elif i == n-1:
        ans = max(ans, left[i-1])
    else:
        ans = max(ans, gcd(left[i-1],right[i+1]))

print(ans)
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = input()
anslist = []
anslist2 = [0]*q
for i in range(n):
  if s[i] == 'A' and s[i+1] == 'C':
    anslist.append([i+1,i+2])
for i in range(q):
  l,r = map(int,input().split())
  cnt = 0
  for j in range(len(anslist)):
    if l <= anslist[j][0] and anslist[j][1] <= r:
      cnt += 1
  anslist2[i] = cnt
for i in range(q):
  print(anslist2[i])


Fixed submission:
n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split()))for i in range(q)]

a = [0]*n
p = 0
for i in range(1,n):
    if s[i-1] == 'A' and s[i] == 'C':
        p += 1
    a[i] = p
ans = []
for i in range(q):
    ans.append(a[lr[i][1]-1]-a[lr[i][0]-1])
for i in range(q):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split())) for i in range(q)]
anslist = []
for i in range(n):
  if s[i] == 'A' and s[i+1] == 'C':
    anslist.append([i,i+1])
for i in range(q):
  cnt = 0
  for j in range(len(anslist)):
    if lr[i][0]-1 <= anslist[j][0] and anslist[j][1] <= lr[i][1]-1:
      cnt += 1
  print(cnt) 



Fixed submission:
n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split()))for i in range(q)]

a = [0]*n
p = 0
for i in range(1,n):
    if s[i-1] == 'A' and s[i] == 'C':
        p += 1
    a[i] = p
ans = []
for i in range(q):
    ans.append(a[lr[i][1]-1]-a[lr[i][0]-1])
for i in range(q):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
anslist = []

for i in range(q):
  l,r = map(int,input().split())
  anslist.append(s[l-1:r])
for i in range(q):
  cnt = 0
  for j in range(len(anslist[i])-1):
    if anslist[i][j] == 'A' and anslist[i][j+1] == 'C':
      cnt += 1 
  print(cnt)

Fixed submission:
n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split()))for i in range(q)]

a = [0]*n
p = 0
for i in range(1,n):
    if s[i-1] == 'A' and s[i] == 'C':
        p += 1
    a[i] = p
ans = []
for i in range(q):
    ans.append(a[lr[i][1]-1]-a[lr[i][0]-1])
for i in range(q):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
slist = [int(i)for i in s]
q = True
ans = 0
while q:
  q = False
  kesu = []
  for i in range(1,len(slist)):
    if slist[i] != slist[i-1]:
      kesu.append(i)
      ans += 2
      q = True
      break
  if kesu:
    p = 0
    for i in kesu:
      del slist[i-1-p:i+1-p]
      p += 2

print(ans)

Fixed submission:
s = input()
cnt1 = s.count('1')
cnt0 = s.count('0')
print(len(s)-abs(cnt1-cnt0))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
slist = [int(i)for i in s]
q = True
ans = 0
while q:
  q = False
  kesu = 0
  for i in range(1,len(slist)):
    if slist[i] != slist[i-1]:
      kesu = i
      ans += 2
      q = True
      break
  if kesu != 0:
    del slist[kesu-1:kesu+1]
print(ans)

Fixed submission:
s = input()
cnt1 = s.count('1')
cnt0 = s.count('0')
print(len(s)-abs(cnt1-cnt0))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s = input()
n = len(s)
slist = [int(i)for i in s]
q = True
ans = 0
while q:
  q = False
  kesu = 0
  for i in range(1,len(slist)):
    if slist[i] != slist[i-1]:
      kesu = i
      ans += 2
      q = True
      break
  if kesu != 0:
    del slist[kesu-1:kesu+1]
print(ans)


Fixed submission:
s = input()
cnt1 = s.count('1')
cnt0 = s.count('0')
print(len(s)-abs(cnt1-cnt0))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
slist = [int(i)for i in s]
q = True
ans = 0
while q:
  q = False
  kesu = []
  for i in range(1,len(slist)):
    if slist[i] != slist[i-1]:
      kesu.append(i)
      ans += 2
      q = True
      break
  if kesu:
    for i in kesu:
      del slist[i-1:i+1]
print(ans)


Fixed submission:
s = input()
cnt1 = s.count('1')
cnt0 = s.count('0')
print(len(s)-abs(cnt1-cnt0))
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
ans = [0]*(n-1)
ans[0] = math.gcd(a[0],a[1])
for i in range(1,n-1):
  ans[i] = math.gcd(ans[i-1],a[i+1])
print(ans[n-2])

Fixed submission:
import fractions
n = int(input())
a = list(map(int,input().split()))
ans = [0]*(n-1)
ans[0] = fractions.gcd(a[0],a[1])
for i in range(1,n-1):
  ans[i] = fractions.gcd(ans[i-1],a[i+1])
print(ans[n-2])
Buggy python submission (verdict: Runtime Error):
imort sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [10**10]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])



Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [10**9]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [float('inf')]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])


Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [10**9]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
hlist = tuple(map(int,input().split()))
dp = [float('inf')]*n
dp[0] = 0
dp[1] = abs(hlist[1]-hlist[0])
for i in range(2,n):
  for j in range(max(0,i-k),i):
      dp[i] = min(dp[i], dp[j] + abs(hlist[i]-hlist[j]))
print(dp[n-1])

Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [10**9]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
hlist = list(map(int,input().split()))
dp = [float('inf')]*n
dp[0] = 0
dp[1] = abs(hlist[1]-hlist[0])
for i in range(2,n):
  for j in range(max(0,i-k),i):
      dp[i] = min(dp[i], dp[j] + abs(hlist[i]-hlist[j]))
print(dp[n-1])

Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [10**9]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
hlist = list(map(int,input().split()))
dp = [float('inf')]*n
dp[0] = 0
dp[1] = abs(hlist[1]-hlist[0])
for i in range(2,n):
  for j in range(i):
    if i-j <= k:
      dp[i] = min(dp[i], dp[j] + abs(hlist[i]-hlist[j]))
print(dp[n-1])

Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [10**9]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input()) #odd
p = list(map(float,input().split()))

#dp[i][j] = i枚まで投げた時の表がj枚出た時の確率。

dp = [[0]*(n+1)for i in range(n+1)]
dp[0][0] = 1
dp[1][0] = 1-p[0]
for i in range(1,n):
    dp[i+1][0] =  dp[i][0] *(1-p[i]) 


for i in range(n):
    for j in range(n):
        dp[i+1][j+1] =  dp[i][j+1] * (1-p[i]) + dp[i][j] * p[i]

ans = 0

for i in range(n//2+1,n+1):
    ans += dp[n][i] 

print(ans)

Fixed submission:
n = int(input())#奇数
p = [0] + list(map(float,input().split()))
ans = 0
#dp[i][j] = i番目までのコインで表がj枚になる確率
'''dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i])
ans = dp[n][n//2+1]+...+dp[n][n]
'''
dp = [[0]*(n+1) for i in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
  dp[i][0] = dp[i-1][0]*(1-p[i])
for i in range(1,n+1):
  for j in range(1,i+1):
    dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i])
for j in range(n//2+1,n+1):
  ans += dp[n][j]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
hlist = [int(input())for i in range(n)]
hlist.sort()
dlist = [0]*(n-1)

ans = float('inf')
i = 0
while i+(k-1) <= n-1:
  ans = min(ans, sum((hlist[j+1]-hlist[j]for j in range(i,k-1+i))))
  i += 1

print(ans)


Fixed submission:
n,k = map(int,input().split())
hlist = sorted([int(input())for i in range(n)])

ans = 10**9
i = 0

while i+(k-1) <= n-1:
  ans = min(ans, hlist[k+i-1]-hlist[i])
  i += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
hlist = [int(input())for i in range(n)]
hlist.sort()
dlist = [0]*(n-1)

for i in range(n-1):
  dlist[i] = hlist[i+1]-hlist[i]

ans = float('inf')
i = 0
while i+(k-1) <= n-1:
  ans = min(ans, sum((dlist[j]for j in range(i,k-1+i))))
  i += 1
print(ans)



Fixed submission:
n,k = map(int,input().split())
hlist = sorted([int(input())for i in range(n)])

ans = 10**9
i = 0

while i+(k-1) <= n-1:
  ans = min(ans, hlist[k+i-1]-hlist[i])
  i += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())

si = [[0]for i in range(n+1)]
a = []


import bisect

for i in range(m):
    p,y = map(int,input().split())
    a.append([p,y])
    bisect.insort_left(si[p],y)




for i in range(m):
    ans = bisect.bisect_right(si[a[i][0]],a[i][1]) - 1
    print('0'*(6-len(str(a[i][0]))) + str(a[i][0]) + '0'*(6-len(str(ans))) + str(ans))
    

    


Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
py = [list(map(int,input().split()))for i in range(m)]
pypy = py[::]
from operator import itemgetter
import bisect
py.sort(key = itemgetter(1))
dic = {}
for i in range(m):
    if py[i][0] not in dic:
        dic[py[i][0]] = []
    dic[py[i][0]].append(py[i][1])


anslist = [0]*m

for i in range(m):
    anslist[i] = str(pypy[i][0]).zfill(6) + str(bisect.bisect_left(dic[pypy[i][0]],pypy[i][1]) + 1).zfill(6)

for ans in anslist:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

si = [[0]for i in range(n+1)]
a = []


import bisect

for i in range(m):
    p,y = map(int,input().split())
    a.append([p,y])
    bisect.insort_left(si[p],y)




for i in range(m):
    ans = bisect.bisect_right(si[a[i][0]],a[i][1]) - 1
    print('0'*(6-len(str(a[i][0]))) + str(a[i][0]) + '0'*(6-len(str(ans))) + str(ans))
    

    


Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
py = [list(map(int,input().split()))for i in range(m)]
pypy = py[::]
from operator import itemgetter
import bisect
py.sort(key = itemgetter(1))
dic = {}
for i in range(m):
    if py[i][0] not in dic:
        dic[py[i][0]] = []
    dic[py[i][0]].append(py[i][1])


anslist = [0]*m

for i in range(m):
    anslist[i] = str(pypy[i][0]).zfill(6) + str(bisect.bisect_left(dic[pypy[i][0]],pypy[i][1]) + 1).zfill(6)

for ans in anslist:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
anslist = [[0]*3for i in range(m)]
for i in range(m):
  p,y = map(int,input().split())
  anslist[i][0] = p
  anslist[i][2] = y
  cnt = 0
  if i >= 1:
    for j in range(i):
      if anslist[j][0] == p and anslist[j][2] > y:
        anslist[j][1] += 1
      elif anslist[j][0] == p and anslist[j][2] < y:
        cnt += 1
    else:anslist[i][1] = cnt + 1
  else:
    anslist[i][1] = 1
for i in range(m):
  #print(anslist[i][0],anslist[i][1])
  print('0'*(6-len(str(anslist[i][0])))+str(anslist[i][0])+'0'*(6-len(str(anslist[i][1])))+str(anslist[i][1]))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
py = [list(map(int,input().split()))for i in range(m)]
pypy = py[::]
from operator import itemgetter
import bisect
py.sort(key = itemgetter(1))
dic = {}
for i in range(m):
    if py[i][0] not in dic:
        dic[py[i][0]] = []
    dic[py[i][0]].append(py[i][1])


anslist = [0]*m

for i in range(m):
    anslist[i] = str(pypy[i][0]).zfill(6) + str(bisect.bisect_left(dic[pypy[i][0]],pypy[i][1]) + 1).zfill(6)

for ans in anslist:
    print(ans)